1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_drawinglayer.hxx" 26 27 #include <drawinglayer/processor2d/vclprocessor2d.hxx> 28 #include <drawinglayer/primitive2d/textprimitive2d.hxx> 29 #include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx> 30 #include <tools/debug.hxx> 31 #include <vcl/outdev.hxx> 32 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 33 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 34 #include <basegfx/polygon/b2dpolygontools.hxx> 35 #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx> 36 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx> 37 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 38 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> 39 #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 40 #include <basegfx/polygon/b2dpolypolygontools.hxx> 41 #include <vclhelperbufferdevice.hxx> 42 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> 43 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> 44 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx> 45 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 46 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx> 47 #include <drawinglayer/primitive2d/pointarrayprimitive2d.hxx> 48 #include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx> 49 #include <svl/ctloptions.hxx> 50 #include <vcl/svapp.hxx> 51 #include <drawinglayer/primitive2d/pagepreviewprimitive2d.hxx> 52 #include <tools/diagnose_ex.h> 53 #include <vcl/metric.hxx> 54 #include <drawinglayer/primitive2d/textenumsprimitive2d.hxx> 55 #include <drawinglayer/primitive2d/epsprimitive2d.hxx> 56 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx> 57 #include <basegfx/color/bcolor.hxx> 58 #include <basegfx/matrix/b2dhommatrixtools.hxx> 59 #include <vcl/graph.hxx> 60 61 ////////////////////////////////////////////////////////////////////////////// 62 // control support 63 64 #include <com/sun/star/awt/XWindow2.hpp> 65 #include <com/sun/star/awt/PosSize.hpp> 66 #include <com/sun/star/awt/XView.hpp> 67 #include <drawinglayer/primitive2d/controlprimitive2d.hxx> 68 #include <drawinglayer/primitive2d/textlayoutdevice.hxx> 69 70 ////////////////////////////////////////////////////////////////////////////// 71 // for test, can be removed again 72 73 #include <basegfx/polygon/b2dpolygonclipper.hxx> 74 #include <basegfx/polygon/b2dtrapezoid.hxx> 75 76 ////////////////////////////////////////////////////////////////////////////// 77 78 using namespace com::sun::star; 79 80 ////////////////////////////////////////////////////////////////////////////// 81 82 namespace 83 { 84 sal_uInt32 calculateStepsForSvgGradient(const basegfx::BColor& rColorA, const basegfx::BColor& rColorB, double fDelta, double fDiscreteUnit) 85 { 86 // use color distance, assume to do every color step 87 sal_uInt32 nSteps(basegfx::fround(rColorA.getDistance(rColorB) * 255.0)); 88 89 if(nSteps) 90 { 91 // calc discrete length to change color each disctete unit (pixel) 92 const sal_uInt32 nDistSteps(basegfx::fround(fDelta / fDiscreteUnit)); 93 94 nSteps = std::min(nSteps, nDistSteps); 95 } 96 97 // reduce quality to 3 discrete units or every 3rd color step for rendering 98 nSteps /= 2; 99 100 // roughly cut when too big or too small (not full quality, reduce complexity) 101 nSteps = std::min(nSteps, sal_uInt32(255)); 102 nSteps = std::max(nSteps, sal_uInt32(1)); 103 104 return nSteps; 105 } 106 } // end of anonymous namespace 107 108 ////////////////////////////////////////////////////////////////////////////// 109 110 namespace drawinglayer 111 { 112 namespace processor2d 113 { 114 ////////////////////////////////////////////////////////////////////////////// 115 // UNO class usages 116 using ::com::sun::star::uno::Reference; 117 using ::com::sun::star::uno::UNO_QUERY; 118 using ::com::sun::star::uno::UNO_QUERY_THROW; 119 using ::com::sun::star::uno::Exception; 120 using ::com::sun::star::awt::XView; 121 using ::com::sun::star::awt::XGraphics; 122 using ::com::sun::star::awt::XWindow; 123 using ::com::sun::star::awt::PosSize::POSSIZE; 124 125 ////////////////////////////////////////////////////////////////////////////// 126 // rendering support 127 128 // directdraw of text simple portion or decorated portion primitive. When decorated, all the extra 129 // information is translated to VCL parameters and set at the font. 130 // Acceptance is restricted to no shearing and positive scaling in X and Y (no font mirroring 131 // for VCL) 132 void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(const primitive2d::TextSimplePortionPrimitive2D& rTextCandidate) 133 { 134 // decompose matrix to have position and size of text 135 basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rTextCandidate.getTextTransform()); 136 basegfx::B2DVector aFontScaling, aTranslate; 137 double fRotate, fShearX; 138 aLocalTransform.decompose(aFontScaling, aTranslate, fRotate, fShearX); 139 bool bPrimitiveAccepted(false); 140 141 if(basegfx::fTools::equalZero(fShearX)) 142 { 143 if(basegfx::fTools::less(aFontScaling.getX(), 0.0) && basegfx::fTools::less(aFontScaling.getY(), 0.0)) 144 { 145 // handle special case: If scale is negative in (x,y) (3rd quadrant), it can 146 // be expressed as rotation by PI. Use this since the Font rendering will not 147 // apply the negative scales in any form 148 aFontScaling = basegfx::absolute(aFontScaling); 149 fRotate += F_PI; 150 } 151 152 if(basegfx::fTools::more(aFontScaling.getX(), 0.0) && basegfx::fTools::more(aFontScaling.getY(), 0.0)) 153 { 154 // Get the VCL font (use FontHeight as FontWidth) 155 Font aFont(primitive2d::getVclFontFromFontAttribute( 156 rTextCandidate.getFontAttribute(), 157 aFontScaling.getX(), 158 aFontScaling.getY(), 159 fRotate, 160 rTextCandidate.getLocale())); 161 162 // handle additional font attributes 163 const primitive2d::TextDecoratedPortionPrimitive2D* pTCPP = 164 dynamic_cast<const primitive2d::TextDecoratedPortionPrimitive2D*>( &rTextCandidate ); 165 166 if( pTCPP != NULL ) 167 { 168 169 // set the color of text decorations 170 const basegfx::BColor aTextlineColor = maBColorModifierStack.getModifiedColor(pTCPP->getTextlineColor()); 171 mpOutputDevice->SetTextLineColor( Color(aTextlineColor) ); 172 173 // set Overline attribute 174 const FontUnderline eFontOverline(primitive2d::mapTextLineToFontUnderline( pTCPP->getFontOverline() )); 175 if( eFontOverline != UNDERLINE_NONE ) 176 { 177 aFont.SetOverline( eFontOverline ); 178 const basegfx::BColor aOverlineColor = maBColorModifierStack.getModifiedColor(pTCPP->getOverlineColor()); 179 mpOutputDevice->SetOverlineColor( Color(aOverlineColor) ); 180 if( pTCPP->getWordLineMode() ) 181 aFont.SetWordLineMode( true ); 182 } 183 184 // set Underline attribute 185 const FontUnderline eFontUnderline(primitive2d::mapTextLineToFontUnderline( pTCPP->getFontUnderline() )); 186 if( eFontUnderline != UNDERLINE_NONE ) 187 { 188 aFont.SetUnderline( eFontUnderline ); 189 if( pTCPP->getWordLineMode() ) 190 aFont.SetWordLineMode( true ); 191 //TODO: ??? if( pTCPP->getUnderlineAbove() ) 192 // aFont.SetUnderlineAbove( true ); 193 } 194 195 // set Strikeout attribute 196 const FontStrikeout eFontStrikeout(primitive2d::mapTextStrikeoutToFontStrikeout(pTCPP->getTextStrikeout())); 197 198 if( eFontStrikeout != STRIKEOUT_NONE ) 199 aFont.SetStrikeout( eFontStrikeout ); 200 201 // set EmphasisMark attribute 202 FontEmphasisMark eFontEmphasisMark = EMPHASISMARK_NONE; 203 switch( pTCPP->getTextEmphasisMark() ) 204 { 205 default: 206 DBG_WARNING1( "DrawingLayer: Unknown EmphasisMark style (%d)!", pTCPP->getTextEmphasisMark() ); 207 // fall through 208 case primitive2d::TEXT_EMPHASISMARK_NONE: eFontEmphasisMark = EMPHASISMARK_NONE; break; 209 case primitive2d::TEXT_EMPHASISMARK_DOT: eFontEmphasisMark = EMPHASISMARK_DOT; break; 210 case primitive2d::TEXT_EMPHASISMARK_CIRCLE: eFontEmphasisMark = EMPHASISMARK_CIRCLE; break; 211 case primitive2d::TEXT_EMPHASISMARK_DISC: eFontEmphasisMark = EMPHASISMARK_DISC; break; 212 case primitive2d::TEXT_EMPHASISMARK_ACCENT: eFontEmphasisMark = EMPHASISMARK_ACCENT; break; 213 } 214 215 if( eFontEmphasisMark != EMPHASISMARK_NONE ) 216 { 217 DBG_ASSERT( (pTCPP->getEmphasisMarkAbove() != pTCPP->getEmphasisMarkBelow()), 218 "DrawingLayer: Bad EmphasisMark position!" ); 219 if( pTCPP->getEmphasisMarkAbove() ) 220 eFontEmphasisMark |= EMPHASISMARK_POS_ABOVE; 221 else 222 eFontEmphasisMark |= EMPHASISMARK_POS_BELOW; 223 aFont.SetEmphasisMark( eFontEmphasisMark ); 224 } 225 226 // set Relief attribute 227 FontRelief eFontRelief = RELIEF_NONE; 228 switch( pTCPP->getTextRelief() ) 229 { 230 default: 231 DBG_WARNING1( "DrawingLayer: Unknown Relief style (%d)!", pTCPP->getTextRelief() ); 232 // fall through 233 case primitive2d::TEXT_RELIEF_NONE: eFontRelief = RELIEF_NONE; break; 234 case primitive2d::TEXT_RELIEF_EMBOSSED: eFontRelief = RELIEF_EMBOSSED; break; 235 case primitive2d::TEXT_RELIEF_ENGRAVED: eFontRelief = RELIEF_ENGRAVED; break; 236 } 237 238 if( eFontRelief != RELIEF_NONE ) 239 aFont.SetRelief( eFontRelief ); 240 241 // set Shadow attribute 242 if( pTCPP->getShadow() ) 243 aFont.SetShadow( true ); 244 } 245 246 // create transformed integer DXArray in view coordinate system 247 ::std::vector< sal_Int32 > aTransformedDXArray; 248 249 if(rTextCandidate.getDXArray().size()) 250 { 251 aTransformedDXArray.reserve(rTextCandidate.getDXArray().size()); 252 const basegfx::B2DVector aPixelVector(maCurrentTransformation * basegfx::B2DVector(1.0, 0.0)); 253 const double fPixelVectorFactor(aPixelVector.getLength()); 254 255 for(::std::vector< double >::const_iterator aStart(rTextCandidate.getDXArray().begin()); 256 aStart != rTextCandidate.getDXArray().end(); aStart++) 257 { 258 aTransformedDXArray.push_back(basegfx::fround((*aStart) * fPixelVectorFactor)); 259 } 260 } 261 262 // set parameters and paint text snippet 263 const basegfx::BColor aRGBFontColor(maBColorModifierStack.getModifiedColor(rTextCandidate.getFontColor())); 264 const basegfx::B2DPoint aPoint(aLocalTransform * basegfx::B2DPoint(0.0, 0.0)); 265 const Point aStartPoint(basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY())); 266 const sal_uInt32 nOldLayoutMode(mpOutputDevice->GetLayoutMode()); 267 268 if(rTextCandidate.getFontAttribute().getRTL()) 269 { 270 sal_uInt32 nRTLLayoutMode(nOldLayoutMode & ~(TEXT_LAYOUT_COMPLEX_DISABLED|TEXT_LAYOUT_BIDI_STRONG)); 271 nRTLLayoutMode |= TEXT_LAYOUT_BIDI_RTL|TEXT_LAYOUT_TEXTORIGIN_LEFT; 272 mpOutputDevice->SetLayoutMode(nRTLLayoutMode); 273 } 274 275 mpOutputDevice->SetFont(aFont); 276 mpOutputDevice->SetTextColor(Color(aRGBFontColor)); 277 278 if(aTransformedDXArray.size()) 279 { 280 mpOutputDevice->DrawTextArray( 281 aStartPoint, 282 rTextCandidate.getText(), 283 &(aTransformedDXArray[0]), 284 rTextCandidate.getTextPosition(), 285 rTextCandidate.getTextLength()); 286 } 287 else 288 { 289 mpOutputDevice->DrawText( 290 aStartPoint, 291 rTextCandidate.getText(), 292 rTextCandidate.getTextPosition(), 293 rTextCandidate.getTextLength()); 294 } 295 296 if(rTextCandidate.getFontAttribute().getRTL()) 297 { 298 mpOutputDevice->SetLayoutMode(nOldLayoutMode); 299 } 300 301 bPrimitiveAccepted = true; 302 } 303 } 304 305 if(!bPrimitiveAccepted) 306 { 307 // let break down 308 process(rTextCandidate.get2DDecomposition(getViewInformation2D())); 309 } 310 } 311 312 // direct draw of hairline 313 void VclProcessor2D::RenderPolygonHairlinePrimitive2D(const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate, bool bPixelBased) 314 { 315 const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rPolygonCandidate.getBColor())); 316 mpOutputDevice->SetLineColor(Color(aHairlineColor)); 317 mpOutputDevice->SetFillColor(); 318 319 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon()); 320 aLocalPolygon.transform(maCurrentTransformation); 321 322 static bool bCheckTrapezoidDecomposition(false); 323 static bool bShowOutlinesThere(false); 324 if(bCheckTrapezoidDecomposition) 325 { 326 // clip against discrete ViewPort 327 const basegfx::B2DRange& rDiscreteViewport = getViewInformation2D().getDiscreteViewport(); 328 basegfx::B2DPolyPolygon aLocalPolyPolygon(basegfx::tools::clipPolygonOnRange( 329 aLocalPolygon, rDiscreteViewport, true, false)); 330 331 if(aLocalPolyPolygon.count()) 332 { 333 // subdivide 334 aLocalPolyPolygon = basegfx::tools::adaptiveSubdivideByDistance( 335 aLocalPolyPolygon, 0.5); 336 337 // trapezoidize 338 static double fLineWidth(2.0); 339 basegfx::B2DTrapezoidVector aB2DTrapezoidVector; 340 basegfx::tools::createLineTrapezoidFromB2DPolyPolygon(aB2DTrapezoidVector, aLocalPolyPolygon, fLineWidth); 341 342 const sal_uInt32 nCount(aB2DTrapezoidVector.size()); 343 344 if(nCount) 345 { 346 basegfx::BColor aInvPolygonColor(aHairlineColor); 347 aInvPolygonColor.invert(); 348 349 for(sal_uInt32 a(0); a < nCount; a++) 350 { 351 const basegfx::B2DPolygon aTempPolygon(aB2DTrapezoidVector[a].getB2DPolygon()); 352 353 if(bShowOutlinesThere) 354 { 355 mpOutputDevice->SetFillColor(Color(aHairlineColor)); 356 mpOutputDevice->SetLineColor(); 357 } 358 359 mpOutputDevice->DrawPolygon(aTempPolygon); 360 361 if(bShowOutlinesThere) 362 { 363 mpOutputDevice->SetFillColor(); 364 mpOutputDevice->SetLineColor(Color(aInvPolygonColor)); 365 mpOutputDevice->DrawPolyLine(aTempPolygon, 0.0); 366 } 367 } 368 } 369 } 370 } 371 else 372 { 373 if(bPixelBased && getOptionsDrawinglayer().IsAntiAliasing() && getOptionsDrawinglayer().IsSnapHorVerLinesToDiscrete()) 374 { 375 // #i98289# 376 // when a Hairline is painted and AntiAliasing is on the option SnapHorVerLinesToDiscrete 377 // allows to suppress AntiAliasing for pure horizontal or vertical lines. This is done since 378 // not-AntiAliased such lines look more pleasing to the eye (e.g. 2D chart content). This 379 // NEEDS to be done in discrete coordinates, so only useful for pixel based rendering. 380 aLocalPolygon = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aLocalPolygon); 381 } 382 383 mpOutputDevice->DrawPolyLine(aLocalPolygon, 0.0); 384 } 385 } 386 387 // direct draw of transformed BitmapEx primitive 388 void VclProcessor2D::RenderBitmapPrimitive2D(const primitive2d::BitmapPrimitive2D& rBitmapCandidate) 389 { 390 BitmapEx aBitmapEx(rBitmapCandidate.getBitmapEx()); 391 const basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rBitmapCandidate.getTransform()); 392 393 if(maBColorModifierStack.count()) 394 { 395 aBitmapEx = aBitmapEx.ModifyBitmapEx(maBColorModifierStack); 396 397 if(aBitmapEx.IsEmpty()) 398 { 399 // color gets completely replaced, get it 400 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor())); 401 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 402 aPolygon.transform(aLocalTransform); 403 404 mpOutputDevice->SetFillColor(Color(aModifiedColor)); 405 mpOutputDevice->SetLineColor(); 406 mpOutputDevice->DrawPolygon(aPolygon); 407 408 return; 409 } 410 } 411 412 // decompose matrix to check for shear, rotate and mirroring 413 basegfx::B2DVector aScale, aTranslate; 414 double fRotate, fShearX; 415 416 aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX); 417 418 const bool bRotated(!basegfx::fTools::equalZero(fRotate)); 419 const bool bSheared(!basegfx::fTools::equalZero(fShearX)); 420 421 if(!aBitmapEx.IsTransparent() && (bSheared || bRotated)) 422 { 423 // parts will be uncovered, extend aBitmapEx with a mask bitmap 424 const Bitmap aContent(aBitmapEx.GetBitmap()); 425 #if defined(MACOSX) 426 AlphaMask aMaskBmp( aContent.GetSizePixel()); 427 aMaskBmp.Erase( 0); 428 #else 429 Bitmap aMaskBmp( aContent.GetSizePixel(), 1); 430 aMaskBmp.Erase(Color(COL_BLACK)); // #122758# Initialize to non-transparent 431 #endif 432 aBitmapEx = BitmapEx(aContent, aMaskBmp); 433 } 434 435 // draw using OutputDevice'sDrawTransformedBitmapEx 436 mpOutputDevice->DrawTransformedBitmapEx(aLocalTransform, aBitmapEx); 437 } 438 439 void VclProcessor2D::RenderFillGraphicPrimitive2D(const primitive2d::FillGraphicPrimitive2D& rFillBitmapCandidate) 440 { 441 const attribute::FillGraphicAttribute& rFillGraphicAttribute(rFillBitmapCandidate.getFillGraphic()); 442 bool bPrimitiveAccepted(false); 443 static bool bTryTilingDirect = true; 444 445 // #121194# when tiling is used and content is bitmap-based, do direct tiling in the 446 // renderer on pixel base to ensure tight fitting. Do not do this when 447 // the fill is rotated or sheared. 448 449 // ovveride static bool (for debug) and tiling is active 450 if(bTryTilingDirect && rFillGraphicAttribute.getTiling()) 451 { 452 // content is bitmap(ex) 453 // 454 // for SVG support, force decomposition when SVG is present. This will lead to use 455 // the primitive representation of the svg directly. 456 // 457 // when graphic is animated, force decomposition to use the correct graphic, else 458 // fill style will not be animated 459 if(GRAPHIC_BITMAP == rFillGraphicAttribute.getGraphic().GetType() 460 && !rFillGraphicAttribute.getGraphic().getSvgData().get() 461 && !rFillGraphicAttribute.getGraphic().IsAnimated()) 462 { 463 // decompose matrix to check for shear, rotate and mirroring 464 basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rFillBitmapCandidate.getTransformation()); 465 basegfx::B2DVector aScale, aTranslate; 466 double fRotate, fShearX; 467 aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX); 468 469 // when nopt rotated/sheared 470 if(basegfx::fTools::equalZero(fRotate) && basegfx::fTools::equalZero(fShearX)) 471 { 472 // no shear or rotate, draw direct in pixel coordinates 473 bPrimitiveAccepted = true; 474 475 // transform object range to device coordinates (pixels). Use 476 // the device transformation for better accuracy 477 basegfx::B2DRange aObjectRange(aTranslate, aTranslate + aScale); 478 aObjectRange.transform(mpOutputDevice->GetViewTransformation()); 479 480 // extract discrete size of object 481 const sal_Int32 nOWidth(basegfx::fround(aObjectRange.getWidth())); 482 const sal_Int32 nOHeight(basegfx::fround(aObjectRange.getHeight())); 483 484 // only do something when object has a size in discrete units 485 if(nOWidth > 0 && nOHeight > 0) 486 { 487 // transform graphic range to device coordinates (pixels). Use 488 // the device transformation for better accuracy 489 basegfx::B2DRange aGraphicRange(rFillGraphicAttribute.getGraphicRange()); 490 aGraphicRange.transform(mpOutputDevice->GetViewTransformation() * aLocalTransform); 491 492 // extract discrete size of graphic 493 const sal_Int32 nBWidth(basegfx::fround(aGraphicRange.getWidth())); 494 const sal_Int32 nBHeight(basegfx::fround(aGraphicRange.getHeight())); 495 496 // only do something when bitmap fill has a size in discrete units 497 if(nBWidth > 0 && nBHeight > 0) 498 { 499 // nBWidth, nBHeight is the pixel size of the neede bitmap. To not need to scale it 500 // in vcl many times, create a size-optimized version 501 const Size aNeededBitmapSizePixel(nBWidth, nBHeight); 502 BitmapEx aBitmapEx(rFillGraphicAttribute.getGraphic().GetBitmapEx()); 503 static bool bEnablePreScaling(true); 504 const bool bPreScaled(bEnablePreScaling && nBWidth * nBHeight < (250 * 250)); 505 506 if(bPreScaled) 507 { 508 // ... but only up to a maximum size, else it gets too expensive 509 aBitmapEx.Scale(aNeededBitmapSizePixel, BMP_SCALE_INTERPOLATE); 510 } 511 512 bool bPainted(false); 513 514 if(maBColorModifierStack.count()) 515 { 516 // when color modifier, apply to bitmap 517 aBitmapEx = aBitmapEx.ModifyBitmapEx(maBColorModifierStack); 518 519 // impModifyBitmapEx uses empty bitmap as sign to return that 520 // the content will be completely replaced to mono color, use shortcut 521 if(aBitmapEx.IsEmpty()) 522 { 523 // color gets completely replaced, get it 524 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor())); 525 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 526 aPolygon.transform(aLocalTransform); 527 528 mpOutputDevice->SetFillColor(Color(aModifiedColor)); 529 mpOutputDevice->SetLineColor(); 530 mpOutputDevice->DrawPolygon(aPolygon); 531 532 bPainted = true; 533 } 534 } 535 536 if(!bPainted) 537 { 538 sal_Int32 nBLeft(basegfx::fround(aGraphicRange.getMinX())); 539 sal_Int32 nBTop(basegfx::fround(aGraphicRange.getMinY())); 540 const sal_Int32 nOLeft(basegfx::fround(aObjectRange.getMinX())); 541 const sal_Int32 nOTop(basegfx::fround(aObjectRange.getMinY())); 542 sal_Int32 nPosX(0); 543 sal_Int32 nPosY(0); 544 545 if(nBLeft > nOLeft) 546 { 547 const sal_Int32 nDiff((nBLeft / nBWidth) + 1); 548 549 nPosX -= nDiff; 550 nBLeft -= nDiff * nBWidth; 551 } 552 553 if(nBLeft + nBWidth <= nOLeft) 554 { 555 const sal_Int32 nDiff(-nBLeft / nBWidth); 556 557 nPosX += nDiff; 558 nBLeft += nDiff * nBWidth; 559 } 560 561 if(nBTop > nOTop) 562 { 563 const sal_Int32 nDiff((nBTop / nBHeight) + 1); 564 565 nPosY -= nDiff; 566 nBTop -= nDiff * nBHeight; 567 } 568 569 if(nBTop + nBHeight <= nOTop) 570 { 571 const sal_Int32 nDiff(-nBTop / nBHeight); 572 573 nPosY += nDiff; 574 nBTop += nDiff * nBHeight; 575 } 576 577 // prepare OutDev 578 const Point aEmptyPoint(0, 0); 579 const Rectangle aVisiblePixel(aEmptyPoint, mpOutputDevice->GetOutputSizePixel()); 580 const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled()); 581 mpOutputDevice->EnableMapMode(false); 582 583 // check if offset is used 584 const sal_Int32 nOffsetX(basegfx::fround(rFillGraphicAttribute.getOffsetX() * nBWidth)); 585 586 if(nOffsetX) 587 { 588 // offset in X, so iterate over Y first and draw lines 589 for(sal_Int32 nYPos(nBTop); nYPos < nOTop + nOHeight; nYPos += nBHeight, nPosY++) 590 { 591 for(sal_Int32 nXPos(nPosY % 2 ? nBLeft - nBWidth + nOffsetX : nBLeft); 592 nXPos < nOLeft + nOWidth; nXPos += nBWidth) 593 { 594 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel); 595 596 if(aOutRectPixel.IsOver(aVisiblePixel)) 597 { 598 if(bPreScaled) 599 { 600 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx); 601 } 602 else 603 { 604 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx); 605 } 606 } 607 } 608 } 609 } 610 else 611 { 612 // check if offset is used 613 const sal_Int32 nOffsetY(basegfx::fround(rFillGraphicAttribute.getOffsetY() * nBHeight)); 614 615 // possible offset in Y, so iterate over X first and draw columns 616 for(sal_Int32 nXPos(nBLeft); nXPos < nOLeft + nOWidth; nXPos += nBWidth, nPosX++) 617 { 618 for(sal_Int32 nYPos(nPosX % 2 ? nBTop - nBHeight + nOffsetY : nBTop); 619 nYPos < nOTop + nOHeight; nYPos += nBHeight) 620 { 621 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel); 622 623 if(aOutRectPixel.IsOver(aVisiblePixel)) 624 { 625 if(bPreScaled) 626 { 627 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx); 628 } 629 else 630 { 631 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx); 632 } 633 } 634 } 635 } 636 } 637 638 // restore OutDev 639 mpOutputDevice->EnableMapMode(bWasEnabled); 640 } 641 } 642 } 643 } 644 } 645 } 646 647 if(!bPrimitiveAccepted) 648 { 649 // do not accept, use decomposition 650 process(rFillBitmapCandidate.get2DDecomposition(getViewInformation2D())); 651 } 652 } 653 654 // direct draw of Graphic 655 void VclProcessor2D::RenderPolyPolygonGraphicPrimitive2D(const primitive2d::PolyPolygonGraphicPrimitive2D& rPolygonCandidate) 656 { 657 bool bDone(false); 658 const basegfx::B2DPolyPolygon& rPolyPolygon = rPolygonCandidate.getB2DPolyPolygon(); 659 660 // #121194# Todo: check if this works 661 if(!rPolyPolygon.count()) 662 { 663 // empty polyPolygon, done 664 bDone = true; 665 } 666 else 667 { 668 const attribute::FillGraphicAttribute& rFillGraphicAttribute = rPolygonCandidate.getFillGraphic(); 669 670 // try to catch cases where the graphic will be color-modified to a single 671 // color (e.g. shadow) 672 switch(rFillGraphicAttribute.getGraphic().GetType()) 673 { 674 case GRAPHIC_GDIMETAFILE: 675 { 676 // metafiles are potentially transparent, cannot optimize�, not done 677 break; 678 } 679 case GRAPHIC_BITMAP: 680 { 681 if(!rFillGraphicAttribute.getGraphic().IsTransparent() && !rFillGraphicAttribute.getGraphic().IsAlpha()) 682 { 683 // bitmap is not transparent and has no alpha 684 const sal_uInt32 nBColorModifierStackCount(maBColorModifierStack.count()); 685 686 if(nBColorModifierStackCount) 687 { 688 const basegfx::BColorModifier& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1); 689 690 if(basegfx::BCOLORMODIFYMODE_REPLACE == rTopmostModifier.getMode()) 691 { 692 // the bitmap fill is in unified color, so we can replace it with 693 // a single polygon fill. The form of the fill depends on tiling 694 if(rFillGraphicAttribute.getTiling()) 695 { 696 // with tiling, fill the whole PolyPolygon with the modifier color 697 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolyPolygon); 698 699 aLocalPolyPolygon.transform(maCurrentTransformation); 700 mpOutputDevice->SetLineColor(); 701 mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); 702 mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon); 703 } 704 else 705 { 706 // without tiling, only the area common to the bitmap tile and the 707 // PolyPolygon is filled. Create the bitmap tile area in object 708 // coordinates. For this, the object transformation needs to be created 709 // from the already scaled PolyPolygon. The tile area in object 710 // coordinates wil always be non-rotated, so it's not necessary to 711 // work with a polygon here 712 basegfx::B2DRange aTileRange(rFillGraphicAttribute.getGraphicRange()); 713 const basegfx::B2DRange aPolyPolygonRange(rPolyPolygon.getB2DRange()); 714 const basegfx::B2DHomMatrix aNewObjectTransform( 715 basegfx::tools::createScaleTranslateB2DHomMatrix( 716 aPolyPolygonRange.getRange(), 717 aPolyPolygonRange.getMinimum())); 718 719 aTileRange.transform(aNewObjectTransform); 720 721 // now clip the object polyPolygon against the tile range 722 // to get the common area 723 basegfx::B2DPolyPolygon aTarget = basegfx::tools::clipPolyPolygonOnRange( 724 rPolyPolygon, 725 aTileRange, 726 true, 727 false); 728 729 if(aTarget.count()) 730 { 731 aTarget.transform(maCurrentTransformation); 732 mpOutputDevice->SetLineColor(); 733 mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); 734 mpOutputDevice->DrawPolyPolygon(aTarget); 735 } 736 } 737 738 // simplified output executed, we are done 739 bDone = true; 740 } 741 } 742 } 743 break; 744 } 745 default: //GRAPHIC_NONE, GRAPHIC_DEFAULT 746 { 747 // empty graphic, we are done 748 bDone = true; 749 break; 750 } 751 } 752 } 753 754 if(!bDone) 755 { 756 // use default decomposition 757 process(rPolygonCandidate.get2DDecomposition(getViewInformation2D())); 758 } 759 } 760 761 // mask group. Force output to VDev and create mask from given mask 762 void VclProcessor2D::RenderMaskPrimitive2DPixel(const primitive2d::MaskPrimitive2D& rMaskCandidate) 763 { 764 if(rMaskCandidate.getChildren().hasElements()) 765 { 766 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask()); 767 768 if(aMask.count()) 769 { 770 aMask.transform(maCurrentTransformation); 771 const basegfx::B2DRange aRange(basegfx::tools::getRange(aMask)); 772 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 773 774 if(aBufferDevice.isVisible()) 775 { 776 // remember last OutDev and set to content 777 OutputDevice* pLastOutputDevice = mpOutputDevice; 778 mpOutputDevice = &aBufferDevice.getContent(); 779 780 // paint to it 781 process(rMaskCandidate.getChildren()); 782 783 // back to old OutDev 784 mpOutputDevice = pLastOutputDevice; 785 786 // draw mask 787 if(getOptionsDrawinglayer().IsAntiAliasing()) 788 { 789 // with AA, use 8bit AlphaMask to get nice borders 790 VirtualDevice& rTransparence = aBufferDevice.getTransparence(); 791 rTransparence.SetLineColor(); 792 rTransparence.SetFillColor(COL_BLACK); 793 rTransparence.DrawPolyPolygon(aMask); 794 795 // dump buffer to outdev 796 aBufferDevice.paint(); 797 } 798 else 799 { 800 // No AA, use 1bit mask 801 VirtualDevice& rMask = aBufferDevice.getMask(); 802 rMask.SetLineColor(); 803 rMask.SetFillColor(COL_BLACK); 804 rMask.DrawPolyPolygon(aMask); 805 806 // dump buffer to outdev 807 aBufferDevice.paint(); 808 } 809 } 810 } 811 } 812 } 813 814 // modified color group. Force output to unified color. 815 void VclProcessor2D::RenderModifiedColorPrimitive2D(const primitive2d::ModifiedColorPrimitive2D& rModifiedCandidate) 816 { 817 if(rModifiedCandidate.getChildren().hasElements()) 818 { 819 maBColorModifierStack.push(rModifiedCandidate.getColorModifier()); 820 process(rModifiedCandidate.getChildren()); 821 maBColorModifierStack.pop(); 822 } 823 } 824 825 // unified sub-transparence. Draw to VDev first. 826 void VclProcessor2D::RenderUnifiedTransparencePrimitive2D(const primitive2d::UnifiedTransparencePrimitive2D& rTransCandidate) 827 { 828 static bool bForceToDecomposition(false); 829 830 if(rTransCandidate.getChildren().hasElements()) 831 { 832 if(bForceToDecomposition) 833 { 834 // use decomposition 835 process(rTransCandidate.get2DDecomposition(getViewInformation2D())); 836 } 837 else 838 { 839 if(0.0 == rTransCandidate.getTransparence()) 840 { 841 // no transparence used, so just use the content 842 process(rTransCandidate.getChildren()); 843 } 844 else if(rTransCandidate.getTransparence() > 0.0 && rTransCandidate.getTransparence() < 1.0) 845 { 846 // transparence is in visible range 847 basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D())); 848 aRange.transform(maCurrentTransformation); 849 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 850 851 if(aBufferDevice.isVisible()) 852 { 853 // remember last OutDev and set to content 854 OutputDevice* pLastOutputDevice = mpOutputDevice; 855 mpOutputDevice = &aBufferDevice.getContent(); 856 857 // paint content to it 858 process(rTransCandidate.getChildren()); 859 860 // back to old OutDev 861 mpOutputDevice = pLastOutputDevice; 862 863 // dump buffer to outdev using given transparence 864 aBufferDevice.paint(rTransCandidate.getTransparence()); 865 } 866 } 867 } 868 } 869 } 870 871 // sub-transparence group. Draw to VDev first. 872 void VclProcessor2D::RenderTransparencePrimitive2D(const primitive2d::TransparencePrimitive2D& rTransCandidate) 873 { 874 if(rTransCandidate.getChildren().hasElements()) 875 { 876 basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D())); 877 aRange.transform(maCurrentTransformation); 878 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 879 880 if(aBufferDevice.isVisible()) 881 { 882 // remember last OutDev and set to content 883 OutputDevice* pLastOutputDevice = mpOutputDevice; 884 mpOutputDevice = &aBufferDevice.getContent(); 885 886 // paint content to it 887 process(rTransCandidate.getChildren()); 888 889 // set to mask 890 mpOutputDevice = &aBufferDevice.getTransparence(); 891 892 // when painting transparence masks, reset the color stack 893 basegfx::BColorModifierStack aLastBColorModifierStack(maBColorModifierStack); 894 maBColorModifierStack = basegfx::BColorModifierStack(); 895 896 // paint mask to it (always with transparence intensities, evtl. with AA) 897 process(rTransCandidate.getTransparence()); 898 899 // back to old color stack 900 maBColorModifierStack = aLastBColorModifierStack; 901 902 // back to old OutDev 903 mpOutputDevice = pLastOutputDevice; 904 905 // dump buffer to outdev 906 aBufferDevice.paint(); 907 } 908 } 909 } 910 911 // transform group. 912 void VclProcessor2D::RenderTransformPrimitive2D(const primitive2d::TransformPrimitive2D& rTransformCandidate) 913 { 914 // remember current transformation and ViewInformation 915 const basegfx::B2DHomMatrix aLastCurrentTransformation(maCurrentTransformation); 916 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 917 918 // create new transformations for CurrentTransformation 919 // and for local ViewInformation2D 920 maCurrentTransformation = maCurrentTransformation * rTransformCandidate.getTransformation(); 921 const geometry::ViewInformation2D aViewInformation2D( 922 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(), 923 getViewInformation2D().getViewTransformation(), 924 getViewInformation2D().getViewport(), 925 getViewInformation2D().getVisualizedPage(), 926 getViewInformation2D().getViewTime(), 927 getViewInformation2D().getExtendedInformationSequence()); 928 updateViewInformation(aViewInformation2D); 929 930 // proccess content 931 process(rTransformCandidate.getChildren()); 932 933 // restore transformations 934 maCurrentTransformation = aLastCurrentTransformation; 935 updateViewInformation(aLastViewInformation2D); 936 } 937 938 // new XDrawPage for ViewInformation2D 939 void VclProcessor2D::RenderPagePreviewPrimitive2D(const primitive2d::PagePreviewPrimitive2D& rPagePreviewCandidate) 940 { 941 // remember current transformation and ViewInformation 942 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 943 944 // create new local ViewInformation2D 945 const geometry::ViewInformation2D aViewInformation2D( 946 getViewInformation2D().getObjectTransformation(), 947 getViewInformation2D().getViewTransformation(), 948 getViewInformation2D().getViewport(), 949 rPagePreviewCandidate.getXDrawPage(), 950 getViewInformation2D().getViewTime(), 951 getViewInformation2D().getExtendedInformationSequence()); 952 updateViewInformation(aViewInformation2D); 953 954 // proccess decomposed content 955 process(rPagePreviewCandidate.get2DDecomposition(getViewInformation2D())); 956 957 // restore transformations 958 updateViewInformation(aLastViewInformation2D); 959 } 960 961 // marker 962 void VclProcessor2D::RenderMarkerArrayPrimitive2D(const primitive2d::MarkerArrayPrimitive2D& rMarkArrayCandidate) 963 { 964 static bool bCheckCompleteMarkerDecompose(false); 965 if(bCheckCompleteMarkerDecompose) 966 { 967 process(rMarkArrayCandidate.get2DDecomposition(getViewInformation2D())); 968 return; 969 } 970 971 // get data 972 const std::vector< basegfx::B2DPoint >& rPositions = rMarkArrayCandidate.getPositions(); 973 const sal_uInt32 nCount(rPositions.size()); 974 975 if(nCount && !rMarkArrayCandidate.getMarker().IsEmpty()) 976 { 977 // get pixel size 978 const BitmapEx& rMarker(rMarkArrayCandidate.getMarker()); 979 const Size aBitmapSize(rMarker.GetSizePixel()); 980 981 if(aBitmapSize.Width() && aBitmapSize.Height()) 982 { 983 // get discrete half size 984 const basegfx::B2DVector aDiscreteHalfSize( 985 (aBitmapSize.getWidth() - 1.0) * 0.5, 986 (aBitmapSize.getHeight() - 1.0) * 0.5); 987 const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled()); 988 989 // do not forget evtl. moved origin in target device MapMode when 990 // switching it off; it would be missing and lead to wrong positions. 991 // All his could be done using logic sizes and coordinates, too, but 992 // we want a 1:1 bitmap rendering here, so it's more safe and faster 993 // to work with switching off MapMode usage completely. 994 const Point aOrigin(mpOutputDevice->GetMapMode().GetOrigin()); 995 996 mpOutputDevice->EnableMapMode(false); 997 998 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++) 999 { 1000 const basegfx::B2DPoint aDiscreteTopLeft((maCurrentTransformation * (*aIter)) - aDiscreteHalfSize); 1001 const Point aDiscretePoint(basegfx::fround(aDiscreteTopLeft.getX()), basegfx::fround(aDiscreteTopLeft.getY())); 1002 1003 mpOutputDevice->DrawBitmapEx(aDiscretePoint + aOrigin, rMarker); 1004 } 1005 1006 mpOutputDevice->EnableMapMode(bWasEnabled); 1007 } 1008 } 1009 } 1010 1011 // point 1012 void VclProcessor2D::RenderPointArrayPrimitive2D(const primitive2d::PointArrayPrimitive2D& rPointArrayCandidate) 1013 { 1014 const std::vector< basegfx::B2DPoint >& rPositions = rPointArrayCandidate.getPositions(); 1015 const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(rPointArrayCandidate.getRGBColor())); 1016 const Color aVCLColor(aRGBColor); 1017 1018 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++) 1019 { 1020 const basegfx::B2DPoint aViewPosition(maCurrentTransformation * (*aIter)); 1021 const Point aPos(basegfx::fround(aViewPosition.getX()), basegfx::fround(aViewPosition.getY())); 1022 1023 mpOutputDevice->DrawPixel(aPos, aVCLColor); 1024 } 1025 } 1026 1027 void VclProcessor2D::RenderPolygonStrokePrimitive2D(const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokeCandidate) 1028 { 1029 // #i101491# method restructured to clearly use the DrawPolyLine 1030 // calls starting from a deined line width 1031 const attribute::LineAttribute& rLineAttribute = rPolygonStrokeCandidate.getLineAttribute(); 1032 const double fLineWidth(rLineAttribute.getWidth()); 1033 bool bDone(false); 1034 1035 if(basegfx::fTools::more(fLineWidth, 0.0)) 1036 { 1037 const basegfx::B2DVector aDiscreteUnit(maCurrentTransformation * basegfx::B2DVector(fLineWidth, 0.0)); 1038 const double fDiscreteLineWidth(aDiscreteUnit.getLength()); 1039 const attribute::StrokeAttribute& rStrokeAttribute = rPolygonStrokeCandidate.getStrokeAttribute(); 1040 const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rLineAttribute.getColor())); 1041 basegfx::B2DPolyPolygon aHairlinePolyPolygon; 1042 1043 mpOutputDevice->SetLineColor(Color(aHairlineColor)); 1044 mpOutputDevice->SetFillColor(); 1045 1046 if(0.0 == rStrokeAttribute.getFullDotDashLen()) 1047 { 1048 // no line dashing, just copy 1049 aHairlinePolyPolygon.append(rPolygonStrokeCandidate.getB2DPolygon()); 1050 } 1051 else 1052 { 1053 // else apply LineStyle 1054 basegfx::tools::applyLineDashing(rPolygonStrokeCandidate.getB2DPolygon(), 1055 rStrokeAttribute.getDotDashArray(), 1056 &aHairlinePolyPolygon, 0, rStrokeAttribute.getFullDotDashLen()); 1057 } 1058 1059 const sal_uInt32 nCount(aHairlinePolyPolygon.count()); 1060 1061 if(nCount) 1062 { 1063 const bool bAntiAliased(getOptionsDrawinglayer().IsAntiAliasing()); 1064 aHairlinePolyPolygon.transform(maCurrentTransformation); 1065 1066 if(bAntiAliased) 1067 { 1068 if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.0)) 1069 { 1070 // line in range ]0.0 .. 1.0[ 1071 // paint as simple hairline 1072 for(sal_uInt32 a(0); a < nCount; a++) 1073 { 1074 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0); 1075 } 1076 1077 bDone = true; 1078 } 1079 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.0)) 1080 { 1081 // line in range [1.0 .. 2.0[ 1082 // paint as 2x2 with dynamic line distance 1083 basegfx::B2DHomMatrix aMat; 1084 const double fDistance(fDiscreteLineWidth - 1.0); 1085 const double fHalfDistance(fDistance * 0.5); 1086 1087 for(sal_uInt32 a(0); a < nCount; a++) 1088 { 1089 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1090 1091 aMat.set(0, 2, -fHalfDistance); 1092 aMat.set(1, 2, -fHalfDistance); 1093 aCandidate.transform(aMat); 1094 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1095 1096 aMat.set(0, 2, fDistance); 1097 aMat.set(1, 2, 0.0); 1098 aCandidate.transform(aMat); 1099 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1100 1101 aMat.set(0, 2, 0.0); 1102 aMat.set(1, 2, fDistance); 1103 aCandidate.transform(aMat); 1104 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1105 1106 aMat.set(0, 2, -fDistance); 1107 aMat.set(1, 2, 0.0); 1108 aCandidate.transform(aMat); 1109 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1110 } 1111 1112 bDone = true; 1113 } 1114 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 3.0)) 1115 { 1116 // line in range [2.0 .. 3.0] 1117 // paint as cross in a 3x3 with dynamic line distance 1118 basegfx::B2DHomMatrix aMat; 1119 const double fDistance((fDiscreteLineWidth - 1.0) * 0.5); 1120 1121 for(sal_uInt32 a(0); a < nCount; a++) 1122 { 1123 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1124 1125 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1126 1127 aMat.set(0, 2, -fDistance); 1128 aMat.set(1, 2, 0.0); 1129 aCandidate.transform(aMat); 1130 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1131 1132 aMat.set(0, 2, fDistance); 1133 aMat.set(1, 2, -fDistance); 1134 aCandidate.transform(aMat); 1135 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1136 1137 aMat.set(0, 2, fDistance); 1138 aMat.set(1, 2, fDistance); 1139 aCandidate.transform(aMat); 1140 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1141 1142 aMat.set(0, 2, -fDistance); 1143 aMat.set(1, 2, fDistance); 1144 aCandidate.transform(aMat); 1145 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1146 } 1147 1148 bDone = true; 1149 } 1150 else 1151 { 1152 // #i101491# line width above 3.0 1153 } 1154 } 1155 else 1156 { 1157 if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.5)) 1158 { 1159 // line width below 1.5, draw the basic hairline polygon 1160 for(sal_uInt32 a(0); a < nCount; a++) 1161 { 1162 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0); 1163 } 1164 1165 bDone = true; 1166 } 1167 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.5)) 1168 { 1169 // line width is in range ]1.5 .. 2.5], use four hairlines 1170 // drawn in a square 1171 for(sal_uInt32 a(0); a < nCount; a++) 1172 { 1173 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1174 basegfx::B2DHomMatrix aMat; 1175 1176 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1177 1178 aMat.set(0, 2, 1.0); 1179 aMat.set(1, 2, 0.0); 1180 aCandidate.transform(aMat); 1181 1182 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1183 1184 aMat.set(0, 2, 0.0); 1185 aMat.set(1, 2, 1.0); 1186 aCandidate.transform(aMat); 1187 1188 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1189 1190 aMat.set(0, 2, -1.0); 1191 aMat.set(1, 2, 0.0); 1192 aCandidate.transform(aMat); 1193 1194 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1195 } 1196 1197 bDone = true; 1198 } 1199 else 1200 { 1201 // #i101491# line width is above 2.5 1202 } 1203 } 1204 1205 if(!bDone && rPolygonStrokeCandidate.getB2DPolygon().count() > 1000) 1206 { 1207 // #i101491# If the polygon complexity uses more than a given amount, do 1208 // use OuputDevice::DrawPolyLine directly; this will avoid buffering all 1209 // decompositions in primtives (memory) and fallback to old line painting 1210 // for very complex polygons, too 1211 for(sal_uInt32 a(0); a < nCount; a++) 1212 { 1213 mpOutputDevice->DrawPolyLine( 1214 aHairlinePolyPolygon.getB2DPolygon(a), 1215 fDiscreteLineWidth, 1216 rLineAttribute.getLineJoin(), 1217 rLineAttribute.getLineCap()); 1218 } 1219 1220 bDone = true; 1221 } 1222 } 1223 } 1224 1225 if(!bDone) 1226 { 1227 // remeber that we enter a PolygonStrokePrimitive2D decomposition, 1228 // used for AA thick line drawing 1229 mnPolygonStrokePrimitive2D++; 1230 1231 // line width is big enough for standard filled polygon visualisation or zero 1232 process(rPolygonStrokeCandidate.get2DDecomposition(getViewInformation2D())); 1233 1234 // leave PolygonStrokePrimitive2D 1235 mnPolygonStrokePrimitive2D--; 1236 } 1237 } 1238 1239 void VclProcessor2D::RenderEpsPrimitive2D(const primitive2d::EpsPrimitive2D& rEpsPrimitive2D) 1240 { 1241 // The new decomposition of Metafiles made it necessary to add an Eps 1242 // primitive to handle embedded Eps data. On some devices, this can be 1243 // painted directly (mac, printer). 1244 // To be able to handle the replacement correctly, i need to handle it myself 1245 // since DrawEPS will not be able e.g. to rotate the replacement. To be able 1246 // to do that, i added a boolean return to OutputDevice::DrawEPS(..) 1247 // to know when EPS was handled directly already. 1248 basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0); 1249 aRange.transform(maCurrentTransformation * rEpsPrimitive2D.getEpsTransform()); 1250 1251 if(!aRange.isEmpty()) 1252 { 1253 const Rectangle aRectangle( 1254 (sal_Int32)floor(aRange.getMinX()), (sal_Int32)floor(aRange.getMinY()), 1255 (sal_Int32)ceil(aRange.getMaxX()), (sal_Int32)ceil(aRange.getMaxY())); 1256 1257 if(!aRectangle.IsEmpty()) 1258 { 1259 // try to paint EPS directly without fallback visualisation 1260 const bool bEPSPaintedDirectly(mpOutputDevice->DrawEPS( 1261 aRectangle.TopLeft(), 1262 aRectangle.GetSize(), 1263 rEpsPrimitive2D.getGfxLink(), 1264 0)); 1265 1266 if(!bEPSPaintedDirectly) 1267 { 1268 // use the decomposition which will correctly handle the 1269 // fallback visualisation using full transformation (e.g. rotation) 1270 process(rEpsPrimitive2D.get2DDecomposition(getViewInformation2D())); 1271 } 1272 } 1273 } 1274 } 1275 1276 void VclProcessor2D::RenderSvgLinearAtomPrimitive2D(const primitive2d::SvgLinearAtomPrimitive2D& rCandidate) 1277 { 1278 const double fDelta(rCandidate.getOffsetB() - rCandidate.getOffsetA()); 1279 1280 if(basegfx::fTools::more(fDelta, 0.0)) 1281 { 1282 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA())); 1283 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB())); 1284 1285 // calculate discrete unit in WorldCoordinates; use diagonal (1.0, 1.0) and divide by sqrt(2) 1286 const basegfx::B2DVector aDiscreteVector(getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); 1287 const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 1.414213562373)); 1288 1289 // use color distance and discrete lengths to calculate step count 1290 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDelta, fDiscreteUnit)); 1291 1292 // switch off line painting 1293 mpOutputDevice->SetLineColor(); 1294 1295 // prepare polygon in needed width at start position (with discrete overlap) 1296 const basegfx::B2DPolygon aPolygon( 1297 basegfx::tools::createPolygonFromRect( 1298 basegfx::B2DRange( 1299 rCandidate.getOffsetA() - fDiscreteUnit, 1300 0.0, 1301 rCandidate.getOffsetA() + (fDelta / nSteps) + fDiscreteUnit, 1302 1.0))); 1303 1304 1305 // prepare loop ([0.0 .. 1.0[) 1306 double fUnitScale(0.0); 1307 const double fUnitStep(1.0 / nSteps); 1308 1309 // loop and paint 1310 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep) 1311 { 1312 basegfx::B2DPolygon aNew(aPolygon); 1313 1314 aNew.transform(maCurrentTransformation * basegfx::tools::createTranslateB2DHomMatrix(fDelta * fUnitScale, 0.0)); 1315 mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorA, aColorB, fUnitScale))); 1316 mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew)); 1317 } 1318 } 1319 } 1320 1321 void VclProcessor2D::RenderSvgRadialAtomPrimitive2D(const primitive2d::SvgRadialAtomPrimitive2D& rCandidate) 1322 { 1323 const double fDeltaScale(rCandidate.getScaleB() - rCandidate.getScaleA()); 1324 1325 if(basegfx::fTools::more(fDeltaScale, 0.0)) 1326 { 1327 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA())); 1328 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB())); 1329 1330 // calculate discrete unit in WorldCoordinates; use diagonal (1.0, 1.0) and divide by sqrt(2) 1331 const basegfx::B2DVector aDiscreteVector(getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); 1332 const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 1.414213562373)); 1333 1334 // use color distance and discrete lengths to calculate step count 1335 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDeltaScale, fDiscreteUnit)); 1336 1337 // switch off line painting 1338 mpOutputDevice->SetLineColor(); 1339 1340 // prepare loop ([0.0 .. 1.0[, full polygons, no polypolygons with holes) 1341 double fUnitScale(0.0); 1342 const double fUnitStep(1.0 / nSteps); 1343 1344 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep) 1345 { 1346 basegfx::B2DHomMatrix aTransform; 1347 const double fEndScale(rCandidate.getScaleB() - (fDeltaScale * fUnitScale)); 1348 1349 if(rCandidate.isTranslateSet()) 1350 { 1351 const basegfx::B2DVector aTranslate( 1352 basegfx::interpolate( 1353 rCandidate.getTranslateB(), 1354 rCandidate.getTranslateA(), 1355 fUnitScale)); 1356 1357 aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix( 1358 fEndScale, 1359 fEndScale, 1360 aTranslate.getX(), 1361 aTranslate.getY()); 1362 } 1363 else 1364 { 1365 aTransform = basegfx::tools::createScaleB2DHomMatrix( 1366 fEndScale, 1367 fEndScale); 1368 } 1369 1370 basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle()); 1371 1372 aNew.transform(maCurrentTransformation * aTransform); 1373 mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorB, aColorA, fUnitScale))); 1374 mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew)); 1375 } 1376 } 1377 } 1378 1379 void VclProcessor2D::adaptLineToFillDrawMode() const 1380 { 1381 const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode()); 1382 1383 if(nOriginalDrawMode & (DRAWMODE_BLACKLINE|DRAWMODE_GRAYLINE|DRAWMODE_GHOSTEDLINE|DRAWMODE_WHITELINE|DRAWMODE_SETTINGSLINE)) 1384 { 1385 sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode); 1386 1387 if(nOriginalDrawMode & DRAWMODE_BLACKLINE) 1388 { 1389 nAdaptedDrawMode |= DRAWMODE_BLACKFILL; 1390 } 1391 else 1392 { 1393 nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL; 1394 } 1395 1396 if(nOriginalDrawMode & DRAWMODE_GRAYLINE) 1397 { 1398 nAdaptedDrawMode |= DRAWMODE_GRAYFILL; 1399 } 1400 else 1401 { 1402 nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL; 1403 } 1404 1405 if(nOriginalDrawMode & DRAWMODE_GHOSTEDLINE) 1406 { 1407 nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL; 1408 } 1409 else 1410 { 1411 nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL; 1412 } 1413 1414 if(nOriginalDrawMode & DRAWMODE_WHITELINE) 1415 { 1416 nAdaptedDrawMode |= DRAWMODE_WHITEFILL; 1417 } 1418 else 1419 { 1420 nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL; 1421 } 1422 1423 if(nOriginalDrawMode & DRAWMODE_SETTINGSLINE) 1424 { 1425 nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL; 1426 } 1427 else 1428 { 1429 nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL; 1430 } 1431 1432 mpOutputDevice->SetDrawMode(nAdaptedDrawMode); 1433 } 1434 } 1435 1436 void VclProcessor2D::adaptTextToFillDrawMode() const 1437 { 1438 const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode()); 1439 if(nOriginalDrawMode & (DRAWMODE_BLACKTEXT|DRAWMODE_GRAYTEXT|DRAWMODE_GHOSTEDTEXT|DRAWMODE_WHITETEXT|DRAWMODE_SETTINGSTEXT)) 1440 { 1441 sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode); 1442 1443 if(nOriginalDrawMode & DRAWMODE_BLACKTEXT) 1444 { 1445 nAdaptedDrawMode |= DRAWMODE_BLACKFILL; 1446 } 1447 else 1448 { 1449 nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL; 1450 } 1451 1452 if(nOriginalDrawMode & DRAWMODE_GRAYTEXT) 1453 { 1454 nAdaptedDrawMode |= DRAWMODE_GRAYFILL; 1455 } 1456 else 1457 { 1458 nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL; 1459 } 1460 1461 if(nOriginalDrawMode & DRAWMODE_GHOSTEDTEXT) 1462 { 1463 nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL; 1464 } 1465 else 1466 { 1467 nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL; 1468 } 1469 1470 if(nOriginalDrawMode & DRAWMODE_WHITETEXT) 1471 { 1472 nAdaptedDrawMode |= DRAWMODE_WHITEFILL; 1473 } 1474 else 1475 { 1476 nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL; 1477 } 1478 1479 if(nOriginalDrawMode & DRAWMODE_SETTINGSTEXT) 1480 { 1481 nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL; 1482 } 1483 else 1484 { 1485 nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL; 1486 } 1487 1488 mpOutputDevice->SetDrawMode(nAdaptedDrawMode); 1489 } 1490 } 1491 1492 ////////////////////////////////////////////////////////////////////////////// 1493 // process support 1494 1495 VclProcessor2D::VclProcessor2D( 1496 const geometry::ViewInformation2D& rViewInformation, 1497 OutputDevice& rOutDev) 1498 : BaseProcessor2D(rViewInformation), 1499 mpOutputDevice(&rOutDev), 1500 maBColorModifierStack(), 1501 maCurrentTransformation(), 1502 maDrawinglayerOpt(), 1503 mnPolygonStrokePrimitive2D(0) 1504 { 1505 // set digit language, derived from SvtCTLOptions to have the correct 1506 // number display for arabic/hindi numerals 1507 const SvtCTLOptions aSvtCTLOptions; 1508 LanguageType eLang(LANGUAGE_SYSTEM); 1509 1510 if(SvtCTLOptions::NUMERALS_HINDI == aSvtCTLOptions.GetCTLTextNumerals()) 1511 { 1512 eLang = LANGUAGE_ARABIC_SAUDI_ARABIA; 1513 } 1514 else if(SvtCTLOptions::NUMERALS_ARABIC == aSvtCTLOptions.GetCTLTextNumerals()) 1515 { 1516 eLang = LANGUAGE_ENGLISH; 1517 } 1518 else 1519 { 1520 eLang = (LanguageType)Application::GetSettings().GetLanguage(); 1521 } 1522 1523 rOutDev.SetDigitLanguage(eLang); 1524 } 1525 1526 VclProcessor2D::~VclProcessor2D() 1527 { 1528 } 1529 } // end of namespace processor2d 1530 } // end of namespace drawinglayer 1531 1532 ////////////////////////////////////////////////////////////////////////////// 1533 // eof 1534