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 .
21 #include <fonthdl.hxx>
23 #include <sax/tools/converter.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmluconv.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <tools/fontenum.hxx>
32 using namespace ::com::sun::star
;
33 using namespace ::xmloff::token
;
35 static const SvXMLEnumMapEntry
* lcl_getFontFamilyGenericMapping()
37 static SvXMLEnumMapEntry
const aFontFamilyGenericMapping
[] =
39 { XML_DECORATIVE
, FAMILY_DECORATIVE
},
41 { XML_MODERN
, FAMILY_MODERN
},
42 { XML_ROMAN
, FAMILY_ROMAN
},
43 { XML_SCRIPT
, FAMILY_SCRIPT
},
44 { XML_SWISS
, FAMILY_SWISS
},
45 { XML_SYSTEM
, FAMILY_SYSTEM
},
46 { XML_TOKEN_INVALID
, 0 }
48 return aFontFamilyGenericMapping
;
51 static SvXMLEnumMapEntry
const aFontPitchMapping
[] =
53 { XML_FIXED
, PITCH_FIXED
},
54 { XML_VARIABLE
, PITCH_VARIABLE
},
55 { XML_TOKEN_INVALID
, 0 }
57 ///////////////////////////////////////////////////////////////////////////////
59 // class XMLFontFamilyNamePropHdl
62 XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
67 sal_Bool
XMLFontFamilyNamePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
69 sal_Bool bRet
= sal_False
;
70 OUStringBuffer sValue
;
75 sal_Int32 nFirst
= nPos
;
76 nPos
= ::sax::Converter::indexOfComma( rStrImpValue
, nPos
);
77 sal_Int32 nLast
= (-1 == nPos
? rStrImpValue
.getLength() - 1 : nPos
- 1);
79 // skip trailing blanks
80 while( nLast
> nFirst
&& sal_Unicode(' ') == rStrImpValue
[nLast
] )
83 // skip leading blanks
84 while(nFirst
<= nLast
&& sal_Unicode(' ') == rStrImpValue
[nFirst
])
88 sal_Unicode c
= rStrImpValue
[nFirst
];
89 if( nFirst
< nLast
&& (sal_Unicode('\'') == c
|| sal_Unicode('\"') == c
) && rStrImpValue
[nLast
] == c
)
97 if( !sValue
.isEmpty() )
100 sValue
.append(rStrImpValue
.copy( nFirst
, nLast
-nFirst
+1));
108 if (!sValue
.isEmpty())
110 rValue
<<= sValue
.makeStringAndClear();
117 sal_Bool
XMLFontFamilyNamePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
119 sal_Bool bRet
= sal_False
;
120 OUString aStrFamilyName
;
122 if( rValue
>>= aStrFamilyName
)
124 OUStringBuffer
sValue( aStrFamilyName
.getLength() + 2L );
128 sal_Int32 nFirst
= nPos
;
129 nPos
= aStrFamilyName
.indexOf( sal_Unicode(';'), nPos
);
130 sal_Int32 nLast
= (-1 == nPos
? aStrFamilyName
.getLength() : nPos
);
132 // Set position to the character behind the ';', so we won't
137 // If the property value was empty, we stop now.
138 // If there is a ';' at the first position, the empty name
139 // at the start will be removed.
143 // nFirst and nLast now denote the first and last character of
147 // skip trailing blanks
148 while( nLast
> nFirst
&& sal_Unicode(' ') == aStrFamilyName
[nLast
] )
151 // skip leading blanks
152 while( nFirst
<= nLast
&& sal_Unicode(' ') == aStrFamilyName
[nFirst
] )
155 if( nFirst
<= nLast
)
157 if( sValue
.getLength() != 0L )
159 sValue
.append( sal_Unicode( ',' ) );
160 sValue
.append( sal_Unicode( ' ' ));
162 sal_Int32 nLen
= nLast
-nFirst
+1;
163 OUString
sFamily( aStrFamilyName
.copy( nFirst
, nLen
) );
164 sal_Bool bQuote
= sal_False
;
165 for( sal_Int32 i
=0; i
< nLen
; i
++ )
167 sal_Unicode c
= sFamily
[i
];
168 if( sal_Unicode(' ') == c
|| sal_Unicode(',') == c
)
175 sValue
.append( sal_Unicode('\'') );
176 sValue
.append( sFamily
);
178 sValue
.append( sal_Unicode('\'') );
181 while( -1L != nPos
);
183 rStrExpValue
= sValue
.makeStringAndClear();
191 ///////////////////////////////////////////////////////////////////////////////
193 // class XMLFontFamilyPropHdl
196 XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
201 sal_Bool
XMLFontFamilyPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
203 sal_uInt16 eNewFamily
;
204 sal_Bool bRet
= SvXMLUnitConverter::convertEnum( eNewFamily
, rStrImpValue
, lcl_getFontFamilyGenericMapping() );
206 rValue
<<= (sal_Int16
)eNewFamily
;
211 sal_Bool
XMLFontFamilyPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
213 sal_Bool bRet
= sal_False
;
216 sal_Int16 nFamily
= sal_Int16();
217 if( rValue
>>= nFamily
)
219 FontFamily eFamily
= (FontFamily
)nFamily
;
220 if( eFamily
!= FAMILY_DONTKNOW
)
221 bRet
= SvXMLUnitConverter::convertEnum( aOut
, eFamily
, lcl_getFontFamilyGenericMapping() );
224 rStrExpValue
= aOut
.makeStringAndClear();
229 ///////////////////////////////////////////////////////////////////////////////
231 // class XMLFontEncodingPropHdl
234 XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
239 sal_Bool
XMLFontEncodingPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
241 sal_Bool bRet
= sal_True
;
243 if( IsXMLToken( rStrImpValue
, XML_X_SYMBOL
) )
244 rValue
<<= (sal_Int16
) RTL_TEXTENCODING_SYMBOL
;
249 sal_Bool
XMLFontEncodingPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
251 sal_Bool bRet
= sal_False
;
253 sal_Int16 nSet
= sal_Int16();
255 if( rValue
>>= nSet
)
257 if( (rtl_TextEncoding
)nSet
== RTL_TEXTENCODING_SYMBOL
)
259 aOut
.append( GetXMLToken(XML_X_SYMBOL
) );
260 rStrExpValue
= aOut
.makeStringAndClear();
268 ///////////////////////////////////////////////////////////////////////////////
270 // class XMLFontPitchPropHdl
273 XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
278 sal_Bool
XMLFontPitchPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
280 sal_uInt16 eNewPitch
;
281 sal_Bool bRet
= SvXMLUnitConverter::convertEnum( eNewPitch
, rStrImpValue
, aFontPitchMapping
);
283 rValue
<<= (sal_Int16
)eNewPitch
;
288 sal_Bool
XMLFontPitchPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
290 sal_Bool bRet
= sal_False
;
291 sal_Int16 nPitch
= sal_Int16();
294 FontPitch ePitch
= PITCH_DONTKNOW
;
295 if( rValue
>>= nPitch
)
296 ePitch
= (FontPitch
)nPitch
;
298 if( PITCH_DONTKNOW
!= ePitch
)
300 bRet
= SvXMLUnitConverter::convertEnum( aOut
, ePitch
, aFontPitchMapping
, XML_FIXED
);
301 rStrExpValue
= aOut
.makeStringAndClear();
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */