LCOV - code coverage report
Current view: top level - svx/source/xoutdev - xtabdash.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 82 85.4 %
Date: 2015-06-13 12:38:46 Functions: 10 13 76.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "svx/XPropertyTable.hxx"
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : #include <vcl/virdev.hxx>
      26             : #include <svx/dialogs.hrc>
      27             : #include <svx/dialmgr.hxx>
      28             : #include <svx/xtable.hxx>
      29             : 
      30             : #include <drawinglayer/attribute/lineattribute.hxx>
      31             : #include <drawinglayer/attribute/strokeattribute.hxx>
      32             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      33             : #include <drawinglayer/processor2d/processor2dtools.hxx>
      34             : #include <boost/scoped_ptr.hpp>
      35             : 
      36             : using namespace com::sun::star;
      37             : 
      38        4192 : XDashList::XDashList(const OUString& rPath, const OUString& rReferer)
      39             :     : XPropertyList(XDASH_LIST, rPath, rReferer)
      40             :     , maBitmapSolidLine()
      41             :     , maStringSolidLine()
      42        4192 :     , maStringNoLine()
      43             : {
      44        4192 : }
      45             : 
      46        8304 : XDashList::~XDashList()
      47             : {
      48        8304 : }
      49             : 
      50           0 : XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
      51             : {
      52           0 :     return static_cast<XDashEntry*>( XPropertyList::Replace(pEntry, nIndex) );
      53             : }
      54             : 
      55           0 : XDashEntry* XDashList::Remove(long nIndex)
      56             : {
      57           0 :     return static_cast<XDashEntry*>( XPropertyList::Remove(nIndex) );
      58             : }
      59             : 
      60          20 : XDashEntry* XDashList::GetDash(long nIndex) const
      61             : {
      62          20 :     return static_cast<XDashEntry*>( XPropertyList::Get(nIndex) );
      63             : }
      64             : 
      65         152 : uno::Reference< container::XNameContainer > XDashList::createInstance()
      66             : {
      67             :     return uno::Reference< container::XNameContainer >(
      68         152 :         SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
      69             : }
      70             : 
      71           0 : bool XDashList::Create()
      72             : {
      73           0 :     const OUString aStr(SVX_RESSTR(RID_SVXSTR_LINESTYLE));
      74             : 
      75           0 :     Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,1, 50,1, 50, 50),aStr + " 1"));
      76           0 :     Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,1,500,1,500,500),aStr + " 2"));
      77           0 :     Insert(new XDashEntry(XDash(css::drawing::DashStyle_RECT,2, 50,3,250,120),aStr + " 3"));
      78             : 
      79           0 :     return true;
      80             : }
      81             : 
      82          11 : Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
      83             : {
      84          11 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      85          11 :     const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
      86          11 :     const sal_uInt32 nFactor(2);
      87          11 :     const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor);
      88             : 
      89             :     // prepare polygon geometry for line
      90          11 :     basegfx::B2DPolygon aLine;
      91             : 
      92          11 :     aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0));
      93          11 :     aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0));
      94             : 
      95             :     // prepare LineAttribute
      96          22 :     const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
      97          11 :     const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1));
      98             :     const drawinglayer::attribute::LineAttribute aLineAttribute(
      99             :         aLineColor,
     100          22 :         fLineWidth);
     101             : 
     102             :     // prepare StrokeAttribute
     103          22 :     ::std::vector< double > aDotDashArray;
     104          11 :     double fFullDotDashLen(0.0);
     105             : 
     106          11 :     if(pDash && (pDash->GetDots() || pDash->GetDashes()))
     107             :     {
     108          10 :         const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL));
     109          20 :         const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
     110          10 :         const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0)));
     111          10 :         const double fLineWidthInUnits(fLineWidth / fScaleValue);
     112             : 
     113          10 :         fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits);
     114             : 
     115          10 :         if(!aDotDashArray.empty())
     116             :         {
     117          74 :             for(size_t a(0); a < aDotDashArray.size(); a++)
     118             :             {
     119          64 :                 aDotDashArray[a] *= fScaleValue;
     120             :             }
     121             : 
     122          10 :             fFullDotDashLen *= fScaleValue;
     123          10 :         }
     124             :     }
     125             : 
     126             :     const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
     127             :         aDotDashArray,
     128          22 :         fFullDotDashLen);
     129             : 
     130             :     // cerate LinePrimitive
     131             :     const drawinglayer::primitive2d::Primitive2DReference aLinePrimitive(
     132             :         new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     133             :             aLine,
     134             :             aLineAttribute,
     135          22 :             aStrokeAttribute));
     136             : 
     137             :     // prepare VirtualDevice
     138          22 :     ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
     139          22 :     const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
     140             : 
     141          11 :     pVirtualDevice->SetOutputSizePixel(aSize);
     142          22 :     pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
     143          11 :         ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
     144          33 :         : DrawModeFlags::Default);
     145             : 
     146          11 :     if(rStyleSettings.GetPreviewUsesCheckeredBackground())
     147             :     {
     148          11 :         const Point aNull(0, 0);
     149             :         static const sal_uInt32 nLen(8 * nFactor);
     150          11 :         static const Color aW(COL_WHITE);
     151          11 :         static const Color aG(0xef, 0xef, 0xef);
     152             : 
     153          11 :         pVirtualDevice->DrawCheckered(aNull, aSize, nLen, aW, aG);
     154             :     }
     155             :     else
     156             :     {
     157           0 :         pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
     158           0 :         pVirtualDevice->Erase();
     159             :     }
     160             : 
     161             :     // create processor and draw primitives
     162             :     boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
     163          11 :         *pVirtualDevice.get(),
     164          22 :         aNewViewInformation2D));
     165             : 
     166          11 :     if(pProcessor2D)
     167             :     {
     168          11 :         const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLinePrimitive, 1);
     169             : 
     170          11 :         pProcessor2D->process(aSequence);
     171          11 :         pProcessor2D.reset();
     172             :     }
     173             : 
     174             :     // get result bitmap and scale
     175          11 :     Bitmap aRetval(pVirtualDevice->GetBitmap(Point(0, 0), pVirtualDevice->GetOutputSizePixel()));
     176             : 
     177             :     if(1 != nFactor)
     178             :     {
     179          11 :         aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()), BmpScaleFlag::Default);
     180             :     }
     181             : 
     182          22 :     return aRetval;
     183             : }
     184             : 
     185          10 : Bitmap XDashList::CreateBitmapForUI( long nIndex )
     186             : {
     187          10 :     const XDash& rDash = GetDash(nIndex)->GetDash();
     188             : 
     189          10 :     return ImpCreateBitmapForXDash(&rDash);
     190             : }
     191             : 
     192           1 : Bitmap XDashList::GetBitmapForUISolidLine() const
     193             : {
     194           1 :     if(maBitmapSolidLine.IsEmpty())
     195             :     {
     196           1 :         const_cast< XDashList* >(this)->maBitmapSolidLine = XDashList::ImpCreateBitmapForXDash(0);
     197             :     }
     198             : 
     199           1 :     return maBitmapSolidLine;
     200             : }
     201             : 
     202           1 : OUString XDashList::GetStringForUiSolidLine() const
     203             : {
     204           1 :     if(maStringSolidLine.isEmpty())
     205             :     {
     206           1 :         const_cast< XDashList* >(this)->maStringSolidLine = ResId(RID_SVXSTR_SOLID, DIALOG_MGR()).toString();
     207             :     }
     208             : 
     209           1 :     return maStringSolidLine;
     210             : }
     211             : 
     212           1 : OUString XDashList::GetStringForUiNoLine() const
     213             : {
     214           1 :     if(maStringNoLine.isEmpty())
     215             :     {
     216             :         // formally was RID_SVXSTR_INVISIBLE, but tomake equal
     217             :         // everywhere, use RID_SVXSTR_NONE
     218           1 :         const_cast< XDashList* >(this)->maStringNoLine = ResId(RID_SVXSTR_NONE, DIALOG_MGR()).toString();
     219             :     }
     220             : 
     221           1 :     return maStringNoLine;
     222             : }
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11