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

Generated by: LCOV version 1.10