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

Generated by: LCOV version 1.11