LibreOffice Module oox (master) 1
misccontexts.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
26#include <oox/token/namespaces.hxx>
27#include <oox/token/tokens.hxx>
29#include <vcl/graph.hxx>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::xml::sax;
34using ::oox::core::ContextHandler2;
36
37namespace oox::drawingml {
38
40 FillProperties& rFillProps ) :
41 ColorContext( rParent, rFillProps.maFillColor )
42{
43}
44
46 const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) :
47 ContextHandler2( rParent ),
48 mrGradientProps( rGradientProps )
49{
50 mrGradientProps.moShadeFlip = rAttribs.getToken( XML_flip );
51 mrGradientProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
52}
53
55 sal_Int32 nElement, const AttributeList& rAttribs )
56{
57 switch( nElement )
58 {
59 case A_TOKEN( gsLst ):
60 return this; // for gs elements
61
62 case A_TOKEN( gs ):
63 if( rAttribs.hasAttribute( XML_pos ) )
64 {
65 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
66 auto aElement = mrGradientProps.maGradientStops.emplace( fPosition, Color() );
67 return new ColorContext( *this, aElement->second );
68 }
69 break;
70
71 case A_TOKEN( lin ):
72 mrGradientProps.moShadeAngle = rAttribs.getInteger( XML_ang );
73 mrGradientProps.moShadeScaled = rAttribs.getBool( XML_scaled );
74 break;
75
76 case A_TOKEN( path ):
77 // always set a path type, this disables linear gradient in conversion
78 mrGradientProps.moGradientPath = rAttribs.getToken( XML_path, XML_rect );
79 return this; // for fillToRect element
80
81 case A_TOKEN( fillToRect ):
83 break;
84
85 case A_TOKEN( tileRect ):
87 break;
88 }
89 return nullptr;
90}
91
93 const AttributeList& rAttribs, PatternFillProperties& rPatternProps ) :
94 ContextHandler2( rParent ),
95 mrPatternProps( rPatternProps )
96{
97 mrPatternProps.moPattPreset = rAttribs.getToken( XML_prst );
98}
99
101 sal_Int32 nElement, const AttributeList& )
102{
103 switch( nElement )
104 {
105 case A_TOKEN( bgClr ):
106 return new ColorContext( *this, mrPatternProps.maPattBgColor );
107 case A_TOKEN( fgClr ):
108 return new ColorContext( *this, mrPatternProps.maPattFgColor );
109 }
110 return nullptr;
111}
112
114 const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
115 ContextHandler2( rParent ),
116 mrBlipProps( rBlipProps )
117{
120 mbUseAlpha = rAttribs.getBool( XML_useA, true );
121}
122
124{
125 if( !mbUseAlpha )
127}
128
130 sal_Int32 nElement, const AttributeList& )
131{
132 switch( nElement )
133 {
134 case A_TOKEN( clrFrom ):
135 return new ColorContext( *this, mrBlipProps.maColorChangeFrom );
136 case A_TOKEN( clrTo ):
137 return new ColorContext( *this, mrBlipProps.maColorChangeTo );
138 }
139 return nullptr;
140}
141
143 const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
144 ContextHandler2( rParent ),
145 mrBlipProps( rBlipProps )
146{
147 if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
148 {
149 // internal picture URL
150 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( embed )) );
151 if (!aFragmentPath.isEmpty())
153 }
154 else if( rAttribs.hasAttribute( R_TOKEN( link ) ) )
155 {
156 // external URL
157
158 // we will embed this link, this is better than just doing nothing...
159 // TODO: import this graphic as real link, but this requires some
160 // code rework.
161 OUString aRelId = rAttribs.getStringDefaulted( R_TOKEN( link ));
162 OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
163 GraphicExternalLink aLink(aTargetLink);
164 Graphic aGraphic(aLink);
166 }
167}
168
170 sal_Int32 nElement, const AttributeList& rAttribs )
171{
172 switch( nElement )
173 {
174 case A_TOKEN( biLevel ):
175 mrBlipProps.moBiLevelThreshold = rAttribs.getInteger( XML_thresh );
176 mrBlipProps.moColorEffect = getBaseToken(nElement);
177 break;
178
179 case A_TOKEN( grayscl ):
180 mrBlipProps.moColorEffect = getBaseToken( nElement );
181 break;
182
183 case A_TOKEN( clrChange ):
184 return new ColorChangeContext( *this, rAttribs, mrBlipProps );
185
186 case A_TOKEN( duotone ):
187 return new DuotoneContext( *this, mrBlipProps );
188
189 case A_TOKEN( extLst ):
190 return new BlipExtensionContext( *this, mrBlipProps );
191
192 case A_TOKEN( lum ):
193 mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
194 mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
195 break;
196 case A_TOKEN( alphaModFix ):
197 mrBlipProps.moAlphaModFix = rAttribs.getInteger(XML_amt);
198 break;
199 }
200 return nullptr;
201}
202
204 BlipFillProperties& rBlipProps ) :
205 ContextHandler2( rParent ),
206 mrBlipProps( rBlipProps ),
207 mnColorIndex( 0 )
208{
211}
212
214{
215}
216
218 sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
219{
220 if( mnColorIndex < 2 )
222 return nullptr;
223}
224
226 const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
227 ContextHandler2( rParent ),
228 mrBlipProps( rBlipProps )
229{
230 mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
231}
232
234 sal_Int32 nElement, const AttributeList& rAttribs )
235{
236 switch( nElement )
237 {
238 case A_TOKEN( blip ):
239 return new BlipContext( *this, rAttribs, mrBlipProps );
240
241 case A_TOKEN( srcRect ):
243 break;
244
245 case A_TOKEN( tile ):
246 mrBlipProps.moBitmapMode = getBaseToken( nElement );
247 mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
248 mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
249 mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
250 mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
251 mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
252 mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
253 break;
254
255 case A_TOKEN( stretch ):
256 mrBlipProps.moBitmapMode = getBaseToken( nElement );
257 return this; // for fillRect element
258
259 case A_TOKEN( fillRect ):
261 break;
262 }
263 return nullptr;
264}
265
267 ContextHandler2( rParent ),
268 mrFillProps( rFillProps )
269{
270}
271
273 sal_Int32 nElement, const AttributeList& rAttribs )
274{
275 return createFillContext( *this, nElement, rAttribs, mrFillProps );
276}
277
279 ContextHandler2Helper const & rParent, sal_Int32 nElement,
280 const AttributeList& rAttribs, FillProperties& rFillProps )
281{
282 switch( nElement )
283 {
284 case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; };
285 case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rFillProps ); };
286 case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
287 case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
288 case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); };
289 case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; }; // TODO
290 }
291 return nullptr;
292}
293
295 FillPropertiesContext( rParent, *this ),
296 mrColor( rColor )
297{
298}
299
301{
303}
304
306 ContextHandler2( rParent ),
307 mrBlipProps( rBlipProps )
308{
309}
310
312{
313}
314
316 sal_Int32 nElement, const AttributeList& )
317{
318 switch( nElement )
319 {
320 case A_TOKEN( ext ):
321 return new BlipExtensionContext( *this, mrBlipProps );
322
323 case OOX_TOKEN( a14, imgProps ):
324 return new ArtisticEffectContext( *this, mrBlipProps.maEffect );
325 }
326 return nullptr;
327}
328
330 ContextHandler2( rParent ),
331 maEffect( rEffect )
332{
333}
334
336{
337}
338
340 sal_Int32 nElement, const AttributeList& rAttribs )
341{
342 // containers
343 if( nElement == OOX_TOKEN( a14, imgLayer ) )
344 {
345 if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
346 {
347 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( embed )) );
348 if( !aFragmentPath.isEmpty() )
349 {
351 maEffect.mrOleObjectInfo.maProgId = aFragmentPath;
352 }
353 }
354 return new ArtisticEffectContext( *this, maEffect );
355 }
356 if( nElement == OOX_TOKEN( a14, imgEffect ) )
357 return new ArtisticEffectContext( *this, maEffect );
358
359 // effects
361 if( maEffect.isEmpty() )
362 return nullptr;
363
364 // effect attributes
365 sal_Int32 const aAttribs[19] = {
366 XML_visible, XML_trans, XML_crackSpacing, XML_pressure, XML_numberOfShades,
367 XML_grainSize, XML_intensity, XML_smoothness, XML_gridSize, XML_pencilSize,
368 XML_size, XML_brushSize, XML_scaling, XML_detail, XML_bright, XML_contrast,
369 XML_colorTemp, XML_sat, XML_amount
370 };
371 for(sal_Int32 nAttrib : aAttribs)
372 {
373 if( rAttribs.hasAttribute( nAttrib ) )
374 {
376 if( !sName.isEmpty() )
377 maEffect.maAttribs[sName] <<= rAttribs.getInteger( nAttrib, 0 );
378 }
379 }
380
381 return nullptr;
382}
383
384} // namespace oox::drawingml
385
386/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
std::optional< double > getDouble(sal_Int32 nAttrToken) const
Returns the double value of the specified attribute.
css::uno::Reference< css::graphic::XGraphic > importEmbeddedGraphic(const OUString &rStreamName, const WmfExternal *pExtHeader=nullptr) const
Imports a graphic from the storage stream with the passed path and name.
Helper class that provides a context stack.
XmlFilterBase & getFilter() const
Returns the filter instance.
OUString getFragmentPathFromRelId(const OUString &rRelId) const
Returns the full fragment path for the passed relation identifier.
const Relations & getRelations() const
Returns the relations of the current fragment.
bool importBinaryData(StreamDataSequence &orDataSeq, const OUString &rStreamName)
Imports the raw binary data from the specified stream.
Definition: filterbase.cxx:382
OUString getAbsoluteUrl(const OUString &rUrl) const
Returns an absolute URL for the passed relative or absolute URL.
Definition: filterbase.cxx:268
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
Definition: filterbase.cxx:346
Context handler that imports a14:imgProps, a14:imgLayer, a14:imgEffect containers and the a14:artisti...
ArtisticEffectContext(::oox::core::ContextHandler2Helper const &rParent, ArtisticEffectProperties &rEffect)
ArtisticEffectProperties & maEffect
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler that imports the a:blip element containing the fill bitmap and bitmap color transform...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
BlipContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
BlipFillProperties & mrBlipProps
Context handler that imports the a:extLst element inside a:blip and its children a:ext,...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
BlipExtensionContext(::oox::core::ContextHandler2Helper const &rParent, BlipFillProperties &rBlipProps)
Context handler that imports the a:blipFill element.
BlipFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
BlipFillProperties & mrBlipProps
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler that imports the a:clrChange element containing the colors of a bitmap color change t...
virtual ~ColorChangeContext() override
ColorChangeContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr,...
Context handler for the different color value elements (a:scrgbClr, a:srgbClr, a:hslClr,...
void setUnused()
Sets the color to unused state.
Definition: color.cxx:250
void clearTransparence()
Removes transparence from the color.
Definition: color.cxx:477
Context handler that imports the a:duotone element containing the colors of a bitmap duotone transfor...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
DuotoneContext(::oox::core::ContextHandler2Helper const &rParent, BlipFillProperties &rBlipProps)
BlipFillProperties & mrBlipProps
virtual ~DuotoneContext() override
Context handler for elements that contain a fill property element (a:noFill, a:solidFill,...
::oox::core::ContextHandlerRef createFillContext(::oox::core::ContextHandler2Helper const &rParent, sal_Int32 nElement, const ::oox::AttributeList &rAttribs, FillProperties &rFillProps)
FillPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, FillProperties &rFillProps)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler that imports the a:gradFill element.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
GradientFillProperties & mrGradientProps
GradientFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, GradientFillProperties &rGradientProps)
Context handler that imports the a:pattFill element.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
PatternFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, PatternFillProperties &rPatternProps)
PatternFillProperties & mrPatternProps
SimpleFillPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, Color &rColor)
Context handler that imports the a:solidFill element.
SolidFillContext(::oox::core::ContextHandler2Helper const &rParent, FillProperties &rFillProps)
OString sName
Definition: drawingml.cxx:4066
::rtl::Reference< ContextHandler > ContextHandlerRef
IntegerRectangle2D GetRelativeRect(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_RelativeRect to an IntegerRectangle2D
void fillRect(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2DRectangle &rRect, ::cppcanvas::IntSRGBA aFillColor)
uno::Sequence< double > maFillColor
bool isEmpty() const
The original graphic as embedded object.
::oox::ole::OleObjectInfo mrOleObjectInfo
std::map< OUString, css::uno::Any > maAttribs
static OUString getEffectString(sal_Int32 nToken)
Translate effect tokens to strings.
std::optional< css::geometry::IntegerRectangle2D > moClipRect
Stretch fill offsets.
Color maColorChangeTo
Start color of color transformation.
std::optional< css::geometry::IntegerRectangle2D > moFillRect
Bitmap tile or stretch.
std::optional< sal_Int32 > moColorEffect
True = rotate bitmap with shape.
std::optional< sal_Int32 > moBitmapMode
The fill graphic.
std::optional< sal_Int32 > moTileFlip
Anchor point inside bitmap.
Color maDuotoneColors[2]
Destination color of color transformation.
std::optional< sal_Int32 > moAlphaModFix
Artistic effect, not supported by core.
std::optional< sal_Int32 > moTileScaleY
Horizontal scaling of bitmap tiles (1/1000 percent).
std::optional< sal_Int32 > moTileOffsetY
Width of bitmap tiles (EMUs).
std::optional< sal_Int32 > moBrightness
XML token for a color effect.
Color maColorChangeFrom
Bi-Level (Black/White) effect threshold (1/1000 percent)
std::optional< bool > moRotateWithShape
Flip mode of bitmap tiles.
std::optional< sal_Int32 > moBiLevelThreshold
Contrast in the range [-100000,100000].
css::uno::Reference< css::graphic::XGraphic > mxFillGraphic
ArtisticEffectProperties maEffect
Duotone Colors.
std::optional< sal_Int32 > moTileAlign
Vertical scaling of bitmap tiles (1/1000 percent).
std::optional< sal_Int32 > moTileScaleX
Height of bitmap tiles (EMUs).
std::optional< sal_Int32 > moTileOffsetX
std::optional< sal_Int32 > moContrast
Brightness in the range [-100000,100000].
PatternFillProperties maPatternProps
Properties for gradient fills.
GradientFillProperties maGradientProps
Whether the background is used as fill type.
BlipFillProperties maBlipProps
Properties for pattern fills.
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
std::optional< sal_Int32 > moFillType
std::optional< css::geometry::IntegerRectangle2D > moFillToRect
Gradient stops (colors/transparence).
std::optional< sal_Int32 > moShadeFlip
Rotation angle of linear gradients.
std::optional< bool > moRotateWithShape
True = scale gradient into shape.
std::optional< sal_Int32 > moGradientPath
std::optional< css::geometry::IntegerRectangle2D > moTileRect
std::optional< bool > moShadeScaled
Flip mode of gradient, if not stretched to shape.
std::optional< sal_Int32 > moShadeAngle
If set, gradient follows rectangle, circle, or shape.
Color maPattBgColor
Pattern foreground color.
std::optional< sal_Int32 > moPattPreset
Pattern background color.
StreamDataSequence maEmbeddedData
Data of an embedded OLE object.