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_cppcanvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <canvas/debug.hxx> 32*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 33*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/rendering/RenderState.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 36*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 37*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 38*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 39*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 40*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx> 41*cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx> 42*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 43*cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 44*cdf0e10cSrcweir #include <vcl/metaact.hxx> 45*cdf0e10cSrcweir #include <vcl/virdev.hxx> 46*cdf0e10cSrcweir #include <vcl/metric.hxx> 47*cdf0e10cSrcweir #include <tools/poly.hxx> 48*cdf0e10cSrcweir #include "mtftools.hxx" 49*cdf0e10cSrcweir #include "outdevstate.hxx" 50*cdf0e10cSrcweir #include "polypolyaction.hxx" 51*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir using namespace ::com::sun::star; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace cppcanvas 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir namespace tools 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir void initRenderState( rendering::RenderState& renderState, 62*cdf0e10cSrcweir const ::cppcanvas::internal::OutDevState& outdevState ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir ::canvas::tools::initRenderState( renderState ); 65*cdf0e10cSrcweir ::canvas::tools::setRenderStateTransform( renderState, 66*cdf0e10cSrcweir outdevState.transform ); 67*cdf0e10cSrcweir renderState.Clip = outdevState.xClipPoly; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ::Size getBaselineOffset( const ::cppcanvas::internal::OutDevState& outdevState, 71*cdf0e10cSrcweir const VirtualDevice& rVDev ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir const ::FontMetric& aMetric = rVDev.GetFontMetric(); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // calc offset for text output, the XCanvas always renders 76*cdf0e10cSrcweir // baseline offset. 77*cdf0e10cSrcweir switch( outdevState.textReferencePoint ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir case ALIGN_TOP: 80*cdf0e10cSrcweir return ::Size( 0, 81*cdf0e10cSrcweir aMetric.GetIntLeading() + aMetric.GetAscent() ); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir default: 84*cdf0e10cSrcweir ENSURE_OR_THROW( false, 85*cdf0e10cSrcweir "tools::getBaselineOffset(): Unexpected TextAlign value" ); 86*cdf0e10cSrcweir // FALLTHROUGH intended (to calm compiler warning - case won't happen) 87*cdf0e10cSrcweir case ALIGN_BASELINE: 88*cdf0e10cSrcweir return ::Size( 0, 0 ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir case ALIGN_BOTTOM: 91*cdf0e10cSrcweir return ::Size( 0, 92*cdf0e10cSrcweir -aMetric.GetDescent() ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir ::basegfx::B2DHomMatrix& calcLogic2PixelLinearTransform( ::basegfx::B2DHomMatrix& o_rMatrix, 98*cdf0e10cSrcweir const VirtualDevice& rVDev ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir // select size value in the middle of the available range, 101*cdf0e10cSrcweir // to have headroom both when map mode scales up, and when 102*cdf0e10cSrcweir // it scales down. 103*cdf0e10cSrcweir const ::Size aSizeLogic( 0x00010000L, 104*cdf0e10cSrcweir 0x00010000L ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir const ::Size aSizePixel( rVDev.LogicToPixel( aSizeLogic ) ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir o_rMatrix = basegfx::tools::createScaleB2DHomMatrix( 109*cdf0e10cSrcweir aSizePixel.Width() / (double)aSizeLogic.Width(), 110*cdf0e10cSrcweir aSizePixel.Height() / (double)aSizeLogic.Height() ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir return o_rMatrix; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir ::basegfx::B2DHomMatrix& calcLogic2PixelAffineTransform( ::basegfx::B2DHomMatrix& o_rMatrix, 116*cdf0e10cSrcweir const VirtualDevice& rVDev ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir // retrieves scale 119*cdf0e10cSrcweir calcLogic2PixelLinearTransform(o_rMatrix, rVDev); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // translate according to curr map mode/pref map mode offset 122*cdf0e10cSrcweir const ::Point aEmptyPoint; 123*cdf0e10cSrcweir const ::Point& rTranslatedPoint( 124*cdf0e10cSrcweir rVDev.LogicToPixel( aEmptyPoint )); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir o_rMatrix.translate(rTranslatedPoint.X(), 127*cdf0e10cSrcweir rTranslatedPoint.Y()); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return o_rMatrix; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir bool modifyClip( rendering::RenderState& o_rRenderState, 133*cdf0e10cSrcweir const struct ::cppcanvas::internal::OutDevState& rOutdevState, 134*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 135*cdf0e10cSrcweir const ::basegfx::B2DPoint& rOffset, 136*cdf0e10cSrcweir const ::basegfx::B2DVector* pScaling, 137*cdf0e10cSrcweir const double* pRotation ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir const ::Point aEmptyPoint; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir const bool bOffsetting( !rOffset.equalZero() ); 142*cdf0e10cSrcweir const bool bScaling( pScaling && 143*cdf0e10cSrcweir pScaling->getX() != 1.0 && 144*cdf0e10cSrcweir pScaling->getY() != 1.0 ); 145*cdf0e10cSrcweir const bool bRotation( pRotation && 146*cdf0e10cSrcweir *pRotation != 0.0 ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir if( !bOffsetting && !bScaling && !bRotation ) 149*cdf0e10cSrcweir return false; // nothing to do 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if( rOutdevState.clip.count() ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir // general polygon case 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon aLocalClip( rOutdevState.clip ); 156*cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTransform; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if( bOffsetting ) 159*cdf0e10cSrcweir aTransform.translate( -rOffset.getX(), 160*cdf0e10cSrcweir -rOffset.getY() ); 161*cdf0e10cSrcweir if( bScaling ) 162*cdf0e10cSrcweir aTransform.scale( 1.0/pScaling->getX(), 1.0/pScaling->getY() ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir if( bRotation ) 165*cdf0e10cSrcweir aTransform.rotate( - *pRotation ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir aLocalClip.transform( aTransform ); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir o_rRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 170*cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 171*cdf0e10cSrcweir aLocalClip ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir return true; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir else if( !rOutdevState.clipRect.IsEmpty() ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir // simple rect case 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir const ::Rectangle aLocalClipRect( rOutdevState.clipRect ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( bRotation ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // rotation involved - convert to polygon first, 184*cdf0e10cSrcweir // then transform that 185*cdf0e10cSrcweir ::basegfx::B2DPolygon aLocalClip( 186*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 187*cdf0e10cSrcweir ::basegfx::B2DRectangle( 188*cdf0e10cSrcweir (double)(aLocalClipRect.Left()), 189*cdf0e10cSrcweir (double)(aLocalClipRect.Top()), 190*cdf0e10cSrcweir (double)(aLocalClipRect.Right()), 191*cdf0e10cSrcweir (double)(aLocalClipRect.Bottom()) ) ) ); 192*cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTransform; 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir if( bOffsetting ) 195*cdf0e10cSrcweir aTransform.translate( -rOffset.getX(), 196*cdf0e10cSrcweir -rOffset.getY() ); 197*cdf0e10cSrcweir if( bScaling ) 198*cdf0e10cSrcweir aTransform.scale( 1.0/pScaling->getX(), 1.0/pScaling->getY() ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir aTransform.rotate( - *pRotation ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir aLocalClip.transform( aTransform ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir o_rRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 205*cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 206*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon( aLocalClip ) ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir else if( bScaling ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir // scale and offset - do it on the fly, have to 211*cdf0e10cSrcweir // convert to float anyway. 212*cdf0e10cSrcweir o_rRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 213*cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 214*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon( 215*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 216*cdf0e10cSrcweir ::basegfx::B2DRectangle( 217*cdf0e10cSrcweir (double)(aLocalClipRect.Left() - rOffset.getX())/pScaling->getX(), 218*cdf0e10cSrcweir (double)(aLocalClipRect.Top() - rOffset.getY())/pScaling->getY(), 219*cdf0e10cSrcweir (double)(aLocalClipRect.Right() - rOffset.getX())/pScaling->getX(), 220*cdf0e10cSrcweir (double)(aLocalClipRect.Bottom() - rOffset.getY())/pScaling->getY() ) ) ) ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir else 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // offset only - do it on the fly, have to convert 225*cdf0e10cSrcweir // to float anyway. 226*cdf0e10cSrcweir o_rRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 227*cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 228*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon( 229*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 230*cdf0e10cSrcweir ::basegfx::B2DRectangle( aLocalClipRect.Left() - rOffset.getX(), 231*cdf0e10cSrcweir aLocalClipRect.Top() - rOffset.getY(), 232*cdf0e10cSrcweir aLocalClipRect.Right() - rOffset.getX(), 233*cdf0e10cSrcweir aLocalClipRect.Bottom() - rOffset.getY() ) ) ) ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir return true; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // empty clip, nothing to do 240*cdf0e10cSrcweir return false; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir bool modifyClip( rendering::RenderState& o_rRenderState, 244*cdf0e10cSrcweir const struct ::cppcanvas::internal::OutDevState& rOutdevState, 245*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 246*cdf0e10cSrcweir const ::Point& rOffset, 247*cdf0e10cSrcweir const ::basegfx::B2DVector* pScaling, 248*cdf0e10cSrcweir const double* pRotation ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir return modifyClip( o_rRenderState, 251*cdf0e10cSrcweir rOutdevState, 252*cdf0e10cSrcweir rCanvas, 253*cdf0e10cSrcweir ::basegfx::B2DPoint( rOffset.X(), 254*cdf0e10cSrcweir rOffset.Y() ), 255*cdf0e10cSrcweir pScaling, 256*cdf0e10cSrcweir pRotation ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir bool modifyClip( rendering::RenderState& o_rRenderState, 260*cdf0e10cSrcweir const struct ::cppcanvas::internal::OutDevState& rOutdevState, 261*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 262*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransform ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if( !rTransform.isIdentity() || 265*cdf0e10cSrcweir !rTransform.isInvertible() ) 266*cdf0e10cSrcweir return false; // nothing to do 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon aLocalClip; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if( rOutdevState.clip.count() ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir aLocalClip = rOutdevState.clip; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir else if( !rOutdevState.clipRect.IsEmpty() ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir const ::Rectangle aLocalClipRect( rOutdevState.clipRect ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir aLocalClip = ::basegfx::B2DPolyPolygon( 279*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 280*cdf0e10cSrcweir ::basegfx::B2DRectangle( 281*cdf0e10cSrcweir aLocalClipRect.Left(), 282*cdf0e10cSrcweir aLocalClipRect.Top(), 283*cdf0e10cSrcweir aLocalClipRect.Right(), 284*cdf0e10cSrcweir aLocalClipRect.Bottom() ) ) ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir else 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir // empty clip, nothing to do 289*cdf0e10cSrcweir return false; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir // invert transformation and modify 293*cdf0e10cSrcweir ::basegfx::B2DHomMatrix aLocalTransform( rTransform ); 294*cdf0e10cSrcweir aLocalTransform.invert(); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir aLocalClip.transform( aLocalTransform ); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir o_rRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 299*cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 300*cdf0e10cSrcweir aLocalClip ); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir return true; 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir // create overline/underline/strikeout line info struct 306*cdf0e10cSrcweir TextLineInfo createTextLineInfo( const ::VirtualDevice& rVDev, 307*cdf0e10cSrcweir const ::cppcanvas::internal::OutDevState& rState ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir const sal_Bool bOldMode( rVDev.IsMapModeEnabled() ); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // #i68512# Force metric regeneration with mapmode enabled 312*cdf0e10cSrcweir // (prolly OutDev bug) 313*cdf0e10cSrcweir rVDev.GetFontMetric(); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // will restore map mode below 316*cdf0e10cSrcweir const_cast< ::VirtualDevice& >(rVDev).EnableMapMode( sal_False ); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir const ::FontMetric aMetric = rVDev.GetFontMetric(); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir TextLineInfo aTextInfo( 321*cdf0e10cSrcweir (aMetric.GetDescent() + 2) / 4.0, 322*cdf0e10cSrcweir ((aMetric.GetIntLeading() + 1.5) / 3.0), 323*cdf0e10cSrcweir (aMetric.GetIntLeading() / 2.0) - aMetric.GetAscent(), 324*cdf0e10cSrcweir aMetric.GetDescent() / 2.0, 325*cdf0e10cSrcweir (aMetric.GetIntLeading() - aMetric.GetAscent()) / 3.0, 326*cdf0e10cSrcweir rState.textOverlineStyle, 327*cdf0e10cSrcweir rState.textUnderlineStyle, 328*cdf0e10cSrcweir rState.textStrikeoutStyle ); 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir const_cast< ::VirtualDevice& >(rVDev).EnableMapMode( bOldMode ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir return aTextInfo; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir namespace 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir void appendRect( ::basegfx::B2DPolyPolygon& o_rPoly, 338*cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPos, 339*cdf0e10cSrcweir const double nX1, 340*cdf0e10cSrcweir const double nY1, 341*cdf0e10cSrcweir const double nX2, 342*cdf0e10cSrcweir const double nY2 ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir const double x( rStartPos.getX() ); 345*cdf0e10cSrcweir const double y( rStartPos.getY() ); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir o_rPoly.append( 348*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 349*cdf0e10cSrcweir ::basegfx::B2DRectangle( x + nX1, y + nY1, x + nX2, y + nY2 ) ) ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir void appendRect( ::basegfx::B2DPolyPolygon& o_rPoly, 353*cdf0e10cSrcweir const double nX1, 354*cdf0e10cSrcweir const double nY1, 355*cdf0e10cSrcweir const double nX2, 356*cdf0e10cSrcweir const double nY2 ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir o_rPoly.append( 359*cdf0e10cSrcweir ::basegfx::tools::createPolygonFromRect( 360*cdf0e10cSrcweir ::basegfx::B2DRectangle( nX1, nY1, nX2, nY2 ) ) ); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir void appendDashes( ::basegfx::B2DPolyPolygon& o_rPoly, 364*cdf0e10cSrcweir const double nX, 365*cdf0e10cSrcweir const double nY, 366*cdf0e10cSrcweir const double nLineWidth, 367*cdf0e10cSrcweir const double nLineHeight, 368*cdf0e10cSrcweir const double nDashWidth, 369*cdf0e10cSrcweir const double nDashSkip ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir const sal_Int32 nNumLoops( 372*cdf0e10cSrcweir static_cast< sal_Int32 >( 373*cdf0e10cSrcweir ::std::max( 1.0, 374*cdf0e10cSrcweir nLineWidth / nDashSkip ) + .5) ); 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir double x = nX; 377*cdf0e10cSrcweir for( sal_Int32 i=0; i<nNumLoops; ++i ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir appendRect( o_rPoly, 380*cdf0e10cSrcweir x, nY, 381*cdf0e10cSrcweir x + nDashWidth, nY + nLineHeight ); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir x += nDashSkip; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // create line actions for text such as underline and 389*cdf0e10cSrcweir // strikeout 390*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const ::basegfx::B2DPoint rStartPos, 391*cdf0e10cSrcweir const double& rLineWidth, 392*cdf0e10cSrcweir const TextLineInfo& rTextLineInfo ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir // fill the polypolygon with all text lines 395*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon aTextLinesPolyPoly; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir switch( rTextLineInfo.mnOverlineStyle ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir case UNDERLINE_NONE: // nothing to do 400*cdf0e10cSrcweir // FALLTHROUGH intended 401*cdf0e10cSrcweir case UNDERLINE_DONTKNOW: 402*cdf0e10cSrcweir break; 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir case UNDERLINE_SMALLWAVE: // TODO(F3): NYI 405*cdf0e10cSrcweir // FALLTHROUGH intended 406*cdf0e10cSrcweir case UNDERLINE_WAVE: // TODO(F3): NYI 407*cdf0e10cSrcweir // FALLTHROUGH intended 408*cdf0e10cSrcweir case UNDERLINE_SINGLE: 409*cdf0e10cSrcweir appendRect( 410*cdf0e10cSrcweir aTextLinesPolyPoly, 411*cdf0e10cSrcweir rStartPos, 412*cdf0e10cSrcweir 0, 413*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset, 414*cdf0e10cSrcweir rLineWidth, 415*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight ); 416*cdf0e10cSrcweir break; 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir case UNDERLINE_BOLDDOTTED: // TODO(F3): NYI 419*cdf0e10cSrcweir // FALLTHROUGH intended 420*cdf0e10cSrcweir case UNDERLINE_BOLDDASH: // TODO(F3): NYI 421*cdf0e10cSrcweir // FALLTHROUGH intended 422*cdf0e10cSrcweir case UNDERLINE_BOLDLONGDASH: // TODO(F3): NYI 423*cdf0e10cSrcweir // FALLTHROUGH intended 424*cdf0e10cSrcweir case UNDERLINE_BOLDDASHDOT: // TODO(F3): NYI 425*cdf0e10cSrcweir // FALLTHROUGH intended 426*cdf0e10cSrcweir case UNDERLINE_BOLDDASHDOTDOT:// TODO(F3): NYI 427*cdf0e10cSrcweir // FALLTHROUGH intended 428*cdf0e10cSrcweir case UNDERLINE_BOLDWAVE: // TODO(F3): NYI 429*cdf0e10cSrcweir // FALLTHROUGH intended 430*cdf0e10cSrcweir case UNDERLINE_BOLD: 431*cdf0e10cSrcweir appendRect( 432*cdf0e10cSrcweir aTextLinesPolyPoly, 433*cdf0e10cSrcweir rStartPos, 434*cdf0e10cSrcweir 0, 435*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset - rTextLineInfo.mnOverlineHeight, 436*cdf0e10cSrcweir rLineWidth, 437*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight ); 438*cdf0e10cSrcweir break; 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir case UNDERLINE_DOUBLEWAVE: // TODO(F3): NYI 441*cdf0e10cSrcweir // FALLTHROUGH intended 442*cdf0e10cSrcweir case UNDERLINE_DOUBLE: 443*cdf0e10cSrcweir appendRect( 444*cdf0e10cSrcweir aTextLinesPolyPoly, 445*cdf0e10cSrcweir rStartPos, 446*cdf0e10cSrcweir 0, 447*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset - rTextLineInfo.mnOverlineHeight * 2.0 , 448*cdf0e10cSrcweir rLineWidth, 449*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset - rTextLineInfo.mnOverlineHeight ); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir appendRect( 452*cdf0e10cSrcweir aTextLinesPolyPoly, 453*cdf0e10cSrcweir rStartPos, 454*cdf0e10cSrcweir 0, 455*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight, 456*cdf0e10cSrcweir rLineWidth, 457*cdf0e10cSrcweir rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight * 2.0 ); 458*cdf0e10cSrcweir break; 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir case UNDERLINE_DASHDOTDOT: // TODO(F3): NYI 461*cdf0e10cSrcweir // FALLTHROUGH intended 462*cdf0e10cSrcweir case UNDERLINE_DOTTED: 463*cdf0e10cSrcweir appendDashes( 464*cdf0e10cSrcweir aTextLinesPolyPoly, 465*cdf0e10cSrcweir rStartPos.getX(), 466*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnOverlineOffset, 467*cdf0e10cSrcweir rLineWidth, 468*cdf0e10cSrcweir rTextLineInfo.mnOverlineHeight, 469*cdf0e10cSrcweir rTextLineInfo.mnOverlineHeight, 470*cdf0e10cSrcweir 2*rTextLineInfo.mnOverlineHeight ); 471*cdf0e10cSrcweir break; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir case UNDERLINE_DASHDOT: // TODO(F3): NYI 474*cdf0e10cSrcweir // FALLTHROUGH intended 475*cdf0e10cSrcweir case UNDERLINE_DASH: 476*cdf0e10cSrcweir appendDashes( 477*cdf0e10cSrcweir aTextLinesPolyPoly, 478*cdf0e10cSrcweir rStartPos.getX(), 479*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnOverlineOffset, 480*cdf0e10cSrcweir rLineWidth, 481*cdf0e10cSrcweir rTextLineInfo.mnOverlineHeight, 482*cdf0e10cSrcweir 3*rTextLineInfo.mnOverlineHeight, 483*cdf0e10cSrcweir 6*rTextLineInfo.mnOverlineHeight ); 484*cdf0e10cSrcweir break; 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir case UNDERLINE_LONGDASH: 487*cdf0e10cSrcweir appendDashes( 488*cdf0e10cSrcweir aTextLinesPolyPoly, 489*cdf0e10cSrcweir rStartPos.getX(), 490*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnOverlineOffset, 491*cdf0e10cSrcweir rLineWidth, 492*cdf0e10cSrcweir rTextLineInfo.mnOverlineHeight, 493*cdf0e10cSrcweir 6*rTextLineInfo.mnOverlineHeight, 494*cdf0e10cSrcweir 12*rTextLineInfo.mnOverlineHeight ); 495*cdf0e10cSrcweir break; 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir default: 498*cdf0e10cSrcweir ENSURE_OR_THROW( false, 499*cdf0e10cSrcweir "::cppcanvas::internal::createTextLinesPolyPolygon(): Unexpected overline case" ); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir switch( rTextLineInfo.mnUnderlineStyle ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir case UNDERLINE_NONE: // nothing to do 505*cdf0e10cSrcweir // FALLTHROUGH intended 506*cdf0e10cSrcweir case UNDERLINE_DONTKNOW: 507*cdf0e10cSrcweir break; 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir case UNDERLINE_SMALLWAVE: // TODO(F3): NYI 510*cdf0e10cSrcweir // FALLTHROUGH intended 511*cdf0e10cSrcweir case UNDERLINE_WAVE: // TODO(F3): NYI 512*cdf0e10cSrcweir // FALLTHROUGH intended 513*cdf0e10cSrcweir case UNDERLINE_SINGLE: 514*cdf0e10cSrcweir appendRect( 515*cdf0e10cSrcweir aTextLinesPolyPoly, 516*cdf0e10cSrcweir rStartPos, 517*cdf0e10cSrcweir 0, 518*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset, 519*cdf0e10cSrcweir rLineWidth, 520*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset + rTextLineInfo.mnLineHeight ); 521*cdf0e10cSrcweir break; 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir case UNDERLINE_BOLDDOTTED: // TODO(F3): NYI 524*cdf0e10cSrcweir // FALLTHROUGH intended 525*cdf0e10cSrcweir case UNDERLINE_BOLDDASH: // TODO(F3): NYI 526*cdf0e10cSrcweir // FALLTHROUGH intended 527*cdf0e10cSrcweir case UNDERLINE_BOLDLONGDASH: // TODO(F3): NYI 528*cdf0e10cSrcweir // FALLTHROUGH intended 529*cdf0e10cSrcweir case UNDERLINE_BOLDDASHDOT: // TODO(F3): NYI 530*cdf0e10cSrcweir // FALLTHROUGH intended 531*cdf0e10cSrcweir case UNDERLINE_BOLDDASHDOTDOT:// TODO(F3): NYI 532*cdf0e10cSrcweir // FALLTHROUGH intended 533*cdf0e10cSrcweir case UNDERLINE_BOLDWAVE: // TODO(F3): NYI 534*cdf0e10cSrcweir // FALLTHROUGH intended 535*cdf0e10cSrcweir case UNDERLINE_BOLD: 536*cdf0e10cSrcweir appendRect( 537*cdf0e10cSrcweir aTextLinesPolyPoly, 538*cdf0e10cSrcweir rStartPos, 539*cdf0e10cSrcweir 0, 540*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset, 541*cdf0e10cSrcweir rLineWidth, 542*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset + 2*rTextLineInfo.mnLineHeight ); 543*cdf0e10cSrcweir break; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir case UNDERLINE_DOUBLEWAVE: // TODO(F3): NYI 546*cdf0e10cSrcweir // FALLTHROUGH intended 547*cdf0e10cSrcweir case UNDERLINE_DOUBLE: 548*cdf0e10cSrcweir appendRect( 549*cdf0e10cSrcweir aTextLinesPolyPoly, 550*cdf0e10cSrcweir rStartPos, 551*cdf0e10cSrcweir 0, 552*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset - rTextLineInfo.mnLineHeight, 553*cdf0e10cSrcweir rLineWidth, 554*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset ); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir appendRect( 557*cdf0e10cSrcweir aTextLinesPolyPoly, 558*cdf0e10cSrcweir rStartPos, 559*cdf0e10cSrcweir 0, 560*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset + 2*rTextLineInfo.mnLineHeight, 561*cdf0e10cSrcweir rLineWidth, 562*cdf0e10cSrcweir rTextLineInfo.mnUnderlineOffset + 3*rTextLineInfo.mnLineHeight ); 563*cdf0e10cSrcweir break; 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir case UNDERLINE_DASHDOTDOT: // TODO(F3): NYI 566*cdf0e10cSrcweir // FALLTHROUGH intended 567*cdf0e10cSrcweir case UNDERLINE_DOTTED: 568*cdf0e10cSrcweir appendDashes( 569*cdf0e10cSrcweir aTextLinesPolyPoly, 570*cdf0e10cSrcweir rStartPos.getX(), 571*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnUnderlineOffset, 572*cdf0e10cSrcweir rLineWidth, 573*cdf0e10cSrcweir rTextLineInfo.mnLineHeight, 574*cdf0e10cSrcweir rTextLineInfo.mnLineHeight, 575*cdf0e10cSrcweir 2*rTextLineInfo.mnLineHeight ); 576*cdf0e10cSrcweir break; 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir case UNDERLINE_DASHDOT: // TODO(F3): NYI 579*cdf0e10cSrcweir // FALLTHROUGH intended 580*cdf0e10cSrcweir case UNDERLINE_DASH: 581*cdf0e10cSrcweir appendDashes( 582*cdf0e10cSrcweir aTextLinesPolyPoly, 583*cdf0e10cSrcweir rStartPos.getX(), 584*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnUnderlineOffset, 585*cdf0e10cSrcweir rLineWidth, 586*cdf0e10cSrcweir rTextLineInfo.mnLineHeight, 587*cdf0e10cSrcweir 3*rTextLineInfo.mnLineHeight, 588*cdf0e10cSrcweir 6*rTextLineInfo.mnLineHeight ); 589*cdf0e10cSrcweir break; 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir case UNDERLINE_LONGDASH: 592*cdf0e10cSrcweir appendDashes( 593*cdf0e10cSrcweir aTextLinesPolyPoly, 594*cdf0e10cSrcweir rStartPos.getX(), 595*cdf0e10cSrcweir rStartPos.getY() + rTextLineInfo.mnUnderlineOffset, 596*cdf0e10cSrcweir rLineWidth, 597*cdf0e10cSrcweir rTextLineInfo.mnLineHeight, 598*cdf0e10cSrcweir 6*rTextLineInfo.mnLineHeight, 599*cdf0e10cSrcweir 12*rTextLineInfo.mnLineHeight ); 600*cdf0e10cSrcweir break; 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir default: 603*cdf0e10cSrcweir ENSURE_OR_THROW( false, 604*cdf0e10cSrcweir "::cppcanvas::internal::createTextLinesPolyPolygon(): Unexpected underline case" ); 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir switch( rTextLineInfo.mnStrikeoutStyle ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir case STRIKEOUT_NONE: // nothing to do 610*cdf0e10cSrcweir // FALLTHROUGH intended 611*cdf0e10cSrcweir case STRIKEOUT_DONTKNOW: 612*cdf0e10cSrcweir break; 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir case STRIKEOUT_SLASH: // TODO(Q1): we should handle this in the text layer 615*cdf0e10cSrcweir // FALLTHROUGH intended 616*cdf0e10cSrcweir case STRIKEOUT_X: 617*cdf0e10cSrcweir break; 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir case STRIKEOUT_SINGLE: 620*cdf0e10cSrcweir appendRect( 621*cdf0e10cSrcweir aTextLinesPolyPoly, 622*cdf0e10cSrcweir rStartPos, 623*cdf0e10cSrcweir 0, 624*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset, 625*cdf0e10cSrcweir rLineWidth, 626*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset + rTextLineInfo.mnLineHeight ); 627*cdf0e10cSrcweir break; 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir case STRIKEOUT_BOLD: 630*cdf0e10cSrcweir appendRect( 631*cdf0e10cSrcweir aTextLinesPolyPoly, 632*cdf0e10cSrcweir rStartPos, 633*cdf0e10cSrcweir 0, 634*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset, 635*cdf0e10cSrcweir rLineWidth, 636*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset + 2*rTextLineInfo.mnLineHeight ); 637*cdf0e10cSrcweir break; 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir case STRIKEOUT_DOUBLE: 640*cdf0e10cSrcweir appendRect( 641*cdf0e10cSrcweir aTextLinesPolyPoly, 642*cdf0e10cSrcweir rStartPos, 643*cdf0e10cSrcweir 0, 644*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset - rTextLineInfo.mnLineHeight, 645*cdf0e10cSrcweir rLineWidth, 646*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset ); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir appendRect( 649*cdf0e10cSrcweir aTextLinesPolyPoly, 650*cdf0e10cSrcweir rStartPos, 651*cdf0e10cSrcweir 0, 652*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset + 2*rTextLineInfo.mnLineHeight, 653*cdf0e10cSrcweir rLineWidth, 654*cdf0e10cSrcweir rTextLineInfo.mnStrikeoutOffset + 3*rTextLineInfo.mnLineHeight ); 655*cdf0e10cSrcweir break; 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir default: 658*cdf0e10cSrcweir ENSURE_OR_THROW( false, 659*cdf0e10cSrcweir "::cppcanvas::internal::createTextLinesPolyPolygon(): Unexpected strikeout case" ); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir return aTextLinesPolyPoly; 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir ::basegfx::B2DRange calcDevicePixelBounds( const ::basegfx::B2DRange& rBounds, 666*cdf0e10cSrcweir const rendering::ViewState& viewState, 667*cdf0e10cSrcweir const rendering::RenderState& renderState ) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTransform; 670*cdf0e10cSrcweir ::canvas::tools::mergeViewAndRenderTransform( aTransform, 671*cdf0e10cSrcweir viewState, 672*cdf0e10cSrcweir renderState ); 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir ::basegfx::B2DRange aTransformedBounds; 675*cdf0e10cSrcweir return ::canvas::tools::calcTransformedRectBounds( aTransformedBounds, 676*cdf0e10cSrcweir rBounds, 677*cdf0e10cSrcweir aTransform ); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir // create line actions for text such as underline and 681*cdf0e10cSrcweir // strikeout 682*cdf0e10cSrcweir ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const double& rStartOffset, 683*cdf0e10cSrcweir const double& rLineWidth, 684*cdf0e10cSrcweir const TextLineInfo& rTextLineInfo ) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir return createTextLinesPolyPolygon( 687*cdf0e10cSrcweir ::basegfx::B2DPoint( rStartOffset, 688*cdf0e10cSrcweir 0.0 ), 689*cdf0e10cSrcweir rLineWidth, 690*cdf0e10cSrcweir rTextLineInfo ); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir } 694