Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 123, column 13
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name vclprocessor2d.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D DRAWINGLAYER_DLLIMPLEMENTATION -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/drawinglayer/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/drawinglayer/source/processor2d/vclprocessor2d.cxx

/home/maarten/src/libreoffice/core/drawinglayer/source/processor2d/vclprocessor2d.cxx

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

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
5
Calling 'Reference::set'
13
Returning; memory was released
16
Calling 'Reference::set'
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody
5.1
'pBody' is non-null
16.1
'pBody' is non-null
5.1
'pBody' is non-null
16.1
'pBody' is non-null
5.1
'pBody' is non-null
16.1
'pBody' is non-null
5.1
'pBody' is non-null
16.1
'pBody' is non-null
)
6
Taking true branch
17
Taking true branch
123 pBody->acquire();
18
Use of memory after it is freed
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld
6.1
'pOld' is non-null
6.1
'pOld' is non-null
6.1
'pOld' is non-null
6.1
'pOld' is non-null
)
7
Taking true branch
127 pOld->release();
8
Calling 'VclReferenceBase::release'
12
Returning; memory was released
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
9
Assuming the condition is true
10
Taking true branch
40 delete this;
11
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif