Get the style color and number just once
[LibreOffice.git] / include / oox / vml / vmlformatting.hxx
blob37414eb9e1cf4f93064f7457e37d658085852178
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <sal/config.h>
25 #include <string_view>
26 #include <utility>
27 #include <vector>
29 #include <com/sun/star/drawing/PolygonFlags.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <oox/dllapi.h>
32 #include <oox/helper/helper.hxx>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
35 #include <tools/degree.hxx>
37 namespace com::sun::star {
38 namespace awt { struct Point; }
39 namespace drawing { class XShape; }
42 namespace oox {
43 class GraphicHelper;
44 namespace drawingml { class Color; }
45 namespace drawingml { class ShapePropertyMap; }
48 namespace oox::vml {
51 typedef ::std::pair< sal_Int32, sal_Int32 > Int32Pair;
52 typedef ::std::pair< double, double > DoublePair;
55 namespace ConversionHelper
57 /** Returns two values contained in rValue separated by cSep.
59 OOX_DLLPUBLIC bool separatePair(
60 std::u16string_view& orValue1, std::u16string_view& orValue2,
61 std::u16string_view rValue, sal_Unicode cSep );
63 /** Returns the boolean value from the passed string of a VML attribute.
64 Supported values: 'f', 't', 'false', 'true'. False for anything else.
66 OOX_DLLPUBLIC bool decodeBool( std::u16string_view rValue );
68 /** Converts the passed VML percentage measure string to a normalized
69 floating-point value.
71 @param rValue The VML percentage value. This is a floating-point value
72 with optional following '%' or 'f' sign. If the sign is missing, the
73 floating point value will be returned unmodified. If the '%' sign
74 is present, the value will be divided by 100. If the 'f' sign is present,
75 the value will be divided by 65536.
77 OOX_DLLPUBLIC double decodePercent(
78 std::u16string_view rValue,
79 double fDefValue );
81 /** Converts the passed VML rotation value to degrees.
82 See DffPropertyReader::Fix16ToAngle(): in VML, positive rotation
83 angles are clockwise, we have them as counter-clockwise.
84 Additionally, VML type is 0..360, our is 0..36000.
86 @param rValue The VML rotation value. This is a floating-point value
87 with optional 'fd' suffix. If the suffix is missing, the floating
88 point value will be returned unmodified. If the 'fd' suffix is
89 present, the value will be divided by 65536.
91 OOX_DLLPUBLIC Degree100 decodeRotation( std::u16string_view rValue );
93 /** Converts the passed VML measure string to EMU (English Metric Units).
95 @param rGraphicHelper The graphic helper needed to perform pixel
96 conversion according to the current output device.
98 @param rValue The VML measure value. This is a floating-point value
99 with optional measure string following the value.
101 @param nRefValue Reference value needed for percentage measure.
103 @param bPixelX Set to true if the value is oriented horizontally (e.g.
104 X coordinates, widths). Set to false if the value is oriented
105 vertically (e.g. Y coordinates, heights). This is needed because
106 output devices may specify different width and height for a pixel.
108 @param bDefaultAsPixel Set to true if omitted measure unit means
109 pixel. Set to false if omitted measure unit means EMU.
111 OOX_DLLPUBLIC sal_Int64 decodeMeasureToEmu(
112 const GraphicHelper& rGraphicHelper,
113 std::u16string_view rValue,
114 sal_Int32 nRefValue,
115 bool bPixelX,
116 bool bDefaultAsPixel );
118 /** Converts the passed VML measure string to 1/100 mm.
120 @param rGraphicHelper See above.
121 @param rValue See above.
122 @param nRefValue See above.
123 @param bPixelX See above.
124 @param bDefaultAsPixel See above.
126 OOX_DLLPUBLIC sal_Int32 decodeMeasureToHmm(
127 const GraphicHelper& rGraphicHelper,
128 std::u16string_view rValue,
129 sal_Int32 nRefValue,
130 bool bPixelX,
131 bool bDefaultAsPixel );
133 /** Converts the passed VML measure string to Twip.
135 @param rGraphicHelper See above.
136 @param rValue See above.
137 @param nRefValue See above.
138 @param bPixelX See above.
139 @param bDefaultAsPixel See above.
141 OOX_DLLPUBLIC sal_Int32 decodeMeasureToTwip(const GraphicHelper& rGraphicHelper,
142 std::u16string_view rValue, sal_Int32 nRefValue,
143 bool bPixelX, bool bDefaultAsPixel);
145 /** Converts VML color attributes to a DrawingML color.
147 @param roVmlColor The VML string representation of the color. If
148 existing, this can be a 3-digit or 6-digit hexadecimal RGB value
149 with leading '#' character, a predefined color name (e.g. 'black',
150 'red', etc.), the index into an application defined color palette
151 in brackets with leading color name (e.g. 'red [9]' or
152 'windowColor [64]'), or a color modifier used in one-color
153 gradients (e.g. 'fill darken(128)' or 'fill lighten(0)').
155 @param roVmlOpacity The opacity of the color. If existing, this should
156 be a floating-point value in the range [0.0;1.0].
158 @param nDefaultRgb Default RGB color used if the parameter roVmlColor
159 is empty.
161 @param nPrimaryRgb If set to something else than API_RGB_TRANSPARENT,
162 specifies the color to be used to resolve the color modifiers used
163 in one-color gradients.
165 @return The resulting DrawingML color.
167 OOX_DLLPUBLIC ::oox::drawingml::Color decodeColor(
168 const GraphicHelper& rGraphicHelper,
169 const std::optional< OUString >& roVmlColor,
170 const std::optional< double >& roVmlOpacity,
171 ::Color nDefaultRgb,
172 ::Color nPrimaryRgb = API_RGB_TRANSPARENT );
174 /** Converts VML path string into point and flag vectors.
176 @param rPoints The point vector to fill with coordinates.
178 @param rFlags The flag vector to fill. PolygonFlags_NORMAL indicates
179 a corresponding plain shape coordinate in rPoints and
180 PolygonFlags_CONTROL indicates a bezier curve control point.
182 @param rPath The VML path string.
184 @param rGraphicHelper See above.
186 OOX_DLLPUBLIC void decodeVmlPath(
187 ::std::vector< ::std::vector< css::awt::Point > >& rPoints,
188 ::std::vector< ::std::vector< css::drawing::PolygonFlags > >& rFlags,
189 std::u16string_view rPath );
193 /** The stroke arrow model structure contains all properties for a line end arrow. */
194 struct StrokeArrowModel
196 std::optional< sal_Int32 > moArrowType;
197 std::optional< sal_Int32 > moArrowWidth;
198 std::optional< sal_Int32 > moArrowLength;
200 void assignUsed( const StrokeArrowModel& rSource );
204 /** The stroke model structure contains all shape border properties. */
205 struct StrokeModel
207 std::optional< bool > moStroked; ///< Shape border line on/off.
208 StrokeArrowModel maStartArrow; ///< Start line arrow style.
209 StrokeArrowModel maEndArrow; ///< End line arrow style.
210 std::optional< OUString > moColor; ///< Solid line color.
211 std::optional< double > moOpacity; ///< Solid line color opacity.
212 std::optional< OUString > moWeight; ///< Line width.
213 std::optional< OUString > moDashStyle; ///< Line dash (predefined or manually).
214 std::optional< sal_Int32 > moLineStyle; ///< Line style (single, double, ...).
215 std::optional< sal_Int32 > moEndCap; ///< Type of line end cap.
216 std::optional< sal_Int32 > moJoinStyle; ///< Type of line join.
218 void assignUsed( const StrokeModel& rSource );
220 /** Writes the properties to the passed property map. */
221 void pushToPropMap(
222 ::oox::drawingml::ShapePropertyMap& rPropMap,
223 const GraphicHelper& rGraphicHelper ) const;
227 /** The fill model structure contains all shape fill properties. */
228 struct OOX_DLLPUBLIC FillModel
230 std::optional< bool > moFilled; ///< Shape fill on/off.
231 std::optional< OUString > moColor; ///< Solid fill color.
232 std::optional< double > moOpacity; ///< Solid fill color opacity.
233 std::optional< OUString > moColor2; ///< End color of gradient.
234 std::optional< double > moOpacity2; ///< End color opacity of gradient.
235 std::optional< sal_Int32 > moType; ///< Fill type.
236 std::optional< sal_Int32 > moAngle; ///< Gradient rotation angle.
237 std::optional< double > moFocus; ///< Linear gradient focus of second color.
238 std::optional< DoublePair > moFocusPos; ///< Rectangular gradient focus position of second color.
239 std::optional< DoublePair > moFocusSize; ///< Rectangular gradient focus size of second color.
240 std::optional< OUString > moBitmapPath; ///< Path to fill bitmap fragment.
241 std::optional< bool > moRotate; ///< True = rotate gradient/bitmap with shape.
243 void assignUsed( const FillModel& rSource );
245 /** Writes the properties to the passed property map. */
246 void pushToPropMap(
247 ::oox::drawingml::ShapePropertyMap& rPropMap,
248 const GraphicHelper& rGraphicHelper ) const;
252 /** The shadow model structure contains all shape shadow properties. */
253 struct OOX_DLLPUBLIC ShadowModel
255 bool mbHasShadow; ///< Is a v:shadow element seen?
256 std::optional<bool> moShadowOn; ///< Is the element turned on?
257 std::optional<OUString> moColor; ///< Specifies the color of the shadow.
258 std::optional<OUString> moOffset; ///< Specifies the shadow's offset from the shape's location.
259 std::optional<double> moOpacity; ///< Specifies the opacity of the shadow.
261 ShadowModel();
263 /** Writes the properties to the passed property map. */
264 void pushToPropMap(oox::drawingml::ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper) const;
267 /** The shadow model structure contains all shape textpath properties. */
268 struct TextpathModel
270 std::optional<OUString> moString; ///< Specifies the string of the textpath.
271 std::optional<OUString> moStyle; ///< Specifies the style of the textpath.
272 std::optional<bool> moTrim; ///< Specifies whether extra space is removed above and below the text
274 TextpathModel();
276 /** Writes the properties to the passed property map. */
277 void pushToPropMap(oox::drawingml::ShapePropertyMap& rPropMap, const css::uno::Reference<css::drawing::XShape>& xShape,
278 const GraphicHelper& rGraphicHelper) const;
281 } // namespace oox::vml
283 #endif
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */