fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / drawingmltypes.cxx
blob9dd42eb015958b506590bceedcc3ac82a9b369bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sax/tools/converter.hxx>
26 #include "oox/token/tokens.hxx"
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::xml::sax::XFastAttributeList;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::drawing;
32 using namespace ::com::sun::star::geometry;
33 using namespace ::com::sun::star::style;
35 namespace oox {
36 namespace drawingml {
38 // ============================================================================
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 )
49 sal_Int32 nRet = 0;
50 if( !::sax::Converter::convertNumber( nRet, sValue ) )
51 nRet = 0;
52 return GetCoordinate( nRet );
55 /** converts a ST_Percentage % string into 1/1000th of % */
56 sal_Int32 GetPercent( const OUString& sValue )
58 sal_Int32 nRet = 0;
59 if( !::sax::Converter::convertNumber( nRet, sValue ) )
60 nRet = 0;
62 return nRet;
65 double GetPositiveFixedPercentage( const OUString& sValue )
67 double fPercent = sValue.toFloat() / 100000.;
68 return fPercent;
71 // --------------------------------------------------------------------
73 /** converts the attributes from an CT_TLPoint into an awt Point with 1/1000% */
74 awt::Point GetPointPercent( const Reference< XFastAttributeList >& xAttribs )
76 return awt::Point( GetPercent( xAttribs->getOptionalValue( XML_x ) ), GetCoordinate( xAttribs->getOptionalValue( XML_y ) ) );
79 // --------------------------------------------------------------------
81 /** converts the ST_TextFontSize to point */
82 float GetTextSize( const OUString& sValue )
84 float fRet = 0;
85 sal_Int32 nRet;
86 if( ::sax::Converter::convertNumber( nRet, sValue ) )
87 fRet = static_cast< float >( static_cast< double >( nRet ) / 100.0 );
88 return fRet;
92 /** converts the ST_TextSpacingPoint to 1/100mm */
93 sal_Int32 GetTextSpacingPoint( const OUString& sValue )
95 sal_Int32 nRet;
96 if( ::sax::Converter::convertNumber( nRet, sValue ) )
97 nRet = GetTextSpacingPoint( nRet );
98 return nRet;
101 sal_Int32 GetTextSpacingPoint( const sal_Int32 nValue )
103 return ( nValue * 254 + 360 ) / 720;
106 float GetFontHeight( sal_Int32 nHeight )
108 // convert 1/100 points to points
109 return static_cast< float >( nHeight / 100.0 );
112 sal_Int16 GetFontUnderline( sal_Int32 nToken )
114 OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
115 switch( nToken )
117 case XML_none: return awt::FontUnderline::NONE;
118 case XML_dash: return awt::FontUnderline::DASH;
119 case XML_dashHeavy: return awt::FontUnderline::BOLDDASH;
120 case XML_dashLong: return awt::FontUnderline::LONGDASH;
121 case XML_dashLongHeavy: return awt::FontUnderline::BOLDLONGDASH;
122 case XML_dbl: return awt::FontUnderline::DOUBLE;
123 case XML_dotDash: return awt::FontUnderline::DASHDOT;
124 case XML_dotDashHeavy: return awt::FontUnderline::BOLDDASHDOT;
125 case XML_dotDotDash: return awt::FontUnderline::DASHDOTDOT;
126 case XML_dotDotDashHeavy: return awt::FontUnderline::BOLDDASHDOTDOT;
127 case XML_dotted: return awt::FontUnderline::DOTTED;
128 case XML_dottedHeavy: return awt::FontUnderline::BOLDDOTTED;
129 case XML_heavy: return awt::FontUnderline::BOLD;
130 case XML_sng: return awt::FontUnderline::SINGLE;
131 case XML_wavy: return awt::FontUnderline::WAVE;
132 case XML_wavyDbl: return awt::FontUnderline::DOUBLEWAVE;
133 case XML_wavyHeavy: return awt::FontUnderline::BOLDWAVE;
134 // case XML_words: // TODO
136 return awt::FontUnderline::DONTKNOW;
139 sal_Int16 GetFontStrikeout( sal_Int32 nToken )
141 OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
142 switch( nToken )
144 case XML_dblStrike: return awt::FontStrikeout::DOUBLE;
145 case XML_noStrike: return awt::FontStrikeout::NONE;
146 case XML_sngStrike: return awt::FontStrikeout::SINGLE;
148 return awt::FontStrikeout::DONTKNOW;
151 sal_Int16 GetCaseMap( sal_Int32 nToken )
153 switch( nToken )
155 case XML_all: return CaseMap::UPPERCASE;
156 case XML_small: return CaseMap::SMALLCAPS;
158 return CaseMap::NONE;
161 /** converts a paragraph align to a ParaAdjust */
162 sal_Int16 GetParaAdjust( sal_Int32 nAlign )
164 OSL_ASSERT((nAlign & sal_Int32(0xFFFF0000))==0);
165 sal_Int16 nEnum;
166 switch( nAlign )
168 case XML_ctr:
169 nEnum = ParagraphAdjust_CENTER;
170 break;
171 case XML_just:
172 case XML_justLow:
173 nEnum = ParagraphAdjust_BLOCK;
174 break;
175 case XML_r:
176 nEnum = ParagraphAdjust_RIGHT;
177 break;
178 case XML_thaiDist:
179 case XML_dist:
180 nEnum = ParagraphAdjust_STRETCH;
181 break;
182 case XML_l:
183 default:
184 nEnum = ParagraphAdjust_LEFT;
185 break;
187 return nEnum;
191 TabAlign GetTabAlign( sal_Int32 aToken )
193 OSL_ASSERT((aToken & sal_Int32(0xFFFF0000))==0);
194 TabAlign nEnum;
195 switch( aToken )
197 case XML_ctr:
198 nEnum = TabAlign_CENTER;
199 break;
200 case XML_dec:
201 nEnum = TabAlign_DECIMAL;
202 break;
203 case XML_l:
204 nEnum = TabAlign_LEFT;
205 break;
206 case XML_r:
207 nEnum = TabAlign_RIGHT;
208 break;
209 default:
210 nEnum = TabAlign_DEFAULT;
211 break;
213 return nEnum;
216 // --------------------------------------------------------------------
218 /** converts the attributes from a CT_RelativeRect to an IntegerRectangle2D */
219 IntegerRectangle2D GetRelativeRect( const Reference< XFastAttributeList >& xAttribs )
221 IntegerRectangle2D r;
223 r.X1 = xAttribs->getOptionalValue( XML_l ).toInt32();
224 r.Y1 = xAttribs->getOptionalValue( XML_t ).toInt32();
225 r.X2 = xAttribs->getOptionalValue( XML_r ).toInt32();
226 r.Y2 = xAttribs->getOptionalValue( XML_b ).toInt32();
228 return r;
231 // ============================================================================
233 /** converts the attributes from an CT_Size2D into an awt Size with 1/100thmm */
234 awt::Size GetSize2D( const Reference< XFastAttributeList >& xAttribs )
236 return awt::Size( GetCoordinate( xAttribs->getOptionalValue( XML_cx ) ), GetCoordinate( xAttribs->getOptionalValue( XML_cy ) ) );
239 IndexRange GetIndexRange( const Reference< XFastAttributeList >& xAttributes )
241 IndexRange range;
242 range.start = xAttributes->getOptionalValue( XML_st ).toInt32();
243 range.end = xAttributes->getOptionalValue( XML_end ).toInt32();
244 return range;
247 // ============================================================================
249 } // namespace drawingml
250 } // namespace oox
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */