LCOV - code coverage report
Current view: top level - vcl/source/gdi - lineinfo.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 149 0.0 %
Date: 2014-04-14 Functions: 0 24 0.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 <tools/stream.hxx>
      21             : #include <tools/vcompat.hxx>
      22             : #include <tools/debug.hxx>
      23             : #include <vcl/lineinfo.hxx>
      24             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      25             : #include <basegfx/polygon/b2dpolygontools.hxx>
      26             : #include <basegfx/polygon/b2dlinegeometry.hxx>
      27             : #include <numeric>
      28             : 
      29             : // - ImplLineInfo -
      30             : 
      31           0 : ImplLineInfo::ImplLineInfo() :
      32             :     mnRefCount  ( 1 ),
      33             :     meStyle     ( LINE_SOLID ),
      34             :     mnWidth     ( 0 ),
      35             :     mnDashCount ( 0 ),
      36             :     mnDashLen   ( 0 ),
      37             :     mnDotCount  ( 0 ),
      38             :     mnDotLen    ( 0 ),
      39             :     mnDistance  ( 0 ),
      40             :     meLineJoin  ( basegfx::B2DLINEJOIN_ROUND ),
      41           0 :     meLineCap   ( com::sun::star::drawing::LineCap_BUTT )
      42             : {
      43           0 : }
      44             : 
      45           0 : ImplLineInfo::ImplLineInfo( const ImplLineInfo& rImplLineInfo ) :
      46             :     mnRefCount  ( 1 ),
      47             :     meStyle     ( rImplLineInfo.meStyle ),
      48             :     mnWidth     ( rImplLineInfo.mnWidth ),
      49             :     mnDashCount ( rImplLineInfo.mnDashCount ),
      50             :     mnDashLen   ( rImplLineInfo.mnDashLen ),
      51             :     mnDotCount  ( rImplLineInfo.mnDotCount ),
      52             :     mnDotLen    ( rImplLineInfo.mnDotLen ),
      53             :     mnDistance  ( rImplLineInfo.mnDistance ),
      54             :     meLineJoin  ( rImplLineInfo.meLineJoin ),
      55           0 :     meLineCap   ( rImplLineInfo.meLineCap )
      56             : {
      57           0 : }
      58             : 
      59           0 : inline bool ImplLineInfo::operator==( const ImplLineInfo& rB ) const
      60             : {
      61           0 :     return(meStyle == rB.meStyle
      62           0 :         && mnWidth == rB.mnWidth
      63           0 :         && mnDashCount == rB.mnDashCount
      64           0 :         && mnDashLen == rB.mnDashLen
      65           0 :         && mnDotCount == rB.mnDotCount
      66           0 :         && mnDotLen == rB.mnDotLen
      67           0 :         && mnDistance == rB.mnDistance
      68           0 :         && meLineJoin == rB.meLineJoin
      69           0 :         && meLineCap == rB.meLineCap);
      70             : }
      71             : 
      72             : // - LineInfo -
      73             : 
      74           0 : LineInfo::LineInfo( LineStyle eStyle, long nWidth )
      75             : {
      76           0 :     mpImplLineInfo = new ImplLineInfo;
      77           0 :     mpImplLineInfo->meStyle = eStyle;
      78           0 :     mpImplLineInfo->mnWidth = nWidth;
      79           0 : }
      80             : 
      81           0 : LineInfo::LineInfo( const LineInfo& rLineInfo )
      82             : {
      83           0 :     mpImplLineInfo = rLineInfo.mpImplLineInfo;
      84           0 :     mpImplLineInfo->mnRefCount++;
      85           0 : }
      86             : 
      87           0 : LineInfo::~LineInfo()
      88             : {
      89           0 :     if( !( --mpImplLineInfo->mnRefCount ) )
      90           0 :         delete mpImplLineInfo;
      91           0 : }
      92             : 
      93           0 : LineInfo& LineInfo::operator=( const LineInfo& rLineInfo )
      94             : {
      95             : 
      96           0 :     rLineInfo.mpImplLineInfo->mnRefCount++;
      97             : 
      98           0 :     if( !( --mpImplLineInfo->mnRefCount ) )
      99           0 :         delete mpImplLineInfo;
     100             : 
     101           0 :     mpImplLineInfo = rLineInfo.mpImplLineInfo;
     102           0 :     return *this;
     103             : }
     104             : 
     105           0 : bool LineInfo::operator==( const LineInfo& rLineInfo ) const
     106             : {
     107             : 
     108           0 :     return( mpImplLineInfo == rLineInfo.mpImplLineInfo ||
     109           0 :            *mpImplLineInfo == *rLineInfo.mpImplLineInfo );
     110             : }
     111             : 
     112           0 : void LineInfo::ImplMakeUnique()
     113             : {
     114           0 :     if( mpImplLineInfo->mnRefCount != 1 )
     115             :     {
     116           0 :         if( mpImplLineInfo->mnRefCount )
     117           0 :             mpImplLineInfo->mnRefCount--;
     118             : 
     119           0 :         mpImplLineInfo = new ImplLineInfo( *mpImplLineInfo );
     120             :     }
     121           0 : }
     122             : 
     123           0 : void LineInfo::SetStyle( LineStyle eStyle )
     124             : {
     125           0 :     ImplMakeUnique();
     126           0 :     mpImplLineInfo->meStyle = eStyle;
     127           0 : }
     128             : 
     129           0 : void LineInfo::SetWidth( long nWidth )
     130             : {
     131           0 :     ImplMakeUnique();
     132           0 :     mpImplLineInfo->mnWidth = nWidth;
     133           0 : }
     134             : 
     135           0 : void LineInfo::SetDashCount( sal_uInt16 nDashCount )
     136             : {
     137           0 :     ImplMakeUnique();
     138           0 :     mpImplLineInfo->mnDashCount = nDashCount;
     139           0 : }
     140             : 
     141           0 : void LineInfo::SetDashLen( long nDashLen )
     142             : {
     143           0 :     ImplMakeUnique();
     144           0 :     mpImplLineInfo->mnDashLen = nDashLen;
     145           0 : }
     146             : 
     147           0 : void LineInfo::SetDotCount( sal_uInt16 nDotCount )
     148             : {
     149           0 :     ImplMakeUnique();
     150           0 :     mpImplLineInfo->mnDotCount = nDotCount;
     151           0 : }
     152             : 
     153           0 : void LineInfo::SetDotLen( long nDotLen )
     154             : {
     155           0 :     ImplMakeUnique();
     156           0 :     mpImplLineInfo->mnDotLen = nDotLen;
     157           0 : }
     158             : 
     159           0 : void LineInfo::SetDistance( long nDistance )
     160             : {
     161           0 :     ImplMakeUnique();
     162           0 :     mpImplLineInfo->mnDistance = nDistance;
     163           0 : }
     164             : 
     165           0 : void LineInfo::SetLineJoin(basegfx::B2DLineJoin eLineJoin)
     166             : {
     167             : 
     168           0 :     if(eLineJoin != mpImplLineInfo->meLineJoin)
     169             :     {
     170           0 :         ImplMakeUnique();
     171           0 :         mpImplLineInfo->meLineJoin = eLineJoin;
     172             :     }
     173           0 : }
     174             : 
     175           0 : void LineInfo::SetLineCap(com::sun::star::drawing::LineCap eLineCap)
     176             : {
     177           0 :     if(eLineCap != mpImplLineInfo->meLineCap)
     178             :     {
     179           0 :         ImplMakeUnique();
     180           0 :         mpImplLineInfo->meLineCap = eLineCap;
     181             :     }
     182           0 : }
     183             : 
     184           0 : bool LineInfo::IsDefault() const
     185             : {
     186           0 :     return( !mpImplLineInfo->mnWidth
     187           0 :         && ( LINE_SOLID == mpImplLineInfo->meStyle )
     188           0 :         && ( com::sun::star::drawing::LineCap_BUTT == mpImplLineInfo->meLineCap));
     189             : }
     190             : 
     191           0 : SvStream& ReadImplLineInfo( SvStream& rIStm, ImplLineInfo& rImplLineInfo )
     192             : {
     193           0 :     VersionCompat   aCompat( rIStm, STREAM_READ );
     194           0 :     sal_uInt16          nTmp16(0);
     195           0 :     sal_Int32       nTmp32(0);
     196             : 
     197             :     //#fdo39428 SvStream no longer supports operator>>(long&)
     198           0 :     rIStm.ReadUInt16( nTmp16 ); rImplLineInfo.meStyle = (LineStyle) nTmp16;
     199           0 :     rIStm.ReadInt32( nTmp32 );
     200           0 :     rImplLineInfo.mnWidth = nTmp32;
     201             : 
     202           0 :     if( aCompat.GetVersion() >= 2 )
     203             :     {
     204             :         // version 2
     205           0 :         rIStm.ReadUInt16( rImplLineInfo.mnDashCount ).ReadInt32( nTmp32 );
     206           0 :         rImplLineInfo.mnDashLen = nTmp32;
     207           0 :         rIStm.ReadUInt16( rImplLineInfo.mnDotCount ).ReadInt32( nTmp32 );
     208           0 :         rImplLineInfo.mnDotLen = nTmp32;
     209           0 :         rIStm.ReadInt32( nTmp32 );
     210           0 :         rImplLineInfo.mnDistance = nTmp32;
     211             :     }
     212             : 
     213           0 :     if( aCompat.GetVersion() >= 3 )
     214             :     {
     215             :         // version 3
     216           0 :         rIStm.ReadUInt16( nTmp16 ); rImplLineInfo.meLineJoin = (basegfx::B2DLineJoin) nTmp16;
     217             :     }
     218             : 
     219           0 :     if( aCompat.GetVersion() >= 4 )
     220             :     {
     221             :         // version 4
     222           0 :         rIStm.ReadUInt16( nTmp16 ); rImplLineInfo.meLineCap = (com::sun::star::drawing::LineCap) nTmp16;
     223             :     }
     224             : 
     225           0 :     return rIStm;
     226             : }
     227             : 
     228           0 : SvStream& WriteImplLineInfo( SvStream& rOStm, const ImplLineInfo& rImplLineInfo )
     229             : {
     230           0 :     VersionCompat aCompat( rOStm, STREAM_WRITE, 4 );
     231             : 
     232             :     //#fdo39428 SvStream no longer supports operator<<(long)
     233             :     // version 1
     234           0 :     rOStm.WriteUInt16( (sal_uInt16) rImplLineInfo.meStyle ).WriteInt32( sal::static_int_cast<sal_Int32>(rImplLineInfo.mnWidth) );
     235             : 
     236             :     // since version2
     237           0 :     rOStm.WriteUInt16( rImplLineInfo.mnDashCount ).WriteInt32( sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDashLen) );
     238           0 :     rOStm.WriteUInt16( rImplLineInfo.mnDotCount ).WriteInt32( sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDotLen) );
     239           0 :     rOStm.WriteInt32( sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDistance) );
     240             : 
     241             :     // since version3
     242           0 :     rOStm.WriteUInt16( (sal_uInt16) rImplLineInfo.meLineJoin );
     243             : 
     244             :     // since version4
     245           0 :     rOStm.WriteUInt16( (sal_uInt16) rImplLineInfo.meLineCap );
     246             : 
     247           0 :     return rOStm;
     248             : }
     249             : 
     250           0 : SvStream& ReadLineInfo( SvStream& rIStm, LineInfo& rLineInfo )
     251             : {
     252           0 :     rLineInfo.ImplMakeUnique();
     253           0 :     return ReadImplLineInfo( rIStm, *rLineInfo.mpImplLineInfo );
     254             : }
     255             : 
     256           0 : SvStream& WriteLineInfo( SvStream& rOStm, const LineInfo& rLineInfo )
     257             : {
     258           0 :     return WriteImplLineInfo( rOStm, *rLineInfo.mpImplLineInfo );
     259             : }
     260             : 
     261           0 : void LineInfo::applyToB2DPolyPolygon(
     262             :     basegfx::B2DPolyPolygon& io_rLinePolyPolygon,
     263             :     basegfx::B2DPolyPolygon& o_rFillPolyPolygon) const
     264             : {
     265           0 :     o_rFillPolyPolygon.clear();
     266             : 
     267           0 :     if(io_rLinePolyPolygon.count())
     268             :     {
     269           0 :         if(LINE_DASH == GetStyle())
     270             :         {
     271           0 :             ::std::vector< double > fDotDashArray;
     272           0 :             const double fDashLen(GetDashLen());
     273           0 :             const double fDotLen(GetDotLen());
     274           0 :             const double fDistance(GetDistance());
     275             : 
     276           0 :             for(sal_uInt16 a(0); a < GetDashCount(); a++)
     277             :             {
     278           0 :                 fDotDashArray.push_back(fDashLen);
     279           0 :                 fDotDashArray.push_back(fDistance);
     280             :             }
     281             : 
     282           0 :             for(sal_uInt16 b(0); b < GetDotCount(); b++)
     283             :             {
     284           0 :                 fDotDashArray.push_back(fDotLen);
     285           0 :                 fDotDashArray.push_back(fDistance);
     286             :             }
     287             : 
     288           0 :             const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
     289             : 
     290           0 :             if(fAccumulated > 0.0)
     291             :             {
     292           0 :                 basegfx::B2DPolyPolygon aResult;
     293             : 
     294           0 :                 for(sal_uInt32 c(0); c < io_rLinePolyPolygon.count(); c++)
     295             :                 {
     296           0 :                     basegfx::B2DPolyPolygon aLineTraget;
     297             :                     basegfx::tools::applyLineDashing(
     298             :                         io_rLinePolyPolygon.getB2DPolygon(c),
     299             :                         fDotDashArray,
     300           0 :                         &aLineTraget);
     301           0 :                     aResult.append(aLineTraget);
     302           0 :                 }
     303             : 
     304           0 :                 io_rLinePolyPolygon = aResult;
     305           0 :             }
     306             :         }
     307             : 
     308           0 :         if(GetWidth() > 1 && io_rLinePolyPolygon.count())
     309             :         {
     310           0 :             const double fHalfLineWidth((GetWidth() * 0.5) + 0.5);
     311             : 
     312           0 :             for(sal_uInt32 a(0); a < io_rLinePolyPolygon.count(); a++)
     313             :             {
     314             :                 o_rFillPolyPolygon.append(basegfx::tools::createAreaGeometry(
     315             :                     io_rLinePolyPolygon.getB2DPolygon(a),
     316             :                     fHalfLineWidth,
     317             :                     GetLineJoin(),
     318           0 :                     GetLineCap()));
     319             :             }
     320             : 
     321           0 :             io_rLinePolyPolygon.clear();
     322             :         }
     323             :     }
     324           0 : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10