LCOV - code coverage report
Current view: top level - sw/source/ui/docvw - DashedLine.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 39 94.9 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 88 48.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <DashedLine.hxx>
      30                 :            : 
      31                 :            : #include <basegfx/color/bcolortools.hxx>
      32                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      33                 :            : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      34                 :            : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      35                 :            : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      36                 :            : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : 
      39                 :         12 : SwDashedLine::SwDashedLine( Window* pParent, Color& ( *pColorFn )() ) :
      40                 :            :     FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
      41                 :         12 :     m_pColorFn( pColorFn )
      42                 :            : {
      43                 :         12 : }
      44                 :            : 
      45                 :          9 : SwDashedLine::~SwDashedLine( )
      46                 :            : {
      47         [ -  + ]:          9 : }
      48                 :            : 
      49                 :         18 : void SwDashedLine::Paint( const Rectangle& )
      50                 :            : {
      51         [ +  - ]:         18 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
      52                 :            :     drawinglayer::processor2d::BaseProcessor2D * pProcessor =
      53                 :            :         drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
      54         [ +  - ]:         18 :                     *this, aNewViewInfos );
      55                 :            : 
      56                 :            :     // Compute the start and end points
      57 [ +  - ][ +  - ]:         18 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
                 [ +  - ]
      58                 :         18 :     double nHalfWidth = double( aRect.Top() + aRect.Bottom() ) / 2.0;
      59                 :            : 
      60                 :         18 :     basegfx::B2DPoint aStart( double( aRect.Left() ), nHalfWidth );
      61                 :         18 :     basegfx::B2DPoint aEnd( double( aRect.Right() ), nHalfWidth );
      62                 :            : 
      63         [ +  - ]:         18 :     basegfx::B2DPolygon aPolygon;
      64         [ +  - ]:         18 :     aPolygon.append( aStart );
      65         [ +  - ]:         18 :     aPolygon.append( aEnd );
      66                 :            : 
      67         [ +  - ]:         18 :     drawinglayer::primitive2d::Primitive2DSequence aSeq( 1 );
      68                 :            : 
      69         [ +  - ]:         18 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
      70                 :            : 
      71         [ +  - ]:         18 :     std::vector< double > aStrokePattern;
      72         [ +  - ]:         18 :     basegfx::BColor aColor = m_pColorFn().getBColor();
      73         [ -  + ]:         18 :     if ( rSettings.GetHighContrastMode( ) )
      74                 :            :     {
      75                 :            :         // Only a solid line in high contrast mode
      76         [ #  # ]:          0 :         aColor = rSettings.GetDialogTextColor().getBColor();
      77                 :            :     }
      78                 :            :     else
      79                 :            :     {
      80                 :            :         // Get a color for the contrast
      81         [ +  - ]:         18 :         basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aColor );
      82                 :         18 :         double nLuminance = aHslLine.getZ();
      83                 :         18 :         nLuminance += ( 1.0 - nLuminance ) * 0.75;
      84         [ -  + ]:         18 :         if ( aHslLine.getZ() > 0.7 )
      85                 :          0 :             nLuminance = aHslLine.getZ() * 0.7;
      86                 :         18 :         aHslLine.setZ( nLuminance );
      87         [ +  - ]:         18 :         const basegfx::BColor aOtherColor = basegfx::tools::hsl2rgb( aHslLine );
      88                 :            : 
      89                 :            :         // Compute the plain line
      90                 :            :         drawinglayer::primitive2d::PolygonHairlinePrimitive2D * pPlainLine =
      91                 :            :             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
      92         [ +  - ]:         18 :                     aPolygon, aOtherColor );
      93                 :            : 
      94 [ +  - ][ +  - ]:         18 :         aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( pPlainLine );
         [ +  - ][ +  - ]
      95                 :            :         // Dashed line in twips
      96         [ +  - ]:         18 :         aStrokePattern.push_back( 3 );
      97         [ +  - ]:         18 :         aStrokePattern.push_back( 3 );
      98                 :            : 
      99         [ +  - ]:         18 :         aSeq.realloc( 2 );
     100                 :            :     }
     101                 :            : 
     102                 :            :     // Compute the dashed line primitive
     103                 :            :     drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pLine =
     104                 :            :             new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D (
     105                 :            :                 basegfx::B2DPolyPolygon( aPolygon ),
     106         [ +  - ]:         18 :                 drawinglayer::attribute::LineAttribute( m_pColorFn().getBColor() ),
     107 [ +  - ][ +  - ]:         36 :                 drawinglayer::attribute::StrokeAttribute( aStrokePattern ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     108                 :            : 
     109 [ +  - ][ +  - ]:         18 :     aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine );
         [ +  - ][ +  - ]
     110                 :            : 
     111         [ +  - ]:         18 :     pProcessor->process( aSeq );
     112 [ +  - ][ +  - ]:         18 :     delete pProcessor;
         [ +  - ][ +  - ]
                 [ +  - ]
     113                 :         18 : }
     114                 :            : 
     115                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10