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/drawing/Hatch.hpp>
24 #include <com/sun/star/style/CaseMap.hpp>
25 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
26 #include <osl/diagnose.h>
27 #include <sax/tools/converter.hxx>
28 #include "oox/token/tokens.hxx"
30 using ::com::sun::star::uno::Reference
;
31 using ::com::sun::star::xml::sax::XFastAttributeList
;
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::drawing
;
34 using namespace ::com::sun::star::geometry
;
35 using namespace ::com::sun::star::style
;
40 /** converts EMUs into 1/100th mmm */
41 sal_Int32
GetCoordinate( sal_Int32 nValue
)
43 return (nValue
+ 180) / 360;
46 /** converts an emu string into 1/100th mmm */
47 sal_Int32
GetCoordinate( const OUString
& sValue
)
50 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
52 return GetCoordinate( nRet
);
55 /** converts a ST_Percentage % string into 1/1000th of % */
56 sal_Int32
GetPercent( const OUString
& sValue
)
59 if( !::sax::Converter::convertNumber( nRet
, sValue
) )
65 double GetPositiveFixedPercentage( const OUString
& sValue
)
67 double fPercent
= sValue
.toFloat() / 100000.;
71 /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
72 awt::Point
GetPointPercent( const Reference
< XFastAttributeList
>& xAttribs
)
74 return awt::Point( GetPercent( xAttribs
->getOptionalValue( XML_x
) ), GetCoordinate( xAttribs
->getOptionalValue( XML_y
) ) );
77 /** converts the ST_TextFontSize to point */
78 float GetTextSize( const OUString
& sValue
)
82 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
83 fRet
= static_cast< float >( static_cast< double >( nRet
) / 100.0 );
87 /** converts the ST_TextSpacingPoint to 1/100mm */
88 sal_Int32
GetTextSpacingPoint( const OUString
& sValue
)
91 if( ::sax::Converter::convertNumber( nRet
, sValue
) )
92 nRet
= GetTextSpacingPoint( nRet
);
96 sal_Int32
GetTextSpacingPoint( const sal_Int32 nValue
)
98 return ( nValue
* 254 + 360 ) / 720;
101 float GetFontHeight( sal_Int32 nHeight
)
103 // convert 1/100 points to points
104 return static_cast< float >( nHeight
/ 100.0 );
107 sal_Int16
GetFontUnderline( sal_Int32 nToken
)
109 OSL_ASSERT((nToken
& sal_Int32(0xFFFF0000))==0);
112 case XML_none
: return awt::FontUnderline::NONE
;
113 case XML_dash
: return awt::FontUnderline::DASH
;
114 case XML_dashHeavy
: return awt::FontUnderline::BOLDDASH
;
115 case XML_dashLong
: return awt::FontUnderline::LONGDASH
;
116 case XML_dashLongHeavy
: return awt::FontUnderline::BOLDLONGDASH
;
117 case XML_dbl
: return awt::FontUnderline::DOUBLE
;
118 case XML_dotDash
: return awt::FontUnderline::DASHDOT
;
119 case XML_dotDashHeavy
: return awt::FontUnderline::BOLDDASHDOT
;
120 case XML_dotDotDash
: return awt::FontUnderline::DASHDOTDOT
;
121 case XML_dotDotDashHeavy
: return awt::FontUnderline::BOLDDASHDOTDOT
;
122 case XML_dotted
: return awt::FontUnderline::DOTTED
;
123 case XML_dottedHeavy
: return awt::FontUnderline::BOLDDOTTED
;
124 case XML_heavy
: return awt::FontUnderline::BOLD
;
125 case XML_sng
: return awt::FontUnderline::SINGLE
;
126 case XML_wavy
: return awt::FontUnderline::WAVE
;
127 case XML_wavyDbl
: return awt::FontUnderline::DOUBLEWAVE
;
128 case XML_wavyHeavy
: return awt::FontUnderline::BOLDWAVE
;
129 // case XML_words: // TODO
131 return awt::FontUnderline::DONTKNOW
;
134 sal_Int16
GetFontStrikeout( sal_Int32 nToken
)
136 OSL_ASSERT((nToken
& sal_Int32(0xFFFF0000))==0);
139 case XML_dblStrike
: return awt::FontStrikeout::DOUBLE
;
140 case XML_noStrike
: return awt::FontStrikeout::NONE
;
141 case XML_sngStrike
: return awt::FontStrikeout::SINGLE
;
143 return awt::FontStrikeout::DONTKNOW
;
146 sal_Int16
GetCaseMap( sal_Int32 nToken
)
150 case XML_all
: return CaseMap::UPPERCASE
;
151 case XML_small
: return CaseMap::SMALLCAPS
;
153 return CaseMap::NONE
;
156 /** converts a paragraph align to a ParaAdjust */
157 ParagraphAdjust
GetParaAdjust( sal_Int32 nAlign
)
159 OSL_ASSERT((nAlign
& sal_Int32(0xFFFF0000))==0);
160 ParagraphAdjust nEnum
;
164 nEnum
= ParagraphAdjust_CENTER
;
168 nEnum
= ParagraphAdjust_BLOCK
;
171 nEnum
= ParagraphAdjust_RIGHT
;
175 nEnum
= ParagraphAdjust_STRETCH
;
179 nEnum
= ParagraphAdjust_LEFT
;
185 TextVerticalAdjust
GetTextVerticalAdjust( sal_Int32 nToken
)
187 TextVerticalAdjust aVertAdjust
;
191 aVertAdjust
= TextVerticalAdjust_BOTTOM
;
196 aVertAdjust
= TextVerticalAdjust_CENTER
;
200 aVertAdjust
= TextVerticalAdjust_TOP
;
206 const char* GetTextVerticalAdjust( TextVerticalAdjust eAdjust
)
208 const char* sVerticalAdjust
= nullptr;
211 case TextVerticalAdjust_BOTTOM
:
212 sVerticalAdjust
= "b";
214 case TextVerticalAdjust_CENTER
:
215 sVerticalAdjust
= "ctr";
217 case TextVerticalAdjust_TOP
:
219 sVerticalAdjust
= "t";
222 return sVerticalAdjust
;
225 TabAlign
GetTabAlign( sal_Int32 aToken
)
227 OSL_ASSERT((aToken
& sal_Int32(0xFFFF0000))==0);
232 nEnum
= TabAlign_CENTER
;
235 nEnum
= TabAlign_DECIMAL
;
238 nEnum
= TabAlign_LEFT
;
241 nEnum
= TabAlign_RIGHT
;
244 nEnum
= TabAlign_DEFAULT
;
250 const char* GetHatchPattern( const drawing::Hatch
& rHatch
)
252 const char* sPattern
= nullptr;
253 const sal_Int32 nAngle
= rHatch
.Angle
> 1800 ? rHatch
.Angle
- 1800 : rHatch
.Angle
;
254 // Angle ~ 0° (horizontal)
255 if( (nAngle
>= 0 && nAngle
< 225) || nAngle
>= 1575 )
257 switch( rHatch
.Style
)
259 case drawing::HatchStyle_SINGLE
:
261 if( rHatch
.Distance
< 75 )
268 case drawing::HatchStyle_DOUBLE
:
269 case drawing::HatchStyle_TRIPLE
:
271 if( rHatch
.Distance
< 75 )
281 // Angle ~ 45° (upward diagonal)
282 else if( nAngle
< 675 )
284 switch( rHatch
.Style
)
286 case drawing::HatchStyle_SINGLE
:
288 if( rHatch
.Distance
< 75 )
289 sPattern
= "ltUpDiag";
291 sPattern
= "wdUpDiag";
295 case drawing::HatchStyle_DOUBLE
:
296 case drawing::HatchStyle_TRIPLE
:
298 if( rHatch
.Distance
< 75 )
299 sPattern
= "smCheck";
301 sPattern
= "openDmnd";
308 // Angle ~ 90° (vertical)
309 else if( nAngle
< 1125 )
311 switch( rHatch
.Style
)
313 case drawing::HatchStyle_SINGLE
:
315 // dkVert is imported as Distance = 25, ltVert as Distance = 50, export them accordingly.
316 if( rHatch
.Distance
< 50 )
318 else if( rHatch
.Distance
< 75 )
325 case drawing::HatchStyle_DOUBLE
:
326 case drawing::HatchStyle_TRIPLE
:
328 if( rHatch
.Distance
< 75 )
338 // Angle ~ 135° (downward diagonal)
339 else if( nAngle
< 1575 )
341 switch( rHatch
.Style
)
343 case drawing::HatchStyle_SINGLE
:
345 if( rHatch
.Distance
< 75 )
346 sPattern
= "ltDnDiag";
348 sPattern
= "wdDnDiag";
352 case drawing::HatchStyle_DOUBLE
:
353 case drawing::HatchStyle_TRIPLE
:
355 if( rHatch
.Distance
< 75 )
356 sPattern
= "smCheck";
358 sPattern
= "openDmnd";
368 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
369 IntegerRectangle2D
GetRelativeRect( const Reference
< XFastAttributeList
>& xAttribs
)
371 IntegerRectangle2D r
;
373 r
.X1
= xAttribs
->getOptionalValue( XML_l
).toInt32();
374 r
.Y1
= xAttribs
->getOptionalValue( XML_t
).toInt32();
375 r
.X2
= xAttribs
->getOptionalValue( XML_r
).toInt32();
376 r
.Y2
= xAttribs
->getOptionalValue( XML_b
).toInt32();
381 /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
382 awt::Size
GetSize2D( const Reference
< XFastAttributeList
>& xAttribs
)
384 return awt::Size( GetCoordinate( xAttribs
->getOptionalValue( XML_cx
) ), GetCoordinate( xAttribs
->getOptionalValue( XML_cy
) ) );
387 IndexRange
GetIndexRange( const Reference
< XFastAttributeList
>& xAttributes
)
390 range
.start
= xAttributes
->getOptionalValue( XML_st
).toInt32();
391 range
.end
= xAttributes
->getOptionalValue( XML_end
).toInt32();
395 } // namespace drawingml
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */