LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/docvw - DashedLine.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 39 94.9 %
Date: 2012-12-17 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             :  * 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          36 : SwDashedLine::SwDashedLine( Window* pParent, Color& ( *pColorFn )() ) :
      40             :     FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
      41          36 :     m_pColorFn( pColorFn )
      42             : {
      43          36 : }
      44             : 
      45           2 : SwDashedLine::~SwDashedLine( )
      46             : {
      47           2 : }
      48             : 
      49          20 : void SwDashedLine::Paint( const Rectangle& )
      50             : {
      51          20 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
      52             :     drawinglayer::processor2d::BaseProcessor2D * pProcessor =
      53             :         drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
      54          20 :                     *this, aNewViewInfos );
      55             : 
      56             :     // Compute the start and end points
      57          20 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
      58          20 :     double nHalfWidth = double( aRect.Top() + aRect.Bottom() ) / 2.0;
      59             : 
      60          20 :     basegfx::B2DPoint aStart( double( aRect.Left() ), nHalfWidth );
      61          20 :     basegfx::B2DPoint aEnd( double( aRect.Right() ), nHalfWidth );
      62             : 
      63          20 :     basegfx::B2DPolygon aPolygon;
      64          20 :     aPolygon.append( aStart );
      65          20 :     aPolygon.append( aEnd );
      66             : 
      67          20 :     drawinglayer::primitive2d::Primitive2DSequence aSeq( 1 );
      68             : 
      69          20 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
      70             : 
      71          20 :     std::vector< double > aStrokePattern;
      72          20 :     basegfx::BColor aColor = m_pColorFn().getBColor();
      73          20 :     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          20 :         basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aColor );
      82          20 :         double nLuminance = aHslLine.getZ();
      83          20 :         nLuminance += ( 1.0 - nLuminance ) * 0.75;
      84          20 :         if ( aHslLine.getZ() > 0.7 )
      85           0 :             nLuminance = aHslLine.getZ() * 0.7;
      86          20 :         aHslLine.setZ( nLuminance );
      87          20 :         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          20 :                     aPolygon, aOtherColor );
      93             : 
      94          20 :         aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( pPlainLine );
      95             :         // Dashed line in twips
      96          20 :         aStrokePattern.push_back( 3 );
      97          20 :         aStrokePattern.push_back( 3 );
      98             : 
      99          20 :         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          20 :                 drawinglayer::attribute::LineAttribute( m_pColorFn().getBColor() ),
     107          40 :                 drawinglayer::attribute::StrokeAttribute( aStrokePattern ) );
     108             : 
     109          20 :     aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine );
     110             : 
     111          20 :     pProcessor->process( aSeq );
     112          20 :     delete pProcessor;
     113          20 : }
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10