LibreOffice Module vcl (master)  1
outdevstate.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 <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <tools/debug.hxx>
24 #include <vcl/gdimtf.hxx>
25 #include <vcl/metaact.hxx>
26 #include <vcl/outdevstate.hxx>
27 #include <vcl/virdev.hxx>
28 #include <vcl/settings.hxx>
29 
30 #include <outdev.h>
31 #include <outdata.hxx>
32 #include <salgdi.hxx>
33 
35  : mbMapActive(false)
36  , meTextAlign(ALIGN_TOP)
37  , meRasterOp(RasterOp::OverPaint)
38  , mnTextLayoutMode(ComplexTextLayoutFlags::Default)
39  , meTextLanguage(0)
41 {
42 }
43 
45 
47 {
48  mpLineColor.reset();
49  mpFillColor.reset();
50  mpFont.reset();
51  mpTextColor.reset();
52  mpTextFillColor.reset();
53  mpTextLineColor.reset();
54  mpOverlineColor.reset();
55  mpMapMode.reset();
56  mpClipRegion.reset();
57  mpRefPoint.reset();
58 }
59 
61 {
62 
63  if ( mpMetaFile )
64  mpMetaFile->AddAction( new MetaPushAction( nFlags ) );
65 
66  maOutDevStateStack.emplace_back();
67  OutDevState& rState = maOutDevStateStack.back();
68 
69  rState.mnFlags = nFlags;
70 
71  if (nFlags & PushFlags::LINECOLOR && mbLineColor)
72  {
73  rState.mpLineColor = maLineColor;
74  }
75  if (nFlags & PushFlags::FILLCOLOR && mbFillColor)
76  {
77  rState.mpFillColor = maFillColor;
78  }
79  if ( nFlags & PushFlags::FONT )
80  rState.mpFont.reset( new vcl::Font( maFont ) );
81  if ( nFlags & PushFlags::TEXTCOLOR )
82  rState.mpTextColor = GetTextColor();
83  if (nFlags & PushFlags::TEXTFILLCOLOR && IsTextFillColor())
84  {
86  }
87  if (nFlags & PushFlags::TEXTLINECOLOR && IsTextLineColor())
88  {
90  }
91  if (nFlags & PushFlags::OVERLINECOLOR && IsOverlineColor())
92  {
94  }
95  if ( nFlags & PushFlags::TEXTALIGN )
96  rState.meTextAlign = GetTextAlign();
97  if( nFlags & PushFlags::TEXTLAYOUTMODE )
99  if( nFlags & PushFlags::TEXTLANGUAGE )
100  rState.meTextLanguage = GetDigitLanguage();
101  if ( nFlags & PushFlags::RASTEROP )
102  rState.meRasterOp = GetRasterOp();
103  if ( nFlags & PushFlags::MAPMODE )
104  {
105  rState.mpMapMode = maMapMode;
106  rState.mbMapActive = mbMap;
107  }
108  if (nFlags & PushFlags::CLIPREGION && mbClipRegion)
109  {
110  rState.mpClipRegion.reset( new vcl::Region( maRegion ) );
111  }
112  if (nFlags & PushFlags::REFPOINT && mbRefPoint)
113  {
114  rState.mpRefPoint = maRefPoint;
115  }
116 
117  if( mpAlphaVDev )
118  mpAlphaVDev->Push();
119 }
120 
122 {
123 
124  if( mpMetaFile )
126 
127  GDIMetaFile* pOldMetaFile = mpMetaFile;
128  mpMetaFile = nullptr;
129 
130  if ( maOutDevStateStack.empty() )
131  {
132  SAL_WARN( "vcl.gdi", "OutputDevice::Pop() without OutputDevice::Push()" );
133  return;
134  }
135  const OutDevState& rState = maOutDevStateStack.back();
136 
137  if( mpAlphaVDev )
138  mpAlphaVDev->Pop();
139 
140  if ( rState.mnFlags & PushFlags::LINECOLOR )
141  {
142  if ( rState.mpLineColor )
143  SetLineColor( *rState.mpLineColor );
144  else
145  SetLineColor();
146  }
147 
148  if ( rState.mnFlags & PushFlags::FILLCOLOR )
149  {
150  if ( rState.mpFillColor )
151  SetFillColor( *rState.mpFillColor );
152  else
153  SetFillColor();
154  }
155 
156  if ( rState.mnFlags & PushFlags::FONT )
157  SetFont( *rState.mpFont );
158 
159  if ( rState.mnFlags & PushFlags::TEXTCOLOR )
160  SetTextColor( *rState.mpTextColor );
161 
162  if ( rState.mnFlags & PushFlags::TEXTFILLCOLOR )
163  {
164  if ( rState.mpTextFillColor )
166  else
168  }
169 
170  if ( rState.mnFlags & PushFlags::TEXTLINECOLOR )
171  {
172  if ( rState.mpTextLineColor )
174  else
176  }
177 
178  if ( rState.mnFlags & PushFlags::OVERLINECOLOR )
179  {
180  if ( rState.mpOverlineColor )
182  else
184  }
185 
186  if ( rState.mnFlags & PushFlags::TEXTALIGN )
187  SetTextAlign( rState.meTextAlign );
188 
189  if( rState.mnFlags & PushFlags::TEXTLAYOUTMODE )
191 
192  if( rState.mnFlags & PushFlags::TEXTLANGUAGE )
194 
195  if ( rState.mnFlags & PushFlags::RASTEROP )
196  SetRasterOp( rState.meRasterOp );
197 
198  if ( rState.mnFlags & PushFlags::MAPMODE )
199  {
200  if ( rState.mpMapMode )
201  SetMapMode( *rState.mpMapMode );
202  else
203  SetMapMode();
204  mbMap = rState.mbMapActive;
205  }
206 
207  if ( rState.mnFlags & PushFlags::CLIPREGION )
208  SetDeviceClipRegion( rState.mpClipRegion.get() );
209 
210  if ( rState.mnFlags & PushFlags::REFPOINT )
211  {
212  if ( rState.mpRefPoint )
213  SetRefPoint( *rState.mpRefPoint );
214  else
215  SetRefPoint();
216  }
217 
218  maOutDevStateStack.pop_back();
219 
220  mpMetaFile = pOldMetaFile;
221 }
222 
224 {
225  return maOutDevStateStack.size();
226 }
227 
228 void OutputDevice::EnableOutput( bool bEnable )
229 {
230  mbOutput = bEnable;
231 
232  if( mpAlphaVDev )
233  mpAlphaVDev->EnableOutput( bEnable );
234 }
235 
237 {
238  if ( mnAntialiasing != nMode )
239  {
240  mnAntialiasing = nMode;
241  mbInitFont = true;
242 
243  if(mpGraphics)
244  {
246  }
247  }
248 
249  if( mpAlphaVDev )
250  mpAlphaVDev->SetAntialiasing( nMode );
251 }
252 
254 {
255 
256  mnDrawMode = nDrawMode;
257 
258  if( mpAlphaVDev )
259  mpAlphaVDev->SetDrawMode( nDrawMode );
260 }
261 
263 {
264  if( mpMetaFile )
265  mpMetaFile->AddAction( new MetaLayoutModeAction( nTextLayoutMode ) );
266 
267  mnTextLayoutMode = nTextLayoutMode;
268 
269  if( mpAlphaVDev )
270  mpAlphaVDev->SetLayoutMode( nTextLayoutMode );
271 }
272 
274 {
275  if( mpMetaFile )
276  mpMetaFile->AddAction( new MetaTextLanguageAction( eTextLanguage ) );
277 
278  meTextLanguage = eTextLanguage;
279 
280  if( mpAlphaVDev )
281  mpAlphaVDev->SetDigitLanguage( eTextLanguage );
282 }
283 
285 {
286 
287  if ( mpMetaFile )
288  mpMetaFile->AddAction( new MetaRasterOpAction( eRasterOp ) );
289 
290  if ( meRasterOp != eRasterOp )
291  {
292  meRasterOp = eRasterOp;
294 
295  if( mpGraphics || AcquireGraphics() )
297  }
298 
299  if( mpAlphaVDev )
300  mpAlphaVDev->SetRasterOp( eRasterOp );
301 }
302 
303 
305 {
306 
307  if ( mpMetaFile )
308  mpMetaFile->AddAction( new MetaFillColorAction( Color(), false ) );
309 
310  if ( mbFillColor )
311  {
312  mbInitFillColor = true;
313  mbFillColor = false;
315  }
316 
317  if( mpAlphaVDev )
319 }
320 
321 void OutputDevice::SetFillColor( const Color& rColor )
322 {
323 
324  Color aColor( rColor );
325 
329  {
330  if( !ImplIsColorTransparent( aColor ) )
331  {
333  {
334  aColor = COL_BLACK;
335  }
337  {
338  aColor = COL_WHITE;
339  }
341  {
342  const sal_uInt8 cLum = aColor.GetLuminance();
343  aColor = Color( cLum, cLum, cLum );
344  }
345  else if( mnDrawMode & DrawModeFlags::NoFill )
346  {
347  aColor = COL_TRANSPARENT;
348  }
350  {
352  }
353  }
354  }
355 
356  if ( mpMetaFile )
357  mpMetaFile->AddAction( new MetaFillColorAction( aColor, true ) );
358 
359  if ( ImplIsColorTransparent( aColor ) )
360  {
361  if ( mbFillColor )
362  {
363  mbInitFillColor = true;
364  mbFillColor = false;
366  }
367  }
368  else
369  {
370  if ( maFillColor != aColor )
371  {
372  mbInitFillColor = true;
373  mbFillColor = true;
374  maFillColor = aColor;
375  }
376  }
377 
378  if( mpAlphaVDev )
380 }
381 
383 {
384 
385  if ( mpMetaFile )
386  mpMetaFile->AddAction( new MetaLineColorAction( Color(), false ) );
387 
388  if ( mbLineColor )
389  {
390  mbInitLineColor = true;
391  mbLineColor = false;
393  }
394 
395  if( mpAlphaVDev )
397 }
398 
399 void OutputDevice::SetLineColor( const Color& rColor )
400 {
401 
402  Color aColor = ImplDrawModeToColor( rColor );
403 
404  if( mpMetaFile )
405  mpMetaFile->AddAction( new MetaLineColorAction( aColor, true ) );
406 
407  if( ImplIsColorTransparent( aColor ) )
408  {
409  if ( mbLineColor )
410  {
411  mbInitLineColor = true;
412  mbLineColor = false;
414  }
415  }
416  else
417  {
418  if( maLineColor != aColor )
419  {
420  mbInitLineColor = true;
421  mbLineColor = true;
422  maLineColor = aColor;
423  }
424  }
425 
426  if( mpAlphaVDev )
428 }
429 
431 {
432 
434  mbBackground = false;
435 
436  if( mpAlphaVDev )
438 }
439 
440 void OutputDevice::SetBackground( const Wallpaper& rBackground )
441 {
442 
443  maBackground = rBackground;
444 
445  if( rBackground.GetStyle() == WallpaperStyle::NONE )
446  mbBackground = false;
447  else
448  mbBackground = true;
449 
450  if( mpAlphaVDev )
451  mpAlphaVDev->SetBackground( rBackground );
452 }
453 
454 void OutputDevice::SetFont( const vcl::Font& rNewFont )
455 {
456 
457  vcl::Font aFont( rNewFont );
461  {
462  Color aTextColor( aFont.GetColor() );
463 
465  aTextColor = COL_BLACK;
467  aTextColor = COL_WHITE;
468  else if ( mnDrawMode & DrawModeFlags::GrayText )
469  {
470  const sal_uInt8 cLum = aTextColor.GetLuminance();
471  aTextColor = Color( cLum, cLum, cLum );
472  }
474  aTextColor = GetSettings().GetStyleSettings().GetFontColor();
475 
476  aFont.SetColor( aTextColor );
477 
478  bool bTransFill = aFont.IsTransparent();
479  if ( !bTransFill )
480  {
481  Color aTextFillColor( aFont.GetFillColor() );
482 
484  aTextFillColor = COL_BLACK;
486  aTextFillColor = COL_WHITE;
487  else if ( mnDrawMode & DrawModeFlags::GrayFill )
488  {
489  const sal_uInt8 cLum = aTextFillColor.GetLuminance();
490  aTextFillColor = Color( cLum, cLum, cLum );
491  }
493  aTextFillColor = GetSettings().GetStyleSettings().GetWindowColor();
494  else if ( mnDrawMode & DrawModeFlags::NoFill )
495  {
496  aTextFillColor = COL_TRANSPARENT;
497  bTransFill = true;
498  }
499 
500  aFont.SetFillColor( aTextFillColor );
501  }
502  }
503 
504  if ( mpMetaFile )
505  {
506  mpMetaFile->AddAction( new MetaFontAction( aFont ) );
507  // the color and alignment actions don't belong here
508  // TODO: get rid of them without breaking anything...
511  }
512 
513  if ( !maFont.IsSameInstance( aFont ) )
514  {
515  // Optimization MT/HDU: COL_TRANSPARENT means SetFont should ignore the font color,
516  // because SetTextColor() is used for this.
517  // #i28759# maTextColor might have been changed behind our back, commit then, too.
518  if( aFont.GetColor() != COL_TRANSPARENT
519  && (aFont.GetColor() != maFont.GetColor() || aFont.GetColor() != maTextColor ) )
520  {
521  maTextColor = aFont.GetColor();
522  mbInitTextColor = true;
523  if( mpMetaFile )
525  }
526  maFont = aFont;
527  mbNewFont = true;
528 
529  if( mpAlphaVDev )
530  {
531  // #i30463#
532  // Since SetFont might change the text color, apply that only
533  // selectively to alpha vdev (which normally paints opaque text
534  // with COL_BLACK)
535  if( aFont.GetColor() != COL_TRANSPARENT )
536  {
538  aFont.SetColor( COL_TRANSPARENT );
539  }
540 
541  mpAlphaVDev->SetFont( aFont );
542  }
543  }
544 }
545 
546 
548 {
550 
551  if( mbLineColor )
552  {
553  if( RasterOp::N0 == meRasterOp )
555  else if( RasterOp::N1 == meRasterOp )
557  else if( RasterOp::Invert == meRasterOp )
559  else
561  }
562  else
564 
565  mbInitLineColor = false;
566 }
567 
568 
570 {
572 
573  if( mbFillColor )
574  {
575  if( RasterOp::N0 == meRasterOp )
577  else if( RasterOp::N1 == meRasterOp )
579  else if( RasterOp::Invert == meRasterOp )
581  else
583  }
584  else
586 
587  mbInitFillColor = false;
588 }
589 
591 {
593 
594  mbNewFont = true;
595  mbInitFont = true;
596 
597  mpFontInstance.clear();
598  mpDeviceFontList.reset();
599  mpDeviceFontSizeList.reset();
600 }
601 
602 
603 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void EnableOutput(bool bEnable=true)
const Color & GetTextColor() const
Definition: outdev.hxx:1110
void SetDigitLanguage(LanguageType)
void SetFillColor(const Color &)
Definition: font/font.cxx:87
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
void SetAntialiasing(AntialiasingFlags nMode)
sal_uInt32 GetGCStackDepth() const
bool mbOutput
Definition: outdev.hxx:379
Color maTextColor
Definition: outdev.hxx:365
DrawModeFlags
Definition: outdev.hxx:200
SAL_DLLPRIVATE void SetDeviceClipRegion(const vcl::Region *pRegion)
const Color & GetTextLineColor() const
Definition: outdev.hxx:1119
DrawModeFlags mnDrawMode
Definition: outdev.hxx:355
Color maLineColor
Definition: outdev.hxx:362
const StyleSettings & GetStyleSettings() const
TextAlign GetTextAlign() const
Definition: outdev.hxx:1128
sal_uInt8 GetLuminance() const
bool IsTextLineColor() const
Definition: outdev.hxx:1120
vcl::Region maRegion
Definition: outdev.hxx:361
ComplexTextLayoutFlags mnTextLayoutMode
Definition: outdevstate.hxx:97
boost::optional< Color > mpTextFillColor
Definition: outdevstate.hxx:91
ComplexTextLayoutFlags GetLayoutMode() const
Definition: outdev.hxx:598
void SetTextFillColor()
Definition: text.cxx:697
SAL_DLLPRIVATE Color ImplDrawModeToColor(const Color &rColor) const
Definition: transparent.cxx:78
void SetLayoutMode(ComplexTextLayoutFlags nTextLayoutMode)
std::unique_ptr< ImplDeviceFontSizeList > mpDeviceFontSizeList
Definition: outdev.hxx:324
WallpaperStyle GetStyle() const
Definition: wall.cxx:218
bool ImplIsColorTransparent(Color aColor)
Definition: outdata.hxx:25
boost::optional< Color > mpTextColor
Definition: outdevstate.hxx:90
bool mbMap
Definition: outdev.hxx:376
void SetMapMode()
Definition: map.cxx:655
FontAlign GetAlignment() const
Definition: font/font.cxx:664
MapMode maMapMode
Definition: outdev.hxx:371
void SetDrawMode(DrawModeFlags nDrawMode)
boost::optional< Color > mpOverlineColor
Definition: outdevstate.hxx:93
const Color & GetOverlineColor() const
Definition: outdev.hxx:1124
Color GetTextFillColor() const
Definition: text.cxx:755
SAL_DLLPRIVATE void InitLineColor()
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
void SetBackground()
PushFlags mnFlags
Definition: outdevstate.hxx:99
RasterOp
Definition: vclenum.hxx:191
virtual void SetROPLineColor(SalROPColor nROPColor)=0
AntialiasingFlags mnAntialiasing
Definition: outdev.hxx:373
bool mbBackground
Definition: outdev.hxx:378
PushFlags
Definition: outdevstate.hxx:38
LanguageType meTextLanguage
Definition: outdevstate.hxx:98
Color maFillColor
Definition: outdev.hxx:363
void SetTextLineColor()
Definition: textline.cxx:800
boost::optional< Color > mpLineColor
Definition: outdevstate.hxx:87
std::unique_ptr< vcl::Font > mpFont
Definition: outdevstate.hxx:89
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:316
std::vector< OutDevState > maOutDevStateStack
Definition: outdev.hxx:325
bool IsTextFillColor() const
Definition: outdev.hxx:1115
virtual void SetFillColor()=0
NONE
void SetLineColor()
SAL_DLLPRIVATE void InitFillColor()
void SetRefPoint()
Definition: outdev.cxx:278
Wallpaper maBackground
Definition: outdev.hxx:369
virtual void SetLineColor()=0
ComplexTextLayoutFlags
Definition: outdevstate.hxx:66
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
std::unique_ptr< ImplDeviceFontList > mpDeviceFontList
Definition: outdev.hxx:323
std::unique_ptr< vcl::Region > mpClipRegion
Definition: outdevstate.hxx:86
bool mbInitLineColor
Definition: outdev.hxx:384
void SetFillColor()
bool mbNewFont
Definition: outdev.hxx:390
AntialiasingFlags
Definition: outdev.hxx:231
const Color & GetFontColor() const
void SetTextColor(const Color &rColor)
Definition: text.cxx:662
boost::optional< Point > mpRefPoint
Definition: outdevstate.hxx:94
TextAlign meTextAlign
Definition: outdevstate.hxx:95
vcl::Font maFont
Definition: outdev.hxx:364
bool mbLineColor
Definition: outdev.hxx:382
void SetOverlineColor()
Definition: textline.cxx:849
RasterOp meRasterOp
Definition: outdev.hxx:368
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
bool mbInitTextColor
Definition: outdev.hxx:387
const Color & GetFillColor() const
Definition: font/font.cxx:661
void ReleaseFonts()
Definition: salgdi.hxx:130
bool mbRefPoint
Definition: outdev.hxx:393
void SetColor(const Color &)
Definition: font/font.cxx:79
boost::optional< Color > mpFillColor
Definition: outdevstate.hxx:88
virtual void SetXORMode(bool bSet, bool bInvertOnly)=0
bool mbFillColor
Definition: outdev.hxx:383
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:331
ALIGN_TOP
RasterOp meRasterOp
Definition: outdevstate.hxx:96
const Color & GetColor() const
Definition: font/font.cxx:660
bool mbClipRegion
Definition: outdev.hxx:377
FuncFlags const mnFlags
unsigned char sal_uInt8
void SetFont(const vcl::Font &rNewFont)
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:539
LanguageType GetDigitLanguage() const
Definition: outdev.hxx:601
boost::optional< MapMode > mpMapMode
Definition: outdevstate.hxx:84
virtual void SetROPFillColor(SalROPColor nROPColor)=0
bool IsTransparent() const
Definition: font/font.cxx:662
void SetRasterOp(RasterOp eRasterOp)
void setAntiAliasB2DDraw(bool bNew)
Definition: salgdi.hxx:83
boost::optional< Color > mpTextLineColor
Definition: outdevstate.hxx:92
const Color & GetWindowColor() const
bool mbInitFont
Definition: outdev.hxx:386
RasterOp GetRasterOp() const
Definition: outdev.hxx:604
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
rtl::Reference< LogicalFontInstance > mpFontInstance
Definition: outdev.hxx:320
bool mbInitFillColor
Definition: outdev.hxx:385
bool IsSameInstance(const Font &) const
Definition: font/font.cxx:711
ComplexTextLayoutFlags mnTextLayoutMode
Definition: outdev.hxx:356
#define SAL_WARN(area, stream)
#define DBG_TESTSOLARMUTEX()
bool IsOverlineColor() const
Definition: outdev.hxx:1125
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
Point maRefPoint
Definition: outdev.hxx:372
virtual void ImplReleaseFonts()
void SetTextAlign(TextAlign eAlign)
Definition: text.cxx:763
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:319
bool mbMapActive
Definition: outdevstate.hxx:85
LanguageType meTextLanguage
Definition: outdev.hxx:374