Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <fonthdl.hxx>
31 : :
32 : : #include <sax/tools/converter.hxx>
33 : :
34 : : #include <xmloff/xmltoken.hxx>
35 : : #include <xmloff/xmluconv.hxx>
36 : : #include <rtl/ustrbuf.hxx>
37 : : #include <com/sun/star/uno/Any.hxx>
38 : : #include <tools/fontenum.hxx>
39 : :
40 : : using ::rtl::OUString;
41 : : using ::rtl::OUStringBuffer;
42 : :
43 : : using namespace ::com::sun::star;
44 : : using namespace ::xmloff::token;
45 : :
46 : 1989 : const SvXMLEnumMapEntry* lcl_getFontFamilyGenericMapping()
47 : : {
48 : : static SvXMLEnumMapEntry const aFontFamilyGenericMapping[] =
49 : : {
50 : : { XML_DECORATIVE, FAMILY_DECORATIVE },
51 : :
52 : : { XML_MODERN, FAMILY_MODERN },
53 : : { XML_ROMAN, FAMILY_ROMAN },
54 : : { XML_SCRIPT, FAMILY_SCRIPT },
55 : : { XML_SWISS, FAMILY_SWISS },
56 : : { XML_SYSTEM, FAMILY_SYSTEM },
57 : : { XML_TOKEN_INVALID, 0 }
58 : : };
59 : 1989 : return aFontFamilyGenericMapping;
60 : : }
61 : :
62 : : static SvXMLEnumMapEntry const aFontPitchMapping[] =
63 : : {
64 : : { XML_FIXED, PITCH_FIXED },
65 : : { XML_VARIABLE, PITCH_VARIABLE },
66 : : { XML_TOKEN_INVALID, 0 }
67 : : };
68 : : ///////////////////////////////////////////////////////////////////////////////
69 : : //
70 : : // class XMLFontFamilyNamePropHdl
71 : : //
72 : :
73 : 3633 : XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
74 : : {
75 : : // Nothing to do
76 [ - + ]: 6230 : }
77 : :
78 : 2311 : sal_Bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
79 : : {
80 : 2311 : sal_Bool bRet = sal_False;
81 : 2311 : OUStringBuffer sValue;
82 : 2311 : sal_Int32 nPos = 0;
83 : :
84 [ + + ]: 2517 : do
85 : : {
86 : 2517 : sal_Int32 nFirst = nPos;
87 [ + - ]: 2517 : nPos = ::sax::Converter::indexOfComma( rStrImpValue, nPos );
88 [ + + ]: 2517 : sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() - 1 : nPos - 1);
89 : :
90 : : // skip trailing blanks
91 [ + + ][ - + ]: 2517 : while( nLast > nFirst && sal_Unicode(' ') == rStrImpValue[nLast] )
[ - + ]
92 : 0 : nLast--;
93 : :
94 : : // skip leading blanks
95 [ + + ][ + + ]: 2723 : while(nFirst <= nLast && sal_Unicode(' ') == rStrImpValue[nFirst])
[ + + ]
96 : 206 : nFirst++;
97 : :
98 : : // remove quotes
99 : 2517 : sal_Unicode c = rStrImpValue[nFirst];
100 [ + + ][ - + ]: 2517 : if( nFirst < nLast && (sal_Unicode('\'') == c || sal_Unicode('\"') == c) && rStrImpValue[nLast] == c )
[ + - ][ + + ]
[ + + ]
101 : : {
102 : 1351 : nFirst++;
103 : 1351 : nLast--;
104 : : }
105 : :
106 [ + + ]: 2517 : if( nFirst <= nLast )
107 : : {
108 [ + + ]: 2511 : if( sValue.getLength() != 0 )
109 [ + - ]: 206 : sValue.append(';');
110 : :
111 [ + - ]: 2511 : sValue.append(rStrImpValue.copy( nFirst, nLast-nFirst+1));
112 : : }
113 : :
114 [ + + ]: 2517 : if( -1 != nPos )
115 : 206 : nPos++;
116 : : }
117 : : while( -1 != nPos );
118 : :
119 [ + + ]: 2311 : if (sValue.getLength())
120 : : {
121 [ + - ][ + - ]: 2305 : rValue <<= sValue.makeStringAndClear();
122 : 2305 : bRet = sal_True;
123 : : }
124 : :
125 : 2311 : return bRet;
126 : : }
127 : :
128 : 710 : sal_Bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
129 : : {
130 : 710 : sal_Bool bRet = sal_False;
131 : 710 : OUString aStrFamilyName;
132 : :
133 [ + - ]: 710 : if( rValue >>= aStrFamilyName )
134 : : {
135 : 710 : OUStringBuffer sValue( aStrFamilyName.getLength() + 2L );
136 : 710 : sal_Int32 nPos = 0;
137 [ + + ]: 806 : do
138 : : {
139 : 806 : sal_Int32 nFirst = nPos;
140 : 806 : nPos = aStrFamilyName.indexOf( sal_Unicode(';'), nPos );
141 [ + + ]: 806 : sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos);
142 : :
143 : : // Set position to the character behind the ';', so we won't
144 : : // forget this.
145 [ + + ]: 806 : if( -1L != nPos )
146 : 96 : nPos++;
147 : :
148 : : // If the property value was empty, we stop now.
149 : : // If there is a ';' at the first position, the empty name
150 : : // at the start will be removed.
151 [ - + ]: 806 : if( 0L == nLast )
152 : 0 : continue;
153 : :
154 : : // nFirst and nLast now denote the first and last character of
155 : : // one font name.
156 : 806 : nLast--;
157 : :
158 : : // skip trailing blanks
159 [ + - ][ - + ]: 806 : while( nLast > nFirst && sal_Unicode(' ') == aStrFamilyName[nLast] )
[ - + ]
160 : 0 : nLast--;
161 : :
162 : : // skip leading blanks
163 [ + - ][ - + ]: 806 : while( nFirst <= nLast && sal_Unicode(' ') == aStrFamilyName[nFirst] )
[ - + ]
164 : 0 : nFirst++;
165 : :
166 [ + - ]: 806 : if( nFirst <= nLast )
167 : : {
168 [ + + ]: 806 : if( sValue.getLength() != 0L )
169 : : {
170 [ + - ]: 96 : sValue.append( sal_Unicode( ',' ) );
171 [ + - ]: 96 : sValue.append( sal_Unicode( ' ' ));
172 : : }
173 : 806 : sal_Int32 nLen = nLast-nFirst+1;
174 : 806 : OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) );
175 : 806 : sal_Bool bQuote = sal_False;
176 [ + + ]: 7480 : for( sal_Int32 i=0; i < nLen; i++ )
177 : : {
178 : 7028 : sal_Unicode c = sFamily[i];
179 [ - + ][ + + ]: 7028 : if( sal_Unicode(' ') == c || sal_Unicode(',') == c )
180 : : {
181 : 354 : bQuote = sal_True;
182 : 354 : break;
183 : : }
184 : : }
185 [ + + ]: 806 : if( bQuote )
186 [ + - ]: 354 : sValue.append( sal_Unicode('\'') );
187 [ + - ]: 806 : sValue.append( sFamily );
188 [ + + ]: 806 : if( bQuote )
189 [ + - ]: 806 : sValue.append( sal_Unicode('\'') );
190 : : }
191 : : }
192 : : while( -1L != nPos );
193 : :
194 [ + - ]: 710 : rStrExpValue = sValue.makeStringAndClear();
195 : :
196 : 710 : bRet = sal_True;
197 : : }
198 : :
199 : 710 : return bRet;
200 : : }
201 : :
202 : : ///////////////////////////////////////////////////////////////////////////////
203 : : //
204 : : // class XMLFontFamilyPropHdl
205 : : //
206 : :
207 : 4036 : XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
208 : : {
209 : : // Nothing to do
210 [ - + ]: 7036 : }
211 : :
212 : 1631 : sal_Bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
213 : : {
214 : : sal_uInt16 eNewFamily;
215 [ + - ]: 1631 : sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
216 [ + - ]: 1631 : if( bRet )
217 [ + - ]: 1631 : rValue <<= (sal_Int16)eNewFamily;
218 : :
219 : 1631 : return bRet;
220 : : }
221 : :
222 : 710 : sal_Bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
223 : : {
224 : 710 : sal_Bool bRet = sal_False;
225 : 710 : OUStringBuffer aOut;
226 : :
227 : 710 : sal_Int16 nFamily = sal_Int16();
228 [ + - ]: 710 : if( rValue >>= nFamily )
229 : : {
230 : 710 : FontFamily eFamily = (FontFamily)nFamily;
231 [ + + ]: 710 : if( eFamily != FAMILY_DONTKNOW )
232 [ + - ]: 358 : bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() );
233 : : }
234 : :
235 [ + - ]: 710 : rStrExpValue = aOut.makeStringAndClear();
236 : :
237 : 710 : return bRet;
238 : : }
239 : :
240 : : ///////////////////////////////////////////////////////////////////////////////
241 : : //
242 : : // class XMLFontEncodingPropHdl
243 : : //
244 : :
245 : 4036 : XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
246 : : {
247 : : // Nothing to do
248 [ - + ]: 7036 : }
249 : :
250 : 6 : sal_Bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
251 : : {
252 : 6 : sal_Bool bRet = sal_True;
253 : :
254 [ + - ]: 6 : if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
255 [ + - ]: 6 : rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL;
256 : :
257 : 6 : return bRet;
258 : : }
259 : :
260 : 710 : sal_Bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
261 : : {
262 : 710 : sal_Bool bRet = sal_False;
263 : 710 : OUStringBuffer aOut;
264 : 710 : sal_Int16 nSet = sal_Int16();
265 : :
266 [ + - ]: 710 : if( rValue >>= nSet )
267 : : {
268 [ - + ]: 710 : if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL )
269 : : {
270 [ # # ][ # # ]: 0 : aOut.append( GetXMLToken(XML_X_SYMBOL) );
271 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
272 : 0 : bRet = sal_True;
273 : : }
274 : : }
275 : :
276 : 710 : return bRet;
277 : : }
278 : :
279 : : ///////////////////////////////////////////////////////////////////////////////
280 : : //
281 : : // class XMLFontPitchPropHdl
282 : : //
283 : :
284 : 4036 : XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
285 : : {
286 : : // Nothing to do
287 [ - + ]: 7036 : }
288 : :
289 : 1637 : sal_Bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
290 : : {
291 : : sal_uInt16 eNewPitch;
292 [ + - ]: 1637 : sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
293 [ + - ]: 1637 : if( bRet )
294 [ + - ]: 1637 : rValue <<= (sal_Int16)eNewPitch;
295 : :
296 : 1637 : return bRet;
297 : : }
298 : :
299 : 710 : sal_Bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
300 : : {
301 : 710 : sal_Bool bRet = sal_False;
302 : 710 : sal_Int16 nPitch = sal_Int16();
303 : 710 : OUStringBuffer aOut;
304 : :
305 : 710 : FontPitch ePitch = PITCH_DONTKNOW;
306 [ + - ]: 710 : if( rValue >>= nPitch )
307 : 710 : ePitch = (FontPitch)nPitch;
308 : :
309 [ + + ]: 710 : if( PITCH_DONTKNOW != ePitch )
310 : : {
311 [ + - ]: 346 : bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED );
312 [ + - ]: 346 : rStrExpValue = aOut.makeStringAndClear();
313 : : }
314 : :
315 : 710 : return bRet;
316 : : }
317 : :
318 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|