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