LibreOffice Module vcl (master)  1
print2.cxx
Go to the documentation of this file.
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 <utility>
21 #include <list>
22 #include <vector>
23 
25 #include <sal/log.hxx>
26 #include <officecfg/Office/Common.hxx>
27 
28 #include <vcl/virdev.hxx>
29 #include <vcl/metaact.hxx>
30 #include <vcl/gdimtf.hxx>
31 #include <vcl/print.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/bitmapaccess.hxx>
34 
35 #include "pdfwriter_impl.hxx"
36 
37 #define MAX_TILE_WIDTH 1024
38 #define MAX_TILE_HEIGHT 1024
39 
40 typedef ::std::pair< MetaAction*, int > Component; // MetaAction plus index in metafile
41 
42 namespace {
43 
44 // List of (intersecting) actions, plus overall bounds
45 struct ConnectedComponents
46 {
47  ConnectedComponents() :
48  aComponentList(),
49  aBounds(),
50  aBgColor(COL_WHITE),
51  bIsSpecial(false),
52  bIsFullyTransparent(false)
53  {}
54 
55  ::std::list< Component > aComponentList;
56  tools::Rectangle aBounds;
57  Color aBgColor;
58  bool bIsSpecial;
59  bool bIsFullyTransparent;
60 };
61 
62 }
63 
64 typedef ::std::vector< ConnectedComponents > ConnectedComponentsList;
65 
66 namespace {
67 
71 bool IsTransparentAction( const MetaAction& rAct )
72 {
73  switch( rAct.GetType() )
74  {
76  return true;
77 
79  return true;
80 
82  return static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx().IsTransparent();
83 
85  return static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx().IsTransparent();
86 
88  return static_cast<const MetaBmpExScalePartAction&>(rAct).GetBitmapEx().IsTransparent();
89 
90  default:
91  return false;
92  }
93 }
94 
95 
100 bool DoesActionHandleTransparency( const MetaAction& rAct )
101 {
102  // MetaActionType::FLOATTRANSPARENT can contain a whole metafile,
103  // which is to be rendered with the given transparent gradient. We
104  // currently cannot emulate transparent painting on a white
105  // background reliably.
106 
107  // the remainder can handle printing itself correctly on a uniform
108  // white background.
109  switch( rAct.GetType() )
110  {
115  return true;
116 
117  default:
118  return false;
119  }
120 }
121 
125 bool checkRect( tools::Rectangle& io_rPrevRect,
126  Color& o_rBgColor,
127  const tools::Rectangle& rCurrRect,
128  OutputDevice const & rMapModeVDev )
129 {
130  // shape needs to fully cover previous content, and have uniform
131  // color
132  const bool bRet(
133  rMapModeVDev.LogicToPixel(rCurrRect).IsInside(io_rPrevRect) &&
134  rMapModeVDev.IsFillColor() );
135 
136  if( bRet )
137  {
138  io_rPrevRect = rCurrRect;
139  o_rBgColor = rMapModeVDev.GetFillColor();
140  }
141 
142  return bRet;
143 }
144 
152 void ImplConvertTransparentAction( GDIMetaFile& o_rMtf,
153  const MetaAction& rAct,
154  const OutputDevice& rStateOutDev,
155  Color aBgColor )
156 {
157  if (rAct.GetType() == MetaActionType::Transparent)
158  {
159  const MetaTransparentAction* pTransAct = static_cast<const MetaTransparentAction*>(&rAct);
160  sal_uInt16 nTransparency( pTransAct->GetTransparence() );
161 
162  // #i10613# Respect transparency for draw color
163  if (nTransparency)
164  {
165  o_rMtf.AddAction(new MetaPushAction(PushFlags::LINECOLOR|PushFlags::FILLCOLOR));
166 
167  // assume white background for alpha blending
168  Color aLineColor(rStateOutDev.GetLineColor());
169  aLineColor.SetRed(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency) * aLineColor.GetRed()) / 100));
170  aLineColor.SetGreen(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency) * aLineColor.GetGreen()) / 100));
171  aLineColor.SetBlue(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency) * aLineColor.GetBlue()) / 100));
172  o_rMtf.AddAction(new MetaLineColorAction(aLineColor, true));
173 
174  Color aFillColor(rStateOutDev.GetFillColor());
175  aFillColor.SetRed(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency)*aFillColor.GetRed()) / 100));
176  aFillColor.SetGreen(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency)*aFillColor.GetGreen()) / 100));
177  aFillColor.SetBlue(static_cast<sal_uInt8>((255*nTransparency + (100 - nTransparency)*aFillColor.GetBlue()) / 100));
178  o_rMtf.AddAction(new MetaFillColorAction(aFillColor, true));
179  }
180 
181  o_rMtf.AddAction(new MetaPolyPolygonAction(pTransAct->GetPolyPolygon()));
182 
183  if(nTransparency)
184  o_rMtf.AddAction(new MetaPopAction());
185  }
186  else
187  {
188  BitmapEx aBmpEx;
189 
190  switch (rAct.GetType())
191  {
193  aBmpEx = static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx();
194  break;
195 
197  aBmpEx = static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx();
198  break;
199 
201  aBmpEx = static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx();
202  break;
203 
205 
206  default:
207  OSL_FAIL("Printer::GetPreparedMetafile impossible state reached");
208  break;
209  }
210 
211  Bitmap aBmp(aBmpEx.GetBitmap());
212  if (!aBmpEx.IsAlpha())
213  {
214  // blend with mask
215  Bitmap::ScopedReadAccess pRA(aBmp);
216 
217  if (!pRA)
218  return; // what else should I do?
219 
220  Color aActualColor(aBgColor);
221 
222  if (pRA->HasPalette())
223  aActualColor = pRA->GetBestPaletteColor(aBgColor);
224 
225  pRA.reset();
226 
227  // did we get true white?
228  if (aActualColor.GetColorError(aBgColor))
229  {
230  // no, create truecolor bitmap, then
231  aBmp.Convert(BmpConversion::N24Bit);
232 
233  // fill masked out areas white
234  aBmp.Replace(aBmpEx.GetMask(), aBgColor);
235  }
236  else
237  {
238  // fill masked out areas white
239  aBmp.Replace(aBmpEx.GetMask(), aActualColor);
240  }
241  }
242  else
243  {
244  // blend with alpha channel
245  aBmp.Convert(BmpConversion::N24Bit);
246  aBmp.Blend(aBmpEx.GetAlpha(), aBgColor);
247  }
248 
249  // add corresponding action
250  switch (rAct.GetType())
251  {
253  o_rMtf.AddAction(new MetaBmpAction(
254  static_cast<const MetaBmpExAction&>(rAct).GetPoint(),
255  aBmp));
256  break;
258  o_rMtf.AddAction(new MetaBmpScaleAction(
259  static_cast<const MetaBmpExScaleAction&>(rAct).GetPoint(),
260  static_cast<const MetaBmpExScaleAction&>(rAct).GetSize(),
261  aBmp));
262  break;
264  o_rMtf.AddAction(new MetaBmpScalePartAction(
265  static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestPoint(),
266  static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestSize(),
267  static_cast<const MetaBmpExScalePartAction&>(rAct).GetSrcPoint(),
268  static_cast<const MetaBmpExScalePartAction&>(rAct).GetSrcSize(),
269  aBmp));
270  break;
271  default:
272  OSL_FAIL("Unexpected case");
273  break;
274  }
275  }
276 }
277 
278 // #i10613# Extracted from ImplCheckRect::ImplCreate
279 // Returns true, if given action creates visible (i.e. non-transparent) output
280 bool ImplIsNotTransparent( const MetaAction& rAct, const OutputDevice& rOut )
281 {
282  const bool bLineTransparency( !rOut.IsLineColor() || rOut.GetLineColor().GetTransparency() == 255 );
283  const bool bFillTransparency( !rOut.IsFillColor() || rOut.GetFillColor().GetTransparency() == 255 );
284  bool bRet( false );
285 
286  switch( rAct.GetType() )
287  {
289  if( !bLineTransparency )
290  bRet = true;
291  break;
292 
294  if( !bLineTransparency )
295  bRet = true;
296  break;
297 
299  if( !bLineTransparency || !bFillTransparency )
300  bRet = true;
301  break;
302 
304  if( !bLineTransparency || !bFillTransparency )
305  bRet = true;
306  break;
307 
309  if( !bLineTransparency || !bFillTransparency )
310  bRet = true;
311  break;
312 
313  case MetaActionType::ARC:
314  if( !bLineTransparency || !bFillTransparency )
315  bRet = true;
316  break;
317 
318  case MetaActionType::PIE:
319  if( !bLineTransparency || !bFillTransparency )
320  bRet = true;
321  break;
322 
324  if( !bLineTransparency || !bFillTransparency )
325  bRet = true;
326  break;
327 
329  if( !bLineTransparency )
330  bRet = true;
331  break;
332 
334  if( !bLineTransparency || !bFillTransparency )
335  bRet = true;
336  break;
337 
339  if( !bLineTransparency || !bFillTransparency )
340  bRet = true;
341  break;
342 
344  {
345  const MetaTextAction& rTextAct = static_cast<const MetaTextAction&>(rAct);
346  const OUString aString( rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen()) );
347  if (!aString.isEmpty())
348  bRet = true;
349  }
350  break;
351 
353  {
354  const MetaTextArrayAction& rTextAct = static_cast<const MetaTextArrayAction&>(rAct);
355  const OUString aString( rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen()) );
356  if (!aString.isEmpty())
357  bRet = true;
358  }
359  break;
360 
362  case MetaActionType::BMP:
377  case MetaActionType::EPS:
381  // all other actions: generate non-transparent output
382  bRet = true;
383  break;
384 
385  default:
386  break;
387  }
388 
389  return bRet;
390 }
391 
392 // #i10613# Extracted from ImplCheckRect::ImplCreate
393 tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevice& rOut )
394 {
395  tools::Rectangle aActionBounds;
396 
397  switch( rAct.GetType() )
398  {
400  aActionBounds = tools::Rectangle( static_cast<const MetaPixelAction&>(rAct).GetPoint(), Size( 1, 1 ) );
401  break;
402 
404  aActionBounds = tools::Rectangle( static_cast<const MetaPointAction&>(rAct).GetPoint(), Size( 1, 1 ) );
405  break;
406 
408  {
409  const MetaLineAction& rMetaLineAction = static_cast<const MetaLineAction&>(rAct);
410  aActionBounds = tools::Rectangle( rMetaLineAction.GetStartPoint(), rMetaLineAction.GetEndPoint() );
411  aActionBounds.Justify();
412  const long nLineWidth(rMetaLineAction.GetLineInfo().GetWidth());
413  if(nLineWidth)
414  {
415  const long nHalfLineWidth((nLineWidth + 1) / 2);
416  aActionBounds.AdjustLeft( -nHalfLineWidth );
417  aActionBounds.AdjustTop( -nHalfLineWidth );
418  aActionBounds.AdjustRight(nHalfLineWidth );
419  aActionBounds.AdjustBottom(nHalfLineWidth );
420  }
421  break;
422  }
423 
425  aActionBounds = static_cast<const MetaRectAction&>(rAct).GetRect();
426  break;
427 
429  aActionBounds = tools::Polygon( static_cast<const MetaRoundRectAction&>(rAct).GetRect(),
430  static_cast<const MetaRoundRectAction&>(rAct).GetHorzRound(),
431  static_cast<const MetaRoundRectAction&>(rAct).GetVertRound() ).GetBoundRect();
432  break;
433 
435  {
436  const tools::Rectangle& rRect = static_cast<const MetaEllipseAction&>(rAct).GetRect();
437  aActionBounds = tools::Polygon( rRect.Center(),
438  rRect.GetWidth() >> 1,
439  rRect.GetHeight() >> 1 ).GetBoundRect();
440  break;
441  }
442 
443  case MetaActionType::ARC:
444  aActionBounds = tools::Polygon( static_cast<const MetaArcAction&>(rAct).GetRect(),
445  static_cast<const MetaArcAction&>(rAct).GetStartPoint(),
446  static_cast<const MetaArcAction&>(rAct).GetEndPoint(), PolyStyle::Arc ).GetBoundRect();
447  break;
448 
449  case MetaActionType::PIE:
450  aActionBounds = tools::Polygon( static_cast<const MetaPieAction&>(rAct).GetRect(),
451  static_cast<const MetaPieAction&>(rAct).GetStartPoint(),
452  static_cast<const MetaPieAction&>(rAct).GetEndPoint(), PolyStyle::Pie ).GetBoundRect();
453  break;
454 
456  aActionBounds = tools::Polygon( static_cast<const MetaChordAction&>(rAct).GetRect(),
457  static_cast<const MetaChordAction&>(rAct).GetStartPoint(),
458  static_cast<const MetaChordAction&>(rAct).GetEndPoint(), PolyStyle::Chord ).GetBoundRect();
459  break;
460 
462  {
463  const MetaPolyLineAction& rMetaPolyLineAction = static_cast<const MetaPolyLineAction&>(rAct);
464  aActionBounds = rMetaPolyLineAction.GetPolygon().GetBoundRect();
465  const long nLineWidth(rMetaPolyLineAction.GetLineInfo().GetWidth());
466  if(nLineWidth)
467  {
468  const long nHalfLineWidth((nLineWidth + 1) / 2);
469  aActionBounds.AdjustLeft( -nHalfLineWidth );
470  aActionBounds.AdjustTop( -nHalfLineWidth );
471  aActionBounds.AdjustRight(nHalfLineWidth );
472  aActionBounds.AdjustBottom(nHalfLineWidth );
473  }
474  break;
475  }
476 
478  aActionBounds = static_cast<const MetaPolygonAction&>(rAct).GetPolygon().GetBoundRect();
479  break;
480 
482  aActionBounds = static_cast<const MetaPolyPolygonAction&>(rAct).GetPolyPolygon().GetBoundRect();
483  break;
484 
485  case MetaActionType::BMP:
486  aActionBounds = tools::Rectangle( static_cast<const MetaBmpAction&>(rAct).GetPoint(),
487  rOut.PixelToLogic( static_cast<const MetaBmpAction&>(rAct).GetBitmap().GetSizePixel() ) );
488  break;
489 
491  aActionBounds = tools::Rectangle( static_cast<const MetaBmpScaleAction&>(rAct).GetPoint(),
492  static_cast<const MetaBmpScaleAction&>(rAct).GetSize() );
493  break;
494 
496  aActionBounds = tools::Rectangle( static_cast<const MetaBmpScalePartAction&>(rAct).GetDestPoint(),
497  static_cast<const MetaBmpScalePartAction&>(rAct).GetDestSize() );
498  break;
499 
501  aActionBounds = tools::Rectangle( static_cast<const MetaBmpExAction&>(rAct).GetPoint(),
502  rOut.PixelToLogic( static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx().GetSizePixel() ) );
503  break;
504 
506  aActionBounds = tools::Rectangle( static_cast<const MetaBmpExScaleAction&>(rAct).GetPoint(),
507  static_cast<const MetaBmpExScaleAction&>(rAct).GetSize() );
508  break;
509 
511  aActionBounds = tools::Rectangle( static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestPoint(),
512  static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestSize() );
513  break;
514 
516  aActionBounds = tools::Rectangle( static_cast<const MetaMaskAction&>(rAct).GetPoint(),
517  rOut.PixelToLogic( static_cast<const MetaMaskAction&>(rAct).GetBitmap().GetSizePixel() ) );
518  break;
519 
521  aActionBounds = tools::Rectangle( static_cast<const MetaMaskScaleAction&>(rAct).GetPoint(),
522  static_cast<const MetaMaskScaleAction&>(rAct).GetSize() );
523  break;
524 
526  aActionBounds = tools::Rectangle( static_cast<const MetaMaskScalePartAction&>(rAct).GetDestPoint(),
527  static_cast<const MetaMaskScalePartAction&>(rAct).GetDestSize() );
528  break;
529 
531  aActionBounds = static_cast<const MetaGradientAction&>(rAct).GetRect();
532  break;
533 
535  aActionBounds = static_cast<const MetaGradientExAction&>(rAct).GetPolyPolygon().GetBoundRect();
536  break;
537 
539  aActionBounds = static_cast<const MetaHatchAction&>(rAct).GetPolyPolygon().GetBoundRect();
540  break;
541 
543  aActionBounds = static_cast<const MetaWallpaperAction&>(rAct).GetRect();
544  break;
545 
547  aActionBounds = static_cast<const MetaTransparentAction&>(rAct).GetPolyPolygon().GetBoundRect();
548  break;
549 
551  aActionBounds = tools::Rectangle( static_cast<const MetaFloatTransparentAction&>(rAct).GetPoint(),
552  static_cast<const MetaFloatTransparentAction&>(rAct).GetSize() );
553  break;
554 
555  case MetaActionType::EPS:
556  aActionBounds = tools::Rectangle( static_cast<const MetaEPSAction&>(rAct).GetPoint(),
557  static_cast<const MetaEPSAction&>(rAct).GetSize() );
558  break;
559 
561  {
562  const MetaTextAction& rTextAct = static_cast<const MetaTextAction&>(rAct);
563  const OUString aString( rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen()) );
564 
565  if (!aString.isEmpty())
566  {
567  const Point aPtLog( rTextAct.GetPoint() );
568 
569  // #105987# Use API method instead of Impl* methods
570  // #107490# Set base parameter equal to index parameter
571  rOut.GetTextBoundRect( aActionBounds, rTextAct.GetText(), rTextAct.GetIndex(),
572  rTextAct.GetIndex(), rTextAct.GetLen() );
573  aActionBounds.Move( aPtLog.X(), aPtLog.Y() );
574  }
575  }
576  break;
577 
579  {
580  const MetaTextArrayAction& rTextAct = static_cast<const MetaTextArrayAction&>(rAct);
581  const OUString aString( rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen()) );
582 
583  if( !aString.isEmpty() )
584  {
585  // #105987# ImplLayout takes everything in logical coordinates
586  std::unique_ptr<SalLayout> pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
587  rTextAct.GetLen(), rTextAct.GetPoint(),
588  0, rTextAct.GetDXArray() );
589  if( pSalLayout )
590  {
591  tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
592  aActionBounds = rOut.PixelToLogic( aBoundRect );
593  }
594  }
595  }
596  break;
597 
599  aActionBounds = static_cast<const MetaTextRectAction&>(rAct).GetRect();
600  break;
601 
603  {
604  const MetaStretchTextAction& rTextAct = static_cast<const MetaStretchTextAction&>(rAct);
605  const OUString aString( rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen()) );
606 
607  // #i16195# Literate copy from TextArray action, the
608  // semantics for the ImplLayout call are copied from the
609  // OutDev::DrawStretchText() code. Unfortunately, also in
610  // this case, public outdev methods such as GetTextWidth()
611  // don't provide enough info.
612  if( !aString.isEmpty() )
613  {
614  // #105987# ImplLayout takes everything in logical coordinates
615  std::unique_ptr<SalLayout> pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
616  rTextAct.GetLen(), rTextAct.GetPoint(),
617  rTextAct.GetWidth() );
618  if( pSalLayout )
619  {
620  tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
621  aActionBounds = rOut.PixelToLogic( aBoundRect );
622  }
623  }
624  }
625  break;
626 
628  OSL_FAIL("MetaActionType::TEXTLINE not supported");
629  break;
630 
631  default:
632  break;
633  }
634 
635  if( !aActionBounds.IsEmpty() )
636  {
637  // fdo#40421 limit current action's output to clipped area
638  if( rOut.IsClipRegion() )
639  return rOut.LogicToPixel(
640  rOut.GetClipRegion().GetBoundRect().Intersection( aActionBounds ) );
641  else
642  return rOut.LogicToPixel( aActionBounds );
643  }
644  else
645  return tools::Rectangle();
646 }
647 
648 } // end anon namespace
649 
651  long nMaxBmpDPIX, long nMaxBmpDPIY,
652  bool bReduceTransparency, bool bTransparencyAutoMode,
653  bool bDownsampleBitmaps,
654  const Color& rBackground
655  )
656 {
657  MetaAction* pCurrAct;
658  bool bTransparent( false );
659 
660  rOutMtf.Clear();
661 
662  if( ! bReduceTransparency || bTransparencyAutoMode )
663  {
664  // watch for transparent drawing actions
665  for( pCurrAct = const_cast<GDIMetaFile&>(rInMtf).FirstAction();
666  pCurrAct && !bTransparent;
667  pCurrAct = const_cast<GDIMetaFile&>(rInMtf).NextAction() )
668  {
669  // #i10613# determine if the action is transparency capable
670 
671  // #107169# Also examine metafiles with masked bitmaps in
672  // detail. Further down, this is optimized in such a way
673  // that there's no unnecessary painting of masked bitmaps
674  // (which are _always_ subdivided into rectangular regions
675  // of uniform opacity): if a masked bitmap is printed over
676  // empty background, we convert to a plain bitmap with
677  // white background.
678  if( IsTransparentAction( *pCurrAct ) )
679  {
680  bTransparent = true;
681  }
682  }
683  }
684 
685  // #i10613# Determine set of connected components containing transparent objects. These are
686  // then processed as bitmaps, the original actions are removed from the metafile.
687  if( !bTransparent )
688  {
689  // nothing transparent -> just copy
690  rOutMtf = rInMtf;
691  }
692  else
693  {
694  // #i10613#
695  // This works as follows: we want a number of distinct sets of
696  // connected components, where each set contains metafile
697  // actions that are intersecting (note: there are possibly
698  // more actions contained as are directly intersecting,
699  // because we can only produce rectangular bitmaps later
700  // on. Thus, each set of connected components is the smallest
701  // enclosing, axis-aligned rectangle that completely bounds a
702  // number of intersecting metafile actions, plus any action
703  // that would otherwise be cut in two). Therefore, we
704  // iteratively add metafile actions from the original metafile
705  // to this connected components list (aCCList), by checking
706  // each element's bounding box against intersection with the
707  // metaaction at hand.
708  // All those intersecting elements are removed from aCCList
709  // and collected in a temporary list (aCCMergeList). After all
710  // elements have been checked, the aCCMergeList elements are
711  // merged with the metaaction at hand into one resulting
712  // connected component, with one big bounding box, and
713  // inserted into aCCList again.
714  // The time complexity of this algorithm is O(n^3), where n is
715  // the number of metafile actions, and it finds all distinct
716  // regions of rectangle-bounded connected components. This
717  // algorithm was designed by AF.
718 
719  // STAGE 1: Detect background
720 
721  // Receives uniform background content, and is _not_ merged
722  // nor checked for intersection against other aCCList elements
723  ConnectedComponents aBackgroundComponent;
724 
725  // Read the configuration value of minimal object area where transparency will be removed
726  double fReduceTransparencyMinArea = officecfg::Office::Common::VCL::ReduceTransparencyMinArea::get() / 100.0;
727  SAL_WARN_IF(fReduceTransparencyMinArea > 1.0, "vcl",
728  "Value of ReduceTransparencyMinArea config option is too high");
729  SAL_WARN_IF(fReduceTransparencyMinArea < 0.0, "vcl",
730  "Value of ReduceTransparencyMinArea config option is too low");
731  fReduceTransparencyMinArea = std::clamp(fReduceTransparencyMinArea, 0.0, 1.0);
732 
733  // create an OutputDevice to record mapmode changes and the like
735  aMapModeVDev->mnDPIX = mnDPIX;
736  aMapModeVDev->mnDPIY = mnDPIY;
737  aMapModeVDev->EnableOutput(false);
738 
739  int nLastBgAction, nActionNum;
740 
741  // weed out page-filling background objects (if they are
742  // uniformly coloured). Keeping them outside the other
743  // connected components often prevents whole-page bitmap
744  // generation.
745  bool bStillBackground=true; // true until first non-bg action
746  nActionNum=0; nLastBgAction=-1;
747  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction();
748  if( rBackground != COL_TRANSPARENT )
749  {
750  aBackgroundComponent.aBgColor = rBackground;
751  aBackgroundComponent.aBounds = SetBackgroundComponentBounds();
752  }
753  while( pCurrAct && bStillBackground )
754  {
755  switch( pCurrAct->GetType() )
756  {
758  {
759  if( !checkRect(
760  aBackgroundComponent.aBounds,
761  aBackgroundComponent.aBgColor,
762  static_cast<const MetaRectAction*>(pCurrAct)->GetRect(),
763  *aMapModeVDev) )
764  bStillBackground=false; // incomplete occlusion of background
765  else
766  nLastBgAction=nActionNum; // this _is_ background
767  break;
768  }
770  {
771  const tools::Polygon aPoly(
772  static_cast<const MetaPolygonAction*>(pCurrAct)->GetPolygon());
774  aPoly.getB2DPolygon()) ||
775  !checkRect(
776  aBackgroundComponent.aBounds,
777  aBackgroundComponent.aBgColor,
778  aPoly.GetBoundRect(),
779  *aMapModeVDev) )
780  bStillBackground=false; // incomplete occlusion of background
781  else
782  nLastBgAction=nActionNum; // this _is_ background
783  break;
784  }
786  {
787  const tools::PolyPolygon aPoly(
788  static_cast<const MetaPolyPolygonAction*>(pCurrAct)->GetPolyPolygon());
789  if( aPoly.Count() != 1 ||
791  aPoly[0].getB2DPolygon()) ||
792  !checkRect(
793  aBackgroundComponent.aBounds,
794  aBackgroundComponent.aBgColor,
795  aPoly.GetBoundRect(),
796  *aMapModeVDev) )
797  bStillBackground=false; // incomplete occlusion of background
798  else
799  nLastBgAction=nActionNum; // this _is_ background
800  break;
801  }
803  {
804  if( !checkRect(
805  aBackgroundComponent.aBounds,
806  aBackgroundComponent.aBgColor,
807  static_cast<const MetaWallpaperAction*>(pCurrAct)->GetRect(),
808  *aMapModeVDev) )
809  bStillBackground=false; // incomplete occlusion of background
810  else
811  nLastBgAction=nActionNum; // this _is_ background
812  break;
813  }
814  default:
815  {
816  if( ImplIsNotTransparent( *pCurrAct,
817  *aMapModeVDev ) )
818  bStillBackground=false; // non-transparent action, possibly
819  // not uniform
820  else
821  // extend current bounds (next uniform action
822  // needs to fully cover this area)
823  aBackgroundComponent.aBounds.Union(
824  ImplCalcActionBounds(*pCurrAct, *aMapModeVDev) );
825  break;
826  }
827  }
828 
829  // execute action to get correct MapModes etc.
830  pCurrAct->Execute( aMapModeVDev.get() );
831 
832  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction();
833  ++nActionNum;
834  }
835 
836  // clean up aMapModeVDev
837  sal_uInt32 nCount = aMapModeVDev->GetGCStackDepth();
838  while( nCount-- )
839  aMapModeVDev->Pop();
840 
841  ConnectedComponentsList aCCList; // list containing distinct sets of connected components as elements.
842 
843  // fast-forward until one after the last background action
844  // (need to reconstruct map mode vdev state)
845  nActionNum=0;
846  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction();
847  while( pCurrAct && nActionNum<=nLastBgAction )
848  {
849  // up to and including last ink-generating background
850  // action go to background component
851  aBackgroundComponent.aComponentList.emplace_back(
852  pCurrAct, nActionNum );
853 
854  // execute action to get correct MapModes etc.
855  pCurrAct->Execute( aMapModeVDev.get() );
856  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction();
857  ++nActionNum;
858  }
859 
860  // STAGE 2: Generate connected components list
861 
862  // iterate over all actions (start where background action
863  // search left off)
864  for( ;
865  pCurrAct;
866  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
867  {
868  // execute action to get correct MapModes etc.
869  pCurrAct->Execute( aMapModeVDev.get() );
870 
871  // cache bounds of current action
872  const tools::Rectangle aBBCurrAct( ImplCalcActionBounds(*pCurrAct, *aMapModeVDev) );
873 
874  // accumulate collected bounds here, initialize with current action
875  tools::Rectangle aTotalBounds( aBBCurrAct ); // thus,
876  // aTotalComponents.aBounds
877  // is
878  // empty
879  // for
880  // non-output-generating
881  // actions
882  bool bTreatSpecial( false );
883  ConnectedComponents aTotalComponents;
884 
885  // STAGE 2.1: Search for intersecting cc entries
886 
887  // if aBBCurrAct is empty, it will intersect with no
888  // aCCList member. Thus, we can save the check.
889  // Furthermore, this ensures that non-output-generating
890  // actions get their own aCCList entry, which is necessary
891  // when copying them to the output metafile (see stage 4
892  // below).
893 
894  // #107169# Wholly transparent objects need
895  // not be considered for connected components,
896  // too. Just put each of them into a separate
897  // component.
898  aTotalComponents.bIsFullyTransparent = !ImplIsNotTransparent(*pCurrAct, *aMapModeVDev);
899 
900  if( !aBBCurrAct.IsEmpty() &&
901  !aTotalComponents.bIsFullyTransparent )
902  {
903  if( !aBackgroundComponent.aComponentList.empty() &&
904  !aBackgroundComponent.aBounds.IsInside(aTotalBounds) )
905  {
906  // it seems the background is not large enough. to
907  // be on the safe side, combine with this component.
908  aTotalBounds.Union( aBackgroundComponent.aBounds );
909 
910  // extract all aCurr actions to aTotalComponents
911  aTotalComponents.aComponentList.splice( aTotalComponents.aComponentList.end(),
912  aBackgroundComponent.aComponentList );
913 
914  if( aBackgroundComponent.bIsSpecial )
915  bTreatSpecial = true;
916  }
917 
918  bool bSomeComponentsChanged;
919 
920  // now, this is unfortunate: since changing anyone of
921  // the aCCList elements (e.g. by merging or addition
922  // of an action) might generate new intersection with
923  // other aCCList elements, have to repeat the whole
924  // element scanning, until nothing changes anymore.
925  // Thus, this loop here makes us O(n^3) in the worst
926  // case.
927  do
928  {
929  // only loop here if 'intersects' branch below was hit
930  bSomeComponentsChanged = false;
931 
932  // iterate over all current members of aCCList
933  for( auto aCurrCC=aCCList.begin(); aCurrCC != aCCList.end(); )
934  {
935  // first check if current element's bounds are
936  // empty. This ensures that empty actions are not
937  // merged into one component, as a matter of fact,
938  // they have no position.
939 
940  // #107169# Wholly transparent objects need
941  // not be considered for connected components,
942  // too. Just put each of them into a separate
943  // component.
944  if( !aCurrCC->aBounds.IsEmpty() &&
945  !aCurrCC->bIsFullyTransparent &&
946  aCurrCC->aBounds.IsOver( aTotalBounds ) )
947  {
948  // union the intersecting aCCList element into aTotalComponents
949 
950  // calc union bounding box
951  aTotalBounds.Union( aCurrCC->aBounds );
952 
953  // extract all aCurr actions to aTotalComponents
954  aTotalComponents.aComponentList.splice( aTotalComponents.aComponentList.end(),
955  aCurrCC->aComponentList );
956 
957  if( aCurrCC->bIsSpecial )
958  bTreatSpecial = true;
959 
960  // remove and delete aCurrCC element from list (we've now merged its content)
961  aCurrCC = aCCList.erase( aCurrCC );
962 
963  // at least one component changed, need to rescan everything
964  bSomeComponentsChanged = true;
965  }
966  else
967  {
968  ++aCurrCC;
969  }
970  }
971  }
972  while( bSomeComponentsChanged );
973  }
974 
975  // STAGE 2.2: Determine special state for cc element
976 
977  // now test whether the whole connected component must be
978  // treated specially (i.e. rendered as a bitmap): if the
979  // added action is the very first action, or all actions
980  // before it are completely transparent, the connected
981  // component need not be treated specially, not even if
982  // the added action contains transparency. This is because
983  // painting of transparent objects on _white background_
984  // works without alpha compositing (you just calculate the
985  // color). Note that for the test "all objects before me
986  // are transparent" no sorting is necessary, since the
987  // added metaaction pCurrAct is always in the order the
988  // metafile is painted. Generally, the order of the
989  // metaactions in the ConnectedComponents are not
990  // guaranteed to be the same as in the metafile.
991  if( bTreatSpecial )
992  {
993  // prev component(s) special -> this one, too
994  aTotalComponents.bIsSpecial = true;
995  }
996  else if( !IsTransparentAction( *pCurrAct ) )
997  {
998  // added action and none of prev components special ->
999  // this one normal, too
1000  aTotalComponents.bIsSpecial = false;
1001  }
1002  else
1003  {
1004  // added action is special and none of prev components
1005  // special -> do the detailed tests
1006 
1007  // can the action handle transparency correctly
1008  // (i.e. when painted on white background, does the
1009  // action still look correct)?
1010  if( !DoesActionHandleTransparency( *pCurrAct ) )
1011  {
1012  // no, action cannot handle its transparency on
1013  // a printer device, render to bitmap
1014  aTotalComponents.bIsSpecial = true;
1015  }
1016  else
1017  {
1018  // yes, action can handle its transparency, so
1019  // check whether we're on white background
1020  if( aTotalComponents.aComponentList.empty() )
1021  {
1022  // nothing between pCurrAct and page
1023  // background -> don't be special
1024  aTotalComponents.bIsSpecial = false;
1025  }
1026  else
1027  {
1028  // #107169# Fixes above now ensure that _no_
1029  // object in the list is fully transparent. Thus,
1030  // if the component list is not empty above, we
1031  // must assume that we have to treat this
1032  // component special.
1033 
1034  // there are non-transparent objects between
1035  // pCurrAct and the empty sheet of paper -> be
1036  // special, then
1037  aTotalComponents.bIsSpecial = true;
1038  }
1039  }
1040  }
1041 
1042  // STAGE 2.3: Add newly generated CC list element
1043 
1044  // set new bounds and add action to list
1045  aTotalComponents.aBounds = aTotalBounds;
1046  aTotalComponents.aComponentList.emplace_back(
1047  pCurrAct, nActionNum );
1048 
1049  // add aTotalComponents as a new entry to aCCList
1050  aCCList.push_back( aTotalComponents );
1051 
1052  SAL_WARN_IF( aTotalComponents.aComponentList.empty(), "vcl",
1053  "Printer::GetPreparedMetaFile empty component" );
1054  SAL_WARN_IF( aTotalComponents.aBounds.IsEmpty() && (aTotalComponents.aComponentList.size() != 1), "vcl",
1055  "Printer::GetPreparedMetaFile non-output generating actions must be solitary");
1056  SAL_WARN_IF( aTotalComponents.bIsFullyTransparent && (aTotalComponents.aComponentList.size() != 1), "vcl",
1057  "Printer::GetPreparedMetaFile fully transparent actions must be solitary");
1058  }
1059 
1060  // well now, we've got the list of disjunct connected
1061  // components. Now we've got to create a map, which contains
1062  // the corresponding aCCList element for every
1063  // metaaction. Later on, we always process the complete
1064  // metafile for each bitmap to be generated, but switch on
1065  // output only for actions contained in the then current
1066  // aCCList element. This ensures correct mapmode and attribute
1067  // settings for all cases.
1068 
1069  // maps mtf actions to CC list entries
1070  ::std::vector< const ConnectedComponents* > aCCList_MemberMap( rInMtf.GetActionSize() );
1071 
1072  // iterate over all aCCList members and their contained metaactions
1073  for (auto const& currentItem : aCCList)
1074  {
1075  for (auto const& currentAction : currentItem.aComponentList)
1076  {
1077  // set pointer to aCCList element for corresponding index
1078  aCCList_MemberMap[ currentAction.second ] = &currentItem;
1079  }
1080  }
1081 
1082  // STAGE 3.1: Output background mtf actions (if there are any)
1083 
1084  for (auto & component : aBackgroundComponent.aComponentList)
1085  {
1086  // simply add this action (above, we inserted the actions
1087  // starting at index 0 up to and including nLastBgAction)
1088  rOutMtf.AddAction( component.first );
1089  }
1090 
1091  // STAGE 3.2: Generate banded bitmaps for special regions
1092 
1093  Point aPageOffset;
1094  Size aTmpSize( GetOutputSizePixel() );
1095  if( meOutDevType == OUTDEV_PDF )
1096  {
1097  auto pPdfWriter = static_cast<vcl::PDFWriterImpl*>(this);
1098  aTmpSize = LogicToPixel(pPdfWriter->getCurPageSize(), MapMode(MapUnit::MapPoint));
1099 
1100  // also add error code to PDFWriter
1101  pPdfWriter->insertError(vcl::PDFWriter::Warning_Transparency_Converted);
1102  }
1103  else if( meOutDevType == OUTDEV_PRINTER )
1104  {
1105  Printer* pThis = dynamic_cast<Printer*>(this);
1106  assert(pThis);
1107  aPageOffset = pThis->GetPageOffsetPixel();
1108  aPageOffset = Point( 0, 0 ) - aPageOffset;
1109  aTmpSize = pThis->GetPaperSizePixel();
1110  }
1111  const tools::Rectangle aOutputRect( aPageOffset, aTmpSize );
1112  bool bTiling = dynamic_cast<Printer*>(this) != nullptr;
1113 
1114  // iterate over all aCCList members and generate bitmaps for the special ones
1115  for (auto & currentItem : aCCList)
1116  {
1117  if( currentItem.bIsSpecial )
1118  {
1119  tools::Rectangle aBoundRect( currentItem.aBounds );
1120  aBoundRect.Intersection( aOutputRect );
1121 
1122  const double fBmpArea( static_cast<double>(aBoundRect.GetWidth()) * aBoundRect.GetHeight() );
1123  const double fOutArea( static_cast<double>(aOutputRect.GetWidth()) * aOutputRect.GetHeight() );
1124 
1125  // check if output doesn't exceed given size
1126  if( bReduceTransparency && bTransparencyAutoMode && ( fBmpArea > ( fReduceTransparencyMinArea * fOutArea ) ) )
1127  {
1128  // output normally. Therefore, we simply clear the
1129  // special attribute, as everything non-special is
1130  // copied to rOutMtf further below.
1131  currentItem.bIsSpecial = false;
1132  }
1133  else
1134  {
1135  // create new bitmap action first
1136  if( aBoundRect.GetWidth() && aBoundRect.GetHeight() )
1137  {
1138  Point aDstPtPix( aBoundRect.TopLeft() );
1139  Size aDstSzPix;
1140 
1141  ScopedVclPtrInstance<VirtualDevice> aMapVDev; // here, we record only mapmode information
1142  aMapVDev->EnableOutput(false);
1143 
1144  ScopedVclPtrInstance<VirtualDevice> aPaintVDev; // into this one, we render.
1145  aPaintVDev->SetBackground( aBackgroundComponent.aBgColor );
1146 
1147  rOutMtf.AddAction( new MetaPushAction( PushFlags::MAPMODE ) );
1148  rOutMtf.AddAction( new MetaMapModeAction() );
1149 
1150  aPaintVDev->SetDrawMode( GetDrawMode() );
1151 
1152  while( aDstPtPix.Y() <= aBoundRect.Bottom() )
1153  {
1154  aDstPtPix.setX( aBoundRect.Left() );
1155  aDstSzPix = bTiling ? Size( MAX_TILE_WIDTH, MAX_TILE_HEIGHT ) : aBoundRect.GetSize();
1156 
1157  if( ( aDstPtPix.Y() + aDstSzPix.Height() - 1 ) > aBoundRect.Bottom() )
1158  aDstSzPix.setHeight( aBoundRect.Bottom() - aDstPtPix.Y() + 1 );
1159 
1160  while( aDstPtPix.X() <= aBoundRect.Right() )
1161  {
1162  if( ( aDstPtPix.X() + aDstSzPix.Width() - 1 ) > aBoundRect.Right() )
1163  aDstSzPix.setWidth( aBoundRect.Right() - aDstPtPix.X() + 1 );
1164 
1165  if( !tools::Rectangle( aDstPtPix, aDstSzPix ).Intersection( aBoundRect ).IsEmpty() &&
1166  aPaintVDev->SetOutputSizePixel( aDstSzPix ) )
1167  {
1168  aPaintVDev->Push();
1169  aMapVDev->Push();
1170 
1171  aMapVDev->mnDPIX = aPaintVDev->mnDPIX = mnDPIX;
1172  aMapVDev->mnDPIY = aPaintVDev->mnDPIY = mnDPIY;
1173 
1174  aPaintVDev->EnableOutput(false);
1175 
1176  // iterate over all actions
1177  for( pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction(), nActionNum=0;
1178  pCurrAct;
1179  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
1180  {
1181  // enable output only for
1182  // actions that are members of
1183  // the current aCCList element
1184  // (currentItem)
1185  if( aCCList_MemberMap[nActionNum] == &currentItem )
1186  aPaintVDev->EnableOutput();
1187 
1188  // but process every action
1189  const MetaActionType nType( pCurrAct->GetType() );
1190 
1192  {
1193  pCurrAct->Execute( aMapVDev.get() );
1194 
1195  MapMode aMtfMap( aMapVDev->GetMapMode() );
1196  const Point aNewOrg( aMapVDev->PixelToLogic( aDstPtPix ) );
1197 
1198  aMtfMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
1199  aPaintVDev->SetMapMode( aMtfMap );
1200  }
1201  else if( ( MetaActionType::PUSH == nType ) || MetaActionType::POP == nType )
1202  {
1203  pCurrAct->Execute( aMapVDev.get() );
1204  pCurrAct->Execute( aPaintVDev.get() );
1205  }
1206  else if( MetaActionType::GRADIENT == nType )
1207  {
1208  MetaGradientAction* pGradientAction = static_cast<MetaGradientAction*>(pCurrAct);
1209  Printer* pPrinter = dynamic_cast< Printer* >(this);
1210  if( pPrinter )
1211  pPrinter->DrawGradientEx( aPaintVDev.get(), pGradientAction->GetRect(), pGradientAction->GetGradient() );
1212  else
1213  DrawGradient( pGradientAction->GetRect(), pGradientAction->GetGradient() );
1214  }
1215  else
1216  {
1217  pCurrAct->Execute( aPaintVDev.get() );
1218  }
1219 
1220  Application::Reschedule( true );
1221  }
1222 
1223  const bool bOldMap = mbMap;
1224  mbMap = aPaintVDev->mbMap = false;
1225 
1226  Bitmap aBandBmp( aPaintVDev->GetBitmap( Point(), aDstSzPix ) );
1227 
1228  // scale down bitmap, if requested
1229  if( bDownsampleBitmaps )
1230  {
1231  aBandBmp = GetDownsampledBitmap( aDstSzPix,
1232  Point(), aBandBmp.GetSizePixel(),
1233  aBandBmp, nMaxBmpDPIX, nMaxBmpDPIY );
1234  }
1235 
1236  rOutMtf.AddAction( new MetaCommentAction( "PRNSPOOL_TRANSPARENTBITMAP_BEGIN" ) );
1237  rOutMtf.AddAction( new MetaBmpScaleAction( aDstPtPix, aDstSzPix, aBandBmp ) );
1238  rOutMtf.AddAction( new MetaCommentAction( "PRNSPOOL_TRANSPARENTBITMAP_END" ) );
1239 
1240  aPaintVDev->mbMap = true;
1241  mbMap = bOldMap;
1242  aMapVDev->Pop();
1243  aPaintVDev->Pop();
1244  }
1245 
1246  // overlapping bands to avoid missing lines (e.g. PostScript)
1247  aDstPtPix.AdjustX(aDstSzPix.Width() );
1248  }
1249 
1250  // overlapping bands to avoid missing lines (e.g. PostScript)
1251  aDstPtPix.AdjustY(aDstSzPix.Height() );
1252  }
1253 
1254  rOutMtf.AddAction( new MetaPopAction() );
1255  }
1256  }
1257  }
1258  }
1259 
1260  // clean up aMapModeVDev
1261  nCount = aMapModeVDev->GetGCStackDepth();
1262  while( nCount-- )
1263  aMapModeVDev->Pop();
1264 
1265  // STAGE 4: Copy actions to output metafile
1266 
1267  // iterate over all actions and duplicate the ones not in a
1268  // special aCCList member into rOutMtf
1269  for( pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction(), nActionNum=0;
1270  pCurrAct;
1271  pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
1272  {
1273  const ConnectedComponents* pCurrAssociatedComponent = aCCList_MemberMap[nActionNum];
1274 
1275  // NOTE: This relies on the fact that map-mode or draw
1276  // mode changing actions are solitary aCCList elements and
1277  // have empty bounding boxes, see comment on stage 2.1
1278  // above
1279  if( pCurrAssociatedComponent &&
1280  (pCurrAssociatedComponent->aBounds.IsEmpty() ||
1281  !pCurrAssociatedComponent->bIsSpecial) )
1282  {
1283  // #107169# Treat transparent bitmaps special, if they
1284  // are the first (or sole) action in their bounds
1285  // list. Note that we previously ensured that no
1286  // fully-transparent objects are before us here.
1287  if( DoesActionHandleTransparency( *pCurrAct ) &&
1288  pCurrAssociatedComponent->aComponentList.begin()->first == pCurrAct )
1289  {
1290  // convert actions, where masked-out parts are of
1291  // given background color
1292  ImplConvertTransparentAction(rOutMtf,
1293  *pCurrAct,
1294  *aMapModeVDev,
1295  aBackgroundComponent.aBgColor);
1296  }
1297  else
1298  {
1299  // simply add this action
1300  rOutMtf.AddAction( pCurrAct );
1301  }
1302 
1303  pCurrAct->Execute(aMapModeVDev.get());
1304  }
1305  }
1306 
1307  rOutMtf.SetPrefMapMode( rInMtf.GetPrefMapMode() );
1308  rOutMtf.SetPrefSize( rInMtf.GetPrefSize() );
1309 
1310 #if OSL_DEBUG_LEVEL > 1
1311  // iterate over all aCCList members and generate rectangles for the bounding boxes
1312  rOutMtf.AddAction( new MetaFillColorAction( COL_WHITE, false ) );
1313  for(auto const& aCurr:aCCList)
1314  {
1315  if( aCurr.bIsSpecial )
1316  rOutMtf.AddAction( new MetaLineColorAction( COL_RED, true) );
1317  else
1318  rOutMtf.AddAction( new MetaLineColorAction( COL_BLUE, true) );
1319 
1320  rOutMtf.AddAction( new MetaRectAction( aMapModeVDev->PixelToLogic( aCurr.aBounds ) ) );
1321  }
1322 #endif
1323  }
1324  return bTransparent;
1325 }
1326 
1327 void Printer::DrawGradientEx( OutputDevice* pOut, const tools::Rectangle& rRect, const Gradient& rGradient )
1328 {
1329  const PrinterOptions& rPrinterOptions = GetPrinterOptions();
1330 
1331  if( rPrinterOptions.IsReduceGradients() )
1332  {
1333  if( PrinterGradientMode::Stripes == rPrinterOptions.GetReducedGradientMode() )
1334  {
1335  if( !rGradient.GetSteps() || ( rGradient.GetSteps() > rPrinterOptions.GetReducedGradientStepCount() ) )
1336  {
1337  Gradient aNewGradient( rGradient );
1338 
1339  aNewGradient.SetSteps( rPrinterOptions.GetReducedGradientStepCount() );
1340  pOut->DrawGradient( rRect, aNewGradient );
1341  }
1342  else
1343  pOut->DrawGradient( rRect, rGradient );
1344  }
1345  else
1346  {
1347  const Color& rStartColor = rGradient.GetStartColor();
1348  const Color& rEndColor = rGradient.GetEndColor();
1349  const long nR = ( ( static_cast<long>(rStartColor.GetRed()) * rGradient.GetStartIntensity() ) / 100 +
1350  ( static_cast<long>(rEndColor.GetRed()) * rGradient.GetEndIntensity() ) / 100 ) >> 1;
1351  const long nG = ( ( static_cast<long>(rStartColor.GetGreen()) * rGradient.GetStartIntensity() ) / 100 +
1352  ( static_cast<long>(rEndColor.GetGreen()) * rGradient.GetEndIntensity() ) / 100 ) >> 1;
1353  const long nB = ( ( static_cast<long>(rStartColor.GetBlue()) * rGradient.GetStartIntensity() ) / 100 +
1354  ( static_cast<long>(rEndColor.GetBlue()) * rGradient.GetEndIntensity() ) / 100 ) >> 1;
1355  const Color aColor( static_cast<sal_uInt8>(nR), static_cast<sal_uInt8>(nG), static_cast<sal_uInt8>(nB) );
1356 
1358  pOut->SetLineColor( aColor );
1359  pOut->SetFillColor( aColor );
1360  pOut->DrawRect( rRect );
1361  pOut->Pop();
1362  }
1363  }
1364  else
1365  pOut->DrawGradient( rRect, rGradient );
1366 }
1367 
1368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 Count() const
Point TopLeft() const
vcl::Region GetClipRegion() const
const PrinterOptions & GetPrinterOptions() const
Definition: print.hxx:304
virtual void Execute(OutputDevice *pOut)
Definition: metaact.cxx:168
const LineInfo & GetLineInfo() const
Definition: metaact.hxx:183
Bitmap GetMask() const
Definition: bitmapex.cxx:258
long GetWidth() const
sal_Int32 GetLen() const
Definition: metaact.hxx:493
long GetHeight() const
sal_uInt8 GetRed() const
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
const BitmapColor & GetBestPaletteColor(const BitmapColor &rBitmapColor) const
constexpr::Color COL_RED(0x80, 0x00, 0x00)
const MapMode & GetPrefMapMode() const
Definition: gdimtf.hxx:176
long AdjustLeft(long nHorzMoveDelta)
sal_uInt8 GetTransparency() const
SAL_DLLPRIVATE Bitmap GetDownsampledBitmap(const Size &rDstSz, const Point &rSrcPt, const Size &rSrcSz, const Bitmap &rBmp, long nMaxBmpDPIX, long nMaxBmpDPIY)
Retrieve downsampled and cropped bitmap.
void SetPrefSize(const Size &rSize)
Definition: gdimtf.hxx:174
void Clear()
Definition: gdimtf.cxx:248
sal_Int32 mnDPIY
Definition: outdev.hxx:348
const tools::PolyPolygon & GetPolyPolygon() const
Definition: metaact.hxx:1524
bool RemoveTransparenciesFromMetaFile(const GDIMetaFile &rInMtf, GDIMetaFile &rOutMtf, long nMaxBmpDPIX, long nMaxBmpDPIY, bool bReduceTransparency, bool bTransparencyAutoMode, bool bDownsampleBitmaps, const Color &rBackground=COL_TRANSPARENT)
helper method removing transparencies from a metafile (e.g.
Definition: print2.cxx:650
const Point & GetEndPoint() const
Definition: metaact.hxx:182
sal_Int32 mnDPIX
Definition: outdev.hxx:347
const OUString & GetText() const
Definition: metaact.hxx:565
bool mbMap
Definition: outdev.hxx:376
tools::Rectangle GetBoundRect() const
Definition: region.cxx:1214
bool GetTextBoundRect(tools::Rectangle &rRect, const OUString &rStr, sal_Int32 nBase=0, sal_Int32 nIndex=0, sal_Int32 nLen=-1, sal_uLong nLayoutWidth=0, const long *pDXArray=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
Return the exact bounding rectangle of rStr.
Definition: text.cxx:2313
long AdjustBottom(long nVertMoveDelta)
void Move(long nHorzMoveDelta, long nVertMoveDelta)
bool IsEmpty() const
void SetSteps(sal_uInt16 nSteps)
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
bool IsAlpha() const
Definition: bitmapex.cxx:226
long Right() const
::std::vector< ConnectedComponents > ConnectedComponentsList
Definition: print2.cxx:64
const OUString & GetText() const
Definition: metaact.hxx:491
int nCount
const Gradient & GetGradient() const
Definition: metaact.hxx:982
const Size & GetPaperSizePixel() const
Definition: print.hxx:330
MetaActionType
void DrawGradientEx(OutputDevice *pOut, const tools::Rectangle &rRect, const Gradient &rGradient)
Definition: print2.cxx:1327
sal_uInt16 GetColorError(const Color &rCompareColor) const
sal_uInt8 GetBlue() const
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
void SetLineColor()
static bool Reschedule(bool bHandleAllCurrentEvents=false)
Attempt to process current pending event(s)
Definition: svapp.cxx:465
const Size & GetPrefSize() const
Definition: gdimtf.hxx:173
bool HasPalette() const
bool IsClipRegion() const
Definition: outdev.hxx:669
sal_uInt16 GetTransparence() const
Definition: metaact.hxx:1525
bool IsLineColor() const
Definition: outdev.hxx:625
const Point & GetPoint() const
Definition: metaact.hxx:490
const tools::Rectangle & GetRect() const
Definition: metaact.hxx:981
virtual tools::Rectangle SetBackgroundComponentBounds()
Definition: outdev.cxx:582
sal_uInt32 GetWidth() const
Definition: metaact.hxx:566
const OutDevType meOutDevType
Definition: outdev.hxx:359
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
const Color & GetLineColor() const
Definition: outdev.hxx:624
void SetRed(sal_uInt8 nRed)
long Bottom() const
sal_uInt16 GetEndIntensity() const
sal_Int32 GetLen() const
Definition: metaact.hxx:568
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
::basegfx::B2DPolygon getB2DPolygon() const
DrawModeFlags GetDrawMode() const
Definition: outdev.hxx:601
std::unique_ptr< SalLayout > ImplLayout(const OUString &, sal_Int32 nIndex, sal_Int32 nLen, const Point &rLogicPos=Point(0, 0), long nLogicWidth=0, const long *pLogicDXArray=nullptr, SalLayoutFlags flags=SalLayoutFlags::NONE, vcl::TextLayoutCache const *=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
Definition: text.cxx:1240
sal_Int32 nLineWidth
Size GetSize() const
sal_uInt16 GetSteps() const
#define MAX_TILE_WIDTH
Definition: print2.cxx:37
const Color & GetStartColor() const
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: bitmapex.cxx:236
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1179
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:934
const Point & GetPoint() const
Definition: metaact.hxx:564
sal_uInt8 GetGreen() const
const Point & GetStartPoint() const
Definition: metaact.hxx:181
const Point & GetPageOffsetPixel() const
Definition: print.hxx:333
AlphaMask GetAlpha() const
Definition: bitmapex.cxx:268
long AdjustRight(long nHorzMoveDelta)
tools::Rectangle & Union(const tools::Rectangle &rRect)
#define SAL_WARN_IF(condition, area, stream)
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:543
const Color & GetEndColor() const
long AdjustTop(long nVertMoveDelta)
size_t GetActionSize() const
Definition: gdimtf.cxx:157
QPRO_FUNC_TYPE nType
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
MetaActionType GetType() const
Definition: metaact.hxx:90
long Left() const
::std::pair< MetaAction *, int > Component
Definition: print2.cxx:40
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
tools::Rectangle GetBoundRect() const
constexpr::Color COL_BLUE(0x00, 0x00, 0x80)
tools::Rectangle GetBoundRect() const
bool IsFillColor() const
Definition: outdev.hxx:630
#define MAX_TILE_HEIGHT
Definition: print2.cxx:38
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
void DrawGradient(const tools::Rectangle &rRect, const Gradient &rGradient)
sal_uInt16 GetStartIntensity() const
sal_Int32 GetIndex() const
Definition: metaact.hxx:567
bool isRectangle(const B2DPolygon &rPoly)
sal_Int32 GetIndex() const
Definition: metaact.hxx:492
Point Center() const
const Color & GetFillColor() const
Definition: outdev.hxx:629
void SetPrefMapMode(const MapMode &rMapMode)
Definition: gdimtf.hxx:177
void setHeight(long nHeight)