Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_OOX_DRAWINGML_DRAWINGMLTYPES_HXX
21 : #define INCLUDED_OOX_DRAWINGML_DRAWINGMLTYPES_HXX
22 :
23 : #include <memory>
24 : #include <com/sun/star/style/TabAlign.hpp>
25 : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
26 : #include <com/sun/star/drawing/Hatch.hpp>
27 : #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
28 : #include <com/sun/star/awt/Point.hpp>
29 : #include <com/sun/star/awt/Size.hpp>
30 : #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
31 :
32 : #include <oox/dllapi.h>
33 : #include <oox/helper/helper.hxx>
34 :
35 : namespace oox {
36 : namespace drawingml {
37 :
38 :
39 :
40 : const sal_Int32 PER_PERCENT = 1000;
41 : const sal_Int32 MAX_PERCENT = 100 * PER_PERCENT;
42 :
43 : const sal_Int32 PER_DEGREE = 60000;
44 : const sal_Int32 MAX_DEGREE = 360 * PER_DEGREE;
45 :
46 :
47 :
48 : struct LineProperties;
49 : typedef std::shared_ptr< LineProperties > LinePropertiesPtr;
50 :
51 : struct FillProperties;
52 : typedef std::shared_ptr< FillProperties > FillPropertiesPtr;
53 :
54 : struct GraphicProperties;
55 : typedef std::shared_ptr< GraphicProperties > GraphicPropertiesPtr;
56 :
57 : struct Shape3DProperties;
58 : typedef std::shared_ptr< Shape3DProperties > Shape3DPropertiesPtr;
59 :
60 : struct TextCharacterProperties;
61 : typedef std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr;
62 :
63 : struct TextBodyProperties;
64 :
65 : struct EffectProperties;
66 : typedef std::shared_ptr< EffectProperties > EffectPropertiesPtr;
67 :
68 : class TextBody;
69 : typedef std::shared_ptr< TextBody > TextBodyPtr;
70 :
71 : class TextListStyle;
72 : typedef std::shared_ptr< TextListStyle > TextListStylePtr;
73 :
74 : class Shape;
75 : typedef std::shared_ptr< Shape > ShapePtr;
76 :
77 : class Theme;
78 : typedef std::shared_ptr< Theme > ThemePtr;
79 :
80 :
81 :
82 : namespace table {
83 :
84 : class TableProperties;
85 : typedef std::shared_ptr< TableProperties > TablePropertiesPtr;
86 :
87 : } // namespace table
88 :
89 :
90 :
91 : /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
92 : com::sun::star::awt::Point GetPointPercent( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs );
93 :
94 :
95 : /** converts the attributes from an CT_Size2D into an awt Size with 1/100th mm */
96 : com::sun::star::awt::Size GetSize2D( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
97 :
98 : /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
99 : com::sun::star::geometry::IntegerRectangle2D GetRelativeRect( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
100 :
101 : /** converts EMUs into 1/100th mmm */
102 : sal_Int32 GetCoordinate( sal_Int32 nValue );
103 :
104 : /** converts an emu string into 1/100th mmm */
105 : sal_Int32 GetCoordinate( const OUString& sValue );
106 :
107 : /** converts a ST_Percentage % string into 1/1000th of % */
108 : sal_Int32 GetPercent( const OUString& sValue );
109 :
110 : /** Converts a ST_PositiveFixedPercentage to a float. 1.0 == 100% */
111 : double GetPositiveFixedPercentage( const OUString& sValue );
112 :
113 : /** converts the ST_TextFontSize to point */
114 : float GetTextSize( const OUString& rValue );
115 :
116 : /** converts the ST_TextSpacingPoint to 1/100mm */
117 : sal_Int32 GetTextSpacingPoint( const OUString& sValue );
118 : sal_Int32 GetTextSpacingPoint( const sal_Int32 nValue );
119 :
120 : /** */
121 : ::com::sun::star::style::TabAlign GetTabAlign( ::sal_Int32 aToken );
122 :
123 : float GetFontHeight( sal_Int32 nHeight );
124 :
125 : sal_Int16 GetFontUnderline( sal_Int32 nToken );
126 :
127 : sal_Int16 GetFontStrikeout( sal_Int32 nToken );
128 :
129 : sal_Int16 GetCaseMap( sal_Int32 nToken );
130 :
131 : /** converts a paragraph align to a ParaAdjust */
132 : sal_Int16 GetParaAdjust( sal_Int32 nAlign );
133 :
134 : // Converts vertical adjust tokens to a TextVerticalAdjust item
135 : ::com::sun::star::drawing::TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken );
136 :
137 : // Converts a TextVerticalAdjust item to string value appearing in ooxml
138 : OOX_DLLPUBLIC const char* GetTextVerticalAdjust( ::com::sun::star::drawing::TextVerticalAdjust eAdjust );
139 :
140 : // Converts a Hatch object to an ooxml pattern.
141 : const char* GetHatchPattern( const ::com::sun::star::drawing::Hatch& rHatch );
142 :
143 :
144 :
145 : // CT_IndexRange
146 : struct IndexRange {
147 : sal_Int32 start;
148 : sal_Int32 end;
149 : };
150 :
151 : /** retrieve the content of CT_IndexRange */
152 : IndexRange GetIndexRange( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes );
153 :
154 :
155 :
156 : const sal_Int32 EMU_PER_HMM = 360; /// 360 EMUs per 1/100 mm.
157 :
158 : /** Converts the passed 32-bit integer value from 1/100 mm to EMUs. */
159 12995 : inline sal_Int64 convertHmmToEmu( sal_Int32 nValue )
160 : {
161 12995 : return static_cast< sal_Int64 >( nValue ) * EMU_PER_HMM;
162 : }
163 :
164 : /** Converts the passed 64-bit integer value from EMUs to 1/100 mm. */
165 26879 : inline sal_Int32 convertEmuToHmm( sal_Int64 nValue )
166 : {
167 26879 : sal_Int32 nCorrection = (nValue > 0 ? 1 : -1) * EMU_PER_HMM / 2; // So that the implicit floor will round.
168 26879 : return getLimitedValue< sal_Int32, sal_Int64 >( (nValue + nCorrection) / EMU_PER_HMM, SAL_MIN_INT32, SAL_MAX_INT32 );
169 : }
170 :
171 :
172 :
173 : /** A structure for a point with 64-bit integer components. */
174 : struct EmuPoint
175 : {
176 : sal_Int64 X;
177 : sal_Int64 Y;
178 :
179 1 : EmuPoint() : X( 0 ), Y( 0 ) {}
180 401 : explicit EmuPoint( sal_Int64 nX, sal_Int64 nY ) : X( nX ), Y( nY ) {}
181 : };
182 :
183 :
184 :
185 : /** A structure for a size with 64-bit integer components. */
186 : struct EmuSize
187 : {
188 : sal_Int64 Width;
189 : sal_Int64 Height;
190 :
191 1 : EmuSize() : Width( 0 ), Height( 0 ) {}
192 302 : explicit EmuSize( sal_Int64 nWidth, sal_Int64 nHeight ) : Width( nWidth ), Height( nHeight ) {}
193 : };
194 :
195 :
196 :
197 : /** A structure for a rectangle with 64-bit integer components. */
198 : struct EmuRectangle : public EmuPoint, public EmuSize
199 : {
200 1 : EmuRectangle() {}
201 : explicit EmuRectangle( const EmuPoint& rPos, const EmuSize& rSize ) : EmuPoint( rPos ), EmuSize( rSize ) {}
202 101 : explicit EmuRectangle( sal_Int64 nX, sal_Int64 nY, sal_Int64 nWidth, sal_Int64 nHeight ) : EmuPoint( nX, nY ), EmuSize( nWidth, nHeight ) {}
203 :
204 100 : void setPos( const EmuPoint& rPos ) { static_cast< EmuPoint& >( *this ) = rPos; }
205 0 : void setSize( const EmuSize& rSize ) { static_cast< EmuSize& >( *this ) = rSize; }
206 : };
207 :
208 :
209 :
210 : } // namespace drawingml
211 : } // namespace oox
212 :
213 : #endif
214 :
215 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|