LCOV - code coverage report
Current view: top level - vcl/source/outdev - polyline.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 83 158 52.5 %
Date: 2014-11-03 Functions: 7 8 87.5 %
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             : #include <sal/types.h>
      20             : 
      21             : #include <basegfx/matrix/b2dhommatrix.hxx>
      22             : #include <basegfx/polygon/b2dpolygontools.hxx>
      23             : #include <basegfx/polygon/b2dlinegeometry.hxx>
      24             : 
      25             : #include <vcl/outdev.hxx>
      26             : #include <vcl/virdev.hxx>
      27             : #include <vcl/settings.hxx>
      28             : 
      29             : #include "salgdi.hxx"
      30             : 
      31       15324 : void OutputDevice::DrawPolyLine( const Polygon& rPoly )
      32             : {
      33             : 
      34       15324 :     if( mpMetaFile )
      35           2 :         mpMetaFile->AddAction( new MetaPolyLineAction( rPoly ) );
      36             : 
      37       15324 :     sal_uInt16 nPoints = rPoly.GetSize();
      38             : 
      39       15324 :     if ( !IsDeviceOutputNecessary() || !mbLineColor || (nPoints < 2) || ImplIsRecordLayout() )
      40           4 :         return;
      41             : 
      42             :     // we need a graphics
      43       15322 :     if ( !mpGraphics && !AcquireGraphics() )
      44           0 :         return;
      45             : 
      46       15322 :     if ( mbInitClipRegion )
      47         730 :         InitClipRegion();
      48             : 
      49       15322 :     if ( mbOutputClipped )
      50           0 :         return;
      51             : 
      52       15322 :     if ( mbInitLineColor )
      53        2365 :         InitLineColor();
      54             : 
      55             :     // use b2dpolygon drawing if possible
      56       15322 :     if ( DrawPolyLineDirect( rPoly.getB2DPolygon() ) )
      57             :     {
      58           0 :         basegfx::B2DPolygon aB2DPolyLine(rPoly.getB2DPolygon());
      59           0 :         const ::basegfx::B2DHomMatrix aTransform = ImplGetDeviceTransformation();
      60           0 :         const ::basegfx::B2DVector aB2DLineWidth( 1.0, 1.0 );
      61             : 
      62             :         // transform the polygon
      63           0 :         aB2DPolyLine.transform( aTransform );
      64             : 
      65           0 :         if(mnAntialiasing & ANTIALIASING_PIXELSNAPHAIRLINE)
      66             :         {
      67           0 :             aB2DPolyLine = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aB2DPolyLine);
      68             :         }
      69             : 
      70           0 :         if(mpGraphics->DrawPolyLine( aB2DPolyLine, 0.0, aB2DLineWidth,
      71           0 :                                      basegfx::B2DLINEJOIN_NONE, css::drawing::LineCap_BUTT, this))
      72             :         {
      73           0 :             return;
      74           0 :         }
      75             :     }
      76             : 
      77       15322 :     Polygon aPoly = ImplLogicToDevicePixel( rPoly );
      78       15322 :     const SalPoint* pPtAry = (const SalPoint*)aPoly.GetConstPointAry();
      79             : 
      80             :     // #100127# Forward beziers to sal, if any
      81       15322 :     if( aPoly.HasFlags() )
      82             :     {
      83           0 :         const sal_uInt8* pFlgAry = aPoly.GetConstFlagAry();
      84           0 :         if( !mpGraphics->DrawPolyLineBezier( nPoints, pPtAry, pFlgAry, this ) )
      85             :         {
      86           0 :             aPoly = Polygon::SubdivideBezier(aPoly);
      87           0 :             pPtAry = (const SalPoint*)aPoly.GetConstPointAry();
      88           0 :             mpGraphics->DrawPolyLine( aPoly.GetSize(), pPtAry, this );
      89             :         }
      90             :     }
      91             :     else
      92             :     {
      93       15322 :         mpGraphics->DrawPolyLine( nPoints, pPtAry, this );
      94             :     }
      95             : 
      96       15322 :     if( mpAlphaVDev )
      97        3430 :         mpAlphaVDev->DrawPolyLine( rPoly );
      98             : }
      99             : 
     100         290 : void OutputDevice::DrawPolyLine( const Polygon& rPoly, const LineInfo& rLineInfo )
     101             : {
     102             : 
     103         290 :     if ( rLineInfo.IsDefault() )
     104             :     {
     105           0 :         DrawPolyLine( rPoly );
     106           0 :         return;
     107             :     }
     108             : 
     109             :     // #i101491#
     110             :     // Try direct Fallback to B2D-Version of DrawPolyLine
     111         290 :     if((mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW) &&
     112           0 :        LINE_SOLID == rLineInfo.GetStyle())
     113             :     {
     114           0 :         DrawPolyLine( rPoly.getB2DPolygon(), (double)rLineInfo.GetWidth(), rLineInfo.GetLineJoin(), rLineInfo.GetLineCap());
     115           0 :         return;
     116             :     }
     117             : 
     118         290 :     if ( mpMetaFile )
     119         212 :         mpMetaFile->AddAction( new MetaPolyLineAction( rPoly, rLineInfo ) );
     120             : 
     121         290 :     drawPolyLine(rPoly, rLineInfo);
     122             : }
     123             : 
     124      220478 : void OutputDevice::DrawPolyLine( const basegfx::B2DPolygon& rB2DPolygon,
     125             :                                  double fLineWidth,
     126             :                                  basegfx::B2DLineJoin eLineJoin,
     127             :                                  css::drawing::LineCap eLineCap)
     128             : {
     129             : 
     130      220478 :     if( mpMetaFile )
     131             :     {
     132        3528 :         LineInfo aLineInfo;
     133        3528 :         if( fLineWidth != 0.0 )
     134         114 :             aLineInfo.SetWidth( static_cast<long>(fLineWidth+0.5) );
     135             : 
     136        7056 :         const Polygon aToolsPolygon( rB2DPolygon );
     137        7056 :         mpMetaFile->AddAction( new MetaPolyLineAction( aToolsPolygon, aLineInfo ) );
     138             :     }
     139             : 
     140             :     // Do not paint empty PolyPolygons
     141      220478 :     if(!rB2DPolygon.count() || !IsDeviceOutputNecessary())
     142        3528 :         return;
     143             : 
     144             :     // we need a graphics
     145      216950 :     if( !mpGraphics && !AcquireGraphics() )
     146           0 :         return;
     147             : 
     148      216950 :     if( mbInitClipRegion )
     149         116 :         InitClipRegion();
     150             : 
     151      216950 :     if( mbOutputClipped )
     152           0 :         return;
     153             : 
     154      216950 :     if( mbInitLineColor )
     155        1339 :         InitLineColor();
     156             : 
     157             :     // use b2dpolygon drawing if possible
     158      216950 :     if ( DrawPolyLineDirect(rB2DPolygon, fLineWidth, 0.0, eLineJoin, eLineCap) )
     159           0 :         return;
     160             : 
     161             :     // #i101491#
     162             :     // no output yet; fallback to geometry decomposition and use filled polygon paint
     163             :     // when line is fat and not too complex. ImplDrawPolyPolygonWithB2DPolyPolygon
     164             :     // will do internal needed AA checks etc.
     165      216950 :     if(fLineWidth >= 2.5 &&
     166      216950 :        rB2DPolygon.count() &&
     167           0 :        rB2DPolygon.count() <= 1000)
     168             :     {
     169           0 :         const double fHalfLineWidth((fLineWidth * 0.5) + 0.5);
     170             :         const basegfx::B2DPolyPolygon aAreaPolyPolygon(
     171             :                 basegfx::tools::createAreaGeometry( rB2DPolygon,
     172             :                                                     fHalfLineWidth,
     173             :                                                     eLineJoin,
     174           0 :                                                     eLineCap));
     175           0 :         const Color aOldLineColor(maLineColor);
     176           0 :         const Color aOldFillColor(maFillColor);
     177             : 
     178           0 :         SetLineColor();
     179           0 :         InitLineColor();
     180           0 :         SetFillColor(aOldLineColor);
     181           0 :         InitFillColor();
     182             : 
     183             :         // draw usig a loop; else the topology will paint a PolyPolygon
     184           0 :         for(sal_uInt32 a(0); a < aAreaPolyPolygon.count(); a++)
     185             :         {
     186             :             ImplDrawPolyPolygonWithB2DPolyPolygon(
     187           0 :                 basegfx::B2DPolyPolygon(aAreaPolyPolygon.getB2DPolygon(a)));
     188             :         }
     189             : 
     190           0 :         SetLineColor(aOldLineColor);
     191           0 :         InitLineColor();
     192           0 :         SetFillColor(aOldFillColor);
     193           0 :         InitFillColor();
     194             : 
     195           0 :         const bool bTryAA((mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW) &&
     196           0 :                           mpGraphics->supportsOperation(OutDevSupport_B2DDraw) &&
     197           0 :                           ROP_OVERPAINT == GetRasterOp() &&
     198           0 :                           IsLineColor());
     199             : 
     200           0 :         if(bTryAA)
     201             :         {
     202             :             // when AA it is necessary to also paint the filled polygon's outline
     203             :             // to avoid optical gaps
     204           0 :             for(sal_uInt32 a(0); a < aAreaPolyPolygon.count(); a++)
     205             :             {
     206           0 :                 drawPolyLineDirectNoAACheck(aAreaPolyPolygon.getB2DPolygon(a));
     207             :             }
     208           0 :         }
     209             :     }
     210             :     else
     211             :     {
     212             :         // fallback to old polygon drawing if needed
     213      216950 :         const Polygon aToolsPolygon( rB2DPolygon );
     214      433900 :         LineInfo aLineInfo;
     215      216950 :         if( fLineWidth != 0.0 )
     216           0 :             aLineInfo.SetWidth( static_cast<long>(fLineWidth+0.5) );
     217             : 
     218      433900 :         drawPolyLine( aToolsPolygon, aLineInfo );
     219             :     }
     220             : }
     221             : 
     222      217240 : void OutputDevice::drawPolyLine(const Polygon& rPoly, const LineInfo& rLineInfo)
     223             : {
     224      217240 :     sal_uInt16 nPoints(rPoly.GetSize());
     225             : 
     226      217240 :     if ( !IsDeviceOutputNecessary() || !mbLineColor || ( nPoints < 2 ) || ( LINE_NONE == rLineInfo.GetStyle() ) || ImplIsRecordLayout() )
     227         752 :         return;
     228             : 
     229      216864 :     Polygon aPoly = ImplLogicToDevicePixel( rPoly );
     230             : 
     231             :     // we need a graphics
     232      216864 :     if ( !mpGraphics && !AcquireGraphics() )
     233           0 :         return;
     234             : 
     235      216864 :     if ( mbInitClipRegion )
     236           6 :         InitClipRegion();
     237             : 
     238      216864 :     if ( mbOutputClipped )
     239           0 :         return;
     240             : 
     241      216864 :     if ( mbInitLineColor )
     242          59 :         InitLineColor();
     243             : 
     244      433728 :     const LineInfo aInfo( ImplLogicToDevicePixel( rLineInfo ) );
     245      216864 :     const bool bDashUsed(LINE_DASH == aInfo.GetStyle());
     246      216864 :     const bool bLineWidthUsed(aInfo.GetWidth() > 1);
     247             : 
     248      216864 :     if(bDashUsed || bLineWidthUsed)
     249             :     {
     250          38 :         PaintLineGeometryWithEvtlExpand(aInfo, basegfx::B2DPolyPolygon(aPoly.getB2DPolygon()));
     251             :     }
     252             :     else
     253             :     {
     254             :         // #100127# the subdivision HAS to be done here since only a pointer
     255             :         // to an array of points is given to the DrawPolyLine method, there is
     256             :         // NO way to find out there that it's a curve.
     257      216826 :         if( aPoly.HasFlags() )
     258             :         {
     259        1943 :             aPoly = Polygon::SubdivideBezier( aPoly );
     260        1943 :             nPoints = aPoly.GetSize();
     261             :         }
     262             : 
     263      216826 :         mpGraphics->DrawPolyLine(nPoints, (const SalPoint*)aPoly.GetConstPointAry(), this);
     264             :     }
     265             : 
     266      216864 :     if( mpAlphaVDev )
     267      216864 :         mpAlphaVDev->DrawPolyLine( rPoly, rLineInfo );
     268             : }
     269             : 
     270           0 : bool OutputDevice::drawPolyLineDirectNoAACheck( const basegfx::B2DPolygon& rB2DPolygon,
     271             :                                               double fLineWidth,
     272             :                                               double fTransparency,
     273             :                                               basegfx::B2DLineJoin eLineJoin,
     274             :                                               css::drawing::LineCap eLineCap)
     275             : {
     276           0 :     const basegfx::B2DHomMatrix aTransform = ImplGetDeviceTransformation();
     277           0 :     basegfx::B2DVector aB2DLineWidth(1.0, 1.0);
     278             : 
     279             :     // transform the line width if used
     280           0 :     if( fLineWidth != 0.0 )
     281             :     {
     282           0 :         aB2DLineWidth = aTransform * ::basegfx::B2DVector( fLineWidth, 0.0 );
     283             :     }
     284             : 
     285             :     // transform the polygon
     286           0 :     basegfx::B2DPolygon aB2DPolygon(rB2DPolygon);
     287           0 :     aB2DPolygon.transform(aTransform);
     288             : 
     289           0 :     if((mnAntialiasing & ANTIALIASING_PIXELSNAPHAIRLINE) &&
     290           0 :        aB2DPolygon.count() < 1000)
     291             :     {
     292             :         // #i98289#, #i101491#
     293             :         // better to remove doubles on device coordinates. Also assume from a given amount
     294             :         // of points that the single edges are not long enough to smooth
     295           0 :         aB2DPolygon.removeDoublePoints();
     296           0 :         aB2DPolygon = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aB2DPolygon);
     297             :     }
     298             : 
     299             :     // draw the polyline
     300             :     return mpGraphics->DrawPolyLine( aB2DPolygon,
     301             :                                      fTransparency,
     302             :                                      aB2DLineWidth,
     303             :                                      eLineJoin,
     304             :                                      eLineCap,
     305           0 :                                      this);
     306             : }
     307             : 
     308      402241 : bool OutputDevice::DrawPolyLineDirect( const basegfx::B2DPolygon& rB2DPolygon,
     309             :                                           double fLineWidth,
     310             :                                           double fTransparency,
     311             :                                           basegfx::B2DLineJoin eLineJoin,
     312             :                                           css::drawing::LineCap eLineCap)
     313             : {
     314             :     // AW: Do NOT paint empty PolyPolygons
     315      402241 :     if(!rB2DPolygon.count())
     316           0 :         return true;
     317             : 
     318             :     // we need a graphics
     319      402241 :     if( !mpGraphics && !AcquireGraphics() )
     320           0 :         return false;
     321             : 
     322      402241 :     if( mbInitClipRegion )
     323       12313 :         InitClipRegion();
     324             : 
     325      402241 :     if( mbOutputClipped )
     326           0 :         return true;
     327             : 
     328      402241 :     if( mbInitLineColor )
     329       19873 :         InitLineColor();
     330             : 
     331      402241 :     const bool bTryAA((mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW) &&
     332           0 :                       mpGraphics->supportsOperation(OutDevSupport_B2DDraw) &&
     333      402241 :                       ROP_OVERPAINT == GetRasterOp() &&
     334      402241 :                       IsLineColor());
     335             : 
     336      402241 :     if(bTryAA)
     337             :     {
     338           0 :         if(drawPolyLineDirectNoAACheck(rB2DPolygon, fLineWidth, fTransparency, eLineJoin, eLineCap))
     339             :         {
     340             :             // worked, add metafile action (if recorded) and return true
     341           0 :             if( mpMetaFile )
     342             :             {
     343           0 :                 LineInfo aLineInfo;
     344           0 :                 if( fLineWidth != 0.0 )
     345           0 :                     aLineInfo.SetWidth( static_cast<long>(fLineWidth+0.5) );
     346             : 
     347           0 :                 const Polygon aToolsPolygon( rB2DPolygon );
     348           0 :                 mpMetaFile->AddAction( new MetaPolyLineAction( aToolsPolygon, aLineInfo ) );
     349             :             }
     350           0 :             return true;
     351             :         }
     352             :     }
     353      402241 :     return false;
     354        1233 : }
     355             : 
     356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10