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 
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 using ::oox::core::ContextHandler2;
36 
37 namespace 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.getString( R_TOKEN( embed ), OUString() ) );
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.getString( R_TOKEN( link ), OUString() );
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  case A_TOKEN( grayscl ):
176  mrBlipProps.moColorEffect = getBaseToken( nElement );
177  break;
178 
179  case A_TOKEN( clrChange ):
180  return new ColorChangeContext( *this, rAttribs, mrBlipProps );
181 
182  case A_TOKEN( duotone ):
183  return new DuotoneContext( *this, mrBlipProps );
184 
185  case A_TOKEN( extLst ):
186  return new BlipExtensionContext( *this, mrBlipProps );
187 
188  case A_TOKEN( lum ):
189  mrBlipProps.moBrightness = rAttribs.getInteger( XML_bright );
190  mrBlipProps.moContrast = rAttribs.getInteger( XML_contrast );
191  break;
192  case A_TOKEN( alphaModFix ):
193  mrBlipProps.moAlphaModFix = rAttribs.getInteger(XML_amt);
194  break;
195  }
196  return nullptr;
197 }
198 
200  BlipFillProperties& rBlipProps ) :
201  ContextHandler2( rParent ),
202  mrBlipProps( rBlipProps ),
203  mnColorIndex( 0 )
204 {
207 }
208 
210 {
211 }
212 
214  sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
215 {
216  if( mnColorIndex < 2 )
218  return nullptr;
219 }
220 
222  const AttributeList& rAttribs, BlipFillProperties& rBlipProps ) :
223  ContextHandler2( rParent ),
224  mrBlipProps( rBlipProps )
225 {
226  mrBlipProps.moRotateWithShape = rAttribs.getBool( XML_rotWithShape );
227 }
228 
230  sal_Int32 nElement, const AttributeList& rAttribs )
231 {
232  switch( nElement )
233  {
234  case A_TOKEN( blip ):
235  return new BlipContext( *this, rAttribs, mrBlipProps );
236 
237  case A_TOKEN( srcRect ):
239  break;
240 
241  case A_TOKEN( tile ):
242  mrBlipProps.moBitmapMode = getBaseToken( nElement );
243  mrBlipProps.moTileOffsetX = rAttribs.getInteger( XML_tx );
244  mrBlipProps.moTileOffsetY = rAttribs.getInteger( XML_ty );
245  mrBlipProps.moTileScaleX = rAttribs.getInteger( XML_sx );
246  mrBlipProps.moTileScaleY = rAttribs.getInteger( XML_sy );
247  mrBlipProps.moTileAlign = rAttribs.getToken( XML_algn );
248  mrBlipProps.moTileFlip = rAttribs.getToken( XML_flip );
249  break;
250 
251  case A_TOKEN( stretch ):
252  mrBlipProps.moBitmapMode = getBaseToken( nElement );
253  return this; // for fillRect element
254 
255  case A_TOKEN( fillRect ):
257  break;
258  }
259  return nullptr;
260 }
261 
263  ContextHandler2( rParent ),
264  mrFillProps( rFillProps )
265 {
266 }
267 
269  sal_Int32 nElement, const AttributeList& rAttribs )
270 {
271  return createFillContext( *this, nElement, rAttribs, mrFillProps );
272 }
273 
275  ContextHandler2Helper const & rParent, sal_Int32 nElement,
276  const AttributeList& rAttribs, FillProperties& rFillProps )
277 {
278  switch( nElement )
279  {
280  case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; };
281  case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rFillProps ); };
282  case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); };
283  case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); };
284  case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); };
285  case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; }; // TODO
286  }
287  return nullptr;
288 }
289 
291  FillPropertiesContext( rParent, *this ),
292  mrColor( rColor )
293 {
294 }
295 
297 {
299 }
300 
302  ContextHandler2( rParent ),
303  mrBlipProps( rBlipProps )
304 {
305 }
306 
308 {
309 }
310 
312  sal_Int32 nElement, const AttributeList& )
313 {
314  switch( nElement )
315  {
316  case A_TOKEN( ext ):
317  return new BlipExtensionContext( *this, mrBlipProps );
318 
319  case OOX_TOKEN( a14, imgProps ):
320  return new ArtisticEffectContext( *this, mrBlipProps.maEffect );
321  }
322  return nullptr;
323 }
324 
326  ContextHandler2( rParent ),
327  maEffect( rEffect )
328 {
329 }
330 
332 {
333 }
334 
336  sal_Int32 nElement, const AttributeList& rAttribs )
337 {
338  // containers
339  if( nElement == OOX_TOKEN( a14, imgLayer ) )
340  {
341  if( rAttribs.hasAttribute( R_TOKEN( embed ) ) )
342  {
343  OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( embed ), OUString() ) );
344  if( !aFragmentPath.isEmpty() )
345  {
347  maEffect.mrOleObjectInfo.maProgId = aFragmentPath;
348  }
349  }
350  return new ArtisticEffectContext( *this, maEffect );
351  }
352  if( nElement == OOX_TOKEN( a14, imgEffect ) )
353  return new ArtisticEffectContext( *this, maEffect );
354 
355  // effects
357  if( maEffect.isEmpty() )
358  return nullptr;
359 
360  // effect attributes
361  sal_Int32 const aAttribs[19] = {
362  XML_visible, XML_trans, XML_crackSpacing, XML_pressure, XML_numberOfShades,
363  XML_grainSize, XML_intensity, XML_smoothness, XML_gridSize, XML_pencilSize,
364  XML_size, XML_brushSize, XML_scaling, XML_detail, XML_bright, XML_contrast,
365  XML_colorTemp, XML_sat, XML_amount
366  };
367  for(sal_Int32 nAttrib : aAttribs)
368  {
369  if( rAttribs.hasAttribute( nAttrib ) )
370  {
371  OUString sName = ArtisticEffectProperties::getEffectString( nAttrib );
372  if( !sName.isEmpty() )
373  maEffect.maAttribs[sName] <<= rAttribs.getInteger( nAttrib, 0 );
374  }
375  }
376 
377  return nullptr;
378 }
379 
380 } // namespace oox::drawingml
381 
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Context handler that imports the a:clrChange element containing the colors of a bitmap color change t...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
ArtisticEffectProperties maEffect
Duotone Colors.
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.
OptValue< bool > moShadeScaled
Flip mode of gradient, if not stretched to shape.
Context handler that imports the a:blipFill element.
OptValue< sal_Int32 > moAlphaModFix
Artistic effect, not supported by core.
const char * sName
Definition: olehelper.cxx:92
PatternFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, PatternFillProperties &rPatternProps)
BlipFillProperties maBlipProps
Properties for pattern fills.
Color maDuotoneColors[2]
Destination color of color transformation.
OptValue< css::geometry::IntegerRectangle2D > moFillToRect
Gradient stops (colors/transparence).
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
Context handler that imports the a:extLst element inside a:blip and its children a:ext, which can contain transformations to the bitmap.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
OptValue< sal_Int32 > moTileAlign
Vertical scaling of bitmap tiles (1/1000 percent).
OptValue< bool > moRotateWithShape
True = scale gradient into shape.
OptValue< sal_Int32 > moFillType
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
BlipFillProperties & mrBlipProps
exports com.sun.star. embed
Context handler that imports the a:solidFill element.
OptValue< css::geometry::IntegerRectangle2D > moClipRect
Stretch fill offsets.
std::map< OUString, css::uno::Any > maAttribs
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
OptValue< double > getDouble(sal_Int32 nAttrToken) const
Returns the double value of the specified attribute.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
ArtisticEffectProperties & maEffect
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
FillPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, FillProperties &rFillProps)
OptValue< sal_Int32 > moBitmapMode
The fill graphic.
OptValue< css::geometry::IntegerRectangle2D > moTileRect
BlipFillProperties & mrBlipProps
virtual ~ColorChangeContext() override
ColorChangeContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
Definition: filterbase.cxx:343
bool importBinaryData(StreamDataSequence &orDataSeq, const OUString &rStreamName)
Imports the raw binary data from the specified stream.
Definition: filterbase.cxx:379
ArtisticEffectContext(::oox::core::ContextHandler2Helper const &rParent, ArtisticEffectProperties &rEffect)
OptValue< sal_Int32 > moBrightness
XML token for a color effect.
OptValue< sal_Int32 > moTileFlip
Anchor point inside bitmap.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
OptValue< bool > moRotateWithShape
Flip mode of bitmap tiles.
OptValue< sal_Int32 > moTileOffsetY
Width of bitmap tiles (EMUs).
void fillRect(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2DRectangle &rRect,::cppcanvas::IntSRGBA aFillColor)
Context handler that imports the a:gradFill element.
Context handler for the different color value elements (a:scrgbClr, a:srgbClr, a:hslClr, a:sysClr, a:schemeClr, a:prstClr).
SolidFillContext(::oox::core::ContextHandler2Helper const &rParent, FillProperties &rFillProps)
DuotoneContext(::oox::core::ContextHandler2Helper const &rParent, BlipFillProperties &rBlipProps)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
OptValue< sal_Int32 > moContrast
Brightness in the range [-100000,100000].
const Relations & getRelations() const
Returns the relations of the current fragment.
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr, a:hslClr, a:sysClr, a:schemeClr, a:prstClr).
GradientFillProperties & mrGradientProps
OptValue< css::geometry::IntegerRectangle2D > moFillRect
Bitmap tile or stretch.
GradientFillProperties maGradientProps
Solid fill color and transparence.
OUString getFragmentPathFromRelId(const OUString &rRelId) const
Returns the full fragment path for the passed relation identifier.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Color maColorChangeTo
Start color of color transformation.
static OUString getEffectString(sal_Int32 nToken)
Translate effect tokens to strings.
StreamDataSequence maEmbeddedData
Data of an embedded OLE object.
Color maColorChangeFrom
Contrast in the range [-100000,100000].
IntegerRectangle2D GetRelativeRect(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_RelativeRect to an IntegerRectangle2D
Provides access to attribute values of an element.
Context handler that imports the a:duotone element containing the colors of a bitmap duotone transfor...
void clearTransparence()
Removes transparence from the color.
Definition: color.cxx:476
OptValue< sal_Int32 > moShadeAngle
If set, gradient follows rectangle, circle, or shape.
PatternFillProperties & mrPatternProps
virtual ~DuotoneContext() override
uno::Sequence< double > maFillColor
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Color maPattBgColor
Pattern foreground color.
BlipFillProperties & mrBlipProps
Context handler for elements that contain a fill property element (a:noFill, a:solidFill, a:gradFill, a:pattFill, a:blipFill, a:grpFill).
XmlFilterBase & getFilter() const
Returns the filter instance.
::rtl::Reference< ContextHandler > ContextHandlerRef
::oox::ole::OleObjectInfo mrOleObjectInfo
OptValue< sal_Int32 > moTileScaleX
Height of bitmap tiles (EMUs).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
void setUnused()
Sets the color to unused state.
Definition: color.cxx:250
SimpleFillPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, Color &rColor)
OptValue< sal_Int32 > moColorEffect
True = rotate bitmap with shape.
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
bool isEmpty() const
The original graphic as embedded object.
::oox::core::ContextHandlerRef createFillContext(::oox::core::ContextHandler2Helper const &rParent, sal_Int32 nElement, const ::oox::AttributeList &rAttribs, FillProperties &rFillProps)
BlipFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
OUString getAbsoluteUrl(const OUString &rUrl) const
Returns an absolute URL for the passed relative or absolute URL.
Definition: filterbase.cxx:265
Context handler that imports a14:imgProps, a14:imgLayer, a14:imgEffect containers and the a14:artisti...
PatternFillProperties maPatternProps
Properties for gradient fills.
BlipExtensionContext(::oox::core::ContextHandler2Helper const &rParent, BlipFillProperties &rBlipProps)
Context handler that imports the a:blip element containing the fill bitmap and bitmap color transform...
OptValue< sal_Int32 > moShadeFlip
Rotation angle of linear gradients.
BlipContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, BlipFillProperties &rBlipProps)
css::uno::Reference< css::graphic::XGraphic > mxFillGraphic
Helper class that provides a context stack.
GradientFillContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, GradientFillProperties &rGradientProps)
OptValue< sal_Int32 > moTileScaleY
Horizontal scaling of bitmap tiles (1/1000 percent).
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
OptValue< sal_Int32 > moPattPreset
Pattern background color.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler that imports the a:pattFill element.