1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/drawingml/drawingmltypes.hxx"
21 #include <com/sun/star/awt/FontUnderline.hpp>
22 #include <com/sun/star/awt/FontStrikeout.hpp>
23 #include <com/sun/star/style/CaseMap.hpp>
24 #include <com/sun/star/style/ParagraphAdjust.hpp>
25 #include <osl/diagnose.h>
26 #include <sax/tools/converter.hxx>
27 #include "oox/token/tokens.hxx"
29 using ::com::sun::star::uno::Reference
;
30 using ::com::sun::star::xml::sax::XFastAttributeList
;
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::drawing
;
33 using namespace ::com::sun::star::geometry
;
34 using namespace ::com::sun::star::style
;
39 /** converts EMUs into 1/100th mmm */
40 sal_Int32
GetCoordinate( sal_Int32 nValue
)
42 return (nValue
+ 180) / 360;
45 /** converts an emu string into 1/100th mmm */
46 sal_Int32
GetCoordinate( const OUString
& sValue
)
49 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
51 return GetCoordinate( nRet
);
54 /** converts a ST_Percentage % string into 1/1000th of % */
55 sal_Int32
GetPercent( const OUString
& sValue
)
58 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
64 double GetPositiveFixedPercentage( const OUString
& sValue
)
66 double fPercent
= sValue
.toFloat() / 100000.;
70 /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
71 awt::Point
GetPointPercent( const Reference
< XFastAttributeList
>& xAttribs
)
73 return awt::Point( GetPercent( xAttribs
->getOptionalValue( XML_x
) ), GetCoordinate( xAttribs
->getOptionalValue( XML_y
) ) );
76 /** converts the ST_TextFontSize to point */
77 float GetTextSize( const OUString
& sValue
)
81 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
82 fRet
= static_cast< float >( static_cast< double >( nRet
) / 100.0 );
86 /** converts the ST_TextSpacingPoint to 1/100mm */
87 sal_Int32
GetTextSpacingPoint( const OUString
& sValue
)
90 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
91 nRet
= GetTextSpacingPoint( nRet
);
95 sal_Int32
GetTextSpacingPoint( const sal_Int32 nValue
)
97 return ( nValue
* 254 + 360 ) / 720;
100 float GetFontHeight( sal_Int32 nHeight
)
102 // convert 1/100 points to points
103 return static_cast< float >( nHeight
/ 100.0 );
106 sal_Int16
GetFontUnderline( sal_Int32 nToken
)
108 OSL_ASSERT((nToken
& sal_Int32(0xFFFF0000))==0);
111 case XML_none
: return awt::FontUnderline::NONE
;
112 case XML_dash
: return awt::FontUnderline::DASH
;
113 case XML_dashHeavy
: return awt::FontUnderline::BOLDDASH
;
114 case XML_dashLong
: return awt::FontUnderline::LONGDASH
;
115 case XML_dashLongHeavy
: return awt::FontUnderline::BOLDLONGDASH
;
116 case XML_dbl
: return awt::FontUnderline::DOUBLE
;
117 case XML_dotDash
: return awt::FontUnderline::DASHDOT
;
118 case XML_dotDashHeavy
: return awt::FontUnderline::BOLDDASHDOT
;
119 case XML_dotDotDash
: return awt::FontUnderline::DASHDOTDOT
;
120 case XML_dotDotDashHeavy
: return awt::FontUnderline::BOLDDASHDOTDOT
;
121 case XML_dotted
: return awt::FontUnderline::DOTTED
;
122 case XML_dottedHeavy
: return awt::FontUnderline::BOLDDOTTED
;
123 case XML_heavy
: return awt::FontUnderline::BOLD
;
124 case XML_sng
: return awt::FontUnderline::SINGLE
;
125 case XML_wavy
: return awt::FontUnderline::WAVE
;
126 case XML_wavyDbl
: return awt::FontUnderline::DOUBLEWAVE
;
127 case XML_wavyHeavy
: return awt::FontUnderline::BOLDWAVE
;
128 // case XML_words: // TODO
130 return awt::FontUnderline::DONTKNOW
;
133 sal_Int16
GetFontStrikeout( sal_Int32 nToken
)
135 OSL_ASSERT((nToken
& sal_Int32(0xFFFF0000))==0);
138 case XML_dblStrike
: return awt::FontStrikeout::DOUBLE
;
139 case XML_noStrike
: return awt::FontStrikeout::NONE
;
140 case XML_sngStrike
: return awt::FontStrikeout::SINGLE
;
142 return awt::FontStrikeout::DONTKNOW
;
145 sal_Int16
GetCaseMap( sal_Int32 nToken
)
149 case XML_all
: return CaseMap::UPPERCASE
;
150 case XML_small
: return CaseMap::SMALLCAPS
;
152 return CaseMap::NONE
;
155 /** converts a paragraph align to a ParaAdjust */
156 sal_Int16
GetParaAdjust( sal_Int32 nAlign
)
158 OSL_ASSERT((nAlign
& sal_Int32(0xFFFF0000))==0);
163 nEnum
= ParagraphAdjust_CENTER
;
167 nEnum
= ParagraphAdjust_BLOCK
;
170 nEnum
= ParagraphAdjust_RIGHT
;
174 nEnum
= ParagraphAdjust_STRETCH
;
178 nEnum
= ParagraphAdjust_LEFT
;
184 TextVerticalAdjust
GetTextVerticalAdjust( sal_Int32 nToken
)
186 TextVerticalAdjust aVertAdjust
;
190 aVertAdjust
= TextVerticalAdjust_BOTTOM
;
195 aVertAdjust
= TextVerticalAdjust_CENTER
;
199 aVertAdjust
= TextVerticalAdjust_TOP
;
205 const char* GetTextVerticalAdjust( TextVerticalAdjust eAdjust
)
207 const char* sVerticalAdjust
= 0;
210 case TextVerticalAdjust_BOTTOM
:
211 sVerticalAdjust
= "b";
213 case TextVerticalAdjust_CENTER
:
214 sVerticalAdjust
= "ctr";
216 case TextVerticalAdjust_TOP
:
218 sVerticalAdjust
= "t";
221 return sVerticalAdjust
;
224 TabAlign
GetTabAlign( sal_Int32 aToken
)
226 OSL_ASSERT((aToken
& sal_Int32(0xFFFF0000))==0);
231 nEnum
= TabAlign_CENTER
;
234 nEnum
= TabAlign_DECIMAL
;
237 nEnum
= TabAlign_LEFT
;
240 nEnum
= TabAlign_RIGHT
;
243 nEnum
= TabAlign_DEFAULT
;
249 const char* GetHatchPattern( const drawing::Hatch
& rHatch
)
251 const char* sPattern
= 0;
252 const sal_Int32 nAngle
= rHatch
.Angle
> 1800 ? rHatch
.Angle
- 1800 : rHatch
.Angle
;
253 // Angle ~ 0° (horizontal)
254 if( (nAngle
>= 0 && nAngle
< 225) || nAngle
>= 1575 )
256 switch( rHatch
.Style
)
258 case drawing::HatchStyle_SINGLE
:
260 if( rHatch
.Distance
< 75 )
267 case drawing::HatchStyle_DOUBLE
:
268 case drawing::HatchStyle_TRIPLE
:
270 if( rHatch
.Distance
< 75 )
280 // Angle ~ 45° (upward diagonal)
281 else if( nAngle
< 675 )
283 switch( rHatch
.Style
)
285 case drawing::HatchStyle_SINGLE
:
287 if( rHatch
.Distance
< 75 )
288 sPattern
= "ltUpDiag";
290 sPattern
= "wdUpDiag";
294 case drawing::HatchStyle_DOUBLE
:
295 case drawing::HatchStyle_TRIPLE
:
297 if( rHatch
.Distance
< 75 )
298 sPattern
= "smCheck";
300 sPattern
= "openDmnd";
307 // Angle ~ 90° (vertical)
308 else if( nAngle
< 1125 )
310 switch( rHatch
.Style
)
312 case drawing::HatchStyle_SINGLE
:
314 // dkVert is imported as Distance = 25, ltVert as Distance = 50, export them accordingly.
315 if( rHatch
.Distance
< 50 )
317 else if( rHatch
.Distance
< 75 )
324 case drawing::HatchStyle_DOUBLE
:
325 case drawing::HatchStyle_TRIPLE
:
327 if( rHatch
.Distance
< 75 )
337 // Angle ~ 135° (downward diagonal)
338 else if( nAngle
< 1575 )
340 switch( rHatch
.Style
)
342 case drawing::HatchStyle_SINGLE
:
344 if( rHatch
.Distance
< 75 )
345 sPattern
= "ltDnDiag";
347 sPattern
= "wdDnDiag";
351 case drawing::HatchStyle_DOUBLE
:
352 case drawing::HatchStyle_TRIPLE
:
354 if( rHatch
.Distance
< 75 )
355 sPattern
= "smCheck";
357 sPattern
= "openDmnd";
367 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
368 IntegerRectangle2D
GetRelativeRect( const Reference
< XFastAttributeList
>& xAttribs
)
370 IntegerRectangle2D r
;
372 r
.X1
= xAttribs
->getOptionalValue( XML_l
).toInt32();
373 r
.Y1
= xAttribs
->getOptionalValue( XML_t
).toInt32();
374 r
.X2
= xAttribs
->getOptionalValue( XML_r
).toInt32();
375 r
.Y2
= xAttribs
->getOptionalValue( XML_b
).toInt32();
380 /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
381 awt::Size
GetSize2D( const Reference
< XFastAttributeList
>& xAttribs
)
383 return awt::Size( GetCoordinate( xAttribs
->getOptionalValue( XML_cx
) ), GetCoordinate( xAttribs
->getOptionalValue( XML_cy
) ) );
386 IndexRange
GetIndexRange( const Reference
< XFastAttributeList
>& xAttributes
)
389 range
.start
= xAttributes
->getOptionalValue( XML_st
).toInt32();
390 range
.end
= xAttributes
->getOptionalValue( XML_end
).toInt32();
394 } // namespace drawingml
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */