LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - DashedLine.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 37 39 94.9 %
Date: 2014-04-11 Functions: 3 4 75.0 %
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             : 
      10             : #include <DashedLine.hxx>
      11             : 
      12             : #include <basegfx/color/bcolortools.hxx>
      13             : #include <basegfx/polygon/b2dpolygon.hxx>
      14             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      15             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      16             : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      17             : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
      18             : #include <vcl/svapp.hxx>
      19             : #include <vcl/settings.hxx>
      20             : 
      21         109 : SwDashedLine::SwDashedLine( Window* pParent, Color& ( *pColorFn )() ) :
      22             :     FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
      23         109 :     m_pColorFn( pColorFn )
      24             : {
      25         109 : }
      26             : 
      27         109 : SwDashedLine::~SwDashedLine( )
      28             : {
      29         109 : }
      30             : 
      31          32 : void SwDashedLine::Paint( const Rectangle& )
      32             : {
      33          32 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
      34             :     drawinglayer::processor2d::BaseProcessor2D * pProcessor =
      35             :         drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
      36          32 :                     *this, aNewViewInfos );
      37             : 
      38             :     // Compute the start and end points
      39          32 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
      40          32 :     double nHalfWidth = double( aRect.Top() + aRect.Bottom() ) / 2.0;
      41             : 
      42          64 :     basegfx::B2DPoint aStart( double( aRect.Left() ), nHalfWidth );
      43          64 :     basegfx::B2DPoint aEnd( double( aRect.Right() ), nHalfWidth );
      44             : 
      45          64 :     basegfx::B2DPolygon aPolygon;
      46          32 :     aPolygon.append( aStart );
      47          32 :     aPolygon.append( aEnd );
      48             : 
      49          64 :     drawinglayer::primitive2d::Primitive2DSequence aSeq( 1 );
      50             : 
      51          32 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
      52             : 
      53          64 :     std::vector< double > aStrokePattern;
      54          64 :     basegfx::BColor aColor = m_pColorFn().getBColor();
      55          32 :     if ( rSettings.GetHighContrastMode( ) )
      56             :     {
      57             :         // Only a solid line in high contrast mode
      58           0 :         aColor = rSettings.GetDialogTextColor().getBColor();
      59             :     }
      60             :     else
      61             :     {
      62             :         // Get a color for the contrast
      63          32 :         basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aColor );
      64          32 :         double nLuminance = aHslLine.getZ();
      65          32 :         nLuminance += ( 1.0 - nLuminance ) * 0.75;
      66          32 :         if ( aHslLine.getZ() > 0.7 )
      67           0 :             nLuminance = aHslLine.getZ() * 0.7;
      68          32 :         aHslLine.setZ( nLuminance );
      69          64 :         const basegfx::BColor aOtherColor = basegfx::tools::hsl2rgb( aHslLine );
      70             : 
      71             :         // Compute the plain line
      72             :         drawinglayer::primitive2d::PolygonHairlinePrimitive2D * pPlainLine =
      73             :             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
      74          32 :                     aPolygon, aOtherColor );
      75             : 
      76          32 :         aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( pPlainLine );
      77             :         // Dashed line in twips
      78          32 :         aStrokePattern.push_back( 3 );
      79          32 :         aStrokePattern.push_back( 3 );
      80             : 
      81          64 :         aSeq.realloc( 2 );
      82             :     }
      83             : 
      84             :     // Compute the dashed line primitive
      85             :     drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pLine =
      86             :             new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D (
      87             :                 basegfx::B2DPolyPolygon( aPolygon ),
      88          32 :                 drawinglayer::attribute::LineAttribute( m_pColorFn().getBColor() ),
      89          64 :                 drawinglayer::attribute::StrokeAttribute( aStrokePattern ) );
      90             : 
      91          32 :     aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine );
      92             : 
      93          32 :     pProcessor->process( aSeq );
      94          64 :     delete pProcessor;
      95          32 : }
      96             : 
      97             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10