1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fonthdl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #ifndef _XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX
35 #include <fonthdl.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include <rtl/ustrbuf.hxx>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <vcl/vclenum.hxx>
43 #ifndef _XMLOFF_XMLEMENT_HXX
44 #include <xmloff/xmlelement.hxx>
46 #include <tools/string.hxx>
48 using ::rtl::OUString
;
49 using ::rtl::OUStringBuffer
;
51 using namespace ::com::sun::star
;
52 using namespace ::xmloff::token
;
54 const SvXMLEnumMapEntry
* lcl_getFontFamilyGenericMapping()
56 static SvXMLEnumMapEntry __READONLY_DATA aFontFamilyGenericMapping
[] =
58 { XML_DECORATIVE
, FAMILY_DECORATIVE
},
60 { XML_MODERN
, FAMILY_MODERN
},
61 { XML_ROMAN
, FAMILY_ROMAN
},
62 { XML_SCRIPT
, FAMILY_SCRIPT
},
63 { XML_SWISS
, FAMILY_SWISS
},
64 { XML_SYSTEM
, FAMILY_SYSTEM
},
65 { XML_TOKEN_INVALID
, 0 }
67 return aFontFamilyGenericMapping
;
70 static SvXMLEnumMapEntry __READONLY_DATA aFontPitchMapping
[] =
72 { XML_FIXED
, PITCH_FIXED
},
73 { XML_VARIABLE
, PITCH_VARIABLE
},
74 { XML_TOKEN_INVALID
, 0 }
76 ///////////////////////////////////////////////////////////////////////////////
78 // class XMLFontFamilyNamePropHdl
81 XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
86 sal_Bool
XMLFontFamilyNamePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
88 sal_Bool bRet
= sal_False
;
94 sal_Int32 nFirst
= nPos
;
95 nPos
= SvXMLUnitConverter::indexOfComma( rStrImpValue
, nPos
);
96 sal_Int32 nLast
= (-1 == nPos
? rStrImpValue
.getLength() : nPos
);
100 // skip trailing blanks
101 while( sal_Unicode(' ') == rStrImpValue
[nLast
] && nLast
> nFirst
)
104 // skip leading blanks
105 while( sal_Unicode(' ') == rStrImpValue
[nFirst
] && nFirst
<= nLast
)
109 sal_Unicode c
= rStrImpValue
[nFirst
];
110 if( nFirst
< nLast
&& (sal_Unicode('\'') == c
|| sal_Unicode('\"') == c
) && rStrImpValue
[nLast
] == c
)
116 if( nFirst
<= nLast
)
118 if( sValue
.Len() != 0 )
119 sValue
+= sal_Unicode(';');
121 OUString sTemp
= rStrImpValue
.copy( nFirst
, nLast
-nFirst
+1 );
122 sValue
+= sTemp
.getStr();
132 rValue
<<= OUString(sValue
.GetBuffer());
139 sal_Bool
XMLFontFamilyNamePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
141 sal_Bool bRet
= sal_False
;
142 OUString aStrFamilyName
;
144 if( rValue
>>= aStrFamilyName
)
146 OUStringBuffer
sValue( aStrFamilyName
.getLength() + 2L );
150 sal_Int32 nFirst
= nPos
;
151 nPos
= aStrFamilyName
.indexOf( sal_Unicode(';'), nPos
);
152 sal_Int32 nLast
= (-1L == nPos
? aStrFamilyName
.getLength() : nPos
);
154 // Set position to the character behind the ';', so we won't
159 // If the property value was empty, we stop now.
160 // If there is a ';' at the first position, the empty name
161 // at the start will be removed.
165 // nFirst and nLast now denote the first and last character of
169 // skip trailing blanks
170 while( sal_Unicode(' ') == aStrFamilyName
[nLast
] && nLast
> nFirst
)
173 // skip leading blanks
174 while( sal_Unicode(' ') == aStrFamilyName
[nFirst
] && nFirst
<= nLast
)
177 if( nFirst
<= nLast
)
179 if( sValue
.getLength() != 0L )
181 sValue
.append( sal_Unicode( ',' ) );
182 sValue
.append( sal_Unicode( ' ' ));
184 sal_Int32 nLen
= nLast
-nFirst
+1L;
185 OUString
sFamily( aStrFamilyName
.copy( nFirst
, nLen
) );
186 sal_Bool bQuote
= sal_False
;
187 for( sal_Int32 i
=0; i
< nLen
; i
++ )
189 sal_Unicode c
= sFamily
[i
];
190 if( sal_Unicode(' ') == c
|| sal_Unicode(',') == c
)
197 sValue
.append( sal_Unicode('\'') );
198 sValue
.append( sFamily
);
200 sValue
.append( sal_Unicode('\'') );
203 while( -1L != nPos
);
205 rStrExpValue
= sValue
.makeStringAndClear();
213 ///////////////////////////////////////////////////////////////////////////////
215 // class XMLFontFamilyPropHdl
218 XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
223 sal_Bool
XMLFontFamilyPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
225 sal_uInt16 eNewFamily
;
226 sal_Bool bRet
= SvXMLUnitConverter::convertEnum( eNewFamily
, rStrImpValue
, lcl_getFontFamilyGenericMapping() );
228 rValue
<<= (sal_Int16
)eNewFamily
;
233 sal_Bool
XMLFontFamilyPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
235 sal_Bool bRet
= sal_False
;
238 sal_Int16 nFamily
= sal_Int16();
239 if( rValue
>>= nFamily
)
241 FontFamily eFamily
= (FontFamily
)nFamily
;
242 if( eFamily
!= FAMILY_DONTKNOW
)
243 bRet
= SvXMLUnitConverter::convertEnum( aOut
, eFamily
, lcl_getFontFamilyGenericMapping() );
246 rStrExpValue
= aOut
.makeStringAndClear();
251 ///////////////////////////////////////////////////////////////////////////////
253 // class XMLFontEncodingPropHdl
256 XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
261 sal_Bool
XMLFontEncodingPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
263 sal_Bool bRet
= sal_True
;
265 if( IsXMLToken( rStrImpValue
, XML_X_SYMBOL
) )
266 rValue
<<= (sal_Int16
) RTL_TEXTENCODING_SYMBOL
;
271 sal_Bool
XMLFontEncodingPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
273 sal_Bool bRet
= sal_False
;
275 sal_Int16 nSet
= sal_Int16();
277 if( rValue
>>= nSet
)
279 if( (rtl_TextEncoding
)nSet
== RTL_TEXTENCODING_SYMBOL
)
281 aOut
.append( GetXMLToken(XML_X_SYMBOL
) );
282 rStrExpValue
= aOut
.makeStringAndClear();
290 ///////////////////////////////////////////////////////////////////////////////
292 // class XMLFontPitchPropHdl
295 XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
300 sal_Bool
XMLFontPitchPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
303 sal_Bool bRet
= SvXMLUnitConverter::convertEnum( eNewPitch
, rStrImpValue
, aFontPitchMapping
);
305 rValue
<<= (sal_Int16
)eNewPitch
;
310 sal_Bool
XMLFontPitchPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
312 sal_Bool bRet
= sal_False
;
313 sal_Int16 nPitch
= sal_Int16();
316 FontPitch ePitch
= PITCH_DONTKNOW
;
317 if( rValue
>>= nPitch
)
318 ePitch
= (FontPitch
)nPitch
;
320 if( PITCH_DONTKNOW
!= ePitch
)
322 bRet
= SvXMLUnitConverter::convertEnum( aOut
, ePitch
, aFontPitchMapping
, XML_FIXED
);
323 rStrExpValue
= aOut
.makeStringAndClear();