Branch data 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 : : #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 <sax/tools/converter.hxx>
26 : : #include "oox/token/tokens.hxx"
27 : :
28 : : using ::rtl::OUString;
29 : : using ::com::sun::star::uno::Reference;
30 : : using ::com::sun::star::xml::sax::XFastAttributeList;
31 : : using namespace ::com::sun::star::awt;
32 : : using namespace ::com::sun::star::drawing;
33 : : using namespace ::com::sun::star::geometry;
34 : : using namespace ::com::sun::star::style;
35 : :
36 : : namespace oox {
37 : : namespace drawingml {
38 : :
39 : : // ============================================================================
40 : :
41 : : /** converts EMUs into 1/100th mmm */
42 : 642 : sal_Int32 GetCoordinate( sal_Int32 nValue )
43 : : {
44 : 642 : return (nValue + 180) / 360;
45 : : }
46 : :
47 : : /** converts an emu string into 1/100th mmm */
48 : 642 : sal_Int32 GetCoordinate( const OUString& sValue )
49 : : {
50 : 642 : sal_Int32 nRet = 0;
51 [ + - ][ - + ]: 642 : if( !::sax::Converter::convertNumber( nRet, sValue ) )
52 : 0 : nRet = 0;
53 : 642 : return GetCoordinate( nRet );
54 : : }
55 : :
56 : : /** converts a ST_Percentage % string into 1/1000th of % */
57 : 162 : sal_Int32 GetPercent( const OUString& sValue )
58 : : {
59 : 162 : sal_Int32 nRet = 0;
60 [ + - ][ - + ]: 162 : if( !::sax::Converter::convertNumber( nRet, sValue ) )
61 : 0 : nRet = 0;
62 : :
63 : 162 : return nRet;
64 : : }
65 : :
66 : 0 : double GetPositiveFixedPercentage( const OUString& sValue )
67 : : {
68 : 0 : double fPercent = sValue.toFloat() / 100000.;
69 : 0 : return fPercent;
70 : : }
71 : :
72 : : // --------------------------------------------------------------------
73 : :
74 : : /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
75 : 0 : Point GetPointPercent( const Reference< XFastAttributeList >& xAttribs )
76 : : {
77 [ # # ][ # # ]: 0 : return Point( GetPercent( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
[ # # ][ # # ]
78 : : }
79 : :
80 : : // --------------------------------------------------------------------
81 : :
82 : : /** converts the ST_TextFontSize to point */
83 : 0 : float GetTextSize( const OUString& sValue )
84 : : {
85 : 0 : float fRet = 0;
86 : : sal_Int32 nRet;
87 [ # # ][ # # ]: 0 : if( ::sax::Converter::convertNumber( nRet, sValue ) )
88 : 0 : fRet = static_cast< float >( static_cast< double >( nRet ) / 100.0 );
89 : 0 : return fRet;
90 : : }
91 : :
92 : :
93 : : /** converts the ST_TextSpacingPoint to 1/100mm */
94 : 0 : sal_Int32 GetTextSpacingPoint( const OUString& sValue )
95 : : {
96 : : sal_Int32 nRet;
97 [ # # ][ # # ]: 0 : if( ::sax::Converter::convertNumber( nRet, sValue ) )
98 : 0 : nRet = GetTextSpacingPoint( nRet );
99 : 0 : return nRet;
100 : : }
101 : :
102 : 207 : sal_Int32 GetTextSpacingPoint( const sal_Int32 nValue )
103 : : {
104 : 207 : return ( nValue * 254 + 360 ) / 720;
105 : : }
106 : :
107 : 216 : float GetFontHeight( sal_Int32 nHeight )
108 : : {
109 : : // convert 1/100 points to points
110 : 216 : return static_cast< float >( nHeight / 100.0 );
111 : : }
112 : :
113 : 207 : sal_Int16 GetFontUnderline( sal_Int32 nToken )
114 : : {
115 : : OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
116 [ + - - - : 207 : switch( nToken )
- - - - -
- - - - +
- - - - ]
117 : : {
118 : 201 : case XML_none: return FontUnderline::NONE;
119 : 0 : case XML_dash: return FontUnderline::DASH;
120 : 0 : case XML_dashHeavy: return FontUnderline::BOLDDASH;
121 : 0 : case XML_dashLong: return FontUnderline::LONGDASH;
122 : 0 : case XML_dashLongHeavy: return FontUnderline::BOLDLONGDASH;
123 : 0 : case XML_dbl: return FontUnderline::DOUBLE;
124 : 0 : case XML_dotDash: return FontUnderline::DASHDOT;
125 : 0 : case XML_dotDashHeavy: return FontUnderline::BOLDDASHDOT;
126 : 0 : case XML_dotDotDash: return FontUnderline::DASHDOTDOT;
127 : 0 : case XML_dotDotDashHeavy: return FontUnderline::BOLDDASHDOTDOT;
128 : 0 : case XML_dotted: return FontUnderline::DOTTED;
129 : 0 : case XML_dottedHeavy: return FontUnderline::BOLDDOTTED;
130 : 0 : case XML_heavy: return FontUnderline::BOLD;
131 : 6 : case XML_sng: return FontUnderline::SINGLE;
132 : 0 : case XML_wavy: return FontUnderline::WAVE;
133 : 0 : case XML_wavyDbl: return FontUnderline::DOUBLEWAVE;
134 : 0 : case XML_wavyHeavy: return FontUnderline::BOLDWAVE;
135 : : // case XML_words: // TODO
136 : : }
137 : 207 : return FontUnderline::DONTKNOW;
138 : : }
139 : :
140 : 207 : sal_Int16 GetFontStrikeout( sal_Int32 nToken )
141 : : {
142 : : OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
143 [ - + - - ]: 207 : switch( nToken )
144 : : {
145 : 0 : case XML_dblStrike: return FontStrikeout::DOUBLE;
146 : 207 : case XML_noStrike: return FontStrikeout::NONE;
147 : 0 : case XML_sngStrike: return FontStrikeout::SINGLE;
148 : : }
149 : 207 : return FontStrikeout::DONTKNOW;
150 : : }
151 : :
152 : 207 : sal_Int16 GetCaseMap( sal_Int32 nToken )
153 : : {
154 [ - - + ]: 207 : switch( nToken )
155 : : {
156 : 0 : case XML_all: return CaseMap::UPPERCASE;
157 : 0 : case XML_small: return CaseMap::SMALLCAPS;
158 : : }
159 : 207 : return CaseMap::NONE;
160 : : }
161 : :
162 : : /** converts a paragraph align to a ParaAdjust */
163 : 375 : sal_Int16 GetParaAdjust( sal_Int32 nAlign )
164 : : {
165 : : OSL_ASSERT((nAlign & sal_Int32(0xFFFF0000))==0);
166 : : sal_Int16 nEnum;
167 [ + - + - : 375 : switch( nAlign )
+ ]
168 : : {
169 : : case XML_ctr:
170 : 66 : nEnum = ParagraphAdjust_CENTER;
171 : 66 : break;
172 : : case XML_just:
173 : : case XML_justLow:
174 : 0 : nEnum = ParagraphAdjust_BLOCK;
175 : 0 : break;
176 : : case XML_r:
177 : 15 : nEnum = ParagraphAdjust_RIGHT;
178 : 15 : break;
179 : : case XML_thaiDist:
180 : : case XML_dist:
181 : 0 : nEnum = ParagraphAdjust_STRETCH;
182 : 0 : break;
183 : : case XML_l:
184 : : default:
185 : 294 : nEnum = ParagraphAdjust_LEFT;
186 : 294 : break;
187 : : }
188 : 375 : return nEnum;
189 : : }
190 : :
191 : :
192 : 0 : TabAlign GetTabAlign( sal_Int32 aToken )
193 : : {
194 : : OSL_ASSERT((aToken & sal_Int32(0xFFFF0000))==0);
195 : : TabAlign nEnum;
196 [ # # # # : 0 : switch( aToken )
# ]
197 : : {
198 : : case XML_ctr:
199 : 0 : nEnum = TabAlign_CENTER;
200 : 0 : break;
201 : : case XML_dec:
202 : 0 : nEnum = TabAlign_DECIMAL;
203 : 0 : break;
204 : : case XML_l:
205 : 0 : nEnum = TabAlign_LEFT;
206 : 0 : break;
207 : : case XML_r:
208 : 0 : nEnum = TabAlign_RIGHT;
209 : 0 : break;
210 : : default:
211 : 0 : nEnum = TabAlign_DEFAULT;
212 : 0 : break;
213 : : }
214 : 0 : return nEnum;
215 : : }
216 : :
217 : : // --------------------------------------------------------------------
218 : :
219 : : /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
220 : 51 : IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
221 : : {
222 : 51 : IntegerRectangle2D r;
223 : :
224 : 51 : r.X1 = xAttribs->getOptionalValue( XML_l ).toInt32();
225 : 51 : r.Y1 = xAttribs->getOptionalValue( XML_t ).toInt32();
226 : 51 : r.X2 = xAttribs->getOptionalValue( XML_r ).toInt32();
227 : 51 : r.Y2 = xAttribs->getOptionalValue( XML_b ).toInt32();
228 : :
229 : 51 : return r;
230 : : }
231 : :
232 : : // ============================================================================
233 : :
234 : : /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
235 : 18 : Size GetSize2D( const Reference< XFastAttributeList >& xAttribs )
236 : : {
237 [ + - ][ + - ]: 18 : return Size( GetCoordinate( xAttribs->getOptionalValue( XML_cx ) ), GetCoordinate( xAttribs->getOptionalValue( XML_cy ) ) );
[ + - ][ + - ]
238 : : }
239 : :
240 : 0 : IndexRange GetIndexRange( const Reference< XFastAttributeList >& xAttributes )
241 : : {
242 : : IndexRange range;
243 : 0 : range.start = xAttributes->getOptionalValue( XML_st ).toInt32();
244 : 0 : range.end = xAttributes->getOptionalValue( XML_end ).toInt32();
245 : 0 : return range;
246 : : }
247 : :
248 : : // ============================================================================
249 : :
250 : : } // namespace drawingml
251 : : } // namespace oox
252 : :
253 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|