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_DRAWINGML_TYPES_HXX
25 #define OOX_DRAWINGML_TYPES_HXX
26 
27 #include <boost/shared_ptr.hpp>
28 #include <com/sun/star/style/TabAlign.hpp>
29 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
30 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
31 #include <com/sun/star/awt/Point.hpp>
32 #include <com/sun/star/awt/Size.hpp>
33 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
34 #include "oox/helper/helper.hxx"
35 
36 namespace oox {
37 namespace drawingml {
38 
39 // ============================================================================
40 
41 const sal_Int32 PER_PERCENT     = 1000;
42 const sal_Int32 MAX_PERCENT     = 100 * PER_PERCENT;
43 
44 const sal_Int32 PER_DEGREE      = 60000;
45 const sal_Int32 MAX_DEGREE      = 360 * PER_DEGREE;
46 
47 // ============================================================================
48 
49 struct LineProperties;
50 typedef ::boost::shared_ptr< LineProperties > LinePropertiesPtr;
51 
52 struct FillProperties;
53 typedef ::boost::shared_ptr< FillProperties > FillPropertiesPtr;
54 
55 struct GraphicProperties;
56 typedef ::boost::shared_ptr< GraphicProperties > GraphicPropertiesPtr;
57 
58 struct TextCharacterProperties;
59 typedef ::boost::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr;
60 
61 struct TextBodyProperties;
62 typedef ::boost::shared_ptr< TextBodyProperties > TextBodyPropertiesPtr;
63 
64 class TextBody;
65 typedef ::boost::shared_ptr< TextBody > TextBodyPtr;
66 
67 class Shape;
68 typedef ::boost::shared_ptr< Shape > ShapePtr;
69 
70 class Theme;
71 typedef ::boost::shared_ptr< Theme > ThemePtr;
72 
73 // ---------------------------------------------------------------------------
74 
75 namespace table {
76 
77 class TableProperties;
78 typedef ::boost::shared_ptr< TableProperties > TablePropertiesPtr;
79 
80 } // namespace table
81 
82 // ============================================================================
83 
84 /** converts the attributes from an CT_Point2D into an awt Point with 1/100th mm */
85 com::sun::star::awt::Point GetPoint2D( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
86 
87 /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
88 com::sun::star::awt::Point GetPointPercent( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs );
89 
90 
91 /** converts the attributes from an CT_Size2D into an awt Size with 1/100th mm */
92 com::sun::star::awt::Size GetSize2D( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
93 
94 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
95 com::sun::star::geometry::IntegerRectangle2D GetRelativeRect( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
96 
97 /** converts an emu string into 1/100th mmm but constrain as per ST_TextMargin
98  * see 5.1.12.73
99  */
100 sal_Int32 GetTextMargin( const ::rtl::OUString& sValue );
101 
102 /** converts EMUs into 1/100th mmm */
103 sal_Int32 GetCoordinate( sal_Int32 nValue );
104 
105 /** converts an emu string into 1/100th mmm */
106 sal_Int32 GetCoordinate( const ::rtl::OUString& sValue );
107 
108 /** converts a ST_Percentage % string into 1/1000th of % */
109 sal_Int32 GetPercent( const ::rtl::OUString& sValue );
110 
111 /** Converts a ST_PositiveFixedPercentage to a float. 1.0 == 100% */
112 double GetPositiveFixedPercentage( const ::rtl::OUString& sValue );
113 
114 /** converts the ST_TextFontSize to point */
115 float GetTextSize( const ::rtl::OUString& rValue );
116 
117 /** converts the ST_TextSpacingPoint to 1/100mm */
118 sal_Int32 GetTextSpacingPoint(  const ::rtl::OUString& sValue );
119 sal_Int32 GetTextSpacingPoint(  const sal_Int32 nValue );
120 
121 ::com::sun::star::drawing::TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken );
122 
123 /** */
124 ::com::sun::star::style::TabAlign GetTabAlign( ::sal_Int32 aToken );
125 
126 float GetFontHeight( sal_Int32 nHeight );
127 
128 sal_Int16 GetFontUnderline( sal_Int32 nToken );
129 
130 sal_Int16 GetFontStrikeout( sal_Int32 nToken );
131 
132 sal_Int16 GetCaseMap( sal_Int32 nToken );
133 
134 /** converts a paragraph align to a ParaAdjust */
135 sal_Int16 GetParaAdjust( sal_Int32 nAlign );
136 
137 // ============================================================================
138 
139 // CT_IndexRange
140 struct IndexRange {
141 	sal_Int32 start;
142 	sal_Int32 end;
143 };
144 
145 /** retrieve the content of CT_IndexRange */
146 IndexRange GetIndexRange( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
147 
148 // ============================================================================
149 
150 const sal_Int32 EMU_PER_HMM = 360;      /// 360 EMUs per 1/100 mm.
151 
152 /** Converts the passed 32-bit integer value from 1/100 mm to EMUs. */
convertHmmToEmu(sal_Int32 nValue)153 inline sal_Int64 convertHmmToEmu( sal_Int32 nValue )
154 {
155     return static_cast< sal_Int64 >( nValue ) * EMU_PER_HMM;
156 }
157 
158 /** Converts the passed 64-bit integer value from EMUs to 1/100 mm. */
convertEmuToHmm(sal_Int64 nValue)159 inline sal_Int32 convertEmuToHmm( sal_Int64 nValue )
160 {
161     return getLimitedValue< sal_Int32, sal_Int64 >( (nValue + EMU_PER_HMM / 2) / EMU_PER_HMM, 0, SAL_MAX_INT32 );
162 }
163 
164 // ============================================================================
165 
166 /** A structure for a point with 64-bit integer components. */
167 struct EmuPoint
168 {
169     sal_Int64           X;
170     sal_Int64           Y;
171 
EmuPointoox::drawingml::EmuPoint172     inline explicit     EmuPoint() : X( 0 ), Y( 0 ) {}
EmuPointoox::drawingml::EmuPoint173     inline explicit     EmuPoint( sal_Int64 nX, sal_Int64 nY ) : X( nX ), Y( nY ) {}
174 };
175 
176 // ============================================================================
177 
178 /** A structure for a size with 64-bit integer components. */
179 struct EmuSize
180 {
181     sal_Int64           Width;
182     sal_Int64           Height;
183 
EmuSizeoox::drawingml::EmuSize184     inline explicit     EmuSize() : Width( 0 ), Height( 0 ) {}
EmuSizeoox::drawingml::EmuSize185     inline explicit     EmuSize( sal_Int64 nWidth, sal_Int64 nHeight ) : Width( nWidth ), Height( nHeight ) {}
186 };
187 
188 // ============================================================================
189 
190 /** A structure for a rectangle with 64-bit integer components. */
191 struct EmuRectangle : public EmuPoint, public EmuSize
192 {
EmuRectangleoox::drawingml::EmuRectangle193     inline explicit     EmuRectangle() {}
EmuRectangleoox::drawingml::EmuRectangle194     inline explicit     EmuRectangle( const EmuPoint& rPos, const EmuSize& rSize ) : EmuPoint( rPos ), EmuSize( rSize ) {}
EmuRectangleoox::drawingml::EmuRectangle195     inline explicit     EmuRectangle( sal_Int64 nX, sal_Int64 nY, sal_Int64 nWidth, sal_Int64 nHeight ) : EmuPoint( nX, nY ), EmuSize( nWidth, nHeight ) {}
196 
setPosoox::drawingml::EmuRectangle197     inline void         setPos( const EmuPoint& rPos ) { static_cast< EmuPoint& >( *this ) = rPos; }
setSizeoox::drawingml::EmuRectangle198     inline void         setSize( const EmuSize& rSize ) { static_cast< EmuSize& >( *this ) = rSize; }
199 };
200 
201 // ============================================================================
202 
203 } // namespace drawingml
204 } // namespace oox
205 
206 #endif
207 
208