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 // #122923# do no longer add Alpha channel here; the right place to do this is when really 413 // the own transformer is used (see OutputDevice::DrawTransformedBitmapEx). 414 415 // draw using OutputDevice'sDrawTransformedBitmapEx 416 mpOutputDevice->DrawTransformedBitmapEx(aLocalTransform, aBitmapEx); 417 } 418 419 void VclProcessor2D::RenderFillGraphicPrimitive2D(const primitive2d::FillGraphicPrimitive2D& rFillBitmapCandidate) 420 { 421 const attribute::FillGraphicAttribute& rFillGraphicAttribute(rFillBitmapCandidate.getFillGraphic()); 422 bool bPrimitiveAccepted(false); 423 static bool bTryTilingDirect = true; 424 425 // #121194# when tiling is used and content is bitmap-based, do direct tiling in the 426 // renderer on pixel base to ensure tight fitting. Do not do this when 427 // the fill is rotated or sheared. 428 429 // ovveride static bool (for debug) and tiling is active 430 if(bTryTilingDirect && rFillGraphicAttribute.getTiling()) 431 { 432 // content is bitmap(ex) 433 // 434 // for SVG support, force decomposition when SVG is present. This will lead to use 435 // the primitive representation of the svg directly. 436 // 437 // when graphic is animated, force decomposition to use the correct graphic, else 438 // fill style will not be animated 439 if(GRAPHIC_BITMAP == rFillGraphicAttribute.getGraphic().GetType() 440 && !rFillGraphicAttribute.getGraphic().getSvgData().get() 441 && !rFillGraphicAttribute.getGraphic().IsAnimated()) 442 { 443 // decompose matrix to check for shear, rotate and mirroring 444 basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rFillBitmapCandidate.getTransformation()); 445 basegfx::B2DVector aScale, aTranslate; 446 double fRotate, fShearX; 447 aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX); 448 449 // when nopt rotated/sheared 450 if(basegfx::fTools::equalZero(fRotate) && basegfx::fTools::equalZero(fShearX)) 451 { 452 // no shear or rotate, draw direct in pixel coordinates 453 bPrimitiveAccepted = true; 454 455 // transform object range to device coordinates (pixels). Use 456 // the device transformation for better accuracy 457 basegfx::B2DRange aObjectRange(aTranslate, aTranslate + aScale); 458 aObjectRange.transform(mpOutputDevice->GetViewTransformation()); 459 460 // extract discrete size of object 461 const sal_Int32 nOWidth(basegfx::fround(aObjectRange.getWidth())); 462 const sal_Int32 nOHeight(basegfx::fround(aObjectRange.getHeight())); 463 464 // only do something when object has a size in discrete units 465 if(nOWidth > 0 && nOHeight > 0) 466 { 467 // transform graphic range to device coordinates (pixels). Use 468 // the device transformation for better accuracy 469 basegfx::B2DRange aGraphicRange(rFillGraphicAttribute.getGraphicRange()); 470 aGraphicRange.transform(mpOutputDevice->GetViewTransformation() * aLocalTransform); 471 472 // extract discrete size of graphic 473 // caution: when getting to zero, nothing would be painted; thus, do not allow this 474 const sal_Int32 nBWidth(std::max(sal_Int32(1), basegfx::fround(aGraphicRange.getWidth()))); 475 const sal_Int32 nBHeight(std::max(sal_Int32(1), basegfx::fround(aGraphicRange.getHeight()))); 476 477 // only do something when bitmap fill has a size in discrete units 478 if(nBWidth > 0 && nBHeight > 0) 479 { 480 // nBWidth, nBHeight is the pixel size of the neede bitmap. To not need to scale it 481 // in vcl many times, create a size-optimized version 482 const Size aNeededBitmapSizePixel(nBWidth, nBHeight); 483 BitmapEx aBitmapEx(rFillGraphicAttribute.getGraphic().GetBitmapEx()); 484 static bool bEnablePreScaling(true); 485 const bool bPreScaled(bEnablePreScaling && nBWidth * nBHeight < (250 * 250)); 486 487 // ... but only up to a maximum size, else it gets too expensive 488 if(bPreScaled) 489 { 490 // if color depth is below 24bit, expand before scaling for better quality. 491 // This is even needed for low colors, else the scale will produce 492 // a bitmap in gray or Black/White (!) 493 if(aBitmapEx.GetBitCount() < 24) 494 { 495 aBitmapEx.Convert(BMP_CONVERSION_24BIT); 496 } 497 498 aBitmapEx.Scale(aNeededBitmapSizePixel, BMP_SCALE_INTERPOLATE); 499 } 500 501 bool bPainted(false); 502 503 if(maBColorModifierStack.count()) 504 { 505 // when color modifier, apply to bitmap 506 aBitmapEx = aBitmapEx.ModifyBitmapEx(maBColorModifierStack); 507 508 // impModifyBitmapEx uses empty bitmap as sign to return that 509 // the content will be completely replaced to mono color, use shortcut 510 if(aBitmapEx.IsEmpty()) 511 { 512 // color gets completely replaced, get it 513 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor())); 514 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 515 aPolygon.transform(aLocalTransform); 516 517 mpOutputDevice->SetFillColor(Color(aModifiedColor)); 518 mpOutputDevice->SetLineColor(); 519 mpOutputDevice->DrawPolygon(aPolygon); 520 521 bPainted = true; 522 } 523 } 524 525 if(!bPainted) 526 { 527 sal_Int32 nBLeft(basegfx::fround(aGraphicRange.getMinX())); 528 sal_Int32 nBTop(basegfx::fround(aGraphicRange.getMinY())); 529 const sal_Int32 nOLeft(basegfx::fround(aObjectRange.getMinX())); 530 const sal_Int32 nOTop(basegfx::fround(aObjectRange.getMinY())); 531 sal_Int32 nPosX(0); 532 sal_Int32 nPosY(0); 533 534 if(nBLeft > nOLeft) 535 { 536 const sal_Int32 nDiff((nBLeft / nBWidth) + 1); 537 538 nPosX -= nDiff; 539 nBLeft -= nDiff * nBWidth; 540 } 541 542 if(nBLeft + nBWidth <= nOLeft) 543 { 544 const sal_Int32 nDiff(-nBLeft / nBWidth); 545 546 nPosX += nDiff; 547 nBLeft += nDiff * nBWidth; 548 } 549 550 if(nBTop > nOTop) 551 { 552 const sal_Int32 nDiff((nBTop / nBHeight) + 1); 553 554 nPosY -= nDiff; 555 nBTop -= nDiff * nBHeight; 556 } 557 558 if(nBTop + nBHeight <= nOTop) 559 { 560 const sal_Int32 nDiff(-nBTop / nBHeight); 561 562 nPosY += nDiff; 563 nBTop += nDiff * nBHeight; 564 } 565 566 // prepare OutDev 567 const Point aEmptyPoint(0, 0); 568 const Rectangle aVisiblePixel(aEmptyPoint, mpOutputDevice->GetOutputSizePixel()); 569 const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled()); 570 mpOutputDevice->EnableMapMode(false); 571 572 // check if offset is used 573 const sal_Int32 nOffsetX(basegfx::fround(rFillGraphicAttribute.getOffsetX() * nBWidth)); 574 575 if(nOffsetX) 576 { 577 // offset in X, so iterate over Y first and draw lines 578 for(sal_Int32 nYPos(nBTop); nYPos < nOTop + nOHeight; nYPos += nBHeight, nPosY++) 579 { 580 for(sal_Int32 nXPos(nPosY % 2 ? nBLeft - nBWidth + nOffsetX : nBLeft); 581 nXPos < nOLeft + nOWidth; nXPos += nBWidth) 582 { 583 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel); 584 585 if(aOutRectPixel.IsOver(aVisiblePixel)) 586 { 587 if(bPreScaled) 588 { 589 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx); 590 } 591 else 592 { 593 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx); 594 } 595 } 596 } 597 } 598 } 599 else 600 { 601 // check if offset is used 602 const sal_Int32 nOffsetY(basegfx::fround(rFillGraphicAttribute.getOffsetY() * nBHeight)); 603 604 // possible offset in Y, so iterate over X first and draw columns 605 for(sal_Int32 nXPos(nBLeft); nXPos < nOLeft + nOWidth; nXPos += nBWidth, nPosX++) 606 { 607 for(sal_Int32 nYPos(nPosX % 2 ? nBTop - nBHeight + nOffsetY : nBTop); 608 nYPos < nOTop + nOHeight; nYPos += nBHeight) 609 { 610 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel); 611 612 if(aOutRectPixel.IsOver(aVisiblePixel)) 613 { 614 if(bPreScaled) 615 { 616 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx); 617 } 618 else 619 { 620 mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx); 621 } 622 } 623 } 624 } 625 } 626 627 // restore OutDev 628 mpOutputDevice->EnableMapMode(bWasEnabled); 629 } 630 } 631 } 632 } 633 } 634 } 635 636 if(!bPrimitiveAccepted) 637 { 638 // do not accept, use decomposition 639 process(rFillBitmapCandidate.get2DDecomposition(getViewInformation2D())); 640 } 641 } 642 643 // direct draw of Graphic 644 void VclProcessor2D::RenderPolyPolygonGraphicPrimitive2D(const primitive2d::PolyPolygonGraphicPrimitive2D& rPolygonCandidate) 645 { 646 bool bDone(false); 647 const basegfx::B2DPolyPolygon& rPolyPolygon = rPolygonCandidate.getB2DPolyPolygon(); 648 649 // #121194# Todo: check if this works 650 if(!rPolyPolygon.count()) 651 { 652 // empty polyPolygon, done 653 bDone = true; 654 } 655 else 656 { 657 const attribute::FillGraphicAttribute& rFillGraphicAttribute = rPolygonCandidate.getFillGraphic(); 658 659 // try to catch cases where the graphic will be color-modified to a single 660 // color (e.g. shadow) 661 switch(rFillGraphicAttribute.getGraphic().GetType()) 662 { 663 case GRAPHIC_GDIMETAFILE: 664 { 665 // metafiles are potentially transparent, cannot optimize�, not done 666 break; 667 } 668 case GRAPHIC_BITMAP: 669 { 670 if(!rFillGraphicAttribute.getGraphic().IsTransparent() && !rFillGraphicAttribute.getGraphic().IsAlpha()) 671 { 672 // bitmap is not transparent and has no alpha 673 const sal_uInt32 nBColorModifierStackCount(maBColorModifierStack.count()); 674 675 if(nBColorModifierStackCount) 676 { 677 const basegfx::BColorModifier& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1); 678 679 if(basegfx::BCOLORMODIFYMODE_REPLACE == rTopmostModifier.getMode()) 680 { 681 // the bitmap fill is in unified color, so we can replace it with 682 // a single polygon fill. The form of the fill depends on tiling 683 if(rFillGraphicAttribute.getTiling()) 684 { 685 // with tiling, fill the whole PolyPolygon with the modifier color 686 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolyPolygon); 687 688 aLocalPolyPolygon.transform(maCurrentTransformation); 689 mpOutputDevice->SetLineColor(); 690 mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); 691 mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon); 692 } 693 else 694 { 695 // without tiling, only the area common to the bitmap tile and the 696 // PolyPolygon is filled. Create the bitmap tile area in object 697 // coordinates. For this, the object transformation needs to be created 698 // from the already scaled PolyPolygon. The tile area in object 699 // coordinates wil always be non-rotated, so it's not necessary to 700 // work with a polygon here 701 basegfx::B2DRange aTileRange(rFillGraphicAttribute.getGraphicRange()); 702 const basegfx::B2DRange aPolyPolygonRange(rPolyPolygon.getB2DRange()); 703 const basegfx::B2DHomMatrix aNewObjectTransform( 704 basegfx::tools::createScaleTranslateB2DHomMatrix( 705 aPolyPolygonRange.getRange(), 706 aPolyPolygonRange.getMinimum())); 707 708 aTileRange.transform(aNewObjectTransform); 709 710 // now clip the object polyPolygon against the tile range 711 // to get the common area 712 basegfx::B2DPolyPolygon aTarget = basegfx::tools::clipPolyPolygonOnRange( 713 rPolyPolygon, 714 aTileRange, 715 true, 716 false); 717 718 if(aTarget.count()) 719 { 720 aTarget.transform(maCurrentTransformation); 721 mpOutputDevice->SetLineColor(); 722 mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); 723 mpOutputDevice->DrawPolyPolygon(aTarget); 724 } 725 } 726 727 // simplified output executed, we are done 728 bDone = true; 729 } 730 } 731 } 732 break; 733 } 734 default: //GRAPHIC_NONE, GRAPHIC_DEFAULT 735 { 736 // empty graphic, we are done 737 bDone = true; 738 break; 739 } 740 } 741 } 742 743 if(!bDone) 744 { 745 // use default decomposition 746 process(rPolygonCandidate.get2DDecomposition(getViewInformation2D())); 747 } 748 } 749 750 // mask group. Force output to VDev and create mask from given mask 751 void VclProcessor2D::RenderMaskPrimitive2DPixel(const primitive2d::MaskPrimitive2D& rMaskCandidate) 752 { 753 if(rMaskCandidate.getChildren().hasElements()) 754 { 755 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask()); 756 757 if(aMask.count()) 758 { 759 aMask.transform(maCurrentTransformation); 760 const basegfx::B2DRange aRange(basegfx::tools::getRange(aMask)); 761 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 762 763 if(aBufferDevice.isVisible()) 764 { 765 // remember last OutDev and set to content 766 OutputDevice* pLastOutputDevice = mpOutputDevice; 767 mpOutputDevice = &aBufferDevice.getContent(); 768 769 // paint to it 770 process(rMaskCandidate.getChildren()); 771 772 // back to old OutDev 773 mpOutputDevice = pLastOutputDevice; 774 775 // draw mask 776 if(getOptionsDrawinglayer().IsAntiAliasing()) 777 { 778 // with AA, use 8bit AlphaMask to get nice borders 779 VirtualDevice& rTransparence = aBufferDevice.getTransparence(); 780 rTransparence.SetLineColor(); 781 rTransparence.SetFillColor(COL_BLACK); 782 rTransparence.DrawPolyPolygon(aMask); 783 784 // dump buffer to outdev 785 aBufferDevice.paint(); 786 } 787 else 788 { 789 // No AA, use 1bit mask 790 VirtualDevice& rMask = aBufferDevice.getMask(); 791 rMask.SetLineColor(); 792 rMask.SetFillColor(COL_BLACK); 793 rMask.DrawPolyPolygon(aMask); 794 795 // dump buffer to outdev 796 aBufferDevice.paint(); 797 } 798 } 799 } 800 } 801 } 802 803 // modified color group. Force output to unified color. 804 void VclProcessor2D::RenderModifiedColorPrimitive2D(const primitive2d::ModifiedColorPrimitive2D& rModifiedCandidate) 805 { 806 if(rModifiedCandidate.getChildren().hasElements()) 807 { 808 maBColorModifierStack.push(rModifiedCandidate.getColorModifier()); 809 process(rModifiedCandidate.getChildren()); 810 maBColorModifierStack.pop(); 811 } 812 } 813 814 // unified sub-transparence. Draw to VDev first. 815 void VclProcessor2D::RenderUnifiedTransparencePrimitive2D(const primitive2d::UnifiedTransparencePrimitive2D& rTransCandidate) 816 { 817 static bool bForceToDecomposition(false); 818 819 if(rTransCandidate.getChildren().hasElements()) 820 { 821 if(bForceToDecomposition) 822 { 823 // use decomposition 824 process(rTransCandidate.get2DDecomposition(getViewInformation2D())); 825 } 826 else 827 { 828 if(0.0 == rTransCandidate.getTransparence()) 829 { 830 // no transparence used, so just use the content 831 process(rTransCandidate.getChildren()); 832 } 833 else if(rTransCandidate.getTransparence() > 0.0 && rTransCandidate.getTransparence() < 1.0) 834 { 835 // transparence is in visible range 836 basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D())); 837 aRange.transform(maCurrentTransformation); 838 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 839 840 if(aBufferDevice.isVisible()) 841 { 842 // remember last OutDev and set to content 843 OutputDevice* pLastOutputDevice = mpOutputDevice; 844 mpOutputDevice = &aBufferDevice.getContent(); 845 846 // paint content to it 847 process(rTransCandidate.getChildren()); 848 849 // back to old OutDev 850 mpOutputDevice = pLastOutputDevice; 851 852 // dump buffer to outdev using given transparence 853 aBufferDevice.paint(rTransCandidate.getTransparence()); 854 } 855 } 856 } 857 } 858 } 859 860 // sub-transparence group. Draw to VDev first. 861 void VclProcessor2D::RenderTransparencePrimitive2D(const primitive2d::TransparencePrimitive2D& rTransCandidate) 862 { 863 if(rTransCandidate.getChildren().hasElements()) 864 { 865 basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D())); 866 aRange.transform(maCurrentTransformation); 867 impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); 868 869 if(aBufferDevice.isVisible()) 870 { 871 // remember last OutDev and set to content 872 OutputDevice* pLastOutputDevice = mpOutputDevice; 873 mpOutputDevice = &aBufferDevice.getContent(); 874 875 // paint content to it 876 process(rTransCandidate.getChildren()); 877 878 // set to mask 879 mpOutputDevice = &aBufferDevice.getTransparence(); 880 881 // when painting transparence masks, reset the color stack 882 basegfx::BColorModifierStack aLastBColorModifierStack(maBColorModifierStack); 883 maBColorModifierStack = basegfx::BColorModifierStack(); 884 885 // paint mask to it (always with transparence intensities, evtl. with AA) 886 process(rTransCandidate.getTransparence()); 887 888 // back to old color stack 889 maBColorModifierStack = aLastBColorModifierStack; 890 891 // back to old OutDev 892 mpOutputDevice = pLastOutputDevice; 893 894 // dump buffer to outdev 895 aBufferDevice.paint(); 896 } 897 } 898 } 899 900 // transform group. 901 void VclProcessor2D::RenderTransformPrimitive2D(const primitive2d::TransformPrimitive2D& rTransformCandidate) 902 { 903 // remember current transformation and ViewInformation 904 const basegfx::B2DHomMatrix aLastCurrentTransformation(maCurrentTransformation); 905 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 906 907 // create new transformations for CurrentTransformation 908 // and for local ViewInformation2D 909 maCurrentTransformation = maCurrentTransformation * rTransformCandidate.getTransformation(); 910 const geometry::ViewInformation2D aViewInformation2D( 911 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(), 912 getViewInformation2D().getViewTransformation(), 913 getViewInformation2D().getViewport(), 914 getViewInformation2D().getVisualizedPage(), 915 getViewInformation2D().getViewTime(), 916 getViewInformation2D().getExtendedInformationSequence()); 917 updateViewInformation(aViewInformation2D); 918 919 // proccess content 920 process(rTransformCandidate.getChildren()); 921 922 // restore transformations 923 maCurrentTransformation = aLastCurrentTransformation; 924 updateViewInformation(aLastViewInformation2D); 925 } 926 927 // new XDrawPage for ViewInformation2D 928 void VclProcessor2D::RenderPagePreviewPrimitive2D(const primitive2d::PagePreviewPrimitive2D& rPagePreviewCandidate) 929 { 930 // remember current transformation and ViewInformation 931 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 932 933 // create new local ViewInformation2D 934 const geometry::ViewInformation2D aViewInformation2D( 935 getViewInformation2D().getObjectTransformation(), 936 getViewInformation2D().getViewTransformation(), 937 getViewInformation2D().getViewport(), 938 rPagePreviewCandidate.getXDrawPage(), 939 getViewInformation2D().getViewTime(), 940 getViewInformation2D().getExtendedInformationSequence()); 941 updateViewInformation(aViewInformation2D); 942 943 // proccess decomposed content 944 process(rPagePreviewCandidate.get2DDecomposition(getViewInformation2D())); 945 946 // restore transformations 947 updateViewInformation(aLastViewInformation2D); 948 } 949 950 // marker 951 void VclProcessor2D::RenderMarkerArrayPrimitive2D(const primitive2d::MarkerArrayPrimitive2D& rMarkArrayCandidate) 952 { 953 static bool bCheckCompleteMarkerDecompose(false); 954 if(bCheckCompleteMarkerDecompose) 955 { 956 process(rMarkArrayCandidate.get2DDecomposition(getViewInformation2D())); 957 return; 958 } 959 960 // get data 961 const std::vector< basegfx::B2DPoint >& rPositions = rMarkArrayCandidate.getPositions(); 962 const sal_uInt32 nCount(rPositions.size()); 963 964 if(nCount && !rMarkArrayCandidate.getMarker().IsEmpty()) 965 { 966 // get pixel size 967 const BitmapEx& rMarker(rMarkArrayCandidate.getMarker()); 968 const Size aBitmapSize(rMarker.GetSizePixel()); 969 970 if(aBitmapSize.Width() && aBitmapSize.Height()) 971 { 972 // get discrete half size 973 const basegfx::B2DVector aDiscreteHalfSize( 974 (aBitmapSize.getWidth() - 1.0) * 0.5, 975 (aBitmapSize.getHeight() - 1.0) * 0.5); 976 const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled()); 977 978 // do not forget evtl. moved origin in target device MapMode when 979 // switching it off; it would be missing and lead to wrong positions. 980 // All his could be done using logic sizes and coordinates, too, but 981 // we want a 1:1 bitmap rendering here, so it's more safe and faster 982 // to work with switching off MapMode usage completely. 983 const Point aOrigin(mpOutputDevice->GetMapMode().GetOrigin()); 984 985 mpOutputDevice->EnableMapMode(false); 986 987 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++) 988 { 989 const basegfx::B2DPoint aDiscreteTopLeft((maCurrentTransformation * (*aIter)) - aDiscreteHalfSize); 990 const Point aDiscretePoint(basegfx::fround(aDiscreteTopLeft.getX()), basegfx::fround(aDiscreteTopLeft.getY())); 991 992 mpOutputDevice->DrawBitmapEx(aDiscretePoint + aOrigin, rMarker); 993 } 994 995 mpOutputDevice->EnableMapMode(bWasEnabled); 996 } 997 } 998 } 999 1000 // point 1001 void VclProcessor2D::RenderPointArrayPrimitive2D(const primitive2d::PointArrayPrimitive2D& rPointArrayCandidate) 1002 { 1003 const std::vector< basegfx::B2DPoint >& rPositions = rPointArrayCandidate.getPositions(); 1004 const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(rPointArrayCandidate.getRGBColor())); 1005 const Color aVCLColor(aRGBColor); 1006 1007 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++) 1008 { 1009 const basegfx::B2DPoint aViewPosition(maCurrentTransformation * (*aIter)); 1010 const Point aPos(basegfx::fround(aViewPosition.getX()), basegfx::fround(aViewPosition.getY())); 1011 1012 mpOutputDevice->DrawPixel(aPos, aVCLColor); 1013 } 1014 } 1015 1016 void VclProcessor2D::RenderPolygonStrokePrimitive2D(const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokeCandidate) 1017 { 1018 // #i101491# method restructured to clearly use the DrawPolyLine 1019 // calls starting from a deined line width 1020 const attribute::LineAttribute& rLineAttribute = rPolygonStrokeCandidate.getLineAttribute(); 1021 const double fLineWidth(rLineAttribute.getWidth()); 1022 bool bDone(false); 1023 1024 if(basegfx::fTools::more(fLineWidth, 0.0)) 1025 { 1026 const basegfx::B2DVector aDiscreteUnit(maCurrentTransformation * basegfx::B2DVector(fLineWidth, 0.0)); 1027 const double fDiscreteLineWidth(aDiscreteUnit.getLength()); 1028 const attribute::StrokeAttribute& rStrokeAttribute = rPolygonStrokeCandidate.getStrokeAttribute(); 1029 const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rLineAttribute.getColor())); 1030 basegfx::B2DPolyPolygon aHairlinePolyPolygon; 1031 1032 mpOutputDevice->SetLineColor(Color(aHairlineColor)); 1033 mpOutputDevice->SetFillColor(); 1034 1035 if(0.0 == rStrokeAttribute.getFullDotDashLen()) 1036 { 1037 // no line dashing, just copy 1038 aHairlinePolyPolygon.append(rPolygonStrokeCandidate.getB2DPolygon()); 1039 } 1040 else 1041 { 1042 // else apply LineStyle 1043 basegfx::tools::applyLineDashing(rPolygonStrokeCandidate.getB2DPolygon(), 1044 rStrokeAttribute.getDotDashArray(), 1045 &aHairlinePolyPolygon, 0, rStrokeAttribute.getFullDotDashLen()); 1046 } 1047 1048 const sal_uInt32 nCount(aHairlinePolyPolygon.count()); 1049 1050 if(nCount) 1051 { 1052 const bool bAntiAliased(getOptionsDrawinglayer().IsAntiAliasing()); 1053 aHairlinePolyPolygon.transform(maCurrentTransformation); 1054 1055 if(bAntiAliased) 1056 { 1057 if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.0)) 1058 { 1059 // line in range ]0.0 .. 1.0[ 1060 // paint as simple hairline 1061 for(sal_uInt32 a(0); a < nCount; a++) 1062 { 1063 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0); 1064 } 1065 1066 bDone = true; 1067 } 1068 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.0)) 1069 { 1070 // line in range [1.0 .. 2.0[ 1071 // paint as 2x2 with dynamic line distance 1072 basegfx::B2DHomMatrix aMat; 1073 const double fDistance(fDiscreteLineWidth - 1.0); 1074 const double fHalfDistance(fDistance * 0.5); 1075 1076 for(sal_uInt32 a(0); a < nCount; a++) 1077 { 1078 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1079 1080 aMat.set(0, 2, -fHalfDistance); 1081 aMat.set(1, 2, -fHalfDistance); 1082 aCandidate.transform(aMat); 1083 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1084 1085 aMat.set(0, 2, fDistance); 1086 aMat.set(1, 2, 0.0); 1087 aCandidate.transform(aMat); 1088 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1089 1090 aMat.set(0, 2, 0.0); 1091 aMat.set(1, 2, fDistance); 1092 aCandidate.transform(aMat); 1093 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1094 1095 aMat.set(0, 2, -fDistance); 1096 aMat.set(1, 2, 0.0); 1097 aCandidate.transform(aMat); 1098 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1099 } 1100 1101 bDone = true; 1102 } 1103 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 3.0)) 1104 { 1105 // line in range [2.0 .. 3.0] 1106 // paint as cross in a 3x3 with dynamic line distance 1107 basegfx::B2DHomMatrix aMat; 1108 const double fDistance((fDiscreteLineWidth - 1.0) * 0.5); 1109 1110 for(sal_uInt32 a(0); a < nCount; a++) 1111 { 1112 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1113 1114 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1115 1116 aMat.set(0, 2, -fDistance); 1117 aMat.set(1, 2, 0.0); 1118 aCandidate.transform(aMat); 1119 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1120 1121 aMat.set(0, 2, fDistance); 1122 aMat.set(1, 2, -fDistance); 1123 aCandidate.transform(aMat); 1124 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1125 1126 aMat.set(0, 2, fDistance); 1127 aMat.set(1, 2, fDistance); 1128 aCandidate.transform(aMat); 1129 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1130 1131 aMat.set(0, 2, -fDistance); 1132 aMat.set(1, 2, fDistance); 1133 aCandidate.transform(aMat); 1134 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1135 } 1136 1137 bDone = true; 1138 } 1139 else 1140 { 1141 // #i101491# line width above 3.0 1142 } 1143 } 1144 else 1145 { 1146 if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.5)) 1147 { 1148 // line width below 1.5, draw the basic hairline polygon 1149 for(sal_uInt32 a(0); a < nCount; a++) 1150 { 1151 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0); 1152 } 1153 1154 bDone = true; 1155 } 1156 else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.5)) 1157 { 1158 // line width is in range ]1.5 .. 2.5], use four hairlines 1159 // drawn in a square 1160 for(sal_uInt32 a(0); a < nCount; a++) 1161 { 1162 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a)); 1163 basegfx::B2DHomMatrix aMat; 1164 1165 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1166 1167 aMat.set(0, 2, 1.0); 1168 aMat.set(1, 2, 0.0); 1169 aCandidate.transform(aMat); 1170 1171 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1172 1173 aMat.set(0, 2, 0.0); 1174 aMat.set(1, 2, 1.0); 1175 aCandidate.transform(aMat); 1176 1177 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1178 1179 aMat.set(0, 2, -1.0); 1180 aMat.set(1, 2, 0.0); 1181 aCandidate.transform(aMat); 1182 1183 mpOutputDevice->DrawPolyLine(aCandidate, 0.0); 1184 } 1185 1186 bDone = true; 1187 } 1188 else 1189 { 1190 // #i101491# line width is above 2.5 1191 } 1192 } 1193 1194 if(!bDone && rPolygonStrokeCandidate.getB2DPolygon().count() > 1000) 1195 { 1196 // #i101491# If the polygon complexity uses more than a given amount, do 1197 // use OuputDevice::DrawPolyLine directly; this will avoid buffering all 1198 // decompositions in primtives (memory) and fallback to old line painting 1199 // for very complex polygons, too 1200 for(sal_uInt32 a(0); a < nCount; a++) 1201 { 1202 mpOutputDevice->DrawPolyLine( 1203 aHairlinePolyPolygon.getB2DPolygon(a), 1204 fDiscreteLineWidth, 1205 rLineAttribute.getLineJoin(), 1206 rLineAttribute.getLineCap()); 1207 } 1208 1209 bDone = true; 1210 } 1211 } 1212 } 1213 1214 if(!bDone) 1215 { 1216 // remeber that we enter a PolygonStrokePrimitive2D decomposition, 1217 // used for AA thick line drawing 1218 mnPolygonStrokePrimitive2D++; 1219 1220 // line width is big enough for standard filled polygon visualisation or zero 1221 process(rPolygonStrokeCandidate.get2DDecomposition(getViewInformation2D())); 1222 1223 // leave PolygonStrokePrimitive2D 1224 mnPolygonStrokePrimitive2D--; 1225 } 1226 } 1227 1228 void VclProcessor2D::RenderEpsPrimitive2D(const primitive2d::EpsPrimitive2D& rEpsPrimitive2D) 1229 { 1230 // The new decomposition of Metafiles made it necessary to add an Eps 1231 // primitive to handle embedded Eps data. On some devices, this can be 1232 // painted directly (mac, printer). 1233 // To be able to handle the replacement correctly, i need to handle it myself 1234 // since DrawEPS will not be able e.g. to rotate the replacement. To be able 1235 // to do that, i added a boolean return to OutputDevice::DrawEPS(..) 1236 // to know when EPS was handled directly already. 1237 basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0); 1238 aRange.transform(maCurrentTransformation * rEpsPrimitive2D.getEpsTransform()); 1239 1240 if(!aRange.isEmpty()) 1241 { 1242 const Rectangle aRectangle( 1243 (sal_Int32)floor(aRange.getMinX()), (sal_Int32)floor(aRange.getMinY()), 1244 (sal_Int32)ceil(aRange.getMaxX()), (sal_Int32)ceil(aRange.getMaxY())); 1245 1246 if(!aRectangle.IsEmpty()) 1247 { 1248 // try to paint EPS directly without fallback visualisation 1249 const bool bEPSPaintedDirectly(mpOutputDevice->DrawEPS( 1250 aRectangle.TopLeft(), 1251 aRectangle.GetSize(), 1252 rEpsPrimitive2D.getGfxLink(), 1253 0)); 1254 1255 if(!bEPSPaintedDirectly) 1256 { 1257 // use the decomposition which will correctly handle the 1258 // fallback visualisation using full transformation (e.g. rotation) 1259 process(rEpsPrimitive2D.get2DDecomposition(getViewInformation2D())); 1260 } 1261 } 1262 } 1263 } 1264 1265 void VclProcessor2D::RenderSvgLinearAtomPrimitive2D(const primitive2d::SvgLinearAtomPrimitive2D& rCandidate) 1266 { 1267 const double fDelta(rCandidate.getOffsetB() - rCandidate.getOffsetA()); 1268 1269 if(basegfx::fTools::more(fDelta, 0.0)) 1270 { 1271 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA())); 1272 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB())); 1273 1274 // calculate discrete unit in WorldCoordinates; use diagonal (1.0, 1.0) and divide by sqrt(2) 1275 const basegfx::B2DVector aDiscreteVector(getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); 1276 const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 1.414213562373)); 1277 1278 // use color distance and discrete lengths to calculate step count 1279 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDelta, fDiscreteUnit)); 1280 1281 // switch off line painting 1282 mpOutputDevice->SetLineColor(); 1283 1284 // prepare polygon in needed width at start position (with discrete overlap) 1285 const basegfx::B2DPolygon aPolygon( 1286 basegfx::tools::createPolygonFromRect( 1287 basegfx::B2DRange( 1288 rCandidate.getOffsetA() - fDiscreteUnit, 1289 0.0, 1290 rCandidate.getOffsetA() + (fDelta / nSteps) + fDiscreteUnit, 1291 1.0))); 1292 1293 1294 // prepare loop ([0.0 .. 1.0[) 1295 double fUnitScale(0.0); 1296 const double fUnitStep(1.0 / nSteps); 1297 1298 // loop and paint 1299 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep) 1300 { 1301 basegfx::B2DPolygon aNew(aPolygon); 1302 1303 aNew.transform(maCurrentTransformation * basegfx::tools::createTranslateB2DHomMatrix(fDelta * fUnitScale, 0.0)); 1304 mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorA, aColorB, fUnitScale))); 1305 mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew)); 1306 } 1307 } 1308 } 1309 1310 void VclProcessor2D::RenderSvgRadialAtomPrimitive2D(const primitive2d::SvgRadialAtomPrimitive2D& rCandidate) 1311 { 1312 const double fDeltaScale(rCandidate.getScaleB() - rCandidate.getScaleA()); 1313 1314 if(basegfx::fTools::more(fDeltaScale, 0.0)) 1315 { 1316 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA())); 1317 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB())); 1318 1319 // calculate discrete unit in WorldCoordinates; use diagonal (1.0, 1.0) and divide by sqrt(2) 1320 const basegfx::B2DVector aDiscreteVector(getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); 1321 const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 1.414213562373)); 1322 1323 // use color distance and discrete lengths to calculate step count 1324 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDeltaScale, fDiscreteUnit)); 1325 1326 // switch off line painting 1327 mpOutputDevice->SetLineColor(); 1328 1329 // prepare loop ([0.0 .. 1.0[, full polygons, no polypolygons with holes) 1330 double fUnitScale(0.0); 1331 const double fUnitStep(1.0 / nSteps); 1332 1333 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep) 1334 { 1335 basegfx::B2DHomMatrix aTransform; 1336 const double fEndScale(rCandidate.getScaleB() - (fDeltaScale * fUnitScale)); 1337 1338 if(rCandidate.isTranslateSet()) 1339 { 1340 const basegfx::B2DVector aTranslate( 1341 basegfx::interpolate( 1342 rCandidate.getTranslateB(), 1343 rCandidate.getTranslateA(), 1344 fUnitScale)); 1345 1346 aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix( 1347 fEndScale, 1348 fEndScale, 1349 aTranslate.getX(), 1350 aTranslate.getY()); 1351 } 1352 else 1353 { 1354 aTransform = basegfx::tools::createScaleB2DHomMatrix( 1355 fEndScale, 1356 fEndScale); 1357 } 1358 1359 basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle()); 1360 1361 aNew.transform(maCurrentTransformation * aTransform); 1362 mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorB, aColorA, fUnitScale))); 1363 mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew)); 1364 } 1365 } 1366 } 1367 1368 void VclProcessor2D::adaptLineToFillDrawMode() const 1369 { 1370 const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode()); 1371 1372 if(nOriginalDrawMode & (DRAWMODE_BLACKLINE|DRAWMODE_GRAYLINE|DRAWMODE_GHOSTEDLINE|DRAWMODE_WHITELINE|DRAWMODE_SETTINGSLINE)) 1373 { 1374 sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode); 1375 1376 if(nOriginalDrawMode & DRAWMODE_BLACKLINE) 1377 { 1378 nAdaptedDrawMode |= DRAWMODE_BLACKFILL; 1379 } 1380 else 1381 { 1382 nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL; 1383 } 1384 1385 if(nOriginalDrawMode & DRAWMODE_GRAYLINE) 1386 { 1387 nAdaptedDrawMode |= DRAWMODE_GRAYFILL; 1388 } 1389 else 1390 { 1391 nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL; 1392 } 1393 1394 if(nOriginalDrawMode & DRAWMODE_GHOSTEDLINE) 1395 { 1396 nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL; 1397 } 1398 else 1399 { 1400 nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL; 1401 } 1402 1403 if(nOriginalDrawMode & DRAWMODE_WHITELINE) 1404 { 1405 nAdaptedDrawMode |= DRAWMODE_WHITEFILL; 1406 } 1407 else 1408 { 1409 nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL; 1410 } 1411 1412 if(nOriginalDrawMode & DRAWMODE_SETTINGSLINE) 1413 { 1414 nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL; 1415 } 1416 else 1417 { 1418 nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL; 1419 } 1420 1421 mpOutputDevice->SetDrawMode(nAdaptedDrawMode); 1422 } 1423 } 1424 1425 void VclProcessor2D::adaptTextToFillDrawMode() const 1426 { 1427 const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode()); 1428 if(nOriginalDrawMode & (DRAWMODE_BLACKTEXT|DRAWMODE_GRAYTEXT|DRAWMODE_GHOSTEDTEXT|DRAWMODE_WHITETEXT|DRAWMODE_SETTINGSTEXT)) 1429 { 1430 sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode); 1431 1432 if(nOriginalDrawMode & DRAWMODE_BLACKTEXT) 1433 { 1434 nAdaptedDrawMode |= DRAWMODE_BLACKFILL; 1435 } 1436 else 1437 { 1438 nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL; 1439 } 1440 1441 if(nOriginalDrawMode & DRAWMODE_GRAYTEXT) 1442 { 1443 nAdaptedDrawMode |= DRAWMODE_GRAYFILL; 1444 } 1445 else 1446 { 1447 nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL; 1448 } 1449 1450 if(nOriginalDrawMode & DRAWMODE_GHOSTEDTEXT) 1451 { 1452 nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL; 1453 } 1454 else 1455 { 1456 nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL; 1457 } 1458 1459 if(nOriginalDrawMode & DRAWMODE_WHITETEXT) 1460 { 1461 nAdaptedDrawMode |= DRAWMODE_WHITEFILL; 1462 } 1463 else 1464 { 1465 nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL; 1466 } 1467 1468 if(nOriginalDrawMode & DRAWMODE_SETTINGSTEXT) 1469 { 1470 nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL; 1471 } 1472 else 1473 { 1474 nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL; 1475 } 1476 1477 mpOutputDevice->SetDrawMode(nAdaptedDrawMode); 1478 } 1479 } 1480 1481 ////////////////////////////////////////////////////////////////////////////// 1482 // process support 1483 1484 VclProcessor2D::VclProcessor2D( 1485 const geometry::ViewInformation2D& rViewInformation, 1486 OutputDevice& rOutDev) 1487 : BaseProcessor2D(rViewInformation), 1488 mpOutputDevice(&rOutDev), 1489 maBColorModifierStack(), 1490 maCurrentTransformation(), 1491 maDrawinglayerOpt(), 1492 mnPolygonStrokePrimitive2D(0) 1493 { 1494 // set digit language, derived from SvtCTLOptions to have the correct 1495 // number display for arabic/hindi numerals 1496 const SvtCTLOptions aSvtCTLOptions; 1497 LanguageType eLang(LANGUAGE_SYSTEM); 1498 1499 if(SvtCTLOptions::NUMERALS_HINDI == aSvtCTLOptions.GetCTLTextNumerals()) 1500 { 1501 eLang = LANGUAGE_ARABIC_SAUDI_ARABIA; 1502 } 1503 else if(SvtCTLOptions::NUMERALS_ARABIC == aSvtCTLOptions.GetCTLTextNumerals()) 1504 { 1505 eLang = LANGUAGE_ENGLISH; 1506 } 1507 else 1508 { 1509 eLang = (LanguageType)Application::GetSettings().GetLanguage(); 1510 } 1511 1512 rOutDev.SetDigitLanguage(eLang); 1513 } 1514 1515 VclProcessor2D::~VclProcessor2D() 1516 { 1517 } 1518 } // end of namespace processor2d 1519 } // end of namespace drawinglayer 1520 1521 ////////////////////////////////////////////////////////////////////////////// 1522 // eof 1523