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