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 $
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>
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
;
49 // ============================================================================
51 /** converts an emu string into 1/100th mmm but constrain as per ST_TextMargin
54 sal_Int32
GetTextMargin( const OUString
& sValue
)
57 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
61 else if( nRet
> 51206400 )
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
)
78 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
80 return GetCoordinate( nRet
);
83 /** converts a ST_Percentage % string into 1/1000th of % */
84 sal_Int32
GetPercent( const OUString
& sValue
)
87 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
93 double GetPositiveFixedPercentage( const OUString
& sValue
)
95 double fPercent
= sValue
.toFloat() / 100000.;
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
)
120 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
121 fRet
= static_cast< float >( static_cast< double >( nRet
) / 100.0 );
126 /** converts the ST_TextSpacingPoint to 1/100mm */
127 sal_Int32
GetTextSpacingPoint( const OUString
& sValue
)
130 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
131 nRet
= ( nRet
* 254 + 360 ) / 720;
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
)
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
)
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
)
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
)
196 nEnum
= ParagraphAdjust_CENTER
;
200 nEnum
= ParagraphAdjust_BLOCK
;
203 nEnum
= ParagraphAdjust_RIGHT
;
207 nEnum
= ParagraphAdjust_STRETCH
;
211 nEnum
= ParagraphAdjust_LEFT
;
218 TabAlign
GetTabAlign( sal_Int32 aToken
)
224 nEnum
= TabAlign_CENTER
;
227 nEnum
= TabAlign_DECIMAL
;
230 nEnum
= TabAlign_LEFT
;
233 nEnum
= TabAlign_RIGHT
;
236 nEnum
= TabAlign_DEFAULT
;
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();
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
)
268 range
.start
= xAttributes
->getOptionalValue( XML_st
).toInt32();
269 range
.end
= xAttributes
->getOptionalValue( XML_end
).toInt32();
273 // ============================================================================
275 } // namespace drawingml