Update ooo320-m1
[ooovba.git] / xmloff / source / style / XMLFontStylesContext.cxx
blob3bb6d98785e243a92449524a3529daccb53c1d11
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLFontStylesContext.cxx,v $
10 * $Revision: 1.12 $
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 _COM_SUN_STAR_AWT_FONTFAMILY_HPP
35 #include <com/sun/star/awt/FontFamily.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_AWT_FONTPITCH_HPP
38 #include <com/sun/star/awt/FontPitch.hpp>
39 #endif
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #ifndef _XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX
44 #include "fonthdl.hxx"
45 #endif
46 #include <xmloff/xmlimp.hxx>
47 #include <xmloff/maptype.hxx>
49 #ifndef _XMLOFF_XMLFONTSTYLESCONTEXT_HXX
50 #include <xmloff/XMLFontStylesContext.hxx>
51 #endif
52 #include <rtl/logfile.hxx>
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::xml::sax;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::awt;
63 using namespace ::xmloff::token;
66 #define XML_STYLE_FAMILY_FONT 1
68 enum XMLFontStyleAttrTokens
70 XML_TOK_FONT_STYLE_ATTR_FAMILY,
71 XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC,
72 XML_TOK_FONT_STYLE_ATTR_STYLENAME,
73 XML_TOK_FONT_STYLE_ATTR_PITCH,
74 XML_TOK_FONT_STYLE_ATTR_CHARSET,
76 XML_TOK_FONT_STYLE_ATTR_END=XML_TOK_UNKNOWN
79 const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap()
81 static __FAR_DATA SvXMLTokenMapEntry aFontStyleAttrTokenMap[] =
83 { XML_NAMESPACE_SVG, XML_FONT_FAMILY,
84 XML_TOK_FONT_STYLE_ATTR_FAMILY },
85 { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC,
86 XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC },
87 { XML_NAMESPACE_STYLE, XML_FONT_ADORNMENTS,
88 XML_TOK_FONT_STYLE_ATTR_STYLENAME },
89 { XML_NAMESPACE_STYLE, XML_FONT_PITCH,
90 XML_TOK_FONT_STYLE_ATTR_PITCH },
91 { XML_NAMESPACE_STYLE, XML_FONT_CHARSET,
92 XML_TOK_FONT_STYLE_ATTR_CHARSET },
94 XML_TOKEN_MAP_END
96 return aFontStyleAttrTokenMap;
99 class XMLFontStyleContext_Impl : public SvXMLStyleContext
101 Any aFamilyName;
102 Any aStyleName;
103 Any aFamily;
104 Any aPitch;
105 Any aEnc;
107 SvXMLImportContextRef xStyles;
109 XMLFontStylesContext *GetStyles()
111 return ((XMLFontStylesContext *)&xStyles);
114 public:
116 TYPEINFO();
118 XMLFontStyleContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
119 const ::rtl::OUString& rLName,
120 const ::com::sun::star::uno::Reference<
121 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
122 XMLFontStylesContext& rStyles );
123 virtual ~XMLFontStyleContext_Impl();
125 void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
126 const OUString& rValue );
128 void FillProperties( ::std::vector< XMLPropertyState > &rProps,
129 sal_Int32 nFamilyNameIdx,
130 sal_Int32 nStyleNameIdx,
131 sal_Int32 nFamilyIdx,
132 sal_Int32 nPitchIdx,
133 sal_Int32 nCharsetIdx ) const;
137 TYPEINIT1( XMLFontStyleContext_Impl, SvXMLStyleContext );
139 XMLFontStyleContext_Impl::XMLFontStyleContext_Impl( SvXMLImport& rImport,
140 sal_uInt16 nPrfx, const OUString& rLName,
141 const Reference< XAttributeList > & xAttrList,
142 XMLFontStylesContext& rStyles ) :
143 SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ),
144 xStyles( &rStyles )
146 OUString sEmpty;
147 aFamilyName <<= sEmpty;
148 aStyleName <<= sEmpty;
149 aFamily <<= (sal_Int16)FontFamily::DONTKNOW;
150 aPitch <<= (sal_Int16)FontPitch::DONTKNOW;
151 aEnc <<= (sal_Int16)rStyles.GetDfltCharset();
154 void XMLFontStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
155 const OUString& rLocalName,
156 const OUString& rValue )
158 SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
159 const SvXMLTokenMap& rTokenMap = GetStyles()->GetFontStyleAttrTokenMap();
160 Any aAny;
162 switch( rTokenMap.Get( nPrefixKey, rLocalName ) )
164 case XML_TOK_FONT_STYLE_ATTR_FAMILY:
165 if( GetStyles()->GetFamilyNameHdl().importXML( rValue, aAny,
166 rUnitConv ) )
167 aFamilyName = aAny;
168 break;
169 case XML_TOK_FONT_STYLE_ATTR_STYLENAME:
170 aStyleName <<= rValue;
171 break;
172 case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC:
173 if( GetStyles()->GetFamilyHdl().importXML( rValue, aAny,
174 rUnitConv ) )
175 aFamily = aAny;
176 break;
177 case XML_TOK_FONT_STYLE_ATTR_PITCH:
178 if( GetStyles()->GetPitchHdl().importXML( rValue, aAny,
179 rUnitConv ) )
180 aPitch = aAny;
181 break;
182 case XML_TOK_FONT_STYLE_ATTR_CHARSET:
183 if( GetStyles()->GetEncodingHdl().importXML( rValue, aAny,
184 rUnitConv ) )
185 aEnc = aAny;
186 break;
187 default:
188 SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
189 break;
193 XMLFontStyleContext_Impl::~XMLFontStyleContext_Impl()
197 void XMLFontStyleContext_Impl::FillProperties(
198 ::std::vector< XMLPropertyState > &rProps,
199 sal_Int32 nFamilyNameIdx,
200 sal_Int32 nStyleNameIdx,
201 sal_Int32 nFamilyIdx,
202 sal_Int32 nPitchIdx,
203 sal_Int32 nCharsetIdx ) const
205 if( nFamilyNameIdx != -1 )
207 XMLPropertyState aPropState( nFamilyNameIdx, aFamilyName );
208 rProps.push_back( aPropState );
210 if( nStyleNameIdx != -1 )
212 XMLPropertyState aPropState( nStyleNameIdx, aStyleName );
213 rProps.push_back( aPropState );
215 if( nFamilyIdx != -1 )
217 XMLPropertyState aPropState( nFamilyIdx, aFamily );
218 rProps.push_back( aPropState );
220 if( nPitchIdx != -1 )
222 XMLPropertyState aPropState( nPitchIdx, aPitch );
223 rProps.push_back( aPropState );
225 if( nCharsetIdx != -1 )
227 XMLPropertyState aPropState( nCharsetIdx, aEnc );
228 rProps.push_back( aPropState );
232 SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext(
233 sal_uInt16 nPrefix,
234 const ::rtl::OUString& rLocalName,
235 const ::com::sun::star::uno::Reference<
236 ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
238 SvXMLStyleContext *pStyle;
239 if( XML_NAMESPACE_STYLE == nPrefix &&
240 IsXMLToken( rLocalName, XML_FONT_FACE ) )
242 pStyle = new XMLFontStyleContext_Impl( GetImport(), nPrefix,
243 rLocalName, xAttrList, *this );
245 else
247 pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix,
248 rLocalName, xAttrList );
251 return pStyle;
254 TYPEINIT1( XMLFontStylesContext, SvXMLStylesContext );
256 XMLFontStylesContext::XMLFontStylesContext( SvXMLImport& rImport,
257 sal_uInt16 nPrfx, const OUString& rLName,
258 const Reference< XAttributeList > & xAttrList,
259 rtl_TextEncoding eDfltEnc ) :
260 SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
261 pFamilyNameHdl( new XMLFontFamilyNamePropHdl ),
262 pFamilyHdl( new XMLFontFamilyPropHdl ),
263 pPitchHdl( new XMLFontPitchPropHdl ),
264 pEncHdl( new XMLFontEncodingPropHdl ),
265 pFontStyleAttrTokenMap( new SvXMLTokenMap(lcl_getFontStyleAttrTokenMap()) ),
266 eDfltEncoding( eDfltEnc )
270 XMLFontStylesContext::~XMLFontStylesContext()
272 delete pFamilyNameHdl;
273 delete pFamilyHdl;
274 delete pPitchHdl;
275 delete pEncHdl;
276 delete pFontStyleAttrTokenMap;
279 sal_Bool XMLFontStylesContext::FillProperties( const OUString& rName,
280 ::std::vector< XMLPropertyState > &rProps,
281 sal_Int32 nFamilyNameIdx,
282 sal_Int32 nStyleNameIdx,
283 sal_Int32 nFamilyIdx,
284 sal_Int32 nPitchIdx,
285 sal_Int32 nCharsetIdx ) const
287 const SvXMLStyleContext* pStyle = FindStyleChildContext( XML_STYLE_FAMILY_FONT, rName, sal_True );
288 const XMLFontStyleContext_Impl *pFontStyle = PTR_CAST( XMLFontStyleContext_Impl,pStyle);// use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
289 if( pFontStyle )
290 pFontStyle->FillProperties( rProps, nFamilyNameIdx, nStyleNameIdx,
291 nFamilyIdx, nPitchIdx, nCharsetIdx );
292 return 0 != pFontStyle;