update dev300-m58
[ooovba.git] / oox / source / drawingml / drawingmltypes.cxx
blob86231ffda98de2c74c33242927ac7fcf95cfd259
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawingmltypes.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/drawingml/drawingmltypes.hxx"
32 #include <com/sun/star/awt/FontUnderline.hpp>
33 #include <com/sun/star/awt/FontStrikeout.hpp>
34 #include <com/sun/star/style/CaseMap.hpp>
35 #include <com/sun/star/style/ParagraphAdjust.hpp>
36 #include <sax/tools/converter.hxx>
37 #include "tokens.hxx"
39 using ::rtl::OUString;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::xml::sax::XFastAttributeList;
42 using namespace ::com::sun::star::awt;
43 using namespace ::com::sun::star::style;
44 using namespace ::com::sun::star::geometry;
46 namespace oox {
47 namespace drawingml {
49 // ============================================================================
51 /** converts an emu string into 1/100th mmm but constrain as per ST_TextMargin
52 * see 5.1.12.73
54 sal_Int32 GetTextMargin( const OUString& sValue )
56 sal_Int32 nRet = 0;
57 if( !::sax::Converter::convertNumber( nRet, sValue ) )
58 nRet = 0;
59 else if( nRet < 0 )
60 nRet = 0;
61 else if( nRet > 51206400 )
62 nRet = 51206400;
64 nRet /= 360;
65 return nRet;
68 /** converts EMUs into 1/100th mmm */
69 sal_Int32 GetCoordinate( sal_Int32 nValue )
71 return (nValue + 180) / 360;
74 /** converts an emu string into 1/100th mmm */
75 sal_Int32 GetCoordinate( const OUString& sValue )
77 sal_Int32 nRet = 0;
78 if( !::sax::Converter::convertNumber( nRet, sValue ) )
79 nRet = 0;
80 return GetCoordinate( nRet );
83 /** converts a ST_Percentage % string into 1/1000th of % */
84 sal_Int32 GetPercent( const OUString& sValue )
86 sal_Int32 nRet = 0;
87 if( !::sax::Converter::convertNumber( nRet, sValue ) )
88 nRet = 0;
90 return nRet;
93 double GetPositiveFixedPercentage( const OUString& sValue )
95 double fPercent = sValue.toFloat() / 100000.;
96 return fPercent;
99 // --------------------------------------------------------------------
101 /** converts the attributes from an CT_Point2D into an awt Point with 1/100thmm */
102 Point GetPoint2D( const Reference< XFastAttributeList >& xAttribs )
104 return Point( GetCoordinate( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
107 /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
108 Point GetPointPercent( const Reference< XFastAttributeList >& xAttribs )
110 return Point( GetPercent( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
113 // --------------------------------------------------------------------
115 /** converts the ST_TextFontSize to point */
116 float GetTextSize( const OUString& sValue )
118 float fRet = 0;
119 sal_Int32 nRet;
120 if( ::sax::Converter::convertNumber( nRet, sValue ) )
121 fRet = static_cast< float >( static_cast< double >( nRet ) / 100.0 );
122 return fRet;
126 /** converts the ST_TextSpacingPoint to 1/100mm */
127 sal_Int32 GetTextSpacingPoint( const OUString& sValue )
129 sal_Int32 nRet;
130 if( ::sax::Converter::convertNumber( nRet, sValue ) )
131 nRet = ( nRet * 254 + 360 ) / 720;
132 return nRet;
136 float GetFontHeight( sal_Int32 nHeight )
138 // convert 1/100 points to points
139 return static_cast< float >( nHeight / 100.0 );
142 sal_Int16 GetFontUnderline( sal_Int32 nToken )
144 switch( nToken )
146 case XML_none: return FontUnderline::NONE;
147 case XML_dash: return FontUnderline::DASH;
148 case XML_dashHeavy: return FontUnderline::BOLDDASH;
149 case XML_dashLong: return FontUnderline::LONGDASH;
150 case XML_dashLongHeavy: return FontUnderline::BOLDLONGDASH;
151 case XML_dbl: return FontUnderline::DOUBLE;
152 case XML_dotDash: return FontUnderline::DASHDOT;
153 case XML_dotDashHeavy: return FontUnderline::BOLDDASHDOT;
154 case XML_dotDotDash: return FontUnderline::DASHDOTDOT;
155 case XML_dotDotDashHeavy: return FontUnderline::BOLDDASHDOTDOT;
156 case XML_dotted: return FontUnderline::DOTTED;
157 case XML_dottedHeavy: return FontUnderline::BOLDDOTTED;
158 case XML_heavy: return FontUnderline::BOLD;
159 case XML_sng: return FontUnderline::SINGLE;
160 case XML_wavy: return FontUnderline::WAVE;
161 case XML_wavyDbl: return FontUnderline::DOUBLEWAVE;
162 case XML_wavyHeavy: return FontUnderline::BOLDWAVE;
163 // case XML_words: // TODO
165 return FontUnderline::DONTKNOW;
168 sal_Int16 GetFontStrikeout( sal_Int32 nToken )
170 switch( nToken )
172 case XML_dblStrike: return FontStrikeout::DOUBLE;
173 case XML_noStrike: return FontStrikeout::NONE;
174 case XML_sngStrike: return FontStrikeout::SINGLE;
176 return FontStrikeout::DONTKNOW;
179 sal_Int16 GetCaseMap( sal_Int32 nToken )
181 switch( nToken )
183 case XML_all: return CaseMap::UPPERCASE;
184 case XML_small: return CaseMap::SMALLCAPS;
186 return CaseMap::NONE;
189 /** converts a paragraph align to a ParaAdjust */
190 sal_Int16 GetParaAdjust( sal_Int32 nAlign )
192 sal_Int16 nEnum;
193 switch( nAlign )
195 case XML_ctr:
196 nEnum = ParagraphAdjust_CENTER;
197 break;
198 case XML_just:
199 case XML_justLow:
200 nEnum = ParagraphAdjust_BLOCK;
201 break;
202 case XML_r:
203 nEnum = ParagraphAdjust_RIGHT;
204 break;
205 case XML_thaiDist:
206 case XML_dist:
207 nEnum = ParagraphAdjust_STRETCH;
208 break;
209 case XML_l:
210 default:
211 nEnum = ParagraphAdjust_LEFT;
212 break;
214 return nEnum;
218 TabAlign GetTabAlign( sal_Int32 aToken )
220 TabAlign nEnum;
221 switch( aToken )
223 case XML_ctr:
224 nEnum = TabAlign_CENTER;
225 break;
226 case XML_dec:
227 nEnum = TabAlign_DECIMAL;
228 break;
229 case XML_l:
230 nEnum = TabAlign_LEFT;
231 break;
232 case XML_r:
233 nEnum = TabAlign_RIGHT;
234 break;
235 default:
236 nEnum = TabAlign_DEFAULT;
237 break;
239 return nEnum;
242 // --------------------------------------------------------------------
244 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
245 IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
247 IntegerRectangle2D r;
249 r.X1 = xAttribs->getOptionalValue( XML_l ).toInt32();
250 r.Y1 = xAttribs->getOptionalValue( XML_t ).toInt32();
251 r.X2 = xAttribs->getOptionalValue( XML_r ).toInt32();
252 r.Y2 = xAttribs->getOptionalValue( XML_b ).toInt32();
254 return r;
257 // ============================================================================
259 /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
260 Size GetSize2D( const Reference< XFastAttributeList >& xAttribs )
262 return Size( GetCoordinate( xAttribs->getOptionalValue( XML_cx ) ), GetCoordinate( xAttribs->getOptionalValue( XML_cy ) ) );
265 IndexRange GetIndexRange( const Reference< XFastAttributeList >& xAttributes )
267 IndexRange range;
268 range.start = xAttributes->getOptionalValue( XML_st ).toInt32();
269 range.end = xAttributes->getOptionalValue( XML_end ).toInt32();
270 return range;
273 // ============================================================================
275 } // namespace drawingml
276 } // namespace oox