Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
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 vmlformatting.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 -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 OOX_DLLIMPLEMENTATION -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/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/oox/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/nss/dist/public/nss -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/nss/dist/out/include -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/oox/source/vml/vmlformatting.cxx

/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.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 <sal/config.h>
21
22#include <cstdlib>
23
24#include <oox/vml/vmlformatting.hxx>
25
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/drawing/XShape.hpp>
29#include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
30#include <com/sun/star/table/ShadowFormat.hpp>
31#include <com/sun/star/text/XTextRange.hpp>
32#include <rtl/strbuf.hxx>
33#include <sal/log.hxx>
34#include <osl/diagnose.h>
35#include <oox/drawingml/color.hxx>
36#include <oox/drawingml/drawingmltypes.hxx>
37#include <drawingml/fillproperties.hxx>
38#include <drawingml/lineproperties.hxx>
39#include <oox/drawingml/shapepropertymap.hxx>
40#include <oox/helper/attributelist.hxx>
41#include <oox/helper/graphichelper.hxx>
42#include <oox/token/properties.hxx>
43#include <oox/token/tokens.hxx>
44#include <svx/svdtrans.hxx>
45#include <comphelper/propertysequence.hxx>
46#include <vcl/virdev.hxx>
47
48namespace oox::vml {
49
50using namespace ::com::sun::star;
51using namespace ::com::sun::star::geometry;
52
53using ::oox::drawingml::Color;
54using ::oox::drawingml::FillProperties;
55using ::oox::drawingml::LineArrowProperties;
56using ::oox::drawingml::LineProperties;
57using ::oox::drawingml::ShapePropertyMap;
58using ::com::sun::star::awt::Point;
59using ::com::sun::star::drawing::PolygonFlags;
60using ::com::sun::star::drawing::PolygonFlags_NORMAL;
61using ::com::sun::star::drawing::PolygonFlags_CONTROL;
62
63namespace {
64
65bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, const OUString& rValue )
66{
67 // extract the double value and find start position of unit characters
68 rtl_math_ConversionStatus eConvStatus = rtl_math_ConversionStatus_Ok;
69 orfValue = ::rtl::math::stringToDouble( rValue, '.', '\0', &eConvStatus, &ornEndPos );
70 return eConvStatus == rtl_math_ConversionStatus_Ok;
71}
72
73} // namespace
74
75bool ConversionHelper::separatePair( OUString& orValue1, OUString& orValue2,
76 const OUString& rValue, sal_Unicode cSep )
77{
78 sal_Int32 nSepPos = rValue.indexOf( cSep );
79 if( nSepPos >= 0 )
80 {
81 orValue1 = rValue.copy( 0, nSepPos ).trim();
82 orValue2 = rValue.copy( nSepPos + 1 ).trim();
83 }
84 else
85 {
86 orValue1 = rValue.trim();
87 }
88 return !orValue1.isEmpty() && !orValue2.isEmpty();
89}
90
91bool ConversionHelper::decodeBool( const OUString& rValue )
92{
93 sal_Int32 nToken = AttributeConversion::decodeToken( rValue );
94 // anything else than 't' or 'true' is considered to be false, as specified
95 return (nToken == XML_t) || (nToken == XML_true);
96}
97
98double ConversionHelper::decodePercent( const OUString& rValue, double fDefValue )
99{
100 if( rValue.isEmpty() )
101 return fDefValue;
102
103 double fValue = 0.0;
104 sal_Int32 nEndPos = 0;
105 if( !lclExtractDouble( fValue, nEndPos, rValue ) )
106 return fDefValue;
107
108 if( nEndPos == rValue.getLength() )
109 return fValue;
110
111 if( (nEndPos + 1 == rValue.getLength()) && (rValue[ nEndPos ] == '%') )
112 return fValue / 100.0;
113
114 if( (nEndPos + 1 == rValue.getLength()) && (rValue[ nEndPos ] == 'f') )
115 return fValue / 65536.0;
116
117 OSL_FAIL( "ConversionHelper::decodePercent - unknown measure unit" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "117" ": "), "%s", "ConversionHelper::decodePercent - unknown measure unit"
); } } while (false)
;
118 return fDefValue;
119}
120
121sal_Int32 ConversionHelper::decodeRotation( const OUString& rValue )
122{
123 if( rValue.isEmpty() )
124 return 0;
125
126 double fValue = 0.0;
127 double fRotation = 0.0;
128 sal_Int32 nEndPos = 0;
129 if( !lclExtractDouble(fValue, nEndPos, rValue) )
130 return 0;
131
132 if( nEndPos == rValue.getLength() )
133 fRotation = fValue;
134 else if( (nEndPos + 2 == rValue.getLength()) && (rValue[nEndPos] == 'f') && (rValue[nEndPos+1] == 'd') )
135 fRotation = fValue / 65536.0;
136 else
137 {
138 OSL_FAIL("ConversionHelper::decodeRotation - unknown measure unit")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "138" ": "), "%s", "ConversionHelper::decodeRotation - unknown measure unit"
); } } while (false)
;
139 return 0;
140 }
141
142 return NormAngle36000(fRotation * -100);
143}
144
145sal_Int64 ConversionHelper::decodeMeasureToEmu( const GraphicHelper& rGraphicHelper,
146 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
147{
148 // default for missing values is 0
149 if( rValue.isEmpty() )
150 return 0;
151
152 // TODO: according to spec, value may contain "auto"
153 if ( rValue == "auto" )
154 {
155 OSL_FAIL( "ConversionHelper::decodeMeasureToEmu - special value 'auto' must be handled by caller" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "155" ": "), "%s", "ConversionHelper::decodeMeasureToEmu - special value 'auto' must be handled by caller"
); } } while (false)
;
156 return nRefValue;
157 }
158
159 // extract the double value and find start position of unit characters
160 double fValue = 0.0;
161 sal_Int32 nEndPos = 0;
162 if( !lclExtractDouble( fValue, nEndPos, rValue ) || (fValue == 0.0) )
163 return 0;
164
165 // process trailing unit, convert to EMU
166 OUString aUnit;
167 if( (0 < nEndPos) && (nEndPos < rValue.getLength()) )
168 aUnit = rValue.copy( nEndPos );
169 else if( bDefaultAsPixel )
170 aUnit = "px";
171 // else default is EMU
172
173 if( aUnit.getLength() == 2 )
174 {
175 sal_Unicode cChar1 = aUnit[ 0 ];
176 sal_Unicode cChar2 = aUnit[ 1 ];
177 if( (cChar1 == 'i') && (cChar2 == 'n') ) // 1 inch = 914,400 EMU
178 fValue *= 914400.0;
179 else if( (cChar1 == 'c') && (cChar2 == 'm') ) // 1 cm = 360,000 EMU
180 fValue *= 360000.0;
181 else if( (cChar1 == 'm') && (cChar2 == 'm') ) // 1 mm = 36,000 EMU
182 fValue *= 36000.0;
183 else if( (cChar1 == 'p') && (cChar2 == 't') ) // 1 point = 1/72 inch = 12,700 EMU
184 fValue *= 12700.0;
185 else if( (cChar1 == 'p') && (cChar2 == 'c') ) // 1 pica = 1/6 inch = 152,400 EMU
186 fValue *= 152400.0;
187 else if( (cChar1 == 'p') && (cChar2 == 'x') ) // 1 pixel, dependent on output device
188 fValue = static_cast< double >( ::oox::drawingml::convertHmmToEmu(
189 bPixelX ?
190 rGraphicHelper.convertScreenPixelXToHmm( fValue ) :
191 rGraphicHelper.convertScreenPixelYToHmm( fValue ) ) );
192 }
193 else if( (aUnit.getLength() == 1) && (aUnit[ 0 ] == '%') )
194 {
195 fValue *= nRefValue / 100.0;
196 }
197 else if( bDefaultAsPixel || !aUnit.isEmpty() ) // default as EMU and no unit -> do nothing
198 {
199 OSL_FAIL( "ConversionHelper::decodeMeasureToEmu - unknown measure unit" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "199" ": "), "%s", "ConversionHelper::decodeMeasureToEmu - unknown measure unit"
); } } while (false)
;
200 fValue = nRefValue;
201 }
202 return static_cast< sal_Int64 >( fValue + 0.5 );
203}
204
205sal_Int32 ConversionHelper::decodeMeasureToHmm( const GraphicHelper& rGraphicHelper,
206 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
207{
208 return ::oox::drawingml::convertEmuToHmm( decodeMeasureToEmu( rGraphicHelper, rValue, nRefValue, bPixelX, bDefaultAsPixel ) );
209}
210
211Color ConversionHelper::decodeColor( const GraphicHelper& rGraphicHelper,
212 const OptValue< OUString >& roVmlColor, const OptValue< double >& roVmlOpacity,
213 ::Color nDefaultRgb, ::Color nPrimaryRgb )
214{
215 Color aDmlColor;
216
217 // convert opacity
218 const sal_Int32 DML_FULL_OPAQUE = ::oox::drawingml::MAX_PERCENT;
219 double fOpacity = roVmlOpacity.get( 1.0 );
220 sal_Int32 nOpacity = getLimitedValue< sal_Int32, double >( fOpacity * DML_FULL_OPAQUE, 0, DML_FULL_OPAQUE );
221 if( nOpacity < DML_FULL_OPAQUE )
222 aDmlColor.addTransformation( XML_alpha, nOpacity );
223
224 // color attribute not present - set passed default color
225 if( !roVmlColor.has() )
226 {
227 aDmlColor.setSrgbClr( nDefaultRgb );
228 return aDmlColor;
229 }
230
231 // separate leading color name or RGB value from following palette index
232 OUString aColorName, aColorIndex;
233 separatePair( aColorName, aColorIndex, roVmlColor.get(), ' ' );
234
235 // RGB colors in the format '#RRGGBB'
236 if( (aColorName.getLength() == 7) && (aColorName[ 0 ] == '#') )
237 {
238 aDmlColor.setSrgbClr( aColorName.copy( 1 ).toUInt32( 16 ) );
239 return aDmlColor;
240 }
241
242 // RGB colors in the format '#RGB'
243 if( (aColorName.getLength() == 4) && (aColorName[ 0 ] == '#') )
244 {
245 sal_Int32 nR = aColorName.copy( 1, 1 ).toUInt32( 16 ) * 0x11;
246 sal_Int32 nG = aColorName.copy( 2, 1 ).toUInt32( 16 ) * 0x11;
247 sal_Int32 nB = aColorName.copy( 3, 1 ).toUInt32( 16 ) * 0x11;
248 aDmlColor.setSrgbClr( (nR << 16) | (nG << 8) | nB );
249 return aDmlColor;
250 }
251
252 /* Predefined color names or system color names (resolve to RGB to detect
253 valid color name). */
254 sal_Int32 nColorToken = AttributeConversion::decodeToken( aColorName );
255 ::Color nRgbValue = Color::getVmlPresetColor( nColorToken, API_RGB_TRANSPARENT );
256 if( nRgbValue == API_RGB_TRANSPARENT )
257 nRgbValue = rGraphicHelper.getSystemColor( nColorToken );
258 if( nRgbValue != API_RGB_TRANSPARENT )
259 {
260 aDmlColor.setSrgbClr( nRgbValue );
261 return aDmlColor;
262 }
263
264 // try palette colors enclosed in brackets
265 if( (aColorIndex.getLength() >= 3) && (aColorIndex[ 0 ] == '[') && (aColorIndex[ aColorIndex.getLength() - 1 ] == ']') )
266 {
267 aDmlColor.setPaletteClr( aColorIndex.copy( 1, aColorIndex.getLength() - 2 ).toInt32() );
268 return aDmlColor;
269 }
270
271 // try fill gradient modificator 'fill <modifier>(<amount>)'
272 if( (nPrimaryRgb != API_RGB_TRANSPARENT) && (nColorToken == XML_fill) )
273 {
274 sal_Int32 nOpenParen = aColorIndex.indexOf( '(' );
275 sal_Int32 nCloseParen = aColorIndex.indexOf( ')' );
276 if( (2 <= nOpenParen) && (nOpenParen + 1 < nCloseParen) && (nCloseParen + 1 == aColorIndex.getLength()) )
277 {
278 sal_Int32 nModToken = XML_TOKEN_INVALID;
279 switch( AttributeConversion::decodeToken( aColorIndex.copy( 0, nOpenParen ) ) )
280 {
281 case XML_darken: nModToken = XML_shade;break;
282 case XML_lighten: nModToken = XML_tint;
283 }
284 sal_Int32 nValue = aColorIndex.copy( nOpenParen + 1, nCloseParen - nOpenParen - 1 ).toInt32();
285 if( (nModToken != XML_TOKEN_INVALID) && (0 <= nValue) && (nValue < 255) )
286 {
287 /* Simulate this modifier color by a color with related transformation.
288 The modifier amount has to be converted from the range [0;255] to
289 percentage [0;100000] used by DrawingML. */
290 aDmlColor.setSrgbClr( nPrimaryRgb );
291 aDmlColor.addTransformation( nModToken, static_cast< sal_Int32 >( nValue * ::oox::drawingml::MAX_PERCENT / 255 ) );
292 return aDmlColor;
293 }
294 }
295 }
296
297 OSL_FAIL( OStringBuffer( "lclGetColor - invalid VML color name '" ).do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "298" ": "), "%s", OStringBuffer( "lclGetColor - invalid VML color name '"
). append( OUStringToOString( roVmlColor.get(), (((rtl_TextEncoding
) 11)) ) ).append( '\'' ).getStr()); } } while (false)
298 append( OUStringToOString( roVmlColor.get(), RTL_TEXTENCODING_ASCII_US ) ).append( '\'' ).getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "298" ": "), "%s", OStringBuffer( "lclGetColor - invalid VML color name '"
). append( OUStringToOString( roVmlColor.get(), (((rtl_TextEncoding
) 11)) ) ).append( '\'' ).getStr()); } } while (false)
;
299 aDmlColor.setSrgbClr( nDefaultRgb );
300 return aDmlColor;
301}
302
303void ConversionHelper::decodeVmlPath( ::std::vector< ::std::vector< Point > >& rPointLists, ::std::vector< ::std::vector< PolygonFlags > >& rFlagLists, const OUString& rPath )
304{
305 ::std::vector< sal_Int32 > aCoordList;
306 Point aCurrentPoint;
307 sal_Int32 nTokenStart = 0;
308 sal_Int32 nTokenLen = 0;
309 sal_Int32 nParamCount = 0;
310 bool bCommand = false;
311 enum VML_State { START, MOVE_REL, MOVE_ABS, BEZIER_REL, BEZIER_ABS,
312 LINE_REL, LINE_ABS, CLOSE, END, UNSUPPORTED };
313 VML_State state = START;
314
315 rPointLists.emplace_back( );
316 rFlagLists.emplace_back( );
317
318 for ( sal_Int32 i = 0; i < rPath.getLength(); i++ )
319 {
320 // Keep track of current integer token
321 if ( ( rPath[ i ] >= '0' && rPath[ i ] <= '9' ) || rPath[ i ] == '-' )
322 nTokenLen++;
323 else if ( rPath[ i ] != ' ' )
324 {
325 // Store coordinate from current token
326 if ( state != START && state != UNSUPPORTED )
327 {
328 if ( nTokenLen > 0 )
329 aCoordList.push_back( rPath.copy( nTokenStart, nTokenLen ).toInt32() );
330 else
331 aCoordList.push_back( 0 );
332 nTokenLen = 0;
333 }
334
335 if (rPath[ i ] == ',' )
336 {
337 nParamCount--;
338 }
339
340 // Upon finding the next command code, deal with stored
341 // coordinates for previous command and reset parameters counter if needed.
342 // See http://www.w3.org/TR/NOTE-VML#_Toc416858382 for params count reference
343 if ( rPath[ i ] != ',' || nParamCount == 0 )
344 {
345 switch ( state )
346 {
347 case MOVE_REL:
348 aCoordList.resize(2, 0); // 2* params -> param count reset
349 if ( !rPointLists.empty() && !rPointLists.back().empty() )
350 {
351 rPointLists.emplace_back( );
352 rFlagLists.emplace_back( );
353 }
354 rPointLists.back().emplace_back( aCoordList[ 0 ], aCoordList[ 1 ] );
355 rFlagLists.back().push_back( PolygonFlags_NORMAL );
356 aCurrentPoint = rPointLists.back().back();
357 nParamCount = 2;
358 break;
359
360 case MOVE_ABS:
361 aCoordList.resize(2, 0); // 2 params -> no param count reset
362 if ( !rPointLists.empty() && !rPointLists.back().empty() )
363 {
364 rPointLists.emplace_back( );
365 rFlagLists.emplace_back( );
366 }
367 rPointLists.back().emplace_back( (aCoordList[ 0 ]), aCoordList[ 1 ] );
368 rFlagLists.back().push_back( PolygonFlags_NORMAL );
369 aCurrentPoint = rPointLists.back().back();
370 break;
371
372 case BEZIER_REL:
373 aCoordList.resize(6, 0); // 6* params -> param count reset
374 rPointLists.back().emplace_back( aCurrentPoint.X + aCoordList[ 0 ],
375 aCurrentPoint.Y + aCoordList[ 1 ] );
376 rPointLists.back().emplace_back( aCurrentPoint.X + aCoordList[ 2 ],
377 aCurrentPoint.Y + aCoordList[ 3 ] );
378 rPointLists.back().emplace_back( aCurrentPoint.X + aCoordList[ 4 ],
379 aCurrentPoint.Y + aCoordList[ 5 ] );
380 rFlagLists.back().push_back( PolygonFlags_CONTROL );
381 rFlagLists.back().push_back( PolygonFlags_CONTROL );
382 rFlagLists.back().push_back( PolygonFlags_NORMAL );
383 aCurrentPoint = rPointLists.back().back();
384 nParamCount = 6;
385 break;
386
387 case BEZIER_ABS:
388 aCoordList.resize(6, 0); // 6* params -> param count reset
389 rPointLists.back().emplace_back( aCoordList[ 0 ], aCoordList[ 1 ] );
390 rPointLists.back().emplace_back( aCoordList[ 2 ], aCoordList[ 3 ] );
391 rPointLists.back().emplace_back( aCoordList[ 4 ], aCoordList[ 5 ] );
392 rFlagLists.back().push_back( PolygonFlags_CONTROL );
393 rFlagLists.back().push_back( PolygonFlags_CONTROL );
394 rFlagLists.back().push_back( PolygonFlags_NORMAL );
395 aCurrentPoint = rPointLists.back().back();
396 nParamCount = 6;
397 break;
398
399 case LINE_REL:
400 aCoordList.resize(2, 0); // 2* params -> param count reset
401 rPointLists.back().emplace_back( aCurrentPoint.X + aCoordList[ 0 ],
402 aCurrentPoint.Y + aCoordList[ 1 ] );
403 rFlagLists.back().push_back( PolygonFlags_NORMAL );
404 aCurrentPoint = rPointLists.back().back();
405 nParamCount = 2;
406 break;
407
408 case LINE_ABS:
409 aCoordList.resize(2, 0); // 2* params -> param count reset
410 rPointLists.back().emplace_back( aCoordList[ 0 ], (aCoordList.size() > 1 ? aCoordList[ 1 ] : 0) );
411 rFlagLists.back().push_back( PolygonFlags_NORMAL );
412 aCurrentPoint = rPointLists.back().back();
413 nParamCount = 2;
414 break;
415
416 case CLOSE: // 0 param
417 SAL_WARN_IF(rPointLists.back().empty() || rFlagLists.back().empty(), "oox", "empty pointlists at close")do { if (true && (rPointLists.back().empty() || rFlagLists
.back().empty())) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "oox")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "empty pointlists at close") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("oox"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "417" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "empty pointlists at close"), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"empty pointlists at close"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("oox"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "417" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "empty pointlists at close") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("oox"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "417" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "empty pointlists at close"), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"empty pointlists at close"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("oox"), ("/home/maarten/src/libreoffice/core/oox/source/vml/vmlformatting.cxx"
":" "417" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
418 if (!rPointLists.back().empty() && !rFlagLists.back().empty())
419 {
420 rPointLists.back().push_back( rPointLists.back()[ 0 ] );
421 rFlagLists.back().push_back( rFlagLists.back()[ 0 ] );
422 aCurrentPoint = rPointLists.back().back();
423 }
424 break;
425
426 case END: // 0 param
427 rPointLists.emplace_back( );
428 rFlagLists.emplace_back( );
429 break;
430
431 case START:
432 case UNSUPPORTED:
433 break;
434 }
435
436 aCoordList.clear();
437 }
438
439 // Allow two-char commands to peek ahead to the next character
440 sal_Unicode nextChar = '\0';
441 if (i+1 < rPath.getLength())
442 nextChar = rPath[i+1];
443
444 // Move to relevant state upon finding a command
445 bCommand = true;
446 switch ( rPath[ i ] )
447 {
448 // Single-character commands
449 case 't': // rmoveto
450 state = MOVE_REL; nParamCount = 2; break;
451 case 'm': // moveto
452 state = MOVE_ABS; nParamCount = 2; break;
453 case 'v': // rcurveto
454 state = BEZIER_REL; nParamCount = 6; break;
455 case 'c': // curveto
456 state = BEZIER_ABS; nParamCount = 6; break;
457 case 'r': // rlineto
458 state = LINE_REL; nParamCount = 2; break;
459 case 'l': // lineto
460 state = LINE_ABS; nParamCount = 2; break;
461 case 'x': // close
462 state = CLOSE; break;
463 case 'e': // end
464 state = END; break;
465
466 // Two-character commands
467 case 'n':
468 {
469 switch ( nextChar )
470 {
471 case 'f': // nf - nofill
472 case 's': // ns - nostroke
473 state = UNSUPPORTED; i++; break;
474 }
475 break;
476 }
477 case 'a': // Elliptical curves
478 {
479 switch ( nextChar )
480 {
481 case 'e': // ae - angleellipseto
482 case 'l': // al - angleellipse
483 state = UNSUPPORTED; i++; break;
484 case 't': // at - arcto
485 case 'r': // ar - arc
486 state = UNSUPPORTED; i++; break;
487 }
488 break;
489 }
490 case 'w': // Clockwise elliptical arcs
491 {
492 switch ( nextChar )
493 {
494 case 'a': // wa - clockwisearcto
495 case 'r': // wr - clockwisearc
496 state = UNSUPPORTED; i++; break;
497 }
498 break;
499 }
500 case 'q':
501 {
502 switch ( nextChar )
503 {
504 case 'x': // qx - ellipticalquadrantx
505 case 'y': // qy - ellipticalquadranty
506 state = UNSUPPORTED; i++; break;
507 case 'b': // qb - quadraticbezier
508 state = UNSUPPORTED; i++; break;
509 }
510 break;
511 }
512 case 'h': // behaviour extensions
513 {
514 switch ( nextChar )
515 {
516 case 'a': // ha - AutoLine
517 case 'b': // hb - AutoCurve
518 case 'c': // hc - CornerLine
519 case 'd': // hd - CornerCurve
520 case 'e': // he - SmoothLine
521 case 'f': // hf - SmoothCurve
522 case 'g': // hg - SymmetricLine
523 case 'h': // hh - SymmetricCurve
524 case 'i': // hi - Freeform
525 state = UNSUPPORTED; i++; break;
526 }
527 break;
528 }
529 default:
530 bCommand = false;
531 break;
532 }
533
534 if (bCommand) nTokenLen = 0;
535 nTokenStart = i+1;
536 }
537 }
538}
539
540namespace {
541
542sal_Int64 lclGetEmu( const GraphicHelper& rGraphicHelper, const OptValue< OUString >& roValue, sal_Int64 nDefValue )
543{
544 return roValue.has() ? ConversionHelper::decodeMeasureToEmu( rGraphicHelper, roValue.get(), 0, false, false ) : nDefValue;
545}
546
547void lclGetDmlLineDash( OptValue< sal_Int32 >& oroPresetDash, LineProperties::DashStopVector& orCustomDash, const OptValue< OUString >& roDashStyle )
548{
549 if( !roDashStyle.has() )
550 return;
551
552 const OUString& rDashStyle = roDashStyle.get();
553 switch( AttributeConversion::decodeToken( rDashStyle ) )
554 {
555 case XML_solid: oroPresetDash = XML_solid; return;
556 case XML_shortdot: oroPresetDash = XML_sysDot; return;
557 case XML_shortdash: oroPresetDash = XML_sysDash; return;
558 case XML_shortdashdot: oroPresetDash = XML_sysDashDot; return;
559 case XML_shortdashdotdot: oroPresetDash = XML_sysDashDotDot; return;
560 case XML_dot: oroPresetDash = XML_dot; return;
561 case XML_dash: oroPresetDash = XML_dash; return;
562 case XML_dashdot: oroPresetDash = XML_dashDot; return;
563 case XML_longdash: oroPresetDash = XML_lgDash; return;
564 case XML_longdashdot: oroPresetDash = XML_lgDashDot; return;
565 case XML_longdashdotdot: oroPresetDash = XML_lgDashDotDot; return;
566
567 // try to convert user-defined dash style
568 default:
569 {
570 ::std::vector< sal_Int32 > aValues;
571 sal_Int32 nIndex = 0;
572 while( nIndex >= 0 )
573 aValues.push_back( rDashStyle.getToken( 0, ' ', nIndex ).toInt32() );
574 size_t nPairs = aValues.size() / 2; // ignore last value if size is odd
575 for( size_t nPairIdx = 0; nPairIdx < nPairs; ++nPairIdx )
576 orCustomDash.emplace_back( aValues[ 2 * nPairIdx ], aValues[ 2 * nPairIdx + 1 ] );
577 }
578 }
579}
580
581sal_Int32 lclGetDmlArrowType( const OptValue< sal_Int32 >& roArrowType )
582{
583 if( roArrowType.has() ) switch( roArrowType.get() )
584 {
585 case XML_none: return XML_none;
586 case XML_block: return XML_triangle;
587 case XML_classic: return XML_stealth;
588 case XML_diamond: return XML_diamond;
589 case XML_oval: return XML_oval;
590 case XML_open: return XML_arrow;
591 }
592 return XML_none;
593}
594
595sal_Int32 lclGetDmlArrowWidth( const OptValue< sal_Int32 >& roArrowWidth )
596{
597 if( roArrowWidth.has() ) switch( roArrowWidth.get() )
598 {
599 case XML_narrow: return XML_sm;
600 case XML_medium: return XML_med;
601 case XML_wide: return XML_lg;
602 }
603 return XML_med;
604}
605
606sal_Int32 lclGetDmlArrowLength( const OptValue< sal_Int32 >& roArrowLength )
607{
608 if( roArrowLength.has() ) switch( roArrowLength.get() )
609 {
610 case XML_short: return XML_sm;
611 case XML_medium: return XML_med;
612 case XML_long: return XML_lg;
613 }
614 return XML_med;
615}
616
617void lclConvertArrow( LineArrowProperties& orArrowProp, const StrokeArrowModel& rStrokeArrow )
618{
619 orArrowProp.moArrowType = lclGetDmlArrowType( rStrokeArrow.moArrowType );
620 orArrowProp.moArrowWidth = lclGetDmlArrowWidth( rStrokeArrow.moArrowWidth );
621 orArrowProp.moArrowLength = lclGetDmlArrowLength( rStrokeArrow.moArrowLength );
622}
623
624sal_Int32 lclGetDmlLineCompound( const OptValue< sal_Int32 >& roLineStyle )
625{
626 if( roLineStyle.has() ) switch( roLineStyle.get() )
627 {
628 case XML_single: return XML_sng;
629 case XML_thinThin: return XML_dbl;
630 case XML_thinThick: return XML_thinThick;
631 case XML_thickThin: return XML_thickThin;
632 case XML_thickBetweenThin: return XML_tri;
633 }
634 return XML_sng;
635}
636
637sal_Int32 lclGetDmlLineCap( const OptValue< sal_Int32 >& roEndCap )
638{
639 if( roEndCap.has() ) switch( roEndCap.get() )
640 {
641 case XML_flat: return XML_flat;
642 case XML_square: return XML_sq;
643 case XML_round: return XML_rnd;
644 }
645 return XML_flat; // different defaults in VML (flat) and DrawingML (square)
646}
647
648sal_Int32 lclGetDmlLineJoint( const OptValue< sal_Int32 >& roJoinStyle )
649{
650 if( roJoinStyle.has() ) switch( roJoinStyle.get() )
651 {
652 case XML_round: return XML_round;
653 case XML_bevel: return XML_bevel;
654 case XML_miter: return XML_miter;
655 }
656 return XML_round;
657}
658
659} // namespace
660
661void StrokeArrowModel::assignUsed( const StrokeArrowModel& rSource )
662{
663 moArrowType.assignIfUsed( rSource.moArrowType );
664 moArrowWidth.assignIfUsed( rSource.moArrowWidth );
665 moArrowLength.assignIfUsed( rSource.moArrowLength );
666}
667
668void StrokeModel::assignUsed( const StrokeModel& rSource )
669{
670 moStroked.assignIfUsed( rSource.moStroked );
671 maStartArrow.assignUsed( rSource.maStartArrow );
672 maEndArrow.assignUsed( rSource.maEndArrow );
673 moColor.assignIfUsed( rSource.moColor );
674 moOpacity.assignIfUsed( rSource.moOpacity );
675 moWeight.assignIfUsed( rSource.moWeight );
676 moDashStyle.assignIfUsed( rSource.moDashStyle );
677 moLineStyle.assignIfUsed( rSource.moLineStyle );
678 moEndCap.assignIfUsed( rSource.moEndCap );
679 moJoinStyle.assignIfUsed( rSource.moJoinStyle );
680}
681
682void StrokeModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const
683{
684 /* Convert VML line formatting to DrawingML line formatting and let the
685 DrawingML code do the hard work. */
686 LineProperties aLineProps;
687
688 if( moStroked.get( true ) )
689 {
690 aLineProps.maLineFill.moFillType = XML_solidFill;
691 lclConvertArrow( aLineProps.maStartArrow, maStartArrow );
692 lclConvertArrow( aLineProps.maEndArrow, maEndArrow );
693 aLineProps.maLineFill.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_BLACK );
694 aLineProps.moLineWidth = getLimitedValue< sal_Int32, sal_Int64 >( lclGetEmu( rGraphicHelper, moWeight, 1 ), 0, SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) );
695 lclGetDmlLineDash( aLineProps.moPresetDash, aLineProps.maCustomDash, moDashStyle );
696 aLineProps.moLineCompound = lclGetDmlLineCompound( moLineStyle );
697 aLineProps.moLineCap = lclGetDmlLineCap( moEndCap );
698 aLineProps.moLineJoint = lclGetDmlLineJoint( moJoinStyle );
699 }
700 else
701 {
702 aLineProps.maLineFill.moFillType = XML_noFill;
703 }
704
705 aLineProps.pushToPropMap( rPropMap, rGraphicHelper );
706}
707
708void FillModel::assignUsed( const FillModel& rSource )
709{
710 moFilled.assignIfUsed( rSource.moFilled );
711 moColor.assignIfUsed( rSource.moColor );
712 moOpacity.assignIfUsed( rSource.moOpacity );
713 moColor2.assignIfUsed( rSource.moColor2 );
714 moOpacity2.assignIfUsed( rSource.moOpacity2 );
715 moType.assignIfUsed( rSource.moType );
716 moAngle.assignIfUsed( rSource.moAngle );
717 moFocus.assignIfUsed( rSource.moFocus );
718 moFocusPos.assignIfUsed( rSource.moFocusPos );
719 moFocusSize.assignIfUsed( rSource.moFocusSize );
720 moBitmapPath.assignIfUsed( rSource.moBitmapPath );
721 moRotate.assignIfUsed( rSource.moRotate );
722}
723
724static void lcl_setGradientStop( std::multimap< double, Color >& rMap, const double fKey, const Color& rValue ) {
725 auto aElement = rMap.find( fKey );
726
727 if (aElement != rMap.end())
728 aElement->second = rValue;
729 else
730 rMap.emplace( fKey, rValue );
731}
732
733void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const
734{
735 /* Convert VML fill formatting to DrawingML fill formatting and let the
736 DrawingML code do the hard work. */
737 FillProperties aFillProps;
738
739 if( moFilled.get( true ) )
740 {
741 sal_Int32 nFillType = moType.get( XML_solid );
742 switch( nFillType )
743 {
744 case XML_gradient:
745 case XML_gradientRadial:
746 {
747 aFillProps.moFillType = XML_gradFill;
748 aFillProps.maGradientProps.moRotateWithShape = moRotate.get( false );
749 double fFocus = moFocus.get( 0.0 );
750
751 // prepare colors
752 Color aColor1 = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE );
753 Color aColor2 = ConversionHelper::decodeColor( rGraphicHelper, moColor2, moOpacity2, API_RGB_WHITE, aColor1.getColor( rGraphicHelper ) );
754
755 // type XML_gradient is linear or axial gradient
756 if( nFillType == XML_gradient )
757 {
758 // normalize angle to range [0;360) degrees
759 sal_Int32 nVmlAngle = getIntervalValue< sal_Int32, sal_Int32 >( moAngle.get( 0 ), 0, 360 );
760
761 // focus of -50% or 50% is axial gradient
762 if( ((-0.75 <= fFocus) && (fFocus <= -0.25)) || ((0.25 <= fFocus) && (fFocus <= 0.75)) )
763 {
764 /* According to spec, focus of 50% is outer-to-inner,
765 and -50% is inner-to-outer (color to color2).
766 BUT: For angles >= 180 deg., the behaviour is
767 reversed... that's not spec'ed of course. So,
768 [0;180) deg. and 50%, or [180;360) deg. and -50% is
769 outer-to-inner in fact. */
770 bool bOuterToInner = (fFocus > 0.0) == (nVmlAngle < 180);
771 // simulate axial gradient by 3-step DrawingML gradient
772 const Color& rOuterColor = bOuterToInner ? aColor1 : aColor2;
773 const Color& rInnerColor = bOuterToInner ? aColor2 : aColor1;
774
775 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, rOuterColor);
776 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, rOuterColor);
777 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.5, rInnerColor );
778 }
779 else // focus of -100%, 0%, and 100% is linear gradient
780 {
781 /* According to spec, focus of -100% or 100% swaps the
782 start and stop colors, effectively reversing the
783 gradient. BUT: For angles >= 180 deg., the
784 behaviour is reversed. This means that in this case
785 a focus of 0% swaps the gradient. */
786 if( fFocus < -0.5 || fFocus > 0.5 )
787 nVmlAngle = (nVmlAngle + 180) % 360;
788 // set the start and stop colors
789 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, aColor1 );
790 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, aColor2 );
791 }
792
793 // VML counts counterclockwise from bottom, DrawingML clockwise from left
794 sal_Int32 nDmlAngle = (630 - nVmlAngle) % 360;
795 aFillProps.maGradientProps.moShadeAngle = nDmlAngle * ::oox::drawingml::PER_DEGREE;
796 }
797 else // XML_gradientRadial is rectangular gradient
798 {
799 aFillProps.maGradientProps.moGradientPath = XML_rect;
800 // convert VML focus position and size to DrawingML fill-to-rect
801 DoublePair aFocusPos = moFocusPos.get( DoublePair( 0.0, 0.0 ) );
802 DoublePair aFocusSize = moFocusSize.get( DoublePair( 0.0, 0.0 ) );
803 double fLeft = getLimitedValue< double, double >( aFocusPos.first, 0.0, 1.0 );
804 double fTop = getLimitedValue< double, double >( aFocusPos.second, 0.0, 1.0 );
805 double fRight = getLimitedValue< double, double >( fLeft + aFocusSize.first, fLeft, 1.0 );
806 double fBottom = getLimitedValue< double, double >( fTop + aFocusSize.second, fTop, 1.0 );
807 aFillProps.maGradientProps.moFillToRect = IntegerRectangle2D(
808 static_cast< sal_Int32 >( fLeft * ::oox::drawingml::MAX_PERCENT ),
809 static_cast< sal_Int32 >( fTop * ::oox::drawingml::MAX_PERCENT ),
810 static_cast< sal_Int32 >( (1.0 - fRight) * ::oox::drawingml::MAX_PERCENT ),
811 static_cast< sal_Int32 >( (1.0 - fBottom) * ::oox::drawingml::MAX_PERCENT ) );
812
813 // set the start and stop colors (focus of 0% means outer-to-inner)
814 bool bOuterToInner = (-0.5 <= fFocus) && (fFocus <= 0.5);
815 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, bOuterToInner ? aColor2 : aColor1 );
816 lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, bOuterToInner ? aColor1 : aColor2 );
817 }
818 }
819 break;
820
821 case XML_pattern:
822 case XML_tile:
823 case XML_frame:
824 {
825 if( moBitmapPath.has() && !moBitmapPath.get().isEmpty() )
826 {
827 aFillProps.maBlipProps.mxFillGraphic = rGraphicHelper.importEmbeddedGraphic(moBitmapPath.get());
828 if (aFillProps.maBlipProps.mxFillGraphic.is())
829 {
830 aFillProps.moFillType = XML_blipFill;
831 aFillProps.maBlipProps.moBitmapMode = (nFillType == XML_frame) ? XML_stretch : XML_tile;
832 break; // do not break if bitmap is missing, but run to XML_solid instead
833 }
834 }
835 }
836 [[fallthrough]]; // to XML_solid in case of missing bitmap path intended!
837
838 case XML_solid:
839 default:
840 {
841 aFillProps.moFillType = XML_solidFill;
842 // fill color (default is white)
843 aFillProps.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE );
844 }
845 }
846 }
847 else
848 {
849 aFillProps.moFillType = XML_noFill;
850 }
851
852 aFillProps.pushToPropMap( rPropMap, rGraphicHelper );
853}
854
855ShadowModel::ShadowModel()
856 : mbHasShadow(false)
857{
858}
859
860void ShadowModel::pushToPropMap(ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper) const
861{
862 if (!mbHasShadow || (moShadowOn.has() && !moShadowOn.get()))
863 return;
864
865 drawingml::Color aColor = ConversionHelper::decodeColor(rGraphicHelper, moColor, moOpacity, API_RGB_GRAY);
866 // nOffset* is in mm100, default value is 35 twips, see DffPropertyReader::ApplyAttributes() in msfilter.
867 sal_Int32 nOffsetX = 62, nOffsetY = 62;
868 if (moOffset.has())
869 {
870 OUString aOffsetX, aOffsetY;
871 ConversionHelper::separatePair(aOffsetX, aOffsetY, moOffset.get(), ',');
872 if (!aOffsetX.isEmpty())
873 nOffsetX = ConversionHelper::decodeMeasureToHmm(rGraphicHelper, aOffsetX, 0, false, false );
874 if (!aOffsetY.isEmpty())
875 nOffsetY = ConversionHelper::decodeMeasureToHmm(rGraphicHelper, aOffsetY, 0, false, false );
876 }
877
878 table::ShadowFormat aFormat;
879 aFormat.Color = sal_Int32(aColor.getColor(rGraphicHelper));
880 aFormat.Location = nOffsetX < 0
881 ? nOffsetY < 0 ? table::ShadowLocation_TOP_LEFT : table::ShadowLocation_BOTTOM_LEFT
882 : nOffsetY < 0 ? table::ShadowLocation_TOP_RIGHT : table::ShadowLocation_BOTTOM_RIGHT;
883 // The width of the shadow is the average of the x and y values, see SwWW8ImplReader::MatchSdrItemsIntoFlySet().
884 aFormat.ShadowWidth = ((std::abs(nOffsetX) + std::abs(nOffsetY)) / 2);
885 rPropMap.setProperty(PROP_ShadowFormat, aFormat);
886}
887
888TextpathModel::TextpathModel()
889{
890}
891
892static beans::PropertyValue lcl_createTextpathProps()
893{
894 uno::Sequence<beans::PropertyValue> aTextpathPropSeq( comphelper::InitPropertySequence({
895 { "TextPath", uno::Any(true) },
896 { "TextPathMode", uno::Any(drawing::EnhancedCustomShapeTextPathMode_SHAPE) },
897 { "ScaleX", uno::Any(false) },
898 { "SameLetterHeights", uno::Any(false) }
899 }));
900
901 beans::PropertyValue aRet;
902 aRet.Name = "TextPath";
903 aRet.Value <<= aTextpathPropSeq;
904 return aRet;
905}
906
907void TextpathModel::pushToPropMap(ShapePropertyMap& rPropMap, const uno::Reference<drawing::XShape>& xShape, const GraphicHelper& rGraphicHelper) const
908{
909 OUString sFont = "";
910
911 if (moString.has())
1
Assuming the condition is false
2
Taking false branch
912 {
913 uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY);
914 xTextRange->setString(moString.get());
915
916 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
917 uno::Sequence<beans::PropertyValue> aGeomPropSeq = xPropertySet->getPropertyValue("CustomShapeGeometry").get< uno::Sequence<beans::PropertyValue> >();
918 bool bFound = false;
919 for (beans::PropertyValue& rProp : aGeomPropSeq)
920 {
921 if (rProp.Name == "TextPath")
922 {
923 bFound = true;
924 rProp = lcl_createTextpathProps();
925 }
926 }
927 if (!bFound)
928 {
929 sal_Int32 nSize = aGeomPropSeq.getLength();
930 aGeomPropSeq.realloc(nSize+1);
931 aGeomPropSeq[nSize] = lcl_createTextpathProps();
932 }
933 rPropMap.setAnyProperty(PROP_CustomShapeGeometry, uno::makeAny(aGeomPropSeq));
934 }
935 if (moStyle.has())
3
Assuming the condition is false
4
Taking false branch
936 {
937 OUString aStyle = moStyle.get(OUString());
938
939 sal_Int32 nIndex = 0;
940 while( nIndex >= 0 )
941 {
942 OUString aName, aValue;
943 if (ConversionHelper::separatePair(aName, aValue, aStyle.getToken(0, ';', nIndex), ':'))
944 {
945 if (aName == "font-family")
946 {
947 // remove " (first, and last character)
948 if (aValue.getLength() > 2)
949 aValue = aValue.copy(1, aValue.getLength() - 2);
950
951 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
952 xPropertySet->setPropertyValue("CharFontName", uno::makeAny(aValue));
953 sFont = aValue;
954 }
955 else if (aName == "font-size")
956 {
957 oox::OptValue<OUString> aOptString(aValue);
958 float nSize = drawingml::convertEmuToPoints(lclGetEmu(rGraphicHelper, aOptString, 1));
959
960 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
961 xPropertySet->setPropertyValue("CharHeight", uno::makeAny(nSize));
962 }
963 }
964 }
965 }
966 if (moTrim.has() && moTrim.get())
5
Assuming the condition is false
967 return;
968
969 OUString sText = moString.get();
970 ScopedVclPtrInstance<VirtualDevice> pDevice;
6
Calling default constructor for 'ScopedVclPtrInstance<VirtualDevice>'
8
Returning from default constructor for 'ScopedVclPtrInstance<VirtualDevice>'
971 vcl::Font aFont = pDevice->GetFont();
972 aFont.SetFamilyName(sFont);
973 aFont.SetFontSize(Size(0, 96));
974 pDevice->SetFont(aFont);
975
976 auto nTextWidth = pDevice->GetTextWidth(sText);
977 if (nTextWidth)
9
Assuming 'nTextWidth' is 0
10
Taking false branch
978 {
979 sal_Int32 nNewHeight = (static_cast<double>(pDevice->GetTextHeight()) / nTextWidth) * xShape->getSize().Width;
980 xShape->setSize(awt::Size(xShape->getSize().Width, nNewHeight));
981 }
982}
11
Calling implicit destructor for 'ScopedVclPtrInstance<VirtualDevice>'
12
Calling '~ScopedVclPtr'
983
984} // namespace oox
985
986/* 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);
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 ;-)
14
Calling 'Reference::clear'
21
Returning; memory was released
205 if (aTmp.get()) {
22
Calling 'Reference::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();
13
Calling 'VclPtr::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 )
7
Memory is allocated
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)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
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
14.1
Field 'm_pBody' is non-null
14.1
Field 'm_pBody' is non-null
14.1
Field 'm_pBody' is non-null
14.1
Field 'm_pBody' is non-null
)
15
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
16
Calling 'VclReferenceBase::release'
20
Returning; memory was released
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;
23
Use of memory after it is freed
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)
17
Assuming the condition is true
18
Taking true branch
40 delete this;
19
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