1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27 #include <com/sun/star/awt/FontFamily.hpp>
28 #include <com/sun/star/awt/FontPitch.hpp>
29
30 #include <rtl/logfile.hxx>
31
32 #include <xmloff/nmspmap.hxx>
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include "fonthdl.hxx"
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/maptype.hxx>
38 #include <xmloff/XMLFontStylesContext.hxx>
39
40
41 using ::rtl::OUString;
42 using ::rtl::OUStringBuffer;
43
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::xml::sax;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::awt;
51 using namespace ::xmloff::token;
52
53
54 #define XML_STYLE_FAMILY_FONT 1
55
56 enum XMLFontStyleAttrTokens
57 {
58 XML_TOK_FONT_STYLE_ATTR_FAMILY,
59 XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC,
60 XML_TOK_FONT_STYLE_ATTR_STYLENAME,
61 XML_TOK_FONT_STYLE_ATTR_PITCH,
62 XML_TOK_FONT_STYLE_ATTR_CHARSET,
63
64 XML_TOK_FONT_STYLE_ATTR_END=XML_TOK_UNKNOWN
65 };
66
lcl_getFontStyleAttrTokenMap()67 const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap()
68 {
69 static __FAR_DATA SvXMLTokenMapEntry aFontStyleAttrTokenMap[] =
70 {
71 { XML_NAMESPACE_SVG, XML_FONT_FAMILY,
72 XML_TOK_FONT_STYLE_ATTR_FAMILY },
73 { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC,
74 XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC },
75 { XML_NAMESPACE_STYLE, XML_FONT_ADORNMENTS,
76 XML_TOK_FONT_STYLE_ATTR_STYLENAME },
77 { XML_NAMESPACE_STYLE, XML_FONT_PITCH,
78 XML_TOK_FONT_STYLE_ATTR_PITCH },
79 { XML_NAMESPACE_STYLE, XML_FONT_CHARSET,
80 XML_TOK_FONT_STYLE_ATTR_CHARSET },
81
82 XML_TOKEN_MAP_END
83 };
84 return aFontStyleAttrTokenMap;
85 }
86
87 class XMLFontStyleContext_Impl : public SvXMLStyleContext
88 {
89 Any aFamilyName;
90 Any aStyleName;
91 Any aFamily;
92 Any aPitch;
93 Any aEnc;
94
95 SvXMLImportContextRef xStyles;
96
GetStyles()97 XMLFontStylesContext *GetStyles()
98 {
99 return ((XMLFontStylesContext *)&xStyles);
100 }
101
102 public:
103
104 TYPEINFO();
105
106 XMLFontStyleContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
107 const ::rtl::OUString& rLName,
108 const ::com::sun::star::uno::Reference<
109 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
110 XMLFontStylesContext& rStyles );
111 virtual ~XMLFontStyleContext_Impl();
112
113 void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
114 const OUString& rValue );
115
116 void FillProperties( ::std::vector< XMLPropertyState > &rProps,
117 sal_Int32 nFamilyNameIdx,
118 sal_Int32 nStyleNameIdx,
119 sal_Int32 nFamilyIdx,
120 sal_Int32 nPitchIdx,
121 sal_Int32 nCharsetIdx ) const;
122
123 };
124
125 TYPEINIT1( XMLFontStyleContext_Impl, SvXMLStyleContext );
126
XMLFontStyleContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,XMLFontStylesContext & rStyles)127 XMLFontStyleContext_Impl::XMLFontStyleContext_Impl( SvXMLImport& rImport,
128 sal_uInt16 nPrfx, const OUString& rLName,
129 const Reference< XAttributeList > & xAttrList,
130 XMLFontStylesContext& rStyles ) :
131 SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ),
132 xStyles( &rStyles )
133 {
134 OUString sEmpty;
135 aFamilyName <<= sEmpty;
136 aStyleName <<= sEmpty;
137 aFamily <<= (sal_Int16)FontFamily::DONTKNOW;
138 aPitch <<= (sal_Int16)FontPitch::DONTKNOW;
139 aEnc <<= (sal_Int16)rStyles.GetDfltCharset();
140 }
141
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)142 void XMLFontStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
143 const OUString& rLocalName,
144 const OUString& rValue )
145 {
146 SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
147 const SvXMLTokenMap& rTokenMap = GetStyles()->GetFontStyleAttrTokenMap();
148 Any aAny;
149
150 switch( rTokenMap.Get( nPrefixKey, rLocalName ) )
151 {
152 case XML_TOK_FONT_STYLE_ATTR_FAMILY:
153 if( GetStyles()->GetFamilyNameHdl().importXML( rValue, aAny,
154 rUnitConv ) )
155 aFamilyName = aAny;
156 break;
157 case XML_TOK_FONT_STYLE_ATTR_STYLENAME:
158 aStyleName <<= rValue;
159 break;
160 case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC:
161 if( GetStyles()->GetFamilyHdl().importXML( rValue, aAny,
162 rUnitConv ) )
163 aFamily = aAny;
164 break;
165 case XML_TOK_FONT_STYLE_ATTR_PITCH:
166 if( GetStyles()->GetPitchHdl().importXML( rValue, aAny,
167 rUnitConv ) )
168 aPitch = aAny;
169 break;
170 case XML_TOK_FONT_STYLE_ATTR_CHARSET:
171 if( GetStyles()->GetEncodingHdl().importXML( rValue, aAny,
172 rUnitConv ) )
173 aEnc = aAny;
174 break;
175 default:
176 SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
177 break;
178 }
179 }
180
~XMLFontStyleContext_Impl()181 XMLFontStyleContext_Impl::~XMLFontStyleContext_Impl()
182 {
183 }
184
FillProperties(::std::vector<XMLPropertyState> & rProps,sal_Int32 nFamilyNameIdx,sal_Int32 nStyleNameIdx,sal_Int32 nFamilyIdx,sal_Int32 nPitchIdx,sal_Int32 nCharsetIdx) const185 void XMLFontStyleContext_Impl::FillProperties(
186 ::std::vector< XMLPropertyState > &rProps,
187 sal_Int32 nFamilyNameIdx,
188 sal_Int32 nStyleNameIdx,
189 sal_Int32 nFamilyIdx,
190 sal_Int32 nPitchIdx,
191 sal_Int32 nCharsetIdx ) const
192 {
193 if( nFamilyNameIdx != -1 )
194 {
195 XMLPropertyState aPropState( nFamilyNameIdx, aFamilyName );
196 rProps.push_back( aPropState );
197 }
198 if( nStyleNameIdx != -1 )
199 {
200 XMLPropertyState aPropState( nStyleNameIdx, aStyleName );
201 rProps.push_back( aPropState );
202 }
203 if( nFamilyIdx != -1 )
204 {
205 XMLPropertyState aPropState( nFamilyIdx, aFamily );
206 rProps.push_back( aPropState );
207 }
208 if( nPitchIdx != -1 )
209 {
210 XMLPropertyState aPropState( nPitchIdx, aPitch );
211 rProps.push_back( aPropState );
212 }
213 if( nCharsetIdx != -1 )
214 {
215 XMLPropertyState aPropState( nCharsetIdx, aEnc );
216 rProps.push_back( aPropState );
217 }
218 }
219
CreateStyleChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)220 SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext(
221 sal_uInt16 nPrefix,
222 const ::rtl::OUString& rLocalName,
223 const ::com::sun::star::uno::Reference<
224 ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
225 {
226 SvXMLStyleContext *pStyle;
227 if( XML_NAMESPACE_STYLE == nPrefix &&
228 IsXMLToken( rLocalName, XML_FONT_FACE ) )
229 {
230 pStyle = new XMLFontStyleContext_Impl( GetImport(), nPrefix,
231 rLocalName, xAttrList, *this );
232 }
233 else
234 {
235 pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix,
236 rLocalName, xAttrList );
237 }
238
239 return pStyle;
240 }
241
242 TYPEINIT1( XMLFontStylesContext, SvXMLStylesContext );
243
XMLFontStylesContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,rtl_TextEncoding eDfltEnc)244 XMLFontStylesContext::XMLFontStylesContext( SvXMLImport& rImport,
245 sal_uInt16 nPrfx, const OUString& rLName,
246 const Reference< XAttributeList > & xAttrList,
247 rtl_TextEncoding eDfltEnc ) :
248 SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
249 pFamilyNameHdl( new XMLFontFamilyNamePropHdl ),
250 pFamilyHdl( new XMLFontFamilyPropHdl ),
251 pPitchHdl( new XMLFontPitchPropHdl ),
252 pEncHdl( new XMLFontEncodingPropHdl ),
253 pFontStyleAttrTokenMap( new SvXMLTokenMap(lcl_getFontStyleAttrTokenMap()) ),
254 eDfltEncoding( eDfltEnc )
255 {
256 }
257
~XMLFontStylesContext()258 XMLFontStylesContext::~XMLFontStylesContext()
259 {
260 delete pFamilyNameHdl;
261 delete pFamilyHdl;
262 delete pPitchHdl;
263 delete pEncHdl;
264 delete pFontStyleAttrTokenMap;
265 }
266
FillProperties(const OUString & rName,::std::vector<XMLPropertyState> & rProps,sal_Int32 nFamilyNameIdx,sal_Int32 nStyleNameIdx,sal_Int32 nFamilyIdx,sal_Int32 nPitchIdx,sal_Int32 nCharsetIdx) const267 sal_Bool XMLFontStylesContext::FillProperties( const OUString& rName,
268 ::std::vector< XMLPropertyState > &rProps,
269 sal_Int32 nFamilyNameIdx,
270 sal_Int32 nStyleNameIdx,
271 sal_Int32 nFamilyIdx,
272 sal_Int32 nPitchIdx,
273 sal_Int32 nCharsetIdx ) const
274 {
275 const SvXMLStyleContext* pStyle = FindStyleChildContext( XML_STYLE_FAMILY_FONT, rName, sal_True );
276 const XMLFontStyleContext_Impl *pFontStyle = PTR_CAST( XMLFontStyleContext_Impl,pStyle);// use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
277 if( pFontStyle )
278 pFontStyle->FillProperties( rProps, nFamilyNameIdx, nStyleNameIdx,
279 nFamilyIdx, nPitchIdx, nCharsetIdx );
280 return 0 != pFontStyle;
281 }
282