summaryrefslogtreecommitdiff
path: root/oox/source/drawingml/drawingmltypes.cxx
blob: 1e80ade4e95bc0ec3d976ed31aca769673be297f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: drawingmltypes.cxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include "oox/drawingml/drawingmltypes.hxx"
#include <com/sun/star/awt/FontPitch.hpp>
#include <com/sun/star/awt/FontUnderline.hpp>
#include <com/sun/star/awt/FontFamily.hpp>
#include <com/sun/star/awt/FontStrikeout.hpp>
#include <com/sun/star/style/CaseMap.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <sax/tools/converter.hxx>
#include "tokens.hxx"

using ::rtl::OUString;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::xml::sax::XFastAttributeList;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::geometry;

namespace oox { namespace drawingml {

// --------------------------------------------------------------------

/** converts an emu string into 1/100th mmm but constrain as per ST_TextMargin
 * see 5.1.12.73
 */
sal_Int32 GetTextMargin( const OUString& sValue )
{
    sal_Int32 nRet = 0;
    if( !::sax::Converter::convertNumber( nRet, sValue ) )
        nRet = 0;
    else if( nRet < 0 )
        nRet = 0;
    else if( nRet > 51206400 )
        nRet = 51206400;

    nRet /= 360;
    return nRet;
}

/** converts an emu string into 1/100th mmm */
sal_Int32 GetCoordinate( const OUString& sValue )
{
    sal_Int32 nRet = 0;
    if( !::sax::Converter::convertNumber( nRet, sValue ) )
        nRet = 0;

    nRet /= 360;
    return nRet;
}

/** converts a ST_Percentage % string into 1/1000th of % */
sal_Int32 GetPercent( const OUString& sValue )
{
    sal_Int32 nRet = 0;
    if( !::sax::Converter::convertNumber( nRet, sValue ) )
        nRet = 0;

    return nRet;
}

double GetPositiveFixedPercentage( const OUString& sValue )
{
    double fPercent = sValue.toFloat() / 100000.;
    return fPercent;
}

// --------------------------------------------------------------------

/** converts the attributes from an CT_Point2D into an awt Point with 1/100thmm */
Point GetPoint2D( const Reference< XFastAttributeList >& xAttribs )
{
    return Point( GetCoordinate( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
}

/** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
Point GetPointPercent( const Reference< XFastAttributeList >& xAttribs )
{
    return Point( GetPercent( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
}

// --------------------------------------------------------------------

/** converts the ST_TextFontSize to point */
float GetTextSize( const OUString& sValue )
{
    float fRet = 0;
    sal_Int32 nRet;
    if( ::sax::Converter::convertNumber( nRet, sValue ) )
        fRet = static_cast< float >( static_cast< double >( nRet ) / 100.0 );
    return fRet;
}


/** converts the ST_TextSpacingPoint to 1/100mm */
sal_Int32 GetTextSpacingPoint( const OUString& sValue )
{
    sal_Int32 nRet;
    if( ::sax::Converter::convertNumber( nRet, sValue ) )
        nRet = ( nRet * 254 + 360 ) / 720;
    return nRet;
}


sal_Int16 GetFontUnderline( ::sal_Int32 nToken )
{
    sal_Int16 nEnum;
    switch( nToken )
    {
    case XML_none:
        nEnum = FontUnderline::NONE;
        break;
    case XML_dash:
        nEnum = FontUnderline::DASH;
        break;
    case XML_dashHeavy:
        nEnum = FontUnderline::BOLDDASH;
        break;
    case XML_dashLong:
        nEnum = FontUnderline::LONGDASH;
        break;
    case XML_dashLongHeavy:
        nEnum = FontUnderline::BOLDLONGDASH;
        break;
    case XML_dbl:
        nEnum = FontUnderline::DOUBLE;
        break;
    case XML_dotDash:
        nEnum = FontUnderline::DASHDOT;
        break;
    case XML_dotDashHeavy:
        nEnum = FontUnderline::BOLDDASHDOT;
        break;
    case XML_dotDotDash:
        nEnum = FontUnderline::DASHDOTDOT;
        break;
    case XML_dotDotDashHeavy:
        nEnum = FontUnderline::BOLDDASHDOTDOT;
        break;
    case XML_dotted:
        nEnum = FontUnderline::DOTTED;
        break;
    case XML_dottedHeavy:
        nEnum = FontUnderline::BOLDDOTTED;
        break;
    case XML_heavy:
        nEnum = FontUnderline::BOLD;
        break;
    case XML_sng:
        nEnum = FontUnderline::SINGLE;
        break;
    case XML_wavy:
        nEnum = FontUnderline::WAVE;
        break;
    case XML_wavyDbl:
        nEnum = FontUnderline::DOUBLEWAVE;
        break;
    case XML_wavyHeavy:
         nEnum = FontUnderline::BOLDWAVE;
        break;
    case XML_words:
        // TODO
    default:
        nEnum = FontUnderline::DONTKNOW;
        break;
    }
    return nEnum;
}

sal_Int16 GetFontStrikeout( sal_Int32 nToken )
{
    sal_Int16 nEnum;
    switch( nToken )
    {
    case XML_dblStrike:
        nEnum = FontStrikeout::DOUBLE;
        break;
    case XML_noStrike:
        nEnum = FontStrikeout::NONE;
        break;
    case XML_sngStrike:
        nEnum = FontStrikeout::SINGLE;
        break;
    default:
        nEnum = FontStrikeout::DONTKNOW;
        break;
    }
    return nEnum;
}

sal_Int16 GetCaseMap( sal_Int32 nToken )
{
    sal_Int16 nEnum;
    switch( nToken )
    {
    case XML_all:
        nEnum = CaseMap::UPPERCASE;
        break;
    case XML_small:
        nEnum = CaseMap::SMALLCAPS;
        break;
    case XML_none:
        // fall through
    default:
        nEnum = CaseMap::NONE;
        break;
    }
    return nEnum;
}

// BEGIN stolen from sd/source/filter/eppt/epptso.cxx
/* Font Families */
#define FF_DONTCARE             0x00
#define FF_ROMAN                0x10
#define FF_SWISS                0x20
#define FF_MODERN               0x30
#define FF_SCRIPT               0x40
#define FF_DECORATIVE           0x50

/* Font pitches */
#define DEFAULT_PITCH           0x00
#define FIXED_PITCH             0x01
#define VARIABLE_PITCH          0x02

// END

void GetFontPitch( sal_Int32 nOoxValue, sal_Int16 & nPitch, sal_Int16 & nFamily )
{
    sal_Int32 oFamily = ( nOoxValue & 0xf0 );
    sal_Int32 oPitch = ( nOoxValue & 0x0f );
    switch( oFamily )
    {
    case FF_ROMAN:
        nFamily = FontFamily::ROMAN;
        break;
    case FF_SWISS:
        nFamily = FontFamily::SWISS;
        break;
    case FF_MODERN:
        nFamily = FontFamily::MODERN;
        break;
    case FF_SCRIPT:
        nFamily = FontFamily::SCRIPT;
        break;
    case FF_DECORATIVE:
        nFamily = FontFamily::DECORATIVE;
        break;
    default:
        nFamily = FontFamily::DONTKNOW;
        break;
    }
    switch( oPitch )
    {
    case FIXED_PITCH:
        nPitch = FontPitch::FIXED;
        break;
    case VARIABLE_PITCH:
        nPitch = FontPitch::VARIABLE;
        break;
    case DEFAULT_PITCH:
    default:
        nPitch = FontPitch::DONTKNOW;
        break;
    }
}

/** converts a paragraph align to a ParaAdjust */
sal_Int16 GetParaAdjust( sal_Int32 nAlign )
{
    sal_Int16 nEnum;
    switch( nAlign )
    {
    case XML_ctr:
        nEnum = ParagraphAdjust_CENTER;
        break;
    case XML_just:
    case XML_justLow:
        nEnum = ParagraphAdjust_BLOCK;
        break;
    case XML_r:
        nEnum = ParagraphAdjust_RIGHT;
        break;
    case XML_thaiDist:
    case XML_dist:
        nEnum = ParagraphAdjust_STRETCH;
        break;
    case XML_l:
    default:
        nEnum = ParagraphAdjust_LEFT;
        break;
    }
    return nEnum;
}


TabAlign GetTabAlign( sal_Int32 aToken )
{
    TabAlign nEnum;
    switch( aToken )
    {
    case XML_ctr:
        nEnum = TabAlign_CENTER;
        break;
    case XML_dec:
        nEnum = TabAlign_DECIMAL;
        break;
    case XML_l:
        nEnum = TabAlign_LEFT;
        break;
    case XML_r:
        nEnum = TabAlign_RIGHT;
        break;
    default:
        nEnum = TabAlign_DEFAULT;
        break;
    }
    return nEnum;
}

// --------------------------------------------------------------------

/** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
{
    IntegerRectangle2D r;

    r.X1 = xAttribs->getOptionalValue( XML_l ).toInt32();
    r.Y1 = xAttribs->getOptionalValue( XML_t ).toInt32();
    r.X2 = xAttribs->getOptionalValue( XML_r ).toInt32();
    r.Y2 = xAttribs->getOptionalValue( XML_b ).toInt32();

    return r;
}

// --------------------------------------------------------------------

/** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
Size GetSize2D( const Reference< XFastAttributeList >& xAttribs )
{
    return Size( GetCoordinate( xAttribs->getOptionalValue( XML_cx ) ), GetCoordinate( xAttribs->getOptionalValue( XML_cy ) ) );
}

IndexRange GetIndexRange( const Reference< XFastAttributeList >& xAttributes )
{
    IndexRange range;
    range.start = xAttributes->getOptionalValue( XML_st ).toInt32();
    range.end = xAttributes->getOptionalValue( XML_end ).toInt32();
    return range;
}

} }