1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_VML_VMLFORMATTING_HXX
21 #define INCLUDED_OOX_VML_VMLFORMATTING_HXX
26 #include <com/sun/star/drawing/PolygonFlags.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <oox/dllapi.h>
29 #include <oox/helper/helper.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
33 namespace com
{ namespace sun
{ namespace star
{
34 namespace awt
{ struct Point
; }
35 namespace drawing
{ class XShape
; }
40 namespace drawingml
{ class Color
; }
41 namespace drawingml
{ class ShapePropertyMap
; }
48 typedef ::std::pair
< sal_Int32
, sal_Int32
> Int32Pair
;
49 typedef ::std::pair
< double, double > DoublePair
;
52 namespace ConversionHelper
54 /** Returns two values contained in rValue separated by cSep.
56 OOX_DLLPUBLIC
bool separatePair(
57 OUString
& orValue1
, OUString
& orValue2
,
58 const OUString
& rValue
, sal_Unicode cSep
);
60 /** Returns the boolean value from the passed string of a VML attribute.
61 Supported values: 'f', 't', 'false', 'true'. False for anything else.
63 OOX_DLLPUBLIC
bool decodeBool( const OUString
& rValue
);
65 /** Converts the passed VML percentage measure string to a normalized
68 @param rValue The VML percentage value. This is a floating-point value
69 with optional following '%' or 'f' sign. If the sign is missing, the
70 floating point value will be returned unmodified. If the '%' sign
71 is present, the value will be divided by 100. If the 'f' sign is present,
72 the value will be divided by 65536.
74 OOX_DLLPUBLIC
double decodePercent(
75 const OUString
& rValue
,
78 /** Converts the passed VML rotation value to degrees.
79 See DffPropertyReader::Fix16ToAngle(): in VML, positive rotation
80 angles are clockwise, we have them as counter-clockwise.
81 Additionally, VML type is 0..360, our is 0..36000.
83 @param rValue The VML rotation value. This is a floating-point value
84 with optional 'fd' suffix. If the suffix is missing, the floating
85 point value will be returned unmodified. If the 'fd' suffix is
86 present, the value will be divided by 65536.
88 OOX_DLLPUBLIC sal_Int32
decodeRotation( const OUString
& rValue
);
90 /** Converts the passed VML measure string to EMU (English Metric Units).
92 @param rGraphicHelper The graphic helper needed to perform pixel
93 conversion according to the current output device.
95 @param rValue The VML measure value. This is a floating-point value
96 with optional measure string following the value.
98 @param nRefValue Reference value needed for percentage measure.
100 @param bPixelX Set to true if the value is oriented horizontally (e.g.
101 X coordinates, widths). Set to false if the value is oriented
102 vertically (e.g. Y coordinates, heights). This is needed because
103 output devices may specify different width and height for a pixel.
105 @param bDefaultAsPixel Set to true if omitted measure unit means
106 pixel. Set to false if omitted measure unit means EMU.
108 OOX_DLLPUBLIC sal_Int64
decodeMeasureToEmu(
109 const GraphicHelper
& rGraphicHelper
,
110 const OUString
& rValue
,
113 bool bDefaultAsPixel
);
115 /** Converts the passed VML measure string to 1/100 mm.
117 @param rGraphicHelper See above.
118 @param rValue See above.
119 @param nRefValue See above.
120 @param bPixelX See above.
121 @param bDefaultAsPixel See above.
123 OOX_DLLPUBLIC sal_Int32
decodeMeasureToHmm(
124 const GraphicHelper
& rGraphicHelper
,
125 const OUString
& rValue
,
128 bool bDefaultAsPixel
);
130 /** Converts VML color attributes to a DrawingML color.
132 @param roVmlColor The VML string representation of the color. If
133 existing, this can be a 3-digit or 6-digit hexadecimal RGB value
134 with leading '#' character, a predefined color name (e.g. 'black',
135 'red', etc.), the index into an application defined color palette
136 in brackets with leading color name (e.g. 'red [9]' or
137 'windowColor [64]'), or a color modifier used in one-color
138 gradients (e.g. 'fill darken(128)' or 'fill lighten(0)').
140 @param roVmlOpacity The opacity of the color. If existing, this should
141 be a floating-point value in the range [0.0;1.0].
143 @param nDefaultRgb Default RGB color used if the parameter roVmlColor
146 @param nPrimaryRgb If set to something else than API_RGB_TRANSPARENT,
147 specifies the color to be used to resolve the color modifiers used
148 in one-color gradients.
150 @return The resulting DrawingML color.
152 OOX_DLLPUBLIC ::oox::drawingml::Color
decodeColor(
153 const GraphicHelper
& rGraphicHelper
,
154 const OptValue
< OUString
>& roVmlColor
,
155 const OptValue
< double >& roVmlOpacity
,
157 ::Color nPrimaryRgb
= API_RGB_TRANSPARENT
);
159 /** Converts VML path string into point and flag vectors.
161 @param rPoints The point vector to fill with coordinates.
163 @param rFlags The flag vector to fill. PolygonFlags_NORMAL indicates
164 a corresponding plain shape coordinate in rPoints and
165 PolygonFlags_CONTROL indicates a bezier curve control point.
167 @param rPath The VML path string.
169 @param rGraphicHelper See above.
171 OOX_DLLPUBLIC
void decodeVmlPath(
172 ::std::vector
< ::std::vector
< css::awt::Point
> >& rPoints
,
173 ::std::vector
< ::std::vector
< css::drawing::PolygonFlags
> >& rFlags
,
174 const OUString
& rPath
);
178 /** The stroke arrow model structure contains all properties for a line end arrow. */
179 struct StrokeArrowModel
181 OptValue
< sal_Int32
> moArrowType
;
182 OptValue
< sal_Int32
> moArrowWidth
;
183 OptValue
< sal_Int32
> moArrowLength
;
185 void assignUsed( const StrokeArrowModel
& rSource
);
189 /** The stroke model structure contains all shape border properties. */
192 OptValue
< bool > moStroked
; ///< Shape border line on/off.
193 StrokeArrowModel maStartArrow
; ///< Start line arrow style.
194 StrokeArrowModel maEndArrow
; ///< End line arrow style.
195 OptValue
< OUString
> moColor
; ///< Solid line color.
196 OptValue
< double > moOpacity
; ///< Solid line color opacity.
197 OptValue
< OUString
> moWeight
; ///< Line width.
198 OptValue
< OUString
> moDashStyle
; ///< Line dash (predefined or manually).
199 OptValue
< sal_Int32
> moLineStyle
; ///< Line style (single, double, ...).
200 OptValue
< sal_Int32
> moEndCap
; ///< Type of line end cap.
201 OptValue
< sal_Int32
> moJoinStyle
; ///< Type of line join.
203 void assignUsed( const StrokeModel
& rSource
);
205 /** Writes the properties to the passed property map. */
207 ::oox::drawingml::ShapePropertyMap
& rPropMap
,
208 const GraphicHelper
& rGraphicHelper
) const;
212 /** The fill model structure contains all shape fill properties. */
213 struct OOX_DLLPUBLIC FillModel
215 OptValue
< bool > moFilled
; ///< Shape fill on/off.
216 OptValue
< OUString
> moColor
; ///< Solid fill color.
217 OptValue
< double > moOpacity
; ///< Solid fill color opacity.
218 OptValue
< OUString
> moColor2
; ///< End color of gradient.
219 OptValue
< double > moOpacity2
; ///< End color opacity of gradient.
220 OptValue
< sal_Int32
> moType
; ///< Fill type.
221 OptValue
< sal_Int32
> moAngle
; ///< Gradient rotation angle.
222 OptValue
< double > moFocus
; ///< Linear gradient focus of second color.
223 OptValue
< DoublePair
> moFocusPos
; ///< Rectangular gradient focus position of second color.
224 OptValue
< DoublePair
> moFocusSize
; ///< Rectangular gradient focus size of second color.
225 OptValue
< OUString
> moBitmapPath
; ///< Path to fill bitmap fragment.
226 OptValue
< bool > moRotate
; ///< True = rotate gradient/bitmap with shape.
228 void assignUsed( const FillModel
& rSource
);
230 /** Writes the properties to the passed property map. */
232 ::oox::drawingml::ShapePropertyMap
& rPropMap
,
233 const GraphicHelper
& rGraphicHelper
) const;
237 /** The shadow model structure contains all shape shadow properties. */
238 struct OOX_DLLPUBLIC ShadowModel
240 bool mbHasShadow
; ///< Is a v:shadow element seen?
241 OptValue
<bool> moShadowOn
; ///< Is the element turned on?
242 OptValue
<OUString
> moColor
; ///< Specifies the color of the shadow.
243 OptValue
<OUString
> moOffset
; ///< Specifies the shadow's offset from the shape's location.
244 OptValue
<double> moOpacity
; ///< Specifies the opacity of the shadow.
248 /** Writes the properties to the passed property map. */
249 void pushToPropMap(oox::drawingml::ShapePropertyMap
& rPropMap
, const GraphicHelper
& rGraphicHelper
) const;
252 /** The shadow model structure contains all shape textpath properties. */
253 struct OOX_DLLPUBLIC TextpathModel
255 OptValue
<OUString
> moString
; ///< Specifies the string of the textpath.
256 OptValue
<OUString
> moStyle
; ///< Specifies the style of the textpath.
257 OptValue
<bool> moTrim
; ///< Specifies whether extra space is removed above and below the text
261 /** Writes the properties to the passed property map. */
262 void pushToPropMap(oox::drawingml::ShapePropertyMap
& rPropMap
, const css::uno::Reference
<css::drawing::XShape
>& xShape
,
263 const GraphicHelper
& rGraphicHelper
) const;
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */