Debian Codegraph @

cppcanvas/source/mtfrenderer/implrenderer.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <comphelper/diagnose_ex.hxx>
21 #include <tools/debug.hxx>
22 #include <utility>
23 #include <vcl/svapp.hxx>
24 #include <comphelper/propertysequence.hxx>
25 #include <comphelper/propertyvalue.hxx>
26 #include <cppcanvas/canvas.hxx>
27 #include <com/sun/star/rendering/XGraphicDevice.hpp>
28 #include <com/sun/star/rendering/TexturingMode.hpp>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/rendering/PanoseProportion.hpp>
31 #include <com/sun/star/rendering/XCanvasFont.hpp>
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 #include <com/sun/star/rendering/PathCapType.hpp>
34 #include <com/sun/star/rendering/PathJoinType.hpp>
35 #include <basegfx/utils/canvastools.hxx>
36 #include <basegfx/utils/gradienttools.hxx>
37 #include <basegfx/numeric/ftools.hxx>
38 #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolypolygon.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <basegfx/vector/b2dsize.hxx>
44 #include <basegfx/range/b2drectangle.hxx>
45 #include <basegfx/point/b2dpoint.hxx>
46 #include <basegfx/polygon/b2dpolygonclipper.hxx>
47 #include <canvas/canvastools.hxx>
48 #include <rtl/ustrbuf.hxx>
49 #include <vcl/alpha.hxx>
50 #include <vcl/canvastools.hxx>
51 #include <vcl/gdimtf.hxx>
52 #include <vcl/metaact.hxx>
53 #include <vcl/virdev.hxx>
54 #include <vcl/metric.hxx>
55 #include <vcl/graphictools.hxx>
56 #include <vcl/BitmapPalette.hxx>
57 #include <tools/poly.hxx>
58 #include <i18nlangtag/languagetag.hxx>
59 #include <implrenderer.hxx>
60 #include <tools.hxx>
61 #include <outdevstate.hxx>
62 #include <action.hxx>
63 #include <sal/log.hxx>
64 #include "bitmapaction.hxx"
65 #include "lineaction.hxx"
66 #include "pointaction.hxx"
67 #include "polypolyaction.hxx"
68 #include "textaction.hxx"
69 #include "transparencygroupaction.hxx"
70 #include <vector>
71 #include <algorithm>
72 #include <memory>
73 #include <string_view>
74 #include "mtftools.hxx"
75
76 using namespace ::com::sun::star;
77
78
79 // free support functions
80 // ======================
81 namespace
82 {
83 template < class MetaActionType > void setStateColor( MetaActionType* pAct,
84 bool& rIsColorSet,
85 uno::Sequence< double >& rColorSequence,
86 const cppcanvas::CanvasSharedPtr& rCanvas )
87 {
88 rIsColorSet = pAct->IsSetting();
89 if (!rIsColorSet)
90 return;
91
92 ::Color aColor( pAct->GetColor() );
93
94 // force alpha part of color to
95 // opaque. transparent painting is done
96 // explicitly via MetaActionType::Transparent
97 aColor.SetAlpha(255);
98 //aColor.SetTransparency(128);
99
100 rColorSequence = vcl::unotools::colorToDoubleSequence(
101 aColor,
102 rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
103 }
104
105 void setupStrokeAttributes( rendering::StrokeAttributes& o_rStrokeAttributes,
106 const ::cppcanvas::internal::ActionFactoryParameters& rParms,
107 const LineInfo& rLineInfo )
108 {
109 const ::basegfx::B2DSize aWidth( rLineInfo.GetWidth(), 0 );
110 o_rStrokeAttributes.StrokeWidth =
111 (rParms.mrStates.getState().mapModeTransform * aWidth).getLength();
112
113 // setup reasonable defaults
114 o_rStrokeAttributes.MiterLimit = 15.0; // 1.0 was no good default; GDI+'s limit is 10.0, our's is 15.0
115 o_rStrokeAttributes.StartCapType = rendering::PathCapType::BUTT;
116 o_rStrokeAttributes.EndCapType = rendering::PathCapType::BUTT;
117
118 switch (rLineInfo.GetLineJoin())
119 {
120 case basegfx::B2DLineJoin::NONE:
121 o_rStrokeAttributes.JoinType = rendering::PathJoinType::NONE;
122 break;
123 case basegfx::B2DLineJoin::Bevel:
124 o_rStrokeAttributes.JoinType = rendering::PathJoinType::BEVEL;
125 break;
126 case basegfx::B2DLineJoin::Miter:
127 o_rStrokeAttributes.JoinType = rendering::PathJoinType::MITER;
128 break;
129 case basegfx::B2DLineJoin::Round:
130 o_rStrokeAttributes.JoinType = rendering::PathJoinType::ROUND;
131 break;
132 }
133
134 switch(rLineInfo.GetLineCap())
135 {
136 default: /* css::drawing::LineCap_BUTT */
137 {
138 o_rStrokeAttributes.StartCapType = rendering::PathCapType::BUTT;
139 o_rStrokeAttributes.EndCapType = rendering::PathCapType::BUTT;
140 break;
141 }
142 case css::drawing::LineCap_ROUND:
143 {
144 o_rStrokeAttributes.StartCapType = rendering::PathCapType::ROUND;
145 o_rStrokeAttributes.EndCapType = rendering::PathCapType::ROUND;
146 break;
147 }
148 case css::drawing::LineCap_SQUARE:
149 {
150 o_rStrokeAttributes.StartCapType = rendering::PathCapType::SQUARE;
151 o_rStrokeAttributes.EndCapType = rendering::PathCapType::SQUARE;
152 break;
153 }
154 }
155
156 if( LineStyle::Dash != rLineInfo.GetStyle() )
157 return;
158
159 const ::cppcanvas::internal::OutDevState& rState( rParms.mrStates.getState() );
160
161 // TODO(F1): Interpret OutDev::GetRefPoint() for the start of the dashing.
162
163 // interpret dash info only if explicitly enabled as
164 // style
165 const ::basegfx::B2DSize aDistance( rLineInfo.GetDistance(), 0 );
166 const double nDistance( (rState.mapModeTransform * aDistance).getLength() );
167
168 const ::basegfx::B2DSize aDashLen( rLineInfo.GetDashLen(), 0 );
169 const double nDashLen( (rState.mapModeTransform * aDashLen).getLength() );
170
171 const ::basegfx::B2DSize aDotLen( rLineInfo.GetDotLen(), 0 );
172 const double nDotLen( (rState.mapModeTransform * aDotLen).getLength() );
173
174 const sal_Int32 nNumArryEntries( 2*rLineInfo.GetDashCount() +
175 2*rLineInfo.GetDotCount() );
176
177 o_rStrokeAttributes.DashArray.realloc( nNumArryEntries );
178 double* pDashArray = o_rStrokeAttributes.DashArray.getArray();
179
180
181 // iteratively fill dash array, first with dashes, then
182 // with dots.
183
184
185 sal_Int32 nCurrEntry=0;
186
187 for( sal_Int32 i=0; i<rLineInfo.GetDashCount(); ++i )
188 {
189 pDashArray[nCurrEntry++] = nDashLen;
190 pDashArray[nCurrEntry++] = nDistance;
191 }
192 for( sal_Int32 i=0; i<rLineInfo.GetDotCount(); ++i )
193 {
194 pDashArray[nCurrEntry++] = nDotLen;
195 pDashArray[nCurrEntry++] = nDistance;
196 }
197 }
198
199
200 /** Create masked Bitmap, where the white areas of rBitmap are
201 transparent, and the other appear in rMaskColor.
202 */
203 Bitmap createMaskBmp( const Bitmap& rBitmap, const ::Color& rMaskColor )
204 {
205 const ::Color aWhite( COL_WHITE );
206 BitmapPalette aBiLevelPalette{
207 aWhite, rMaskColor
208 };
209
210 AlphaMask aMask( rBitmap.CreateAlphaMask( aWhite ));
211 Bitmap aSolid( rBitmap.GetSizePixel(),
212 vcl::PixelFormat::N8_BPP,
213 &aBiLevelPalette );
214 aSolid.Erase( rMaskColor );
215
216 return Bitmap( aSolid, aMask );
217 }
218 }
219
220 namespace cppcanvas::internal
221 {
222 // state stack manipulators
223
224 void VectorOfOutDevStates::clearStateStack()
225 {
226 m_aStates.clear();
227 m_aStates.push_back(OutDevState());
228 }
229
230 OutDevState& VectorOfOutDevStates::getState()
231 {
232 return m_aStates.back();
233 }
234
235 const OutDevState& VectorOfOutDevStates::getState() const
236 {
237 return m_aStates.back();
238 }
239
240 void VectorOfOutDevStates::pushState(vcl::PushFlags nFlags)
241 {
242 m_aStates.push_back( getState() );
243 getState().pushFlags = nFlags;
244 }
245
246 void VectorOfOutDevStates::popState()
247 {
248 if( getState().pushFlags != vcl::PushFlags::ALL )
249 {
250 // a state is pushed which is incomplete, i.e. does not
251 // restore everything to the previous stack level when
252 // popped.
253 // That means, we take the old state, and restore every
254 // OutDevState member whose flag is set, from the new to the
255 // old state. Then the new state gets overwritten by the
256 // calculated state
257
258 // preset to-be-calculated new state with old state
259 OutDevState aCalculatedNewState( getState() );
260
261 // selectively copy to-be-restored content over saved old
262 // state
263 m_aStates.pop_back();
264
265 const OutDevState& rNewState( getState() );
266
267 if( aCalculatedNewState.pushFlags & vcl::PushFlags::LINECOLOR )
268 {
269 aCalculatedNewState.lineColor = rNewState.lineColor;
270 aCalculatedNewState.isLineColorSet = rNewState.isLineColorSet;
271 }
272
273 if( aCalculatedNewState.pushFlags & vcl::PushFlags::FILLCOLOR )
274 {
275 aCalculatedNewState.fillColor = rNewState.fillColor;
276 aCalculatedNewState.isFillColorSet = rNewState.isFillColorSet;
277 }
278
279 if( aCalculatedNewState.pushFlags & vcl::PushFlags::FONT )
280 {
281 aCalculatedNewState.xFont = rNewState.xFont;
282 aCalculatedNewState.fontRotation = rNewState.fontRotation;
283 aCalculatedNewState.textReliefStyle = rNewState.textReliefStyle;
284 aCalculatedNewState.textOverlineStyle = rNewState.textOverlineStyle;
285 aCalculatedNewState.textUnderlineStyle = rNewState.textUnderlineStyle;
286 aCalculatedNewState.textStrikeoutStyle = rNewState.textStrikeoutStyle;
287 aCalculatedNewState.textEmphasisMark = rNewState.textEmphasisMark;
288 aCalculatedNewState.isTextEffectShadowSet = rNewState.isTextEffectShadowSet;
289 aCalculatedNewState.isTextWordUnderlineSet = rNewState.isTextWordUnderlineSet;
290 aCalculatedNewState.isTextOutlineModeSet = rNewState.isTextOutlineModeSet;
291 }
292
293 if( aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTCOLOR )
294 {
295 aCalculatedNewState.textColor = rNewState.textColor;
296 }
297
298 if( aCalculatedNewState.pushFlags & vcl::PushFlags::MAPMODE )
299 {
300 aCalculatedNewState.mapModeTransform = rNewState.mapModeTransform;
301 }
302
303 if( aCalculatedNewState.pushFlags & vcl::PushFlags::CLIPREGION )
304 {
305 aCalculatedNewState.clip = rNewState.clip;
306 aCalculatedNewState.clipRect = rNewState.clipRect;
307 aCalculatedNewState.xClipPoly = rNewState.xClipPoly;
308 }
309
310 // TODO(F2): Raster ops NYI
311 // if( (aCalculatedNewState.pushFlags & vcl::PushFlags::RASTEROP) )
312 // {
313 // }
314
315 if( aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTFILLCOLOR )
316 {
317 aCalculatedNewState.textFillColor = rNewState.textFillColor;
318 aCalculatedNewState.isTextFillColorSet = rNewState.isTextFillColorSet;
319 }
320
321 if( aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTALIGN )
322 {
323 aCalculatedNewState.textReferencePoint = rNewState.textReferencePoint;
324 }
325
326 // TODO(F1): Refpoint handling NYI
327 // if( (aCalculatedNewState.pushFlags & vcl::PushFlags::REFPOINT) )
328 // {
329 // }
330
331 if( aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTLINECOLOR )
332 {
333 aCalculatedNewState.textLineColor = rNewState.textLineColor;
334 aCalculatedNewState.isTextLineColorSet = rNewState.isTextLineColorSet;
335 }
336
337 if( aCalculatedNewState.pushFlags & vcl::PushFlags::OVERLINECOLOR )
338 {
339 aCalculatedNewState.textOverlineColor = rNewState.textOverlineColor;
340 aCalculatedNewState.isTextOverlineColorSet = rNewState.isTextOverlineColorSet;
341 }
342
343 if( aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTLAYOUTMODE )
344 {
345 aCalculatedNewState.textAlignment = rNewState.textAlignment;
346 aCalculatedNewState.textDirection = rNewState.textDirection;
347 }
348
349 // TODO(F2): Text language handling NYI
350 // if( (aCalculatedNewState.pushFlags & vcl::PushFlags::TEXTLANGUAGE) )
351 // {
352 // }
353
354 // always copy push mode
355 aCalculatedNewState.pushFlags = rNewState.pushFlags;
356
357 // flush to stack
358 getState() = std::move(aCalculatedNewState);
359 }
360 else
361 {
362 m_aStates.pop_back();
363 }
364 }
365
366 bool ImplRenderer::createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
367 const ActionFactoryParameters& rParms )
368 {
369 const OutDevState& rState( rParms.mrStates.getState() );
370 if( (!rState.isLineColorSet &&
371 !rState.isFillColorSet) ||
372 (!rState.lineColor.hasElements() &&
373 !rState.fillColor.hasElements()) )
374 {
375 return false;
376 }
377
378 std::shared_ptr<Action> pPolyAction(
379 internal::PolyPolyActionFactory::createPolyPolyAction(
380 rPolyPoly, rParms.mrCanvas, rState ) );
381
382 if( pPolyAction )
383 {
384 maActions.emplace_back(
385 pPolyAction,
386 rParms.mrCurrActionIndex );
387
388 rParms.mrCurrActionIndex += pPolyAction->getActionCount()-1;
389 }
390
391 return true;
392 }
393
394 bool ImplRenderer::createFillAndStroke( const ::basegfx::B2DPolygon& rPoly,
395 const ActionFactoryParameters& rParms )
396 {
397 return createFillAndStroke( ::basegfx::B2DPolyPolygon( rPoly ),
398 rParms );
399 }
400
401 void ImplRenderer::skipContent( GDIMetaFile& rMtf,
402 const char* pCommentString,
403 sal_Int32& io_rCurrActionIndex )
404 {
405 ENSURE_OR_THROW( pCommentString,
406 "ImplRenderer::skipContent(): NULL string given" );
407
408 MetaAction* pCurrAct;
409 while( (pCurrAct=rMtf.NextAction()) != nullptr )
410 {
411 // increment action index, we've skipped an action.
412 ++io_rCurrActionIndex;
413
414 if( pCurrAct->GetType() == MetaActionType::COMMENT &&
415 static_cast<MetaCommentAction*>(pCurrAct)->GetComment().equalsIgnoreAsciiCase(
416 pCommentString) )
417 {
418 // requested comment found, done
419 return;
420 }
421 }
422
423 // EOF
424 }
425
426 bool ImplRenderer::isActionContained( GDIMetaFile& rMtf,
427 const char* pCommentString,
428 MetaActionType nType )
429 {
430 ENSURE_OR_THROW( pCommentString,
431 "ImplRenderer::isActionContained(): NULL string given" );
432
433 bool bRet( false );
434
435 // at least _one_ call to GDIMetaFile::NextAction() is
436 // executed
437 size_t nPos( 1 );
438
439 MetaAction* pCurrAct;
440 while( (pCurrAct=rMtf.NextAction()) != nullptr )
441 {
442 if( pCurrAct->GetType() == nType )
443 {
444 bRet = true; // action type found
445 break;
446 }
447
448 if( pCurrAct->GetType() == MetaActionType::COMMENT &&
449 static_cast<MetaCommentAction*>(pCurrAct)->GetComment().equalsIgnoreAsciiCase(
450 pCommentString) )
451 {
452 // delimiting end comment found, done
453 bRet = false; // not yet found
454 break;
455 }
456
457 ++nPos;
458 }
459
460 // rewind metafile to previous position (this method must
461 // not change the current metaaction)
462 while (nPos)
463 {
464 --nPos;
465 rMtf.WindPrev();
466 }
467
468 if( !pCurrAct )
469 {
470 // EOF, and not yet found
471 bRet = false;
472 }
473
474 return bRet;
475 }
476
477 void ImplRenderer::createGradientAction( const ::tools::PolyPolygon& rPoly,
478 const ::Gradient& rGradient,
479 const ActionFactoryParameters& rParms,
480 bool bIsPolygonRectangle,
481 bool bSubsettableActions )
482 {
483 DBG_TESTSOLARMUTEX();
484
485 ::basegfx::B2DPolyPolygon aDevicePoly( rPoly.getB2DPolyPolygon() );
486 aDevicePoly.transform( rParms.mrStates.getState().mapModeTransform );
487
488 // decide, whether this gradient can be rendered natively
489 // by the canvas, or must be emulated via VCL gradient
490 // action extraction.
491 const sal_uInt16 nSteps( rGradient.GetSteps() );
492
493 if( // step count is infinite, can use native canvas
494 // gradients here
495 nSteps == 0 ||
496 // step count is sufficiently high, such that no
497 // discernible difference should be visible.
498 nSteps > 64 )
499 {
500 uno::Reference< lang::XMultiServiceFactory> xFactory(
501 rParms.mrCanvas->getUNOCanvas()->getDevice()->getParametricPolyPolygonFactory() );
502
503 if( xFactory.is() )
504 {
505 rendering::Texture aTexture;
506
507 aTexture.RepeatModeX = rendering::TexturingMode::CLAMP;
508 aTexture.RepeatModeY = rendering::TexturingMode::CLAMP;
509 aTexture.Alpha = 1.0;
510
511
512 // setup start/end color values
513
514
515 // scale color coefficients with gradient intensities
516 const sal_uInt16 nStartIntensity( rGradient.GetStartIntensity() );
517 ::Color aVCLStartColor( rGradient.GetStartColor() );
518 aVCLStartColor.SetRed( static_cast<sal_uInt8>(aVCLStartColor.GetRed() * nStartIntensity / 100) );
519 aVCLStartColor.SetGreen( static_cast<sal_uInt8>(aVCLStartColor.GetGreen() * nStartIntensity / 100) );
520 aVCLStartColor.SetBlue( static_cast<sal_uInt8>(aVCLStartColor.GetBlue() * nStartIntensity / 100) );
521
522 const sal_uInt16 nEndIntensity( rGradient.GetEndIntensity() );
523 ::Color aVCLEndColor( rGradient.GetEndColor() );
524 aVCLEndColor.SetRed( static_cast<sal_uInt8>(aVCLEndColor.GetRed() * nEndIntensity / 100) );
525 aVCLEndColor.SetGreen( static_cast<sal_uInt8>(aVCLEndColor.GetGreen() * nEndIntensity / 100) );
526 aVCLEndColor.SetBlue( static_cast<sal_uInt8>(aVCLEndColor.GetBlue() * nEndIntensity / 100) );
527
528 uno::Reference<rendering::XColorSpace> xColorSpace(
529 rParms.mrCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace());
530 const uno::Sequence< double > aStartColor(
531 vcl::unotools::colorToDoubleSequence( aVCLStartColor,
532 xColorSpace ));
533 const uno::Sequence< double > aEndColor(
534 vcl::unotools::colorToDoubleSequence( aVCLEndColor,
535 xColorSpace ));
536
537 uno::Sequence< uno::Sequence < double > > aColors;
538 uno::Sequence< double > aStops;
539
540 if( rGradient.GetStyle() == css::awt::GradientStyle_AXIAL )
541 {
542 aStops = { 0.0, 0.5, 1.0 };
543 aColors = { aEndColor, aStartColor, aEndColor };
544 }
545 else
546 {
547 aStops = { 0.0, 1.0 };
548 aColors = { aStartColor, aEndColor };
549 }
550
551 const ::basegfx::B2DRectangle aBounds(
552 aDevicePoly.getB2DRange() );
553 const ::basegfx::B2DVector aOffset(
554 rGradient.GetOfsX() / 100.0,
555 rGradient.GetOfsY() / 100.0);
556 double fRotation = toRadians( rGradient.GetAngle() );
557 const double fBorder( rGradient.GetBorder() / 100.0 );
558
559 basegfx::B2DHomMatrix aRot90;
560 aRot90.rotate(M_PI_2);
561
562 basegfx::ODFGradientInfo aGradInfo;
563 OUString aGradientService;
564 switch( rGradient.GetStyle() )
565 {
566 case css::awt::GradientStyle_LINEAR:
567 aGradInfo = basegfx::utils::createLinearODFGradientInfo(
568 aBounds,
569 nSteps,
570 fBorder,
571 fRotation);
572 // map ODF to svg gradient orientation - x
573 // instead of y direction
574 aGradInfo.setTextureTransform(aGradInfo.getTextureTransform() * aRot90);
575 aGradientService = "LinearGradient";
576 break;
577
578 case css::awt::GradientStyle_AXIAL:
579 {
580 // Adapt the border so that it is suitable
581 // for the axial gradient. An axial
582 // gradient consists of two linear
583 // gradients. Each of those covers half
584 // of the total size. In order to
585 // compensate for the condensed display of
586 // the linear gradients, we have to
587 // enlarge the area taken up by the actual
588 // gradient (1-fBorder). After that we
589 // have to turn the result back into a
590 // border value, hence the second (left
591 // most 1-...
592 const double fAxialBorder (1-2*(1-fBorder));
593 aGradInfo = basegfx::utils::createAxialODFGradientInfo(
594 aBounds,
595 nSteps,
596 fAxialBorder,
597 fRotation);
598 // map ODF to svg gradient orientation - x
599 // instead of y direction
600 aGradInfo.setTextureTransform(aGradInfo.getTextureTransform() * aRot90);
601
602 // map ODF axial gradient to 3-stop linear
603 // gradient - shift left by 0.5
604 basegfx::B2DHomMatrix aShift;
605
606 aShift.translate(-0.5,0);
607 aGradInfo.setTextureTransform(aGradInfo.getTextureTransform() * aShift);
608 aGradientService = "LinearGradient";
609 break;
610 }
611
612 case css::awt::GradientStyle_RADIAL:
613 aGradInfo = basegfx::utils::createRadialODFGradientInfo(
614 aBounds,
615 aOffset,
616 nSteps,
617 fBorder);
618 aGradientService = "EllipticalGradient";
619 break;
620
621 case css::awt::GradientStyle_ELLIPTICAL:
622 aGradInfo = basegfx::utils::createEllipticalODFGradientInfo(
623 aBounds,
624 aOffset,
625 nSteps,
626 fBorder,
627 fRotation);
628 aGradientService = "EllipticalGradient";
629 break;
630
631 case css::awt::GradientStyle_SQUARE:
632 aGradInfo = basegfx::utils::createSquareODFGradientInfo(
633 aBounds,
634 aOffset,
635 nSteps,
636 fBorder,
637 fRotation);
638 aGradientService = "RectangularGradient";
639 break;
640
641 case css::awt::GradientStyle_RECT:
642 aGradInfo = basegfx::utils::createRectangularODFGradientInfo(
643 aBounds,
644 aOffset,
645 nSteps,
646 fBorder,
647 fRotation);
648 aGradientService = "RectangularGradient";
649 break;
650
651 default:
652 ENSURE_OR_THROW( false,
653 "ImplRenderer::createGradientAction(): Unexpected gradient type" );
654 break;
655 }
656
657 ::basegfx::unotools::affineMatrixFromHomMatrix( aTexture.AffineTransform,
658 aGradInfo.getTextureTransform() );
659
660 uno::Sequence<uno::Any> args(comphelper::InitAnyPropertySequence(
661 {
662 {"Colors", uno::Any(aColors)},
663 {"Stops", uno::Any(aStops)},
664 {"AspectRatio", uno::Any(aGradInfo.getAspectRatio())},
665 }));
666 aTexture.Gradient.set(
667 xFactory->createInstanceWithArguments(aGradientService,
668 args),
669 uno::UNO_QUERY);
670 if( aTexture.Gradient.is() )
671 {
672 std::shared_ptr<Action> pPolyAction(
673 internal::PolyPolyActionFactory::createPolyPolyAction(
674 aDevicePoly,
675 rParms.mrCanvas,
676 rParms.mrStates.getState(),
677 aTexture ) );
678
679 if( pPolyAction )
680 {
681 maActions.emplace_back(
682 pPolyAction,
683 rParms.mrCurrActionIndex );
684
685 rParms.mrCurrActionIndex += pPolyAction->getActionCount()-1;
686 }
687
688 // done, using native gradients
689 return;
690 }
691 }
692 }
693
694 // cannot currently use native canvas gradients, as a
695 // finite step size is given (this funny feature is not
696 // supported by the XCanvas API)
697 rParms.mrStates.pushState(vcl::PushFlags::ALL);
698
699 if( !bIsPolygonRectangle )
700 {
701 // only clip, if given polygon is not a rectangle in
702 // the first place (the gradient is always limited to
703 // the given bound rect)
704 updateClipping(
705 aDevicePoly,
706 rParms,
707 true );
708 }
709
710 GDIMetaFile aTmpMtf;
711 Gradient aGradient(rGradient);
712 aGradient.AddGradientActions( rPoly.GetBoundRect(), aTmpMtf );
713
714 createActions( aTmpMtf, rParms, bSubsettableActions );
715
716 rParms.mrStates.popState();
717 }
718
719 uno::Reference< rendering::XCanvasFont > ImplRenderer::createFont( double& o_rFontRotation,
720 const vcl::Font& rFont,
721 const ActionFactoryParameters& rParms )
722 {
723 rendering::FontRequest aFontRequest;
724
725 if( rParms.mrParms.maFontName )
726 aFontRequest.FontDescription.FamilyName = *rParms.mrParms.maFontName;
727 else
728 aFontRequest.FontDescription.FamilyName = rFont.GetFamilyName();
729
730 aFontRequest.FontDescription.StyleName = rFont.GetStyleName();
731
732 aFontRequest.FontDescription.IsSymbolFont = (rFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL) ? util::TriState_YES : util::TriState_NO;
733 aFontRequest.FontDescription.IsVertical = rFont.IsVertical() ? util::TriState_YES : util::TriState_NO;
734
735 // TODO(F2): improve vclenum->panose conversion
736 aFontRequest.FontDescription.FontDescription.Weight =
737 rParms.mrParms.maFontWeight ?
738 *rParms.mrParms.maFontWeight :
739 ::canvastools::numeric_cast<sal_Int8>( ::basegfx::fround( rFont.GetWeight() ) );
740 aFontRequest.FontDescription.FontDescription.Letterform =
741 rParms.mrParms.maFontLetterForm ?
742 *rParms.mrParms.maFontLetterForm :
743 (rFont.GetItalic() == ITALIC_NONE) ? 0 : 9;
744 aFontRequest.FontDescription.FontDescription.Proportion =
745 (rFont.GetPitch() == PITCH_FIXED)
746 ? rendering::PanoseProportion::MONO_SPACED
747 : rendering::PanoseProportion::ANYTHING;
748
749 LanguageType aLang = rFont.GetLanguage();
750 aFontRequest.Locale = LanguageTag::convertToLocale( aLang, false);
751
752 // setup state-local text transformation,
753 // if the font be rotated
754 const auto nFontAngle( rFont.GetOrientation() );
755 if( nFontAngle )
756 {
757 // set to unity transform rotated by font angle
758 const double nAngle( toRadians(nFontAngle) );
759 o_rFontRotation = -nAngle;
760 }
761 else
762 {
763 o_rFontRotation = 0.0;
764 }
765
766 geometry::Matrix2D aFontMatrix;
767 ::canvastools::setIdentityMatrix2D( aFontMatrix );
768
769 // TODO(F2): use correct scale direction, font
770 // height might be width or anything else
771
772 // TODO(Q3): This code smells of programming by
773 // coincidence (the next two if statements)
774
775 ::Size rFontSizeLog( rFont.GetFontSize() );
776
777 if (rFontSizeLog.Height() == 0)
778 {
779 // guess 16 pixel (as in VCL)
780 rFontSizeLog = ::Size(0, 16);
781
782 // convert to target MapUnit if not pixels
783 rFontSizeLog = OutputDevice::LogicToLogic(rFontSizeLog, MapMode(MapUnit::MapPixel), rParms.mrVDev.GetMapMode());
784 }
785
786 const sal_Int32 nFontWidthLog = rFontSizeLog.Width();
787 if( nFontWidthLog != 0 )
788 {
789 vcl::Font aTestFont = rFont;
790 aTestFont.SetAverageFontWidth( 0 );
791 sal_Int32 nNormalWidth = rParms.mrVDev.GetFontMetric( aTestFont ).GetAverageFontWidth();
792 if( nNormalWidth != nFontWidthLog )
793 if( nNormalWidth )
794 aFontMatrix.m00 = static_cast<double>(nFontWidthLog) / nNormalWidth;
795 }
796
797 // #i52608# apply map mode scale also to font matrix - an
798 // anisotrophic mapmode must be reflected in an
799 // anisotrophic font matrix scale.
800 const OutDevState& rState( rParms.mrStates.getState() );
801 if( !::basegfx::fTools::equal(
802 rState.mapModeTransform.get(0,0),
803 rState.mapModeTransform.get(1,1)) )
804 {
805 const double nScaleX( rState.mapModeTransform.get(0,0) );
806 const double nScaleY( rState.mapModeTransform.get(1,1) );
807
808 // note: no reason to check for division by zero, we
809 // always have the value closer (or equal) to zero as
810 // the nominator.
811 if( fabs(nScaleX) < fabs(nScaleY) )
812 aFontMatrix.m00 *= nScaleX / nScaleY;
813 else
814 aFontMatrix.m11 *= nScaleY / nScaleX;
815 }
816 aFontRequest.CellSize = (rState.mapModeTransform * vcl::unotools::b2DSizeFromSize(rFontSizeLog)).getHeight();
817
818 if (rFont.GetEmphasisMark() != FontEmphasisMark::NONE)
819 {
820 uno::Sequence< beans::PropertyValue > aProperties{ comphelper::makePropertyValue(
821 u"EmphasisMark"_ustr, sal_uInt32(rFont.GetEmphasisMark())) };
822 return rParms.mrCanvas->getUNOCanvas()->createFont(aFontRequest,
823 aProperties,
824 aFontMatrix);
825 }
826
827 return rParms.mrCanvas->getUNOCanvas()->createFont( aFontRequest,
828 uno::Sequence< beans::PropertyValue >(),
829 aFontMatrix );
830 }
831
832 // create text effects such as shadow/relief/embossed
833 void ImplRenderer::createTextAction( const ::Point& rStartPoint,
834 const OUString& rString,
835 int nIndex,
836 int nLength,
837 KernArraySpan pCharWidths,
838 std::span<const sal_Bool> pKashidaArray,
839 const ActionFactoryParameters& rParms,
840 bool bSubsettableActions )
841 {
842 ENSURE_OR_THROW( nIndex >= 0 && nLength <= rString.getLength() + nIndex,
843 "ImplRenderer::createTextWithEffectsAction(): Invalid text index" );
844
845 if( !nLength )
846 return; // zero-length text, no visible output
847
848 const OutDevState& rState( rParms.mrStates.getState() );
849
850 // TODO(F2): implement all text effects
851 // if( rState.textAlignment ); // TODO(F2): NYI
852
853 ::Color aTextFillColor( COL_AUTO );
854 ::Color aShadowColor( COL_AUTO );
855 ::Color aReliefColor( COL_AUTO );
856 ::Size aShadowOffset;
857 ::Size aReliefOffset;
858
859 uno::Reference<rendering::XColorSpace> xColorSpace(
860 rParms.mrCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
861
862 if( rState.isTextEffectShadowSet )
863 {
864 // calculate shadow offset (similar to outdev3.cxx)
865 // TODO(F3): better match with outdev3.cxx
866 sal_Int32 nShadowOffset = static_cast<sal_Int32>(1.5 + ((rParms.mrVDev.GetFont().GetFontHeight()-24.0)/24.0));
867 if( nShadowOffset < 1 )
868 nShadowOffset = 1;
869
870 aShadowOffset.setWidth( nShadowOffset );
871 aShadowOffset.setHeight( nShadowOffset );
872
873 // determine shadow color (from outdev3.cxx)
874 ::Color aTextColor = vcl::unotools::doubleSequenceToColor(
875 rState.textColor, xColorSpace );
876 bool bIsDark = (aTextColor == COL_BLACK)
877 || (aTextColor.GetLuminance() < 8);
878
879 aShadowColor = bIsDark ? COL_LIGHTGRAY : COL_BLACK;
880 aShadowColor.SetAlpha( aTextColor.GetAlpha() );
881 }
882
883 if( rState.textReliefStyle != FontRelief::NONE )
884 {
885 // calculate relief offset (similar to outdev3.cxx)
886 sal_Int32 nReliefOffset = rParms.mrVDev.PixelToLogic( Size( 1, 1 ) ).Height();
887 nReliefOffset += nReliefOffset/2;
888 if( nReliefOffset < 1 )
889 nReliefOffset = 1;
890
891 if( rState.textReliefStyle == FontRelief::Engraved )
892 nReliefOffset = -nReliefOffset;
893
894 aReliefOffset.setWidth( nReliefOffset );
895 aReliefOffset.setHeight( nReliefOffset );
896
897 // determine relief color (from outdev3.cxx)
898 ::Color aTextColor = vcl::unotools::doubleSequenceToColor(
899 rState.textColor, xColorSpace );
900
901 aReliefColor = COL_LIGHTGRAY;
902
903 // we don't have an automatic color, so black is always
904 // drawn on white (literally copied from
905 // vcl/source/gdi/outdev3.cxx)
906 if( aTextColor == COL_BLACK )
907 {
908 aTextColor = COL_WHITE;
909 rParms.mrStates.getState().textColor =
910 vcl::unotools::colorToDoubleSequence(
911 aTextColor, xColorSpace );
912 }
913
914 if( aTextColor == COL_WHITE )
915 aReliefColor = COL_BLACK;
916 aReliefColor.SetAlpha( aTextColor.GetAlpha() );
917 }
918
919 if (rState.isTextFillColorSet)
920 aTextFillColor = vcl::unotools::doubleSequenceToColor(rState.textFillColor, xColorSpace);
921
922 // create the actual text action
923 std::shared_ptr<Action> pTextAction(
924 TextActionFactory::createTextAction(
925 rStartPoint,
926 aReliefOffset,
927 aReliefColor,
928 aShadowOffset,
929 aShadowColor,
930 aTextFillColor,
931 rString,
932 nIndex,
933 nLength,
934 pCharWidths,
935 pKashidaArray,
936 rParms.mrVDev,
937 rParms.mrCanvas,
938 rState,
939 rParms.mrParms,
940 bSubsettableActions ) );
941
942 std::shared_ptr<Action> pStrikeoutTextAction;
943
944 if ( rState.textStrikeoutStyle == STRIKEOUT_X || rState.textStrikeoutStyle == STRIKEOUT_SLASH )
945 {
946 ::tools::Long nWidth = rParms.mrVDev.GetTextWidth( rString,nIndex,nLength );
947
948 sal_Unicode pChars[4];
949 if ( rState.textStrikeoutStyle == STRIKEOUT_X )
950 pChars[0] = 'X';
951 else
952 pChars[0] = '/';
953 pChars[3]=pChars[2]=pChars[1]=pChars[0];
954
955 ::tools::Long nStrikeoutWidth = (rParms.mrVDev.GetTextWidth(
956 OUString(pChars, std::size(pChars))) + 2) / 4;
957
958 if( nStrikeoutWidth <= 0 )
959 nStrikeoutWidth = 1;
960
961 ::tools::Long nMaxWidth = nStrikeoutWidth/2;
962 if ( nMaxWidth < 2 )
963 nMaxWidth = 2;
964 nMaxWidth += nWidth + 1;
965
966 ::tools::Long nFullStrikeoutWidth = 0;
967 OUStringBuffer aStrikeoutText;
968 while( (nFullStrikeoutWidth+=nStrikeoutWidth ) < nMaxWidth+1 )
969 aStrikeoutText.append(pChars[0]);
970
971 sal_Int32 nLen = aStrikeoutText.getLength();
972
973 if( nLen )
974 {
975 ::tools::Long nInterval = ( nWidth - nStrikeoutWidth * nLen ) / nLen;
976 nStrikeoutWidth += nInterval;
977 KernArray aStrikeoutCharWidths;
978
979 for ( int i = 0;i< nLen; i++ )
980 aStrikeoutCharWidths.push_back(nStrikeoutWidth * (i + 1));
981
982 pStrikeoutTextAction =
983 TextActionFactory::createTextAction(
984 rStartPoint,
985 aReliefOffset,
986 aReliefColor,
987 aShadowOffset,
988 aShadowColor,
989 aTextFillColor,
990 aStrikeoutText.makeStringAndClear(),
991 0/*nStartPos*/,
992 nLen,
993 aStrikeoutCharWidths,
994 pKashidaArray,
995 rParms.mrVDev,
996 rParms.mrCanvas,
997 rState,
998 rParms.mrParms,
999 bSubsettableActions ) ;
1000 }
1001 }
1002
1003 if( !pTextAction )
1004 return;
1005
1006 maActions.emplace_back(
1007 pTextAction,
1008 rParms.mrCurrActionIndex );
1009
1010 if ( pStrikeoutTextAction )
1011 {
1012 maActions.emplace_back(
1013 pStrikeoutTextAction,
1014 rParms.mrCurrActionIndex );
1015 }
1016
1017 rParms.mrCurrActionIndex += pTextAction->getActionCount()-1;
1018 }
1019
1020 void ImplRenderer::updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
1021 const ActionFactoryParameters& rParms,
1022 bool bIntersect )
1023 {
1024 ::cppcanvas::internal::OutDevState& rState( rParms.mrStates.getState() );
1025
1026 const bool bEmptyClipRect( rState.clipRect.IsEmpty() );
1027 const bool bEmptyClipPoly( rState.clip.count() == 0 );
1028
1029 ENSURE_OR_THROW( bEmptyClipPoly || bEmptyClipRect,
1030 "ImplRenderer::updateClipping(): Clip rect and polygon are both set!" );
1031
1032 if( !bIntersect ||
1033 (bEmptyClipRect && bEmptyClipPoly) )
1034 {
1035 rState.clip = rClipPoly;
1036 }
1037 else
1038 {
1039 if( !bEmptyClipRect )
1040 {
1041 // TODO(P3): Use Liang-Barsky polygon clip here,
1042 // after all, one object is just a rectangle!
1043
1044 // convert rect to polygon beforehand, must revert
1045 // to general polygon clipping here.
1046 ::tools::Rectangle aRect = rState.clipRect;
1047 // #121100# VCL rectangular clips always
1048 // include one more pixel to the right
1049 // and the bottom
1050 aRect.AdjustRight(1);
1051 aRect.AdjustBottom(1);
1052 rState.clip = ::basegfx::B2DPolyPolygon(
1053 ::basegfx::utils::createPolygonFromRect(
1054 vcl::unotools::b2DRectangleFromRectangle(aRect) ) );
1055 }
1056
1057 // AW: Simplified
1058 rState.clip = basegfx::utils::clipPolyPolygonOnPolyPolygon(
1059 rClipPoly, rState.clip, true, false);
1060 }
1061
1062 // by now, our clip resides in the OutDevState::clip
1063 // poly-polygon.
1064 rState.clipRect.SetEmpty();
1065
1066 if( rState.clip.count() == 0 )
1067 {
1068 if( rState.clipRect.IsEmpty() )
1069 {
1070 rState.xClipPoly.clear();
1071 }
1072 else
1073 {
1074 ::tools::Rectangle aRect = rState.clipRect;
1075 // #121100# VCL rectangular clips
1076 // always include one more pixel to
1077 // the right and the bottom
1078 aRect.AdjustRight(1);
1079 aRect.AdjustBottom(1);
1080 rState.xClipPoly = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1081 rParms.mrCanvas->getUNOCanvas()->getDevice(),
1082 ::basegfx::B2DPolyPolygon(
1083 ::basegfx::utils::createPolygonFromRect(
1084 vcl::unotools::b2DRectangleFromRectangle(aRect) ) ) );
1085 }
1086 }
1087 else
1088 {
1089 rState.xClipPoly = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1090 rParms.mrCanvas->getUNOCanvas()->getDevice(),
1091 rState.clip );
1092 }
1093 }
1094
1095 void ImplRenderer::updateClipping( const ::tools::Rectangle& rClipRect,
1096 const ActionFactoryParameters& rParms,
1097 bool bIntersect )
1098 {
1099 ::cppcanvas::internal::OutDevState& rState( rParms.mrStates.getState() );
1100
1101 const bool bEmptyClipRect( rState.clipRect.IsEmpty() );
1102 const bool bEmptyClipPoly( rState.clip.count() == 0 );
1103
1104 ENSURE_OR_THROW( bEmptyClipPoly || bEmptyClipRect,
1105 "ImplRenderer::updateClipping(): Clip rect and polygon are both set!" );
1106
1107 if( !bIntersect ||
1108 (bEmptyClipRect && bEmptyClipPoly) )
1109 {
1110 rState.clipRect = rClipRect;
1111 rState.clip.clear();
1112 }
1113 else if( bEmptyClipPoly )
1114 {
1115 rState.clipRect.Intersection( rClipRect );
1116 rState.clip.clear();
1117 }
1118 else
1119 {
1120 // TODO(P3): Handle a fourth case here, when all clip
1121 // polygons are rectangular, once B2DMultiRange's
1122 // sweep line implementation is done.
1123
1124 // general case: convert to polygon and clip
1125
1126
1127 // convert rect to polygon beforehand, must revert
1128 // to general polygon clipping here.
1129 ::basegfx::B2DPolyPolygon aClipPoly(
1130 ::basegfx::utils::createPolygonFromRect(
1131 vcl::unotools::b2DRectangleFromRectangle(rClipRect) ) );
1132
1133 rState.clipRect.SetEmpty();
1134
1135 // AW: Simplified
1136 rState.clip = basegfx::utils::clipPolyPolygonOnPolyPolygon(
1137 aClipPoly, rState.clip, true, false);
1138 }
1139
1140 if( rState.clip.count() == 0 )
1141 {
1142 if( rState.clipRect.IsEmpty() )
1143 {
1144 rState.xClipPoly.clear();
1145 }
1146 else
1147 {
1148 // #121100# VCL rectangular clips
1149 // always include one more pixel to
1150 // the right and the bottom
1151 ::tools::Rectangle aRect = rState.clipRect;
1152 aRect.AdjustRight(1);
1153 aRect.AdjustBottom(1);
1154 rState.xClipPoly = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1155 rParms.mrCanvas->getUNOCanvas()->getDevice(),
1156 ::basegfx::B2DPolyPolygon(
1157 ::basegfx::utils::createPolygonFromRect(
1158 vcl::unotools::b2DRectangleFromRectangle(aRect) ) ) );
1159 }
1160 }
1161 else
1162 {
1163 rState.xClipPoly = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1164 rParms.mrCanvas->getUNOCanvas()->getDevice(),
1165 rState.clip );
1166 }
1167 }
1168
1169 void ImplRenderer::createActions( GDIMetaFile& rMtf,
1170 const ActionFactoryParameters& rFactoryParms,
1171 bool bSubsettableActions )
1172 {
1173 /* TODO(P2): interpret mtf-comments
1174 ================================
1175
1176 - gradient fillings (do that via comments)
1177
1178 - think about mapping. _If_ we do everything in logical
1179 coordinates (which would solve the probs for stroke
1180 widths and text offsets), then we would have to
1181 recalc scaling for every drawing operation. This is
1182 because the outdev map mode might change at any time.
1183 Also keep in mind, that, although we've double precision
1184 float arithmetic now, different offsets might still
1185 generate different roundings (aka
1186 'OutputDevice::SetPixelOffset())
1187
1188 */
1189
1190 // alias common parameters
1191 VectorOfOutDevStates& rStates(rFactoryParms.mrStates);
1192 const CanvasSharedPtr& rCanvas(rFactoryParms.mrCanvas);
1193 ::VirtualDevice& rVDev(rFactoryParms.mrVDev);
1194 const Parameters& rParms(rFactoryParms.mrParms);
1195 sal_Int32& io_rCurrActionIndex(rFactoryParms.mrCurrActionIndex);
1196
1197
1198 // Loop over every metaaction
1199 // ==========================
1200 MetaAction* pCurrAct;
1201
1202 // TODO(P1): think about caching
1203 for( pCurrAct=rMtf.FirstAction();
1204 pCurrAct;
1205 pCurrAct = rMtf.NextAction() )
1206 {
1207 // execute every action, to keep VDev state up-to-date
1208 // currently used only for
1209 // - the map mode
1210 // - the line/fill color when processing a MetaActionType::Transparent
1211 // - SetFont to process font metric specific actions
1212 pCurrAct->Execute( &rVDev );
1213
1214 SAL_INFO("cppcanvas.emf", "MTF\trecord type: 0x" << static_cast<sal_uInt16>(pCurrAct->GetType()) << " (" << static_cast<sal_uInt16>(pCurrAct->GetType()) << ")");
1215
1216 switch( pCurrAct->GetType() )
1217 {
1218
1219
1220 // In the first part of this monster-switch, we
1221 // handle all state-changing meta actions. These
1222 // are all handled locally.
1223
1224
1225 case MetaActionType::PUSH:
1226 {
1227 MetaPushAction* pPushAction = static_cast<MetaPushAction*>(pCurrAct);
1228 rStates.pushState(pPushAction->GetFlags());
1229 }
1230 break;
1231
1232 case MetaActionType::POP:
1233 rStates.popState();
1234 break;
1235
1236 case MetaActionType::TEXTLANGUAGE:
1237 case MetaActionType::REFPOINT:
1238 // handled via pCurrAct->Execute( &rVDev )
1239 break;
1240
1241 case MetaActionType::MAPMODE:
1242 // modify current mapModeTransformation
1243 // transformation, such that subsequent
1244 // coordinates map correctly
1245 cppcanvastools::calcLogic2PixelAffineTransform( rStates.getState().mapModeTransform,
1246 rVDev );
1247 break;
1248
1249 // monitor clip regions, to assemble clip polygon on our own
1250 case MetaActionType::CLIPREGION:
1251 {
1252 MetaClipRegionAction* pClipAction = static_cast<MetaClipRegionAction*>(pCurrAct);
1253
1254 if( !pClipAction->IsClipping() )
1255 {
1256 // clear clipping
1257 rStates.getState().clip.clear();
1258 }
1259 else
1260 {
1261 if( !pClipAction->GetRegion().HasPolyPolygonOrB2DPolyPolygon() )
1262 {
1263 SAL_INFO( "cppcanvas.emf", "ImplRenderer::createActions(): non-polygonal clip "
1264 "region encountered, falling back to bounding box!" );
1265
1266 // #121806# explicitly kept integer
1267 ::tools::Rectangle aClipRect(
1268 rVDev.LogicToPixel(
1269 pClipAction->GetRegion().GetBoundRect() ) );
1270
1271 // intersect current clip with given rect
1272 updateClipping(
1273 aClipRect,
1274 rFactoryParms,
1275 false );
1276 }
1277 else
1278 {
1279 // set new clip polygon (don't intersect
1280 // with old one, just set it)
1281
1282 // #121806# explicitly kept integer
1283 basegfx::B2DPolyPolygon aPolyPolygon(pClipAction->GetRegion().GetAsB2DPolyPolygon());
1284
1285 aPolyPolygon.transform(rVDev.GetViewTransformation());
1286 updateClipping(
1287 aPolyPolygon,
1288 rFactoryParms,
1289 false );
1290 }
1291 }
1292
1293 break;
1294 }
1295
1296 case MetaActionType::ISECTRECTCLIPREGION:
1297 {
1298 MetaISectRectClipRegionAction* pClipAction = static_cast<MetaISectRectClipRegionAction*>(pCurrAct);
1299
1300 // #121806# explicitly kept integer
1301 ::tools::Rectangle aClipRect(
1302 rVDev.LogicToPixel( pClipAction->GetRect() ) );
1303
1304 // intersect current clip with given rect
1305 updateClipping(
1306 aClipRect,
1307 rFactoryParms,
1308 true );
1309
1310 break;
1311 }
1312
1313 case MetaActionType::ISECTREGIONCLIPREGION:
1314 {
1315 MetaISectRegionClipRegionAction* pClipAction = static_cast<MetaISectRegionClipRegionAction*>(pCurrAct);
1316
1317 if( !pClipAction->GetRegion().HasPolyPolygonOrB2DPolyPolygon() )
1318 {
1319 SAL_INFO( "cppcanvas.emf", "ImplRenderer::createActions(): non-polygonal clip "
1320 "region encountered, falling back to bounding box!" );
1321
1322 // #121806# explicitly kept integer
1323 ::tools::Rectangle aClipRect(
1324 rVDev.LogicToPixel( pClipAction->GetRegion().GetBoundRect() ) );
1325
1326 // intersect current clip with given rect
1327 updateClipping(
1328 aClipRect,
1329 rFactoryParms,
1330 true );
1331 }
1332 else
1333 {
1334 // intersect current clip with given clip polygon
1335
1336 // #121806# explicitly kept integer
1337 basegfx::B2DPolyPolygon aPolyPolygon(pClipAction->GetRegion().GetAsB2DPolyPolygon());
1338
1339 aPolyPolygon.transform(rVDev.GetViewTransformation());
1340 updateClipping(
1341 aPolyPolygon,
1342 rFactoryParms,
1343 true );
1344 }
1345
1346 break;
1347 }
1348
1349 case MetaActionType::MOVECLIPREGION:
1350 // TODO(F2): NYI
1351 break;
1352
1353 case MetaActionType::LINECOLOR:
1354 if( !rParms.maLineColor )
1355 {
1356 setStateColor( static_cast<MetaLineColorAction*>(pCurrAct),
1357 rStates.getState().isLineColorSet,
1358 rStates.getState().lineColor,
1359 rCanvas );
1360 }
1361 else
1362 {
1363 // #120994# Do switch on/off LineColor, even when an overriding one is set
1364 bool bSetting(static_cast<MetaLineColorAction*>(pCurrAct)->IsSetting());
1365
1366 rStates.getState().isLineColorSet = bSetting;
1367 }
1368 break;
1369
1370 case MetaActionType::FILLCOLOR:
1371 if( !rParms.maFillColor )
1372 {
1373 setStateColor( static_cast<MetaFillColorAction*>(pCurrAct),
1374 rStates.getState().isFillColorSet,
1375 rStates.getState().fillColor,
1376 rCanvas );
1377 }
1378 else
1379 {
1380 // #120994# Do switch on/off FillColor, even when an overriding one is set
1381 bool bSetting(static_cast<MetaFillColorAction*>(pCurrAct)->IsSetting());
1382
1383 rStates.getState().isFillColorSet = bSetting;
1384 }
1385 break;
1386
1387 case MetaActionType::TEXTCOLOR:
1388 {
1389 if( !rParms.maTextColor )
1390 {
1391 // Text color is set unconditionally, thus, no
1392 // use of setStateColor here
1393 ::Color aColor( static_cast<MetaTextColorAction*>(pCurrAct)->GetColor() );
1394
1395 // force alpha part of color to
1396 // opaque. transparent painting is done
1397 // explicitly via MetaActionType::Transparent
1398 aColor.SetAlpha(255);
1399
1400 rStates.getState().textColor =
1401 vcl::unotools::colorToDoubleSequence(
1402 aColor,
1403 rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
1404 }
1405 }
1406 break;
1407
1408 case MetaActionType::TEXTFILLCOLOR:
1409 if( !rParms.maTextColor )
1410 {
1411 setStateColor( static_cast<MetaTextFillColorAction*>(pCurrAct),
1412 rStates.getState().isTextFillColorSet,
1413 rStates.getState().textFillColor,
1414 rCanvas );
1415 }
1416 else
1417 {
1418 // #120994# Do switch on/off TextFillColor, even when an overriding one is set
1419 bool bSetting(static_cast<MetaTextFillColorAction*>(pCurrAct)->IsSetting());
1420
1421 rStates.getState().isTextFillColorSet = bSetting;
1422 }
1423 break;
1424
1425 case MetaActionType::TEXTLINECOLOR:
1426 if( !rParms.maTextColor )
1427 {
1428 setStateColor( static_cast<MetaTextLineColorAction*>(pCurrAct),
1429 rStates.getState().isTextLineColorSet,
1430 rStates.getState().textLineColor,
1431 rCanvas );
1432 }
1433 else
1434 {
1435 // #120994# Do switch on/off TextLineColor, even when an overriding one is set
1436 bool bSetting(static_cast<MetaTextLineColorAction*>(pCurrAct)->IsSetting());
1437
1438 rStates.getState().isTextLineColorSet = bSetting;
1439 }
1440 break;
1441
1442 case MetaActionType::OVERLINECOLOR:
1443 if( !rParms.maTextColor )
1444 {
1445 setStateColor( static_cast<MetaOverlineColorAction*>(pCurrAct),
1446 rStates.getState().isTextOverlineColorSet,
1447 rStates.getState().textOverlineColor,
1448 rCanvas );
1449 }
1450 else
1451 {
1452 bool bSetting(static_cast<MetaOverlineColorAction*>(pCurrAct)->IsSetting());
1453
1454 rStates.getState().isTextOverlineColorSet = bSetting;
1455 }
1456 break;
1457
1458 case MetaActionType::TEXTALIGN:
1459 {
1460 ::cppcanvas::internal::OutDevState& rState = rStates.getState();
1461 const TextAlign eTextAlign( static_cast<MetaTextAlignAction*>(pCurrAct)->GetTextAlign() );
1462
1463 rState.textReferencePoint = eTextAlign;
1464 }
1465 break;
1466
1467 case MetaActionType::FONT:
1468 {
1469 ::cppcanvas::internal::OutDevState& rState = rStates.getState();
1470 const vcl::Font& rFont( static_cast<MetaFontAction*>(pCurrAct)->GetFont() );
1471
1472 rState.xFont = createFont( rState.fontRotation,
1473 rFont,
1474 rFactoryParms );
1475
1476 // TODO(Q2): define and use appropriate enumeration types
1477 rState.textReliefStyle = rFont.GetRelief();
1478 rState.textOverlineStyle = static_cast<sal_Int8>(rFont.GetOverline());
1479 rState.textUnderlineStyle = rParms.maFontUnderline.has_value() ?
1480 (*rParms.maFontUnderline ? sal_Int8(LINESTYLE_SINGLE) : sal_Int8(LINESTYLE_NONE)) :
1481 static_cast<sal_Int8>(rFont.GetUnderline());
1482 rState.textStrikeoutStyle = static_cast<sal_Int8>(rFont.GetStrikeout());
1483 rState.textEmphasisMark = rFont.GetEmphasisMark();
1484 rState.isTextEffectShadowSet = rFont.IsShadow();
1485 rState.isTextWordUnderlineSet = rFont.IsWordLineMode();
1486 rState.isTextOutlineModeSet = rFont.IsOutline();
1487 }
1488 break;
1489
1490 case MetaActionType::RASTEROP:
1491 // TODO(F2): NYI
1492 break;
1493
1494 case MetaActionType::LAYOUTMODE:
1495 {
1496 // TODO(F2): A lot is missing here
1497 vcl::text::ComplexTextLayoutFlags nLayoutMode = static_cast<MetaLayoutModeAction*>(pCurrAct)->GetLayoutMode();
1498 ::cppcanvas::internal::OutDevState& rState = rStates.getState();
1499
1500 vcl::text::ComplexTextLayoutFlags nBidiLayoutMode = nLayoutMode & (vcl::text::ComplexTextLayoutFlags::BiDiRtl|vcl::text::ComplexTextLayoutFlags::BiDiStrong);
1501 if( nBidiLayoutMode == vcl::text::ComplexTextLayoutFlags::Default)
1502 rState.textDirection = rendering::TextDirection::WEAK_LEFT_TO_RIGHT;
1503 else if( nBidiLayoutMode == vcl::text::ComplexTextLayoutFlags::BiDiStrong)
1504 rState.textDirection = rendering::TextDirection::STRONG_LEFT_TO_RIGHT;
1505 else if( nBidiLayoutMode == vcl::text::ComplexTextLayoutFlags::BiDiRtl)
1506 rState.textDirection = rendering::TextDirection::WEAK_RIGHT_TO_LEFT;
1507 else if( nBidiLayoutMode == (vcl::text::ComplexTextLayoutFlags::BiDiRtl | vcl::text::ComplexTextLayoutFlags::BiDiStrong))
1508 rState.textDirection = rendering::TextDirection::STRONG_RIGHT_TO_LEFT;
1509
1510 rState.textAlignment = 0; // TODO(F2): rendering::TextAlignment::LEFT_ALIGNED;
1511 if( (nLayoutMode & (vcl::text::ComplexTextLayoutFlags::BiDiRtl | vcl::text::ComplexTextLayoutFlags::TextOriginRight) )
1512 && !(nLayoutMode & vcl::text::ComplexTextLayoutFlags::TextOriginLeft ) )
1513 {
1514 rState.textAlignment = 1; // TODO(F2): rendering::TextAlignment::RIGHT_ALIGNED;
1515 }
1516 }
1517 break;
1518
1519
1520 // In the second part of this monster-switch, we
1521 // handle all recursing meta actions. These are the
1522 // ones generating a metafile by themselves, which is
1523 // then processed by recursively calling this method.
1524
1525
1526 case MetaActionType::GRADIENT:
1527 {
1528 MetaGradientAction* pGradAct = static_cast<MetaGradientAction*>(pCurrAct);
1529 createGradientAction( ::tools::PolyPolygon( pGradAct->GetRect() ),
1530 pGradAct->GetGradient(),
1531 rFactoryParms,
1532 true,
1533 bSubsettableActions );
1534 }
1535 break;
1536
1537 case MetaActionType::HATCH:
1538 {
1539 // TODO(F2): use native Canvas hatches here
1540 GDIMetaFile aTmpMtf;
1541
1542 rVDev.AddHatchActions( static_cast<MetaHatchAction*>(pCurrAct)->GetPolyPolygon(),
1543 static_cast<MetaHatchAction*>(pCurrAct)->GetHatch(),
1544 aTmpMtf );
1545 createActions( aTmpMtf, rFactoryParms,
1546 bSubsettableActions );
1547 }
1548 break;
1549
1550 case MetaActionType::EPS:
1551 {
1552 MetaEPSAction* pAct = static_cast<MetaEPSAction*>(pCurrAct);
1553 const GDIMetaFile& rSubstitute = pAct->GetSubstitute();
1554
1555 // #121806# explicitly kept integer
1556 const Size aMtfSize( rSubstitute.GetPrefSize() );
1557 const Size aMtfSizePixPre( rVDev.LogicToPixel( aMtfSize,
1558 rSubstitute.GetPrefMapMode() ) );
1559
1560 // #i44110# correct null-sized output - there
1561 // are metafiles which have zero size in at
1562 // least one dimension
1563
1564 // Remark the 1L cannot be replaced, that would cause max to compare long/int
1565 const Size aMtfSizePix( std::max( aMtfSizePixPre.Width(), ::tools::Long(1) ),
1566 std::max( aMtfSizePixPre.Height(), ::tools::Long(1) ) );
1567
1568 // Setup local transform, such that the
1569 // metafile renders itself into the given
1570 // output rectangle
1571 rStates.pushState(vcl::PushFlags::ALL);
1572
1573 rVDev.Push();
1574 rVDev.SetMapMode( rSubstitute.GetPrefMapMode() );
1575
1576 const ::Point aPos( rVDev.LogicToPixel( pAct->GetPoint() ) );
1577 const ::Size aSize( rVDev.LogicToPixel( pAct->GetSize() ) );
1578
1579 rStates.getState().transform.translate( aPos.X(),
1580 aPos.Y() );
1581 rStates.getState().transform.scale( static_cast<double>(aSize.Width()) / aMtfSizePix.Width(),
1582 static_cast<double>(aSize.Height()) / aMtfSizePix.Height() );
1583
1584 createActions( const_cast<GDIMetaFile&>(pAct->GetSubstitute()),
1585 rFactoryParms,
1586 bSubsettableActions );
1587
1588 rVDev.Pop();
1589 rStates.popState();
1590 }
1591 break;
1592
1593 // handle metafile comments, to retrieve
1594 // meta-information for gradients, fills and
1595 // strokes. May skip actions, and may recurse.
1596 case MetaActionType::COMMENT:
1597 {
1598 MetaCommentAction* pAct = static_cast<MetaCommentAction*>(pCurrAct);
1599
1600 // Handle gradients
1601 if (pAct->GetComment().equalsIgnoreAsciiCase("XGRAD_SEQ_BEGIN"))
1602 {
1603 MetaGradientExAction* pGradAction = nullptr;
1604 bool bDone( false );
1605 while( !bDone )
1606 {
1607 pCurrAct=rMtf.NextAction();
1608 if (!pCurrAct)
1609 break;
1610 switch( pCurrAct->GetType() )
1611 {
1612 // extract gradient info
1613 case MetaActionType::GRADIENTEX:
1614 pGradAction = static_cast<MetaGradientExAction*>(pCurrAct);
1615 break;
1616
1617 // skip broken-down rendering, output gradient when sequence is ended
1618 case MetaActionType::COMMENT:
1619 if( static_cast<MetaCommentAction*>(pCurrAct)->GetComment().equalsIgnoreAsciiCase("XGRAD_SEQ_END") )
1620 {
1621 bDone = true;
1622
1623 if( pGradAction )
1624 {
1625 createGradientAction( pGradAction->GetPolyPolygon(),
1626 pGradAction->GetGradient(),
1627 rFactoryParms,
1628 false,
1629 bSubsettableActions );
1630 }
1631 }
1632 break;
1633 default: break;
1634 }
1635 }
1636 }
1637 // TODO(P2): Handle drawing layer strokes, via
1638 // XPATHSTROKE_SEQ_BEGIN comment
1639
1640 // Handle drawing layer fills
1641 else if( pAct->GetComment() == "XPATHFILL_SEQ_BEGIN" )
1642 {
1643 const sal_uInt8* pData = pAct->GetData();
1644 if ( pData )
1645 {
1646 SvMemoryStream aMemStm( const_cast<sal_uInt8 *>(pData), pAct->GetDataSize(), StreamMode::READ );
1647
1648 SvtGraphicFill aFill;
1649 ReadSvtGraphicFill( aMemStm, aFill );
1650
1651 // TODO(P2): Also handle gradients and
1652 // hatches like this
1653
1654 // only evaluate comment for pure
1655 // bitmap fills. If a transparency
1656 // gradient is involved (denoted by
1657 // the FloatTransparent action), take
1658 // the normal meta actions.
1659 if( aFill.getFillType() == SvtGraphicFill::fillTexture &&
1660 !isActionContained( rMtf,
1661 "XPATHFILL_SEQ_END",
1662 MetaActionType::FLOATTRANSPARENT ) )
1663 {
1664 rendering::Texture aTexture;
1665
1666 // TODO(F1): the SvtGraphicFill
1667 // can also transport metafiles
1668 // here, handle that case, too
1669 Graphic aGraphic;
1670 aFill.getGraphic( aGraphic );
1671
1672 Bitmap aBmp( aGraphic.GetBitmap() );
1673 const ::Size aBmpSize( aBmp.GetSizePixel() );
1674
1675 ::SvtGraphicFill::Transform aTransform;
1676 aFill.getTransform( aTransform );
1677
1678 ::basegfx::B2DHomMatrix aMatrix;
1679
1680 // convert to basegfx matrix
1681 aMatrix.set(0,0, aTransform.matrix[ 0 ] );
1682 aMatrix.set(0,1, aTransform.matrix[ 1 ] );
1683 aMatrix.set(0,2, aTransform.matrix[ 2 ] );
1684 aMatrix.set(1,0, aTransform.matrix[ 3 ] );
1685 aMatrix.set(1,1, aTransform.matrix[ 4 ] );
1686 aMatrix.set(1,2, aTransform.matrix[ 5 ] );
1687
1688 ::basegfx::B2DHomMatrix aScale;
1689 aScale.scale( aBmpSize.Width(),
1690 aBmpSize.Height() );
1691
1692 // post-multiply with the bitmap
1693 // size (XCanvas' texture assumes
1694 // the given bitmap to be
1695 // normalized to [0,1]x[0,1]
1696 // rectangle)
1697 aMatrix = aMatrix * aScale;
1698
1699 // pre-multiply with the
1700 // logic-to-pixel scale factor
1701 // (the metafile comment works in
1702 // logical coordinates).
1703 ::basegfx::B2DHomMatrix aLogic2PixelTransform;
1704 aMatrix *= cppcanvastools::calcLogic2PixelLinearTransform( aLogic2PixelTransform,
1705 rVDev );
1706
1707 ::basegfx::unotools::affineMatrixFromHomMatrix(
1708 aTexture.AffineTransform,
1709 aMatrix );
1710
1711 aTexture.Alpha = 1.0 - aFill.getTransparency();
1712 aTexture.Bitmap = vcl::unotools::xBitmapFromBitmap( aBmp );
1713 if( aFill.isTiling() )
1714 {
1715 aTexture.RepeatModeX = rendering::TexturingMode::REPEAT;
1716 aTexture.RepeatModeY = rendering::TexturingMode::REPEAT;
1717 }
1718 else
1719 {
1720 aTexture.RepeatModeX = rendering::TexturingMode::NONE;
1721 aTexture.RepeatModeY = rendering::TexturingMode::NONE;
1722 }
1723
1724 ::tools::PolyPolygon aPath;
1725 aFill.getPath( aPath );
1726
1727 ::basegfx::B2DPolyPolygon aPoly( aPath.getB2DPolyPolygon() );
1728 aPoly.transform( rStates.getState().mapModeTransform );
1729 std::shared_ptr<Action> pPolyAction(
1730 internal::PolyPolyActionFactory::createPolyPolyAction(
1731 aPoly,
1732 rCanvas,
1733 rStates.getState(),
1734 aTexture ) );
1735
1736 if( pPolyAction )
1737 {
1738 maActions.emplace_back(
1739 pPolyAction,
1740 io_rCurrActionIndex );
1741
1742 io_rCurrActionIndex += pPolyAction->getActionCount()-1;
1743 }
1744
1745 // skip broken-down render output
1746 skipContent( rMtf,
1747 "XPATHFILL_SEQ_END",
1748 io_rCurrActionIndex );
1749 }
1750 }
1751 }
1752 // Handle drawing layer fills
1753 else if( pAct->GetComment() == "EMF_PLUS" ) {
1754 SAL_WARN ("cppcanvas.emf", "EMF+ code was refactored and removed");
1755 } else if( pAct->GetComment() == "EMF_PLUS_HEADER_INFO" ) {
1756 SAL_INFO ("cppcanvas.emf", "EMF+ passed to canvas mtf renderer - header info, size: " << pAct->GetDataSize ());
1757
1758 SvMemoryStream rMF (const_cast<sal_uInt8 *>(pAct->GetData ()), pAct->GetDataSize (), StreamMode::READ);
1759
1760 rMF.ReadInt32( nFrameLeft ).ReadInt32( nFrameTop ).ReadInt32( nFrameRight ).ReadInt32( nFrameBottom );
1761 SAL_INFO ("cppcanvas.emf", "EMF+ picture frame: " << nFrameLeft << "," << nFrameTop << " - " << nFrameRight << "," << nFrameBottom);
1762 rMF.ReadInt32( nPixX ).ReadInt32( nPixY ).ReadInt32( nMmX ).ReadInt32( nMmY );
1763 SAL_INFO ("cppcanvas.emf", "EMF+ ref device pixel size: " << nPixX << "x" << nPixY << " mm size: " << nMmX << "x" << nMmY);
1764
1765 ReadXForm( rMF, aBaseTransform );
1766 //aWorldTransform.Set (aBaseTransform);
1767 }
1768 }
1769 break;
1770
1771
1772 // In the third part of this monster-switch, we
1773 // handle all 'acting' meta actions. These are all
1774 // processed by constructing function objects for
1775 // them, which will later ease caching.
1776
1777
1778 case MetaActionType::POINT:
1779 {
1780 const OutDevState& rState( rStates.getState() );
1781 if( rState.lineColor.hasElements() )
1782 {
1783 std::shared_ptr<Action> pPointAction(
1784 internal::PointActionFactory::createPointAction(
1785 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint(
1786 static_cast<MetaPointAction*>(pCurrAct)->GetPoint() ),
1787 rCanvas,
1788 rState ) );
1789
1790 if( pPointAction )
1791 {
1792 maActions.emplace_back(
1793 pPointAction,
1794 io_rCurrActionIndex );
1795
1796 io_rCurrActionIndex += pPointAction->getActionCount()-1;
1797 }
1798 }
1799 }
1800 break;
1801
1802 case MetaActionType::PIXEL:
1803 {
1804 const OutDevState& rState( rStates.getState() );
1805 if( rState.lineColor.hasElements() )
1806 {
1807 std::shared_ptr<Action> pPointAction(
1808 internal::PointActionFactory::createPointAction(
1809 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint(
1810 static_cast<MetaPixelAction*>(pCurrAct)->GetPoint() ),
1811 rCanvas,
1812 rState,
1813 static_cast<MetaPixelAction*>(pCurrAct)->GetColor() ) );
1814
1815 if( pPointAction )
1816 {
1817 maActions.emplace_back(
1818 pPointAction,
1819 io_rCurrActionIndex );
1820
1821 io_rCurrActionIndex += pPointAction->getActionCount()-1;
1822 }
1823 }
1824 }
1825 break;
1826
1827 case MetaActionType::LINE:
1828 {
1829 const OutDevState& rState( rStates.getState() );
1830 if( rState.lineColor.hasElements() )
1831 {
1832 MetaLineAction* pLineAct = static_cast<MetaLineAction*>(pCurrAct);
1833
1834 const LineInfo& rLineInfo( pLineAct->GetLineInfo() );
1835
1836 const ::basegfx::B2DPoint aStartPoint(
1837 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint( pLineAct->GetStartPoint() ));
1838 const ::basegfx::B2DPoint aEndPoint(
1839 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint( pLineAct->GetEndPoint() ));
1840
1841 std::shared_ptr<Action> pLineAction;
1842
1843 if( rLineInfo.IsDefault() )
1844 {
1845 // plain hair line
1846 pLineAction =
1847 internal::LineActionFactory::createLineAction(
1848 aStartPoint,
1849 aEndPoint,
1850 rCanvas,
1851 rState );
1852
1853 if( pLineAction )
1854 {
1855 maActions.emplace_back(
1856 pLineAction,
1857 io_rCurrActionIndex );
1858
1859 io_rCurrActionIndex += pLineAction->getActionCount()-1;
1860 }
1861 }
1862 else if( LineStyle::NONE != rLineInfo.GetStyle() )
1863 {
1864 // 'thick' line
1865 rendering::StrokeAttributes aStrokeAttributes;
1866
1867 setupStrokeAttributes( aStrokeAttributes,
1868 rFactoryParms,
1869 rLineInfo );
1870
1871 // XCanvas can only stroke polygons,
1872 // not simple lines - thus, handle
1873 // this case via the polypolygon
1874 // action
1875 ::basegfx::B2DPolygon aPoly;
1876 aPoly.append( aStartPoint );
1877 aPoly.append( aEndPoint );
1878 pLineAction =
1879 internal::PolyPolyActionFactory::createPolyPolyAction(
1880 ::basegfx::B2DPolyPolygon( aPoly ),
1881 rCanvas, rState, aStrokeAttributes );
1882
1883 if( pLineAction )
1884 {
1885 maActions.emplace_back(
1886 pLineAction,
1887 io_rCurrActionIndex );
1888
1889 io_rCurrActionIndex += pLineAction->getActionCount()-1;
1890 }
1891 }
1892 // else: line style is default
1893 // (i.e. invisible), don't generate action
1894 }
1895 }
1896 break;
1897
1898 case MetaActionType::RECT:
1899 {
1900 const ::tools::Rectangle& rRect(
1901 static_cast<MetaRectAction*>(pCurrAct)->GetRect() );
1902
1903 if( rRect.IsEmpty() )
1904 break;
1905
1906 const OutDevState& rState( rStates.getState() );
1907 const ::basegfx::B2DPoint aTopLeftPixel(
1908 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint( rRect.TopLeft() ) );
1909 const ::basegfx::B2DPoint aBottomRightPixel(
1910 rState.mapModeTransform * vcl::unotools::b2DPointFromPoint( rRect.BottomRight() ) +
1911 // #121100# OutputDevice::DrawRect() fills
1912 // rectangles Apple-like, i.e. with one
1913 // additional pixel to the right and bottom.
1914 ::basegfx::B2DPoint(1,1) );
1915
1916 createFillAndStroke( ::basegfx::utils::createPolygonFromRect(
1917 ::basegfx::B2DRange( aTopLeftPixel,
1918 aBottomRightPixel )),
1919 rFactoryParms );
1920 break;
1921 }
1922
1923 case MetaActionType::ROUNDRECT:
1924 {
1925 const ::tools::Rectangle& rRect(
1926 static_cast<MetaRoundRectAction*>(pCurrAct)->GetRect());
1927
1928 if( rRect.IsEmpty() )
1929 break;
1930
1931 ::basegfx::B2DPolygon aPoly(
1932 ::basegfx::utils::createPolygonFromRect(
1933 ::basegfx::B2DRange(
1934 vcl::unotools::b2DPointFromPoint( rRect.TopLeft() ),
1935 vcl::unotools::b2DPointFromPoint( rRect.BottomRight() ) +
1936 ::basegfx::B2DPoint(1,1) ),
1937 static_cast<double>(static_cast<MetaRoundRectAction*>(pCurrAct)->GetHorzRound()) / rRect.GetWidth(),
1938 static_cast<double>(static_cast<MetaRoundRectAction*>(pCurrAct)->GetVertRound()) / rRect.GetHeight() ) );
1939 aPoly.transform( rStates.getState().mapModeTransform );
1940
1941 createFillAndStroke( aPoly,
1942 rFactoryParms );
1943 }
1944 break;
1945
1946 case MetaActionType::ELLIPSE:
1947 {
1948 const ::tools::Rectangle& rRect(
1949 static_cast<MetaEllipseAction*>(pCurrAct)->GetRect() );
1950
1951 if( rRect.IsEmpty() )
1952 break;
1953
1954 const ::basegfx::B2DRange aRange(
1955 vcl::unotools::b2DPointFromPoint( rRect.TopLeft() ),
1956 vcl::unotools::b2DPointFromPoint( rRect.BottomRight() ) +
1957 ::basegfx::B2DPoint(1,1) );
1958
1959 ::basegfx::B2DPolygon aPoly(
1960 ::basegfx::utils::createPolygonFromEllipse(
1961 aRange.getCenter(),
1962 aRange.getWidth() / 2, // divide by 2 since createPolygonFromEllipse
1963 aRange.getHeight() / 2 )); // expects the radius and NOT the diameter!
1964 aPoly.transform( rStates.getState().mapModeTransform );
1965
1966 createFillAndStroke( aPoly,
1967 rFactoryParms );
1968 }
1969 break;
1970
1971 case MetaActionType::ARC:
1972 {
1973 // TODO(F1): Missing basegfx functionality. Mind empty rects!
1974 const ::tools::Polygon aToolsPoly( static_cast<MetaArcAction*>(pCurrAct)->GetRect(),
1975 static_cast<MetaArcAction*>(pCurrAct)->GetStartPoint(),
1976 static_cast<MetaArcAction*>(pCurrAct)->GetEndPoint(), PolyStyle::Arc );
1977 ::basegfx::B2DPolygon aPoly( aToolsPoly.getB2DPolygon() );
1978 aPoly.transform( rStates.getState().mapModeTransform );
1979
1980 createFillAndStroke( aPoly,
1981 rFactoryParms );
1982 }
1983 break;
1984
1985 case MetaActionType::PIE:
1986 {
1987 // TODO(F1): Missing basegfx functionality. Mind empty rects!
1988 const ::tools::Polygon aToolsPoly( static_cast<MetaPieAction*>(pCurrAct)->GetRect(),
1989 static_cast<MetaPieAction*>(pCurrAct)->GetStartPoint(),
1990 static_cast<MetaPieAction*>(pCurrAct)->GetEndPoint(), PolyStyle::Pie );
1991 ::basegfx::B2DPolygon aPoly( aToolsPoly.getB2DPolygon() );
1992 aPoly.transform( rStates.getState().mapModeTransform );
1993
1994 createFillAndStroke( aPoly,
1995 rFactoryParms );
1996 }
1997 break;
1998
1999 case MetaActionType::CHORD:
2000 {
2001 // TODO(F1): Missing basegfx functionality. Mind empty rects!
2002 const ::tools::Polygon aToolsPoly( static_cast<MetaChordAction*>(pCurrAct)->GetRect(),
2003 static_cast<MetaChordAction*>(pCurrAct)->GetStartPoint(),
2004 static_cast<MetaChordAction*>(pCurrAct)->GetEndPoint(), PolyStyle::Chord );
2005 ::basegfx::B2DPolygon aPoly( aToolsPoly.getB2DPolygon() );
2006 aPoly.transform( rStates.getState().mapModeTransform );
2007
2008 createFillAndStroke( aPoly,
2009 rFactoryParms );
2010 }
2011 break;
2012
2013 case MetaActionType::POLYLINE:
2014 {
2015 const OutDevState& rState( rStates.getState() );
2016 if( rState.lineColor.hasElements() ||
2017 rState.fillColor.hasElements() )
2018 {
2019 MetaPolyLineAction* pPolyLineAct = static_cast<MetaPolyLineAction*>(pCurrAct);
2020
2021 const LineInfo& rLineInfo( pPolyLineAct->GetLineInfo() );
2022 ::basegfx::B2DPolygon aPoly( pPolyLineAct->GetPolygon().getB2DPolygon() );
2023 aPoly.transform( rState.mapModeTransform );
2024
2025 std::shared_ptr<Action> pLineAction;
2026
2027 if( rLineInfo.IsDefault() )
2028 {
2029 // plain hair line polygon
2030 pLineAction =
2031 internal::PolyPolyActionFactory::createLinePolyPolyAction(
2032 ::basegfx::B2DPolyPolygon(aPoly),
2033 rCanvas,
2034 rState );
2035
2036 if( pLineAction )
2037 {
2038 maActions.emplace_back(
2039 pLineAction,
2040 io_rCurrActionIndex );
2041
2042 io_rCurrActionIndex += pLineAction->getActionCount()-1;
2043 }
2044 }
2045 else if( LineStyle::NONE != rLineInfo.GetStyle() )
2046 {
2047 // 'thick' line polygon
2048 rendering::StrokeAttributes aStrokeAttributes;
2049
2050 setupStrokeAttributes( aStrokeAttributes,
2051 rFactoryParms,
2052 rLineInfo );
2053
2054 pLineAction =
2055 internal::PolyPolyActionFactory::createPolyPolyAction(
2056 ::basegfx::B2DPolyPolygon(aPoly),
2057 rCanvas,
2058 rState,
2059 aStrokeAttributes ) ;
2060
2061 if( pLineAction )
2062 {
2063 maActions.emplace_back(
2064 pLineAction,
2065 io_rCurrActionIndex );
2066
2067 io_rCurrActionIndex += pLineAction->getActionCount()-1;
2068 }
2069 }
2070 // else: line style is default
2071 // (i.e. invisible), don't generate action
2072 }
2073 }
2074 break;
2075
2076 case MetaActionType::POLYGON:
2077 {
2078 ::basegfx::B2DPolygon aPoly( static_cast<MetaPolygonAction*>(pCurrAct)->GetPolygon().getB2DPolygon() );
2079 aPoly.transform( rStates.getState().mapModeTransform );
2080 createFillAndStroke( aPoly,
2081 rFactoryParms );
2082 }
2083 break;
2084
2085 case MetaActionType::POLYPOLYGON:
2086 {
2087 ::basegfx::B2DPolyPolygon aPoly( static_cast<MetaPolyPolygonAction*>(pCurrAct)->GetPolyPolygon().getB2DPolyPolygon() );
2088 aPoly.transform( rStates.getState().mapModeTransform );
2089 createFillAndStroke( aPoly,
2090 rFactoryParms );
2091 }
2092 break;
2093
2094 case MetaActionType::BMP:
2095 {
2096 MetaBmpAction* pAct = static_cast<MetaBmpAction*>(pCurrAct);
2097
2098 std::shared_ptr<Action> pBmpAction(
2099 internal::BitmapActionFactory::createBitmapAction(
2100 pAct->GetBitmap(),
2101 rStates.getState().mapModeTransform *
2102 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2103 rCanvas,
2104 rStates.getState() ) );
2105
2106 if( pBmpAction )
2107 {
2108 maActions.emplace_back(
2109 pBmpAction,
2110 io_rCurrActionIndex );
2111
2112 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2113 }
2114 }
2115 break;
2116
2117 case MetaActionType::BMPSCALE:
2118 {
2119 MetaBmpScaleAction* pAct = static_cast<MetaBmpScaleAction*>(pCurrAct);
2120
2121 std::shared_ptr<Action> pBmpAction(
2122 internal::BitmapActionFactory::createBitmapAction(
2123 pAct->GetBitmap(),
2124 rStates.getState().mapModeTransform * vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2125 rStates.getState().mapModeTransform * vcl::unotools::b2DVectorFromSize( pAct->GetSize() ),
2126 rCanvas,
2127 rStates.getState() ) );
2128
2129 if( pBmpAction )
2130 {
2131 maActions.emplace_back(
2132 pBmpAction,
2133 io_rCurrActionIndex );
2134
2135 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2136 }
2137 }
2138 break;
2139
2140 case MetaActionType::BMPSCALEPART:
2141 {
2142 MetaBmpScalePartAction* pAct = static_cast<MetaBmpScalePartAction*>(pCurrAct);
2143
2144 // crop bitmap to given source rectangle (no
2145 // need to copy and convert the whole bitmap)
2146 ::Bitmap aBmp( pAct->GetBitmap() );
2147 const ::tools::Rectangle aCropRect( pAct->GetSrcPoint(),
2148 pAct->GetSrcSize() );
2149 aBmp.Crop( aCropRect );
2150
2151 std::shared_ptr<Action> pBmpAction(
2152 internal::BitmapActionFactory::createBitmapAction(
2153 aBmp,
2154 rStates.getState().mapModeTransform *
2155 vcl::unotools::b2DPointFromPoint( pAct->GetDestPoint() ),
2156 rStates.getState().mapModeTransform *
2157 vcl::unotools::b2DVectorFromSize( pAct->GetDestSize() ),
2158 rCanvas,
2159 rStates.getState() ) );
2160
2161 if( pBmpAction )
2162 {
2163 maActions.emplace_back(
2164 pBmpAction,
2165 io_rCurrActionIndex );
2166
2167 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2168 }
2169 }
2170 break;
2171
2172 case MetaActionType::BMPEX:
2173 {
2174 MetaBmpExAction* pAct = static_cast<MetaBmpExAction*>(pCurrAct);
2175
2176 std::shared_ptr<Action> pBmpAction(
2177 internal::BitmapActionFactory::createBitmapAction(
2178 pAct->GetBitmap(),
2179 rStates.getState().mapModeTransform *
2180 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2181 rCanvas,
2182 rStates.getState() ) );
2183
2184 if( pBmpAction )
2185 {
2186 maActions.emplace_back(
2187 pBmpAction,
2188 io_rCurrActionIndex );
2189
2190 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2191 }
2192 }
2193 break;
2194
2195 case MetaActionType::BMPEXSCALE:
2196 {
2197 MetaBmpExScaleAction* pAct = static_cast<MetaBmpExScaleAction*>(pCurrAct);
2198
2199 std::shared_ptr<Action> pBmpAction(
2200 internal::BitmapActionFactory::createBitmapAction(
2201 pAct->GetBitmap(),
2202 rStates.getState().mapModeTransform *
2203 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2204 rStates.getState().mapModeTransform *
2205 vcl::unotools::b2DVectorFromSize( pAct->GetSize() ),
2206 rCanvas,
2207 rStates.getState() ) );
2208
2209 if( pBmpAction )
2210 {
2211 maActions.emplace_back(
2212 pBmpAction,
2213 io_rCurrActionIndex );
2214
2215 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2216 }
2217 }
2218 break;
2219
2220 case MetaActionType::BMPEXSCALEPART:
2221 {
2222 MetaBmpExScalePartAction* pAct = static_cast<MetaBmpExScalePartAction*>(pCurrAct);
2223
2224 // crop bitmap to given source rectangle (no
2225 // need to copy and convert the whole bitmap)
2226 Bitmap aBmp( pAct->GetBitmap() );
2227 const ::tools::Rectangle aCropRect( pAct->GetSrcPoint(),
2228 pAct->GetSrcSize() );
2229 aBmp.Crop( aCropRect );
2230
2231 std::shared_ptr<Action> pBmpAction(
2232 internal::BitmapActionFactory::createBitmapAction(
2233 aBmp,
2234 rStates.getState().mapModeTransform *
2235 vcl::unotools::b2DPointFromPoint( pAct->GetDestPoint() ),
2236 rStates.getState().mapModeTransform *
2237 vcl::unotools::b2DVectorFromSize( pAct->GetDestSize() ),
2238 rCanvas,
2239 rStates.getState() ) );
2240
2241 if( pBmpAction )
2242 {
2243 maActions.emplace_back(
2244 pBmpAction,
2245 io_rCurrActionIndex );
2246
2247 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2248 }
2249 }
2250 break;
2251
2252 case MetaActionType::MASK:
2253 {
2254 MetaMaskAction* pAct = static_cast<MetaMaskAction*>(pCurrAct);
2255
2256 // create masked Bitmap right here, as the
2257 // canvas does not provide equivalent
2258 // functionality
2259 Bitmap aBmp( createMaskBmp( pAct->GetBitmap(),
2260 pAct->GetColor() ));
2261
2262 std::shared_ptr<Action> pBmpAction(
2263 internal::BitmapActionFactory::createBitmapAction(
2264 aBmp,
2265 rStates.getState().mapModeTransform *
2266 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2267 rCanvas,
2268 rStates.getState() ) );
2269
2270 if( pBmpAction )
2271 {
2272 maActions.emplace_back(
2273 pBmpAction,
2274 io_rCurrActionIndex );
2275
2276 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2277 }
2278 }
2279 break;
2280
2281 case MetaActionType::MASKSCALE:
2282 {
2283 MetaMaskScaleAction* pAct = static_cast<MetaMaskScaleAction*>(pCurrAct);
2284
2285 // create masked Bitmap right here, as the
2286 // canvas does not provide equivalent
2287 // functionality
2288 Bitmap aBmp( createMaskBmp( pAct->GetBitmap(),
2289 pAct->GetColor() ));
2290
2291 std::shared_ptr<Action> pBmpAction(
2292 internal::BitmapActionFactory::createBitmapAction(
2293 aBmp,
2294 rStates.getState().mapModeTransform *
2295 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2296 rStates.getState().mapModeTransform *
2297 vcl::unotools::b2DVectorFromSize( pAct->GetSize() ),
2298 rCanvas,
2299 rStates.getState() ) );
2300
2301 if( pBmpAction )
2302 {
2303 maActions.emplace_back(
2304 pBmpAction,
2305 io_rCurrActionIndex );
2306
2307 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2308 }
2309 }
2310 break;
2311
2312 case MetaActionType::MASKSCALEPART:
2313 {
2314 MetaMaskScalePartAction* pAct = static_cast<MetaMaskScalePartAction*>(pCurrAct);
2315
2316 // create masked Bitmap right here, as the
2317 // canvas does not provide equivalent
2318 // functionality
2319 Bitmap aBmp( createMaskBmp( pAct->GetBitmap(),
2320 pAct->GetColor() ));
2321
2322 // crop bitmap to given source rectangle (no
2323 // need to copy and convert the whole bitmap)
2324 const ::tools::Rectangle aCropRect( pAct->GetSrcPoint(),
2325 pAct->GetSrcSize() );
2326 aBmp.Crop( aCropRect );
2327
2328 std::shared_ptr<Action> pBmpAction(
2329 internal::BitmapActionFactory::createBitmapAction(
2330 aBmp,
2331 rStates.getState().mapModeTransform *
2332 vcl::unotools::b2DPointFromPoint( pAct->GetDestPoint() ),
2333 rStates.getState().mapModeTransform *
2334 vcl::unotools::b2DVectorFromSize( pAct->GetDestSize() ),
2335 rCanvas,
2336 rStates.getState() ) );
2337
2338 if( pBmpAction )
2339 {
2340 maActions.emplace_back(
2341 pBmpAction,
2342 io_rCurrActionIndex );
2343
2344 io_rCurrActionIndex += pBmpAction->getActionCount()-1;
2345 }
2346 }
2347 break;
2348
2349 case MetaActionType::GRADIENTEX:
2350 // TODO(F1): use native Canvas gradients here
2351 // action is ignored here, because redundant to MetaActionType::GRADIENT
2352 break;
2353
2354 case MetaActionType::WALLPAPER:
2355 // TODO(F2): NYI
2356 break;
2357
2358 case MetaActionType::Transparent:
2359 {
2360 const OutDevState& rState( rStates.getState() );
2361 if( rState.lineColor.hasElements() ||
2362 rState.fillColor.hasElements() )
2363 {
2364 MetaTransparentAction* pAct = static_cast<MetaTransparentAction*>(pCurrAct);
2365 ::basegfx::B2DPolyPolygon aPoly( pAct->GetPolyPolygon().getB2DPolyPolygon() );
2366 aPoly.transform( rState.mapModeTransform );
2367
2368 std::shared_ptr<Action> pPolyAction(
2369 internal::PolyPolyActionFactory::createPolyPolyAction(
2370 aPoly,
2371 rCanvas,
2372 rState,
2373 pAct->GetTransparence() ) );
2374
2375 if( pPolyAction )
2376 {
2377 maActions.emplace_back(
2378 pPolyAction,
2379 io_rCurrActionIndex );
2380
2381 io_rCurrActionIndex += pPolyAction->getActionCount()-1;
2382 }
2383 }
2384 }
2385 break;
2386
2387 case MetaActionType::FLOATTRANSPARENT:
2388 {
2389 MetaFloatTransparentAction* pAct = static_cast<MetaFloatTransparentAction*>(pCurrAct);
2390
2391 std::unique_ptr< GDIMetaFile > pMtf(
2392 new ::GDIMetaFile( pAct->GetGDIMetaFile() ) );
2393
2394 // TODO(P2): Use native canvas gradients here (saves a lot of UNO calls)
2395 std::optional< Gradient > pGradient( pAct->GetGradient() );
2396
2397 DBG_TESTSOLARMUTEX();
2398
2399 std::shared_ptr<Action> pFloatTransAction(
2400 internal::TransparencyGroupActionFactory::createTransparencyGroupAction(
2401 std::move(pMtf),
2402 std::move(pGradient),
2403 rStates.getState().mapModeTransform *
2404 vcl::unotools::b2DPointFromPoint( pAct->GetPoint() ),
2405 rStates.getState().mapModeTransform *
2406 vcl::unotools::b2DVectorFromSize( pAct->GetSize() ),
2407 rCanvas,
2408 rStates.getState() ) );
2409
2410 if( pFloatTransAction )
2411 {
2412 maActions.emplace_back(
2413 pFloatTransAction,
2414 io_rCurrActionIndex );
2415
2416 io_rCurrActionIndex += pFloatTransAction->getActionCount()-1;
2417 }
2418 }
2419 break;
2420
2421 case MetaActionType::TEXT:
2422 {
2423 MetaTextAction* pAct = static_cast<MetaTextAction*>(pCurrAct);
2424 OUString sText = pAct->GetText();
2425
2426 if (rVDev.GetDigitLanguage())
2427 sText = LocalizeDigitsInString(sText, rVDev.GetDigitLanguage());
2428
2429 const sal_Int32 nLen = std::min(pAct->GetLen(), pAct->GetText().getLength() - pAct->GetIndex());
2430
2431 createTextAction(
2432 pAct->GetPoint(),
2433 sText,
2434 pAct->GetIndex(),
2435 nLen,
2436 {},
2437 {},
2438 rFactoryParms,
2439 bSubsettableActions );
2440 }
2441 break;
2442
2443 case MetaActionType::TEXTARRAY:
2444 {
2445 MetaTextArrayAction* pAct = static_cast<MetaTextArrayAction*>(pCurrAct);
2446 OUString sText = pAct->GetText();
2447
2448 if (rVDev.GetDigitLanguage())
2449 sText = LocalizeDigitsInString(sText, rVDev.GetDigitLanguage());
2450
2451 const sal_Int32 nLen = std::min(pAct->GetLen(), pAct->GetText().getLength() - pAct->GetIndex());
2452
2453 createTextAction(
2454 pAct->GetPoint(),
2455 sText,
2456 pAct->GetIndex(),
2457 nLen,
2458 pAct->GetDXArray(),
2459 pAct->GetKashidaArray(),
2460 rFactoryParms,
2461 bSubsettableActions );
2462 }
2463 break;
2464
2465 case MetaActionType::TEXTLINE:
2466 {
2467 MetaTextLineAction* pAct = static_cast<MetaTextLineAction*>(pCurrAct);
2468
2469 const OutDevState& rState( rStates.getState() );
2470 const ::Size aBaselineOffset( cppcanvastools::getBaselineOffset( rState,
2471 rVDev ) );
2472 const ::basegfx::B2DSize aSize( rState.mapModeTransform *
2473 ::basegfx::B2DSize(pAct->GetWidth(),
2474 0 ));
2475
2476 std::shared_ptr<Action> pPolyAction(
2477 PolyPolyActionFactory::createPolyPolyAction(
2478 cppcanvastools::createTextLinesPolyPolygon(
2479 rState.mapModeTransform *
2480 ::basegfx::B2DPoint(
2481 vcl::unotools::b2DPointFromPoint(pAct->GetStartPoint()) +
2482 vcl::unotools::b2DVectorFromSize(aBaselineOffset)),
2483 aSize.getWidth(),
2484 cppcanvastools::createTextLineInfo( rVDev,
2485 rState )),
2486 rCanvas,
2487 rState ) );
2488
2489 if( pPolyAction )
2490 {
2491 maActions.emplace_back(
2492 pPolyAction,
2493 io_rCurrActionIndex );
2494
2495 io_rCurrActionIndex += pPolyAction->getActionCount()-1;
2496 }
2497 }
2498 break;
2499
2500 case MetaActionType::TEXTRECT:
2501 {
2502 MetaTextRectAction* pAct = static_cast<MetaTextRectAction*>(pCurrAct);
2503
2504 rStates.pushState(vcl::PushFlags::ALL);
2505
2506 // use the VDev to break up the text rect
2507 // action into readily formatted lines
2508 GDIMetaFile aTmpMtf;
2509 rVDev.AddTextRectActions( pAct->GetRect(),
2510 pAct->GetText(),
2511 pAct->GetStyle(),
2512 aTmpMtf );
2513
2514 createActions( aTmpMtf,
2515 rFactoryParms,
2516 bSubsettableActions );
2517
2518 rStates.popState();
2519
2520 break;
2521 }
2522
2523 case MetaActionType::STRETCHTEXT:
2524 {
2525 MetaStretchTextAction* pAct = static_cast<MetaStretchTextAction*>(pCurrAct);
2526 OUString sText = pAct->GetText();
2527
2528 if (rVDev.GetDigitLanguage())
2529 sText = LocalizeDigitsInString(sText, rVDev.GetDigitLanguage());
2530
2531 const sal_Int32 nLen = std::min(pAct->GetLen(), pAct->GetText().getLength() - pAct->GetIndex());
2532
2533 // #i70897# Nothing to do, actually...
2534 if( nLen == 0 )
2535 break;
2536
2537 // have to fit the text into the given
2538 // width. This is achieved by internally
2539 // generating a DX array, and uniformly
2540 // distributing the excess/insufficient width
2541 // to every logical character.
2542 KernArray aDXArray;
2543
2544 rVDev.GetTextArray( pAct->GetText(), &aDXArray,
2545 pAct->GetIndex(), pAct->GetLen() );
2546
2547 const double nWidthDifferencePerDx = ( pAct->GetWidth() - aDXArray[ nLen-1 ] ) / nLen;
2548
2549 // Last entry of pDXArray contains total width of the text
2550 for (sal_Int32 i = 1; i <= nLen; ++i)
2551 {
2552 // calc ratio for every array entry, to
2553 // distribute rounding errors 'evenly'
2554 // across the characters. Note that each
2555 // entry represents the 'end' position of
2556 // the corresponding character, thus, we
2557 // let i run from 1 to nLen.
2558 aDXArray[i - 1] += i * nWidthDifferencePerDx;
2559 }
2560
2561 createTextAction(
2562 pAct->GetPoint(),
2563 sText,
2564 pAct->GetIndex(),
2565 nLen,
2566 aDXArray,
2567 {},
2568 rFactoryParms,
2569 bSubsettableActions );
2570 }
2571 break;
2572
2573 default:
2574 SAL_WARN( "cppcanvas.emf", "Unknown meta action type encountered" );
2575 break;
2576 }
2577
2578 // increment action index (each mtf action counts _at
2579 // least_ one. Some count for more, therefore,
2580 // io_rCurrActionIndex is sometimes incremented by
2581 // pAct->getActionCount()-1 above, the -1 being the
2582 // correction for the unconditional increment here).
2583 ++io_rCurrActionIndex;
2584 }
2585 }
2586
2587
2588 namespace
2589 {
2590 class ActionRenderer
2591 {
2592 public:
2593 explicit ActionRenderer( ::basegfx::B2DHomMatrix aTransformation ) :
2594 maTransformation(std::move( aTransformation )),
2595 mbRet( true )
2596 {
2597 }
2598
2599 bool result() const
2600 {
2601 return mbRet;
2602 }
2603
2604 void operator()( const ::cppcanvas::internal::ImplRenderer::MtfAction& rAction )
2605 {
2606 // ANDing the result. We want to fail if at least
2607 // one action failed.
2608 mbRet &= rAction.mpAction->render( maTransformation );
2609 }
2610
2611 void operator()( const ::cppcanvas::internal::ImplRenderer::MtfAction& rAction,
2612 const Action::Subset& rSubset )
2613 {
2614 // ANDing the result. We want to fail if at least
2615 // one action failed.
2616 mbRet &= rAction.mpAction->renderSubset( maTransformation,
2617 rSubset );
2618 }
2619
2620 private:
2621 ::basegfx::B2DHomMatrix maTransformation;
2622 bool mbRet;
2623 };
2624
2625 class AreaQuery
2626 {
2627 public:
2628 explicit AreaQuery( ::basegfx::B2DHomMatrix aTransformation ) :
2629 maTransformation(std::move( aTransformation ))
2630 {
2631 }
2632
2633 static bool result()
2634 {
2635 return true; // nothing can fail here
2636 }
2637
2638 void operator()( const ::cppcanvas::internal::ImplRenderer::MtfAction& rAction )
2639 {
2640 maBounds.expand( rAction.mpAction->getBounds( maTransformation ) );
2641 }
2642
2643 void operator()( const ::cppcanvas::internal::ImplRenderer::MtfAction& rAction,
2644 const Action::Subset& rSubset )
2645 {
2646 maBounds.expand( rAction.mpAction->getBounds( maTransformation,
2647 rSubset ) );
2648 }
2649
2650 const ::basegfx::B2DRange& getBounds() const
2651 {
2652 return maBounds;
2653 }
2654
2655 private:
2656 ::basegfx::B2DHomMatrix maTransformation;
2657 ::basegfx::B2DRange maBounds;
2658 };
2659
2660 // Doing that via inline class. Compilers tend to not inline free
2661 // functions.
2662 struct UpperBoundActionIndexComparator
2663 {
2664 bool operator()( const ::cppcanvas::internal::ImplRenderer::MtfAction& rLHS,
2665 const ::cppcanvas::internal::ImplRenderer::MtfAction& rRHS )
2666 {
2667 const sal_Int32 nLHSCount( rLHS.mpAction ?
2668 rLHS.mpAction->getActionCount() : 0 );
2669 const sal_Int32 nRHSCount( rRHS.mpAction ?
2670 rRHS.mpAction->getActionCount() : 0 );
2671
2672 // compare end of action range, to have an action selected
2673 // by lower_bound even if the requested index points in
2674 // the middle of the action's range
2675 return rLHS.mnOrigIndex + nLHSCount < rRHS.mnOrigIndex + nRHSCount;
2676 }
2677 };
2678
2679 /** Algorithm to apply given functor to a subset range
2680
2681 @tpl Functor
2682
2683 Functor to call for each element of the subset
2684 range. Must provide the following method signatures:
2685 bool result() (returning false if operation failed)
2686
2687 */
2688 template< typename Functor > bool
2689 forSubsetRange( Functor& rFunctor,
2690 ImplRenderer::ActionVector::const_iterator aRangeBegin,
2691 const ImplRenderer::ActionVector::const_iterator& aRangeEnd,
2692 sal_Int32 nStartIndex,
2693 sal_Int32 nEndIndex,
2694 const ImplRenderer::ActionVector::const_iterator& rEnd )
2695 {
2696 if( aRangeBegin == aRangeEnd )
2697 {
2698 // only a single action. Setup subset, and call functor
2699 Action::Subset aSubset;
2700 aSubset.mnSubsetBegin = std::max( sal_Int32( 0 ),
2701 nStartIndex - aRangeBegin->mnOrigIndex );
2702 aSubset.mnSubsetEnd = std::min( aRangeBegin->mpAction->getActionCount(),
2703 nEndIndex - aRangeBegin->mnOrigIndex );
2704
2705 ENSURE_OR_RETURN_FALSE( aSubset.mnSubsetBegin >= 0 && aSubset.mnSubsetEnd >= 0,
2706 "ImplRenderer::forSubsetRange(): Invalid indices" );
2707
2708 rFunctor( *aRangeBegin, aSubset );
2709 }
2710 else
2711 {
2712 // more than one action.
2713
2714 // render partial first, full intermediate, and
2715 // partial last action
2716 Action::Subset aSubset;
2717 aSubset.mnSubsetBegin = std::max( sal_Int32( 0 ),
2718 nStartIndex - aRangeBegin->mnOrigIndex );
2719 aSubset.mnSubsetEnd = aRangeBegin->mpAction->getActionCount();
2720
2721 ENSURE_OR_RETURN_FALSE( aSubset.mnSubsetBegin >= 0 && aSubset.mnSubsetEnd >= 0,
2722 "ImplRenderer::forSubsetRange(): Invalid indices" );
2723
2724 rFunctor( *aRangeBegin, aSubset );
2725
2726 // first action rendered, skip to next
2727 ++aRangeBegin;
2728
2729 // render full middle actions
2730 while( aRangeBegin != aRangeEnd )
2731 rFunctor( *aRangeBegin++ );
2732
2733 if( aRangeEnd == rEnd ||
2734 aRangeEnd->mnOrigIndex > nEndIndex )
2735 {
2736 // aRangeEnd denotes end of action vector,
2737
2738 // or
2739
2740 // nEndIndex references something _after_
2741 // aRangeBegin, but _before_ aRangeEnd
2742
2743 // either way: no partial action left
2744 return rFunctor.result();
2745 }
2746
2747 aSubset.mnSubsetBegin = 0;
2748 aSubset.mnSubsetEnd = nEndIndex - aRangeEnd->mnOrigIndex;
2749
2750 ENSURE_OR_RETURN_FALSE(aSubset.mnSubsetEnd >= 0,
2751 "ImplRenderer::forSubsetRange(): Invalid indices" );
2752
2753 rFunctor( *aRangeEnd, aSubset );
2754 }
2755
2756 return rFunctor.result();
2757 }
2758 }
2759
2760 bool ImplRenderer::getSubsetIndices( sal_Int32& io_rStartIndex,
2761 sal_Int32& io_rEndIndex,
2762 ActionVector::const_iterator& o_rRangeBegin,
2763 ActionVector::const_iterator& o_rRangeEnd ) const
2764 {
2765 ENSURE_OR_RETURN_FALSE( io_rStartIndex<=io_rEndIndex,
2766 "ImplRenderer::getSubsetIndices(): invalid action range" );
2767
2768 ENSURE_OR_RETURN_FALSE( !maActions.empty(),
2769 "ImplRenderer::getSubsetIndices(): no actions to render" );
2770
2771 const sal_Int32 nMinActionIndex( maActions.front().mnOrigIndex );
2772 const sal_Int32 nMaxActionIndex( maActions.back().mnOrigIndex +
2773 maActions.back().mpAction->getActionCount() );
2774
2775 // clip given range to permissible values (there might be
2776 // ranges before and behind the valid indices)
2777 io_rStartIndex = std::max( nMinActionIndex,
2778 io_rStartIndex );
2779 io_rEndIndex = std::min( nMaxActionIndex,
2780 io_rEndIndex );
2781
2782 if( io_rStartIndex == io_rEndIndex ||
2783 io_rStartIndex > io_rEndIndex )
2784 {
2785 // empty range, don't render anything. The second
2786 // condition e.g. happens if the requested range lies
2787 // fully before or behind the valid action indices.
2788 return false;
2789 }
2790
2791
2792 const ActionVector::const_iterator aBegin( maActions.begin() );
2793 const ActionVector::const_iterator aEnd( maActions.end() );
2794
2795
2796 // find start and end action
2797 // =========================
2798 o_rRangeBegin = std::lower_bound( aBegin, aEnd,
2799 MtfAction( std::shared_ptr<Action>(), io_rStartIndex ),
2800 UpperBoundActionIndexComparator() );
2801 o_rRangeEnd = std::lower_bound( aBegin, aEnd,
2802 MtfAction( std::shared_ptr<Action>(), io_rEndIndex ),
2803 UpperBoundActionIndexComparator() );
2804 return true;
2805 }
2806
2807
2808 // Public methods
2809
2810
2811 ImplRenderer::ImplRenderer( const CanvasSharedPtr& rCanvas,
2812 const GDIMetaFile& rMtf,
2813 const Parameters& rParams )
2814 : CanvasGraphicHelper(rCanvas)
2815 , nFrameLeft(0)
2816 , nFrameTop(0)
2817 , nFrameRight(0)
2818 , nFrameBottom(0)
2819 , nPixX(0)
2820 , nPixY(0)
2821 , nMmX(0)
2822 , nMmY(0)
2823 {
2824 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::ImplRenderer::ImplRenderer(mtf)" );
2825
2826 OSL_ENSURE( rCanvas && rCanvas->getUNOCanvas().is(),
2827 "ImplRenderer::ImplRenderer(): Invalid canvas" );
2828 OSL_ENSURE( rCanvas->getUNOCanvas()->getDevice().is(),
2829 "ImplRenderer::ImplRenderer(): Invalid graphic device" );
2830
2831 // make sure canvas and graphic device are valid; action
2832 // creation don't check that every time
2833 if( !rCanvas ||
2834 !rCanvas->getUNOCanvas().is() ||
2835 !rCanvas->getUNOCanvas()->getDevice().is() )
2836 {
2837 // leave actions empty
2838 return;
2839 }
2840
2841 VectorOfOutDevStates aStateStack;
2842
2843 ScopedVclPtrInstance< VirtualDevice > aVDev;
2844 aVDev->EnableOutput( false );
2845
2846 // Setup VDev for state tracking and mapping
2847 // =========================================
2848
2849 aVDev->SetMapMode( rMtf.GetPrefMapMode() );
2850
2851 const Size aMtfSize( rMtf.GetPrefSize() );
2852 const Size aMtfSizePixPre( aVDev->LogicToPixel( aMtfSize,
2853 rMtf.GetPrefMapMode() ) );
2854
2855 // #i44110# correct null-sized output - there are shapes
2856 // which have zero size in at least one dimension
2857 // Remark the 1L cannot be replaced, that would cause max to compare long/int
2858 const Size aMtfSizePix( std::max( aMtfSizePixPre.Width(), ::tools::Long(1) ),
2859 std::max( aMtfSizePixPre.Height(), ::tools::Long(1) ) );
2860
2861 sal_Int32 nCurrActions(0);
2862 ActionFactoryParameters aParms(aStateStack,
2863 rCanvas,
2864 *aVDev,
2865 rParams,
2866 nCurrActions );
2867
2868 // init state stack
2869 aStateStack.clearStateStack();
2870
2871 // Setup local state, such that the metafile renders
2872 // itself into a one-by-one square at the origin for
2873 // identity view and render transformations
2874 aStateStack.getState().transform.scale( 1.0 / aMtfSizePix.Width(),
2875 1.0 / aMtfSizePix.Height() );
2876
2877 cppcanvastools::calcLogic2PixelAffineTransform( aStateStack.getState().mapModeTransform,
2878 *aVDev );
2879
2880 {
2881 ::cppcanvas::internal::OutDevState& rState = aStateStack.getState();
2882 // setup default text color to black
2883 rState.textColor =
2884 rState.textFillColor =
2885 rState.textOverlineColor =
2886 rState.textLineColor = cppcanvastools::intSRGBAToDoubleSequence( 0x000000FF );
2887 }
2888
2889 // apply overrides from the Parameters struct
2890 if( rParams.maFillColor )
2891 {
2892 ::cppcanvas::internal::OutDevState& rState = aStateStack.getState();
2893 rState.isFillColorSet = true;
2894 rState.fillColor = cppcanvastools::intSRGBAToDoubleSequence( *rParams.maFillColor );
2895 }
2896 if( rParams.maLineColor )
2897 {
2898 ::cppcanvas::internal::OutDevState& rState = aStateStack.getState();
2899 rState.isLineColorSet = true;
2900 rState.lineColor = cppcanvastools::intSRGBAToDoubleSequence( *rParams.maLineColor );
2901 }
2902 if( rParams.maTextColor )
2903 {
2904 ::cppcanvas::internal::OutDevState& rState = aStateStack.getState();
2905 rState.isTextFillColorSet = true;
2906 rState.isTextOverlineColorSet = true;
2907 rState.isTextLineColorSet = true;
2908 rState.textColor =
2909 rState.textFillColor =
2910 rState.textOverlineColor =
2911 rState.textLineColor = cppcanvastools::intSRGBAToDoubleSequence( *rParams.maTextColor );
2912 }
2913 if( rParams.maFontName ||
2914 rParams.maFontWeight ||
2915 rParams.maFontLetterForm ||
2916 rParams.maFontUnderline.has_value() )
2917 {
2918 ::cppcanvas::internal::OutDevState& rState = aStateStack.getState();
2919
2920 rState.xFont = createFont( rState.fontRotation,
2921 vcl::Font(), // default font
2922 aParms );
2923 }
2924
2925 /* EMF+ */
2926 createActions( const_cast<GDIMetaFile&>(rMtf), // HACK(Q2):
2927 // we're
2928 // changing
2929 // the
2930 // current
2931 // action
2932 // in
2933 // createActions!
2934 aParms,
2935 true // TODO(P1): make subsettability configurable
2936 );
2937 }
2938
2939 ImplRenderer::~ImplRenderer()
2940 {
2941 }
2942
2943 bool ImplRenderer::drawSubset( sal_Int32 nStartIndex,
2944 sal_Int32 nEndIndex ) const
2945 {
2946 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::ImplRenderer::drawSubset()" );
2947
2948 ActionVector::const_iterator aRangeBegin;
2949 ActionVector::const_iterator aRangeEnd;
2950
2951 try
2952 {
2953 if( !getSubsetIndices( nStartIndex, nEndIndex,
2954 aRangeBegin, aRangeEnd ) )
2955 return true; // nothing to render (but _that_ was successful)
2956
2957 // now, aRangeBegin references the action in which the
2958 // subset rendering must start, and aRangeEnd references
2959 // the action in which the subset rendering must end (it
2960 // might also end right at the start of the referenced
2961 // action, such that zero of that action needs to be
2962 // rendered).
2963
2964
2965 // render subset of actions
2966 // ========================
2967
2968 ::basegfx::B2DHomMatrix aMatrix = ::canvastools::getRenderStateTransform( getRenderState() );
2969
2970 ActionRenderer aRenderer( aMatrix );
2971
2972 return forSubsetRange( aRenderer,
2973 aRangeBegin,
2974 aRangeEnd,
2975 nStartIndex,
2976 nEndIndex,
2977 maActions.end() );
2978 }
2979 catch( uno::Exception& )
2980 {
2981 DBG_UNHANDLED_EXCEPTION("cppcanvas.emf");
2982 // convert error to return value
2983 return false;
2984 }
2985 }
2986
2987 ::basegfx::B2DRange ImplRenderer::getSubsetArea( sal_Int32 nStartIndex,
2988 sal_Int32 nEndIndex ) const
2989 {
2990 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::ImplRenderer::getSubsetArea()" );
2991
2992 ActionVector::const_iterator aRangeBegin;
2993 ActionVector::const_iterator aRangeEnd;
2994
2995 if( !getSubsetIndices( nStartIndex, nEndIndex,
2996 aRangeBegin, aRangeEnd ) )
2997 return ::basegfx::B2DRange(); // nothing to render -> empty range
2998
2999 // now, aRangeBegin references the action in which the
3000 // subset querying must start, and aRangeEnd references
3001 // the action in which the subset querying must end (it
3002 // might also end right at the start of the referenced
3003 // action, such that zero of that action needs to be
3004 // queried).
3005
3006
3007 // query bounds for subset of actions
3008 // ==================================
3009
3010 ::basegfx::B2DHomMatrix aMatrix = ::canvastools::getRenderStateTransform(
3011 getRenderState() );
3012
3013 AreaQuery aQuery( aMatrix );
3014 forSubsetRange( aQuery,
3015 aRangeBegin,
3016 aRangeEnd,
3017 nStartIndex,
3018 nEndIndex,
3019 maActions.end() );
3020
3021 return aQuery.getBounds();
3022 }
3023
3024 bool ImplRenderer::draw() const
3025 {
3026 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::ImplRenderer::draw()" );
3027
3028 ::basegfx::B2DHomMatrix aMatrix = ::canvastools::getRenderStateTransform(
3029 getRenderState() );
3030
3031 try
3032 {
3033 return std::for_each( maActions.begin(), maActions.end(), ActionRenderer( aMatrix ) ).result();
3034 }
3035 catch( uno::Exception& )
3036 {
3037 DBG_UNHANDLED_EXCEPTION( "cppcanvas.emf");
3038 return false;
3039 }
3040 }
3041 }
3042
3043 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */