1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir #include <tools/stream.hxx> 31*cdf0e10cSrcweir #include <tools/vcompat.hxx> 32*cdf0e10cSrcweir #include <tools/debug.hxx> 33*cdf0e10cSrcweir #include <vcl/lineinfo.hxx> 34*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 36*cdf0e10cSrcweir #include <basegfx/polygon/b2dlinegeometry.hxx> 37*cdf0e10cSrcweir #include <numeric> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir DBG_NAME( LineInfo ) 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // ---------------- 42*cdf0e10cSrcweir // - ImplLineInfo - 43*cdf0e10cSrcweir // ---------------- 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir ImplLineInfo::ImplLineInfo() : 46*cdf0e10cSrcweir mnRefCount ( 1 ), 47*cdf0e10cSrcweir meStyle ( LINE_SOLID ), 48*cdf0e10cSrcweir mnWidth ( 0 ), 49*cdf0e10cSrcweir mnDashCount ( 0 ), 50*cdf0e10cSrcweir mnDashLen ( 0 ), 51*cdf0e10cSrcweir mnDotCount ( 0 ), 52*cdf0e10cSrcweir mnDotLen ( 0 ), 53*cdf0e10cSrcweir mnDistance ( 0 ), 54*cdf0e10cSrcweir meLineJoin ( basegfx::B2DLINEJOIN_ROUND ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // ----------------------------------------------------------------------- 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir ImplLineInfo::ImplLineInfo( const ImplLineInfo& rImplLineInfo ) : 61*cdf0e10cSrcweir mnRefCount ( 1 ), 62*cdf0e10cSrcweir meStyle ( rImplLineInfo.meStyle ), 63*cdf0e10cSrcweir mnWidth ( rImplLineInfo.mnWidth ), 64*cdf0e10cSrcweir mnDashCount ( rImplLineInfo.mnDashCount ), 65*cdf0e10cSrcweir mnDashLen ( rImplLineInfo.mnDashLen ), 66*cdf0e10cSrcweir mnDotCount ( rImplLineInfo.mnDotCount ), 67*cdf0e10cSrcweir mnDotLen ( rImplLineInfo.mnDotLen ), 68*cdf0e10cSrcweir mnDistance ( rImplLineInfo.mnDistance ), 69*cdf0e10cSrcweir meLineJoin ( rImplLineInfo.meLineJoin ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // ----------------------------------------------------------------------- 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir inline bool ImplLineInfo::operator==( const ImplLineInfo& rB ) const 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir return(meStyle == rB.meStyle 78*cdf0e10cSrcweir && mnWidth == rB.mnWidth 79*cdf0e10cSrcweir && mnDashCount == rB.mnDashCount 80*cdf0e10cSrcweir && mnDashLen == rB.mnDashLen 81*cdf0e10cSrcweir && mnDotCount == rB.mnDotCount 82*cdf0e10cSrcweir && mnDotLen == rB.mnDotLen 83*cdf0e10cSrcweir && mnDistance == rB.mnDistance 84*cdf0e10cSrcweir && meLineJoin == rB.meLineJoin); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // ------------ 88*cdf0e10cSrcweir // - LineInfo - 89*cdf0e10cSrcweir // ------------ 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir LineInfo::LineInfo( LineStyle eStyle, long nWidth ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir DBG_CTOR( LineInfo, NULL ); 94*cdf0e10cSrcweir mpImplLineInfo = new ImplLineInfo; 95*cdf0e10cSrcweir mpImplLineInfo->meStyle = eStyle; 96*cdf0e10cSrcweir mpImplLineInfo->mnWidth = nWidth; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // ----------------------------------------------------------------------- 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir LineInfo::LineInfo( const LineInfo& rLineInfo ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir DBG_CTOR( LineInfo, NULL ); 104*cdf0e10cSrcweir DBG_CHKOBJ( &rLineInfo, LineInfo, NULL ); 105*cdf0e10cSrcweir mpImplLineInfo = rLineInfo.mpImplLineInfo; 106*cdf0e10cSrcweir mpImplLineInfo->mnRefCount++; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ----------------------------------------------------------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir LineInfo::~LineInfo() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir DBG_DTOR( LineInfo, NULL ); 114*cdf0e10cSrcweir if( !( --mpImplLineInfo->mnRefCount ) ) 115*cdf0e10cSrcweir delete mpImplLineInfo; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // ----------------------------------------------------------------------- 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir LineInfo& LineInfo::operator=( const LineInfo& rLineInfo ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 123*cdf0e10cSrcweir DBG_CHKOBJ( &rLineInfo, LineInfo, NULL ); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir rLineInfo.mpImplLineInfo->mnRefCount++; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if( !( --mpImplLineInfo->mnRefCount ) ) 128*cdf0e10cSrcweir delete mpImplLineInfo; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir mpImplLineInfo = rLineInfo.mpImplLineInfo; 131*cdf0e10cSrcweir return *this; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // ----------------------------------------------------------------------- 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sal_Bool LineInfo::operator==( const LineInfo& rLineInfo ) const 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 139*cdf0e10cSrcweir DBG_CHKOBJ( &rLineInfo, LineInfo, NULL ); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir return( mpImplLineInfo == rLineInfo.mpImplLineInfo || 142*cdf0e10cSrcweir *mpImplLineInfo == *rLineInfo.mpImplLineInfo ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // ----------------------------------------------------------------------- 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void LineInfo::ImplMakeUnique() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir if( mpImplLineInfo->mnRefCount != 1 ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir if( mpImplLineInfo->mnRefCount ) 152*cdf0e10cSrcweir mpImplLineInfo->mnRefCount--; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir mpImplLineInfo = new ImplLineInfo( *mpImplLineInfo ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // ----------------------------------------------------------------------- 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir void LineInfo::SetStyle( LineStyle eStyle ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 163*cdf0e10cSrcweir ImplMakeUnique(); 164*cdf0e10cSrcweir mpImplLineInfo->meStyle = eStyle; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // ----------------------------------------------------------------------- 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void LineInfo::SetWidth( long nWidth ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 172*cdf0e10cSrcweir ImplMakeUnique(); 173*cdf0e10cSrcweir mpImplLineInfo->mnWidth = nWidth; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // ----------------------------------------------------------------------- 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir void LineInfo::SetDashCount( sal_uInt16 nDashCount ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 181*cdf0e10cSrcweir ImplMakeUnique(); 182*cdf0e10cSrcweir mpImplLineInfo->mnDashCount = nDashCount; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // ----------------------------------------------------------------------- 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void LineInfo::SetDashLen( long nDashLen ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 190*cdf0e10cSrcweir ImplMakeUnique(); 191*cdf0e10cSrcweir mpImplLineInfo->mnDashLen = nDashLen; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // ----------------------------------------------------------------------- 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir void LineInfo::SetDotCount( sal_uInt16 nDotCount ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 199*cdf0e10cSrcweir ImplMakeUnique(); 200*cdf0e10cSrcweir mpImplLineInfo->mnDotCount = nDotCount; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // ----------------------------------------------------------------------- 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void LineInfo::SetDotLen( long nDotLen ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 208*cdf0e10cSrcweir ImplMakeUnique(); 209*cdf0e10cSrcweir mpImplLineInfo->mnDotLen = nDotLen; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir // ----------------------------------------------------------------------- 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir void LineInfo::SetDistance( long nDistance ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 217*cdf0e10cSrcweir ImplMakeUnique(); 218*cdf0e10cSrcweir mpImplLineInfo->mnDistance = nDistance; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // ----------------------------------------------------------------------- 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void LineInfo::SetLineJoin(basegfx::B2DLineJoin eLineJoin) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir DBG_CHKTHIS( LineInfo, NULL ); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if(eLineJoin != mpImplLineInfo->meLineJoin) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir ImplMakeUnique(); 230*cdf0e10cSrcweir mpImplLineInfo->meLineJoin = eLineJoin; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // ----------------------------------------------------------------------- 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, ImplLineInfo& rImplLineInfo ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir VersionCompat aCompat( rIStm, STREAM_READ ); 239*cdf0e10cSrcweir sal_uInt16 nTmp16; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir rIStm >> nTmp16; rImplLineInfo.meStyle = (LineStyle) nTmp16; 242*cdf0e10cSrcweir rIStm >> rImplLineInfo.mnWidth; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir if( aCompat.GetVersion() >= 2 ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // version 2 247*cdf0e10cSrcweir rIStm >> rImplLineInfo.mnDashCount >> rImplLineInfo.mnDashLen; 248*cdf0e10cSrcweir rIStm >> rImplLineInfo.mnDotCount >> rImplLineInfo.mnDotLen; 249*cdf0e10cSrcweir rIStm >> rImplLineInfo.mnDistance; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir if( aCompat.GetVersion() >= 3 ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir // version 3 255*cdf0e10cSrcweir rIStm >> nTmp16; rImplLineInfo.meLineJoin = (basegfx::B2DLineJoin) nTmp16; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir return rIStm; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // ----------------------------------------------------------------------- 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const ImplLineInfo& rImplLineInfo ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir VersionCompat aCompat( rOStm, STREAM_WRITE, 3 ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir // version 1 268*cdf0e10cSrcweir rOStm << (sal_uInt16) rImplLineInfo.meStyle << rImplLineInfo.mnWidth; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // since version2 271*cdf0e10cSrcweir rOStm << rImplLineInfo.mnDashCount << rImplLineInfo.mnDashLen; 272*cdf0e10cSrcweir rOStm << rImplLineInfo.mnDotCount << rImplLineInfo.mnDotLen; 273*cdf0e10cSrcweir rOStm << rImplLineInfo.mnDistance; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // since version3 276*cdf0e10cSrcweir rOStm << (sal_uInt16) rImplLineInfo.meLineJoin; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir return rOStm; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // ----------------------------------------------------------------------- 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, LineInfo& rLineInfo ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir rLineInfo.ImplMakeUnique(); 286*cdf0e10cSrcweir return( rIStm >> *rLineInfo.mpImplLineInfo ); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir // ----------------------------------------------------------------------- 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const LineInfo& rLineInfo ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir return( rOStm << *rLineInfo.mpImplLineInfo ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir // ----------------------------------------------------------------------- 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir bool LineInfo::isDashDotOrFatLineUsed() const 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir return (LINE_DASH == GetStyle() || GetWidth() > 1); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir // ----------------------------------------------------------------------- 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir void LineInfo::applyToB2DPolyPolygon( 306*cdf0e10cSrcweir basegfx::B2DPolyPolygon& io_rLinePolyPolygon, 307*cdf0e10cSrcweir basegfx::B2DPolyPolygon& o_rFillPolyPolygon) const 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir o_rFillPolyPolygon.clear(); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir if(io_rLinePolyPolygon.count()) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir if(LINE_DASH == GetStyle()) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir ::std::vector< double > fDotDashArray; 316*cdf0e10cSrcweir const double fDashLen(GetDashLen()); 317*cdf0e10cSrcweir const double fDotLen(GetDotLen()); 318*cdf0e10cSrcweir const double fDistance(GetDistance()); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir for(sal_uInt16 a(0); a < GetDashCount(); a++) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir fDotDashArray.push_back(fDashLen); 323*cdf0e10cSrcweir fDotDashArray.push_back(fDistance); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir for(sal_uInt16 b(0); b < GetDotCount(); b++) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir fDotDashArray.push_back(fDotLen); 329*cdf0e10cSrcweir fDotDashArray.push_back(fDistance); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0)); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir if(fAccumulated > 0.0) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir basegfx::B2DPolyPolygon aResult; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir for(sal_uInt32 c(0); c < io_rLinePolyPolygon.count(); c++) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir basegfx::B2DPolyPolygon aLineTraget; 341*cdf0e10cSrcweir basegfx::tools::applyLineDashing( 342*cdf0e10cSrcweir io_rLinePolyPolygon.getB2DPolygon(c), 343*cdf0e10cSrcweir fDotDashArray, 344*cdf0e10cSrcweir &aLineTraget); 345*cdf0e10cSrcweir aResult.append(aLineTraget); 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir io_rLinePolyPolygon = aResult; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir if(GetWidth() > 1 && io_rLinePolyPolygon.count()) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir const double fHalfLineWidth((GetWidth() * 0.5) + 0.5); 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir for(sal_uInt32 a(0); a < io_rLinePolyPolygon.count(); a++) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir o_rFillPolyPolygon.append(basegfx::tools::createAreaGeometry( 359*cdf0e10cSrcweir io_rLinePolyPolygon.getB2DPolygon(a), 360*cdf0e10cSrcweir fHalfLineWidth, 361*cdf0e10cSrcweir GetLineJoin())); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir io_rLinePolyPolygon.clear(); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir // ----------------------------------------------------------------------- 370