xref: /aoo4110/main/oox/inc/oox/vml/vmlformatting.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_VML_VMLFORMATTING_HXX
25 #define OOX_VML_VMLFORMATTING_HXX
26 
27 #include "oox/helper/helper.hxx"
28 
29 namespace oox {
30     class GraphicHelper;
31     namespace drawingml { class Color; }
32     namespace drawingml { class ShapePropertyMap; }
33 }
34 
35 namespace oox {
36 namespace vml {
37 
38 // ============================================================================
39 
40 typedef ::std::pair< sal_Int32, sal_Int32 > Int32Pair;
41 typedef ::std::pair< double, double >       DoublePair;
42 
43 // ============================================================================
44 
45 class ConversionHelper
46 {
47 public:
48     /** Returns two values contained in rValue separated by cSep.
49      */
50     static bool         separatePair(
51                             ::rtl::OUString& orValue1, ::rtl::OUString& orValue2,
52                             const ::rtl::OUString& rValue, sal_Unicode cSep );
53 
54     /** Returns the boolean value from the passed string of a VML attribute.
55         Supported values: 'f', 't', 'false', 'true'. False for anything else.
56      */
57     static bool         decodeBool( const ::rtl::OUString& rValue );
58 
59     /** Converts the passed VML percentage measure string to a normalized
60         floating-point value.
61 
62         @param rValue  The VML percentage value. This is a floating-point value
63             with optional following '%' sign. If the '%' sign is missing, the
64             floating point value will be returned unmodified. If the '%' sign
65             is present, the value will be divided by 100.
66      */
67     static double       decodePercent(
68                             const ::rtl::OUString& rValue,
69                             double fDefValue );
70 
71     /** Converts the passed VML measure string to EMU (English Metric Units).
72 
73         @param rGraphicHelper  The graphic helper needed to perform pixel
74             conversion according to the current output device.
75 
76         @param rValue  The VML measure value. This is a floating-point value
77             with optional measure string following the value.
78 
79         @param nRefValue  Reference value needed for percentage measure.
80 
81         @param bPixelX  Set to true if the value is oriented horizontally (e.g.
82             X coordinates, widths). Set to false if the value is oriented
83             vertically (e.g. Y coordinates, heights). This is needed because
84             output devices may specify different width and height for a pixel.
85 
86         @param bDefaultAsPixel  Set to true if omitted measure unit means
87             pixel. Set to false if omitted measure unit means EMU.
88      */
89     static sal_Int64    decodeMeasureToEmu(
90                             const GraphicHelper& rGraphicHelper,
91                             const ::rtl::OUString& rValue,
92                             sal_Int32 nRefValue,
93                             bool bPixelX,
94                             bool bDefaultAsPixel );
95 
96     /** Converts the passed VML measure string to 1/100 mm.
97 
98         @param rGraphicHelper  See above.
99         @param rValue  See above.
100         @param nRefValue  See above.
101         @param bPixelX  See above.
102         @param bDefaultAsPixel  See above.
103      */
104     static sal_Int32    decodeMeasureToHmm(
105                             const GraphicHelper& rGraphicHelper,
106                             const ::rtl::OUString& rValue,
107                             sal_Int32 nRefValue,
108                             bool bPixelX,
109                             bool bDefaultAsPixel );
110 
111     /** Converts VML color attributes to a DrawingML color.
112 
113         @param roVmlColor  The VML string representation of the color. If
114             existing, this can be a 3-digit or 6-digit hexadecimal RGB value
115             with leading '#' character, a predefined color name (e.g. 'black',
116             'red', etc.), the index into an application defined color palette
117             in brackets with leading color name (e.g. 'red [9]' or
118             'windowColor [64]'), or a color modifier used in one-color
119             gradients (e.g. 'fill darken(128)' or 'fill lighten(0)').
120 
121         @param roVmlOpacity  The opacity of the color. If existing, this should
122             be a floating-point value in the range [0.0;1.0].
123 
124         @param nDefaultRgb  Deafult RGB color used if the parameter roVmlColor
125             is empty.
126 
127         @param nPrimaryRgb  If set to something else than API_RGB_TRANSPARENT,
128             specifies the color to be used to resolve the color modifiers used
129             in one-color gradients.
130 
131         @return  The resulting DrawingML color.
132      */
133     static ::oox::drawingml::Color decodeColor(
134                             const GraphicHelper& rGraphicHelper,
135                             const OptValue< ::rtl::OUString >& roVmlColor,
136                             const OptValue< double >& roVmlOpacity,
137                             sal_Int32 nDefaultRgb,
138                             sal_Int32 nPrimaryRgb = API_RGB_TRANSPARENT );
139 
140 private:
141                         ConversionHelper();
142                         ~ConversionHelper();
143 };
144 
145 // ============================================================================
146 
147 /** The stroke arrow model structure contains all properties for an line end arrow. */
148 struct StrokeArrowModel
149 {
150     OptValue< sal_Int32 > moArrowType;
151     OptValue< sal_Int32 > moArrowWidth;
152     OptValue< sal_Int32 > moArrowLength;
153 
154     void                assignUsed( const StrokeArrowModel& rSource );
155 };
156 
157 // ============================================================================
158 
159 /** The stroke model structure contains all shape border properties. */
160 struct StrokeModel
161 {
162     OptValue< bool >    moStroked;              /// Shape border line on/off.
163     StrokeArrowModel    maStartArrow;           /// Start line arrow style.
164     StrokeArrowModel    maEndArrow;             /// End line arrow style.
165     OptValue< ::rtl::OUString > moColor;        /// Solid line color.
166     OptValue< double > moOpacity;               /// Solid line color opacity.
167     OptValue< ::rtl::OUString > moWeight;       /// Line width.
168     OptValue< ::rtl::OUString > moDashStyle;    /// Line dash (predefined or manually).
169     OptValue< sal_Int32 > moLineStyle;          /// Line style (single, double, ...).
170     OptValue< sal_Int32 > moEndCap;             /// Type of line end cap.
171     OptValue< sal_Int32 > moJoinStyle;          /// Type of line join.
172 
173     void                assignUsed( const StrokeModel& rSource );
174 
175     /** Writes the properties to the passed property map. */
176     void                pushToPropMap(
177                             ::oox::drawingml::ShapePropertyMap& rPropMap,
178                             const GraphicHelper& rGraphicHelper ) const;
179 };
180 
181 // ============================================================================
182 
183 /** The fill model structure contains all shape fill properties. */
184 struct FillModel
185 {
186     OptValue< bool >    moFilled;               /// Shape fill on/off.
187     OptValue< ::rtl::OUString > moColor;        /// Solid fill color.
188     OptValue< double >  moOpacity;              /// Solid fill color opacity.
189     OptValue< ::rtl::OUString > moColor2;       /// End color of gradient.
190     OptValue< double >  moOpacity2;             /// End color opycity of gradient.
191     OptValue< sal_Int32 > moType;               /// Fill type.
192     OptValue< sal_Int32 > moAngle;              /// Gradient rotation angle.
193     OptValue< double >  moFocus;                /// Linear gradient focus of second color.
194     OptValue< DoublePair > moFocusPos;          /// Rectanguar gradient focus position of second color.
195     OptValue< DoublePair > moFocusSize;         /// Rectanguar gradient focus size of second color.
196     OptValue< ::rtl::OUString > moBitmapPath;   /// Path to fill bitmap fragment.
197     OptValue< bool >    moRotate;               /// True = rotate gradient/bitmap with shape.
198 
199     void                assignUsed( const FillModel& rSource );
200 
201     /** Writes the properties to the passed property map. */
202     void                pushToPropMap(
203                             ::oox::drawingml::ShapePropertyMap& rPropMap,
204                             const GraphicHelper& rGraphicHelper ) const;
205 };
206 
207 // ============================================================================
208 
209 } // namespace vml
210 } // namespace oox
211 
212 #endif
213