LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - DashedLine.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 38 94.7 %
Date: 2015-06-13 12:38:46 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             : 
      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             : #include <boost/scoped_ptr.hpp>
      21             : 
      22         267 : SwDashedLine::SwDashedLine( vcl::Window* pParent, Color& ( *pColorFn )() ) :
      23             :     FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
      24         267 :     m_pColorFn( pColorFn )
      25             : {
      26         267 : }
      27             : 
      28         267 : SwDashedLine::~SwDashedLine( )
      29             : {
      30         267 : }
      31             : 
      32          92 : void SwDashedLine::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
      33             : {
      34          92 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
      35             :     boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
      36         184 :         drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos));
      37             : 
      38             :     // Compute the start and end points
      39          92 :     const Rectangle aRect(Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel())));
      40          92 :     double nHalfWidth = double(aRect.Top() + aRect.Bottom()) / 2.0;
      41             : 
      42         184 :     basegfx::B2DPoint aStart(double(aRect.Left()), nHalfWidth);
      43         184 :     basegfx::B2DPoint aEnd(double(aRect.Right()), nHalfWidth);
      44             : 
      45         184 :     basegfx::B2DPolygon aPolygon;
      46          92 :     aPolygon.append(aStart);
      47          92 :     aPolygon.append(aEnd);
      48             : 
      49         184 :     drawinglayer::primitive2d::Primitive2DSequence aSeq(1);
      50             : 
      51          92 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
      52             : 
      53         184 :     std::vector<double> aStrokePattern;
      54         184 :     basegfx::BColor aColor = m_pColorFn().getBColor();
      55          92 :     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          92 :         basegfx::BColor aHslLine = basegfx::tools::rgb2hsl(aColor);
      64          92 :         double nLuminance = aHslLine.getZ();
      65          92 :         nLuminance += (1.0 - nLuminance) * 0.75;
      66          92 :         if (aHslLine.getZ() > 0.7)
      67           0 :             nLuminance = aHslLine.getZ() * 0.7;
      68          92 :         aHslLine.setZ(nLuminance);
      69         184 :         const basegfx::BColor aOtherColor = basegfx::tools::hsl2rgb(aHslLine);
      70             : 
      71             :         // Compute the plain line
      72             :         drawinglayer::primitive2d::PolygonHairlinePrimitive2D * pPlainLine =
      73          92 :             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPolygon, aOtherColor);
      74             : 
      75          92 :         aSeq[0] = drawinglayer::primitive2d::Primitive2DReference(pPlainLine);
      76             :         // Dashed line in twips
      77          92 :         aStrokePattern.push_back(3);
      78          92 :         aStrokePattern.push_back(3);
      79             : 
      80         184 :         aSeq.realloc(2);
      81             :     }
      82             : 
      83             :     // Compute the dashed line primitive
      84             :     drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pLine =
      85             :             new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
      86             :                 basegfx::B2DPolyPolygon(aPolygon),
      87          92 :                 drawinglayer::attribute::LineAttribute(m_pColorFn().getBColor()),
      88         184 :                 drawinglayer::attribute::StrokeAttribute(aStrokePattern));
      89             : 
      90          92 :     aSeq[aSeq.getLength() - 1] = drawinglayer::primitive2d::Primitive2DReference(pLine);
      91             : 
      92         184 :     pProcessor->process(aSeq);
      93         269 : }
      94             : 
      95             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11