LCOV - code coverage report
Current view: top level - vcl/source/outdev - line.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 84 134 62.7 %
Date: 2015-06-13 12:38:46 Functions: 4 5 80.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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <numeric>
      21             : 
      22             : #include <vcl/outdev.hxx>
      23             : #include <vcl/virdev.hxx>
      24             : #include <vcl/window.hxx>
      25             : 
      26             : #include <salgdi.hxx>
      27             : 
      28             : #include "outdata.hxx"
      29             : 
      30             : #include <basegfx/matrix/b2dhommatrix.hxx>
      31             : #include <basegfx/polygon/b2dpolygontools.hxx>
      32             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      33             : #include <basegfx/polygon/b2dlinegeometry.hxx>
      34             : 
      35           0 : void OutputDevice::DrawLine( const Point& rStartPt, const Point& rEndPt,
      36             :                              const LineInfo& rLineInfo )
      37             : {
      38           0 :     assert_if_double_buffered_window();
      39             : 
      40           0 :     if ( rLineInfo.IsDefault() )
      41             :     {
      42           0 :         DrawLine( rStartPt, rEndPt );
      43           0 :         return;
      44             :     }
      45             : 
      46           0 :     if ( mpMetaFile )
      47           0 :         mpMetaFile->AddAction( new MetaLineAction( rStartPt, rEndPt, rLineInfo ) );
      48             : 
      49           0 :     if ( !IsDeviceOutputNecessary() || !mbLineColor || ( LINE_NONE == rLineInfo.GetStyle() ) || ImplIsRecordLayout() )
      50           0 :         return;
      51             : 
      52           0 :     if( !mpGraphics )
      53             :     {
      54           0 :         if ( !AcquireGraphics() )
      55           0 :             return;
      56             :     }
      57             : 
      58           0 :     if ( mbInitClipRegion )
      59           0 :         InitClipRegion();
      60             : 
      61           0 :     if ( mbOutputClipped )
      62           0 :         return;
      63             : 
      64           0 :     const Point aStartPt( ImplLogicToDevicePixel( rStartPt ) );
      65           0 :     const Point aEndPt( ImplLogicToDevicePixel( rEndPt ) );
      66           0 :     const LineInfo aInfo( ImplLogicToDevicePixel( rLineInfo ) );
      67           0 :     const bool bDashUsed(LINE_DASH == aInfo.GetStyle());
      68           0 :     const bool bLineWidthUsed(aInfo.GetWidth() > 1);
      69             : 
      70           0 :     if ( mbInitLineColor )
      71           0 :         InitLineColor();
      72             : 
      73           0 :     if(bDashUsed || bLineWidthUsed)
      74             :     {
      75           0 :         basegfx::B2DPolygon aLinePolygon;
      76           0 :         aLinePolygon.append(basegfx::B2DPoint(aStartPt.X(), aStartPt.Y()));
      77           0 :         aLinePolygon.append(basegfx::B2DPoint(aEndPt.X(), aEndPt.Y()));
      78             : 
      79           0 :         drawLine( basegfx::B2DPolyPolygon(aLinePolygon), aInfo );
      80             :     }
      81             :     else
      82             :     {
      83           0 :         mpGraphics->DrawLine( aStartPt.X(), aStartPt.Y(), aEndPt.X(), aEndPt.Y(), this );
      84             :     }
      85             : 
      86           0 :     if( mpAlphaVDev )
      87           0 :         mpAlphaVDev->DrawLine( rStartPt, rEndPt, rLineInfo );
      88             : }
      89             : 
      90     1129274 : void OutputDevice::DrawLine( const Point& rStartPt, const Point& rEndPt )
      91             : {
      92     1129274 :     assert_if_double_buffered_window();
      93             : 
      94     1129274 :     if ( mpMetaFile )
      95       55982 :         mpMetaFile->AddAction( new MetaLineAction( rStartPt, rEndPt ) );
      96             : 
      97     1129274 :     if ( !IsDeviceOutputNecessary() || !mbLineColor || ImplIsRecordLayout() )
      98       66141 :         return;
      99             : 
     100     1124247 :     if ( !mpGraphics )
     101             :     {
     102        3180 :         if ( !AcquireGraphics() )
     103           0 :             return;
     104             :     }
     105             : 
     106     1124247 :     if ( mbInitClipRegion )
     107       38045 :         InitClipRegion();
     108             : 
     109     1124247 :     if ( mbOutputClipped )
     110       56087 :         return;
     111             : 
     112     1068160 :     if ( mbInitLineColor )
     113      449164 :         InitLineColor();
     114             : 
     115             :     // #i101598# support AA and snap for lines, too
     116     2136320 :     if((mnAntialiasing & AntialiasingFlags::EnableB2dDraw)
     117     1068160 :         && mpGraphics->supportsOperation(OutDevSupport_B2DDraw)
     118           0 :         && ROP_OVERPAINT == GetRasterOp()
     119     3204480 :         && IsLineColor())
     120             :     {
     121             :         // at least transform with double precision to device coordinates; this will
     122             :         // avoid pixel snap of single, appended lines
     123           0 :         const basegfx::B2DHomMatrix aTransform(ImplGetDeviceTransformation());
     124           0 :         const basegfx::B2DVector aB2DLineWidth( 1.0, 1.0 );
     125           0 :         basegfx::B2DPolygon aB2DPolyLine;
     126             : 
     127           0 :         aB2DPolyLine.append(basegfx::B2DPoint(rStartPt.X(), rStartPt.Y()));
     128           0 :         aB2DPolyLine.append(basegfx::B2DPoint(rEndPt.X(), rEndPt.Y()));
     129           0 :         aB2DPolyLine.transform( aTransform );
     130             : 
     131           0 :         if(mnAntialiasing & AntialiasingFlags::PixelSnapHairline)
     132             :         {
     133           0 :             aB2DPolyLine = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aB2DPolyLine);
     134             :         }
     135             : 
     136           0 :         if( mpGraphics->DrawPolyLine( aB2DPolyLine, 0.0, aB2DLineWidth, basegfx::B2DLineJoin::NONE, css::drawing::LineCap_BUTT, this))
     137             :         {
     138           0 :             return;
     139           0 :         }
     140             :     }
     141             : 
     142     1068160 :     const Point aStartPt(ImplLogicToDevicePixel(rStartPt));
     143     1068160 :     const Point aEndPt(ImplLogicToDevicePixel(rEndPt));
     144             : 
     145     1068160 :     mpGraphics->DrawLine( aStartPt.X(), aStartPt.Y(), aEndPt.X(), aEndPt.Y(), this );
     146             : 
     147     1068160 :     if( mpAlphaVDev )
     148       55473 :         mpAlphaVDev->DrawLine( rStartPt, rEndPt );
     149             : }
     150             : 
     151          13 : void OutputDevice::drawLine( basegfx::B2DPolyPolygon aLinePolyPolygon, const LineInfo& rInfo )
     152             : {
     153          39 :     const bool bTryAA((mnAntialiasing & AntialiasingFlags::EnableB2dDraw)
     154          13 :         && mpGraphics->supportsOperation(OutDevSupport_B2DDraw)
     155           0 :         && ROP_OVERPAINT == GetRasterOp()
     156          39 :         && IsLineColor());
     157          13 :     basegfx::B2DPolyPolygon aFillPolyPolygon;
     158          13 :     const bool bDashUsed(LINE_DASH == rInfo.GetStyle());
     159          13 :     const bool bLineWidthUsed(rInfo.GetWidth() > 1);
     160             : 
     161          13 :     if(bDashUsed && aLinePolyPolygon.count())
     162             :     {
     163           3 :         ::std::vector< double > fDotDashArray;
     164           3 :         const double fDashLen(rInfo.GetDashLen());
     165           3 :         const double fDotLen(rInfo.GetDotLen());
     166           3 :         const double fDistance(rInfo.GetDistance());
     167             : 
     168           3 :         for(sal_uInt16 a(0); a < rInfo.GetDashCount(); a++)
     169             :         {
     170           0 :             fDotDashArray.push_back(fDashLen);
     171           0 :             fDotDashArray.push_back(fDistance);
     172             :         }
     173             : 
     174           6 :         for(sal_uInt16 b(0); b < rInfo.GetDotCount(); b++)
     175             :         {
     176           3 :             fDotDashArray.push_back(fDotLen);
     177           3 :             fDotDashArray.push_back(fDistance);
     178             :         }
     179             : 
     180           3 :         const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
     181             : 
     182           3 :         if(fAccumulated > 0.0)
     183             :         {
     184           3 :             basegfx::B2DPolyPolygon aResult;
     185             : 
     186           6 :             for(sal_uInt32 c(0); c < aLinePolyPolygon.count(); c++)
     187             :             {
     188           3 :                 basegfx::B2DPolyPolygon aLineTarget;
     189             :                 basegfx::tools::applyLineDashing(
     190             :                     aLinePolyPolygon.getB2DPolygon(c),
     191             :                     fDotDashArray,
     192           3 :                     &aLineTarget);
     193           3 :                 aResult.append(aLineTarget);
     194           3 :             }
     195             : 
     196           3 :             aLinePolyPolygon = aResult;
     197           3 :         }
     198             :     }
     199             : 
     200          13 :     if(bLineWidthUsed && aLinePolyPolygon.count())
     201             :     {
     202          10 :         const double fHalfLineWidth((rInfo.GetWidth() * 0.5) + 0.5);
     203             : 
     204          10 :         if(aLinePolyPolygon.areControlPointsUsed())
     205             :         {
     206             :             // #i110768# When area geometry has to be created, do not
     207             :             // use the fallback bezier decomposition inside createAreaGeometry,
     208             :             // but one that is at least as good as ImplSubdivideBezier was.
     209             :             // There, Polygon::AdaptiveSubdivide was used with default parameter
     210             :             // 1.0 as quality index.
     211           0 :             aLinePolyPolygon = basegfx::tools::adaptiveSubdivideByDistance(aLinePolyPolygon, 1.0);
     212             :         }
     213             : 
     214          20 :         for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++)
     215             :         {
     216             :             aFillPolyPolygon.append(basegfx::tools::createAreaGeometry(
     217             :                 aLinePolyPolygon.getB2DPolygon(a),
     218             :                 fHalfLineWidth,
     219             :                 rInfo.GetLineJoin(),
     220          10 :                 rInfo.GetLineCap()));
     221             :         }
     222             : 
     223          10 :         aLinePolyPolygon.clear();
     224             :     }
     225             : 
     226          13 :     GDIMetaFile* pOldMetaFile = mpMetaFile;
     227          13 :     mpMetaFile = NULL;
     228             : 
     229          13 :     if(aLinePolyPolygon.count())
     230             :     {
     231         426 :         for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++)
     232             :         {
     233         423 :             const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a));
     234         423 :             bool bDone(false);
     235             : 
     236         423 :             if(bTryAA)
     237             :             {
     238           0 :                 bDone = mpGraphics->DrawPolyLine( aCandidate, 0.0, basegfx::B2DVector(1.0,1.0), basegfx::B2DLineJoin::NONE, css::drawing::LineCap_BUTT, this);
     239             :             }
     240             : 
     241         423 :             if(!bDone)
     242             :             {
     243         423 :                 const Polygon aPolygon(aCandidate);
     244         423 :                 mpGraphics->DrawPolyLine(aPolygon.GetSize(), reinterpret_cast<const SalPoint*>(aPolygon.GetConstPointAry()), this);
     245             :             }
     246         423 :         }
     247             :     }
     248             : 
     249          13 :     if(aFillPolyPolygon.count())
     250             :     {
     251          10 :         const Color     aOldLineColor( maLineColor );
     252          10 :         const Color     aOldFillColor( maFillColor );
     253             : 
     254          10 :         SetLineColor();
     255          10 :         InitLineColor();
     256          10 :         SetFillColor( aOldLineColor );
     257          10 :         InitFillColor();
     258             : 
     259          10 :         bool bDone(false);
     260             : 
     261          10 :         if(bTryAA)
     262             :         {
     263           0 :             bDone = mpGraphics->DrawPolyPolygon(aFillPolyPolygon, 0.0, this);
     264             :         }
     265             : 
     266          10 :         if(!bDone)
     267             :         {
     268         159 :             for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++)
     269             :             {
     270         149 :                 Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a));
     271             : 
     272             :                 // need to subdivide, mpGraphics->DrawPolygon ignores curves
     273         149 :                 aPolygon.AdaptiveSubdivide(aPolygon);
     274         149 :                 mpGraphics->DrawPolygon(aPolygon.GetSize(), reinterpret_cast<const SalPoint*>(aPolygon.GetConstPointAry()), this);
     275         149 :             }
     276             :         }
     277             : 
     278          10 :         SetFillColor( aOldFillColor );
     279          10 :         SetLineColor( aOldLineColor );
     280             :     }
     281             : 
     282          13 :     mpMetaFile = pOldMetaFile;
     283         814 : }
     284             : 
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11