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