1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"
#ifndef _COM_SUN_STAR_AWT_FONTFAMILY_HPP
#include <com/sun/star/awt/FontFamily.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTPITCH_HPP
#include <com/sun/star/awt/FontPitch.hpp>
#endif
#include <xmloff/nmspmap.hxx>
#include "xmloff/xmlnmspe.hxx"
#include <xmloff/xmltoken.hxx>
#ifndef _XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX
#include "fonthdl.hxx"
#endif
#include <xmloff/xmlimp.hxx>
#include <xmloff/maptype.hxx>
#ifndef _XMLOFF_XMLFONTSTYLESCONTEXT_HXX
#include <xmloff/XMLFontStylesContext.hxx>
#endif
#include <rtl/logfile.hxx>
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::awt;
using namespace ::xmloff::token;
#define XML_STYLE_FAMILY_FONT 1
enum XMLFontStyleAttrTokens
{
XML_TOK_FONT_STYLE_ATTR_FAMILY,
XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC,
XML_TOK_FONT_STYLE_ATTR_STYLENAME,
XML_TOK_FONT_STYLE_ATTR_PITCH,
XML_TOK_FONT_STYLE_ATTR_CHARSET,
XML_TOK_FONT_STYLE_ATTR_END=XML_TOK_UNKNOWN
};
const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap()
{
static __FAR_DATA SvXMLTokenMapEntry aFontStyleAttrTokenMap[] =
{
{ XML_NAMESPACE_SVG, XML_FONT_FAMILY,
XML_TOK_FONT_STYLE_ATTR_FAMILY },
{ XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC,
XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC },
{ XML_NAMESPACE_STYLE, XML_FONT_ADORNMENTS,
XML_TOK_FONT_STYLE_ATTR_STYLENAME },
{ XML_NAMESPACE_STYLE, XML_FONT_PITCH,
XML_TOK_FONT_STYLE_ATTR_PITCH },
{ XML_NAMESPACE_STYLE, XML_FONT_CHARSET,
XML_TOK_FONT_STYLE_ATTR_CHARSET },
XML_TOKEN_MAP_END
};
return aFontStyleAttrTokenMap;
}
class XMLFontStyleContext_Impl : public SvXMLStyleContext
{
Any aFamilyName;
Any aStyleName;
Any aFamily;
Any aPitch;
Any aEnc;
SvXMLImportContextRef xStyles;
XMLFontStylesContext *GetStyles()
{
return ((XMLFontStylesContext *)&xStyles);
}
public:
TYPEINFO();
XMLFontStyleContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & xAttrList,
XMLFontStylesContext& rStyles );
virtual ~XMLFontStyleContext_Impl();
void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
const OUString& rValue );
void FillProperties( ::std::vector< XMLPropertyState > &rProps,
sal_Int32 nFamilyNameIdx,
sal_Int32 nStyleNameIdx,
sal_Int32 nFamilyIdx,
sal_Int32 nPitchIdx,
sal_Int32 nCharsetIdx ) const;
};
TYPEINIT1( XMLFontStyleContext_Impl, SvXMLStyleContext );
XMLFontStyleContext_Impl::XMLFontStyleContext_Impl( SvXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLName,
const Reference< XAttributeList > & xAttrList,
XMLFontStylesContext& rStyles ) :
SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ),
xStyles( &rStyles )
{
OUString sEmpty;
aFamilyName <<= sEmpty;
aStyleName <<= sEmpty;
aFamily <<= (sal_Int16)FontFamily::DONTKNOW;
aPitch <<= (sal_Int16)FontPitch::DONTKNOW;
aEnc <<= (sal_Int16)rStyles.GetDfltCharset();
}
void XMLFontStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey,
const OUString& rLocalName,
const OUString& rValue )
{
SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
const SvXMLTokenMap& rTokenMap = GetStyles()->GetFontStyleAttrTokenMap();
Any aAny;
switch( rTokenMap.Get( nPrefixKey, rLocalName ) )
{
case XML_TOK_FONT_STYLE_ATTR_FAMILY:
if( GetStyles()->GetFamilyNameHdl().importXML( rValue, aAny,
rUnitConv ) )
aFamilyName = aAny;
break;
case XML_TOK_FONT_STYLE_ATTR_STYLENAME:
aStyleName <<= rValue;
break;
case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC:
if( GetStyles()->GetFamilyHdl().importXML( rValue, aAny,
rUnitConv ) )
aFamily = aAny;
break;
case XML_TOK_FONT_STYLE_ATTR_PITCH:
if( GetStyles()->GetPitchHdl().importXML( rValue, aAny,
rUnitConv ) )
aPitch = aAny;
break;
case XML_TOK_FONT_STYLE_ATTR_CHARSET:
if( GetStyles()->GetEncodingHdl().importXML( rValue, aAny,
rUnitConv ) )
aEnc = aAny;
break;
default:
SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
break;
}
}
XMLFontStyleContext_Impl::~XMLFontStyleContext_Impl()
{
}
void XMLFontStyleContext_Impl::FillProperties(
::std::vector< XMLPropertyState > &rProps,
sal_Int32 nFamilyNameIdx,
sal_Int32 nStyleNameIdx,
sal_Int32 nFamilyIdx,
sal_Int32 nPitchIdx,
sal_Int32 nCharsetIdx ) const
{
if( nFamilyNameIdx != -1 )
{
XMLPropertyState aPropState( nFamilyNameIdx, aFamilyName );
rProps.push_back( aPropState );
}
if( nStyleNameIdx != -1 )
{
XMLPropertyState aPropState( nStyleNameIdx, aStyleName );
rProps.push_back( aPropState );
}
if( nFamilyIdx != -1 )
{
XMLPropertyState aPropState( nFamilyIdx, aFamily );
rProps.push_back( aPropState );
}
if( nPitchIdx != -1 )
{
XMLPropertyState aPropState( nPitchIdx, aPitch );
rProps.push_back( aPropState );
}
if( nCharsetIdx != -1 )
{
XMLPropertyState aPropState( nCharsetIdx, aEnc );
rProps.push_back( aPropState );
}
}
SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext(
sal_uInt16 nPrefix,
const ::rtl::OUString& rLocalName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & xAttrList )
{
SvXMLStyleContext *pStyle;
if( XML_NAMESPACE_STYLE == nPrefix &&
IsXMLToken( rLocalName, XML_FONT_FACE ) )
{
pStyle = new XMLFontStyleContext_Impl( GetImport(), nPrefix,
rLocalName, xAttrList, *this );
}
else
{
pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix,
rLocalName, xAttrList );
}
return pStyle;
}
TYPEINIT1( XMLFontStylesContext, SvXMLStylesContext );
XMLFontStylesContext::XMLFontStylesContext( SvXMLImport& rImport,
sal_uInt16 nPrfx, const OUString& rLName,
const Reference< XAttributeList > & xAttrList,
rtl_TextEncoding eDfltEnc ) :
SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
pFamilyNameHdl( new XMLFontFamilyNamePropHdl ),
pFamilyHdl( new XMLFontFamilyPropHdl ),
pPitchHdl( new XMLFontPitchPropHdl ),
pEncHdl( new XMLFontEncodingPropHdl ),
pFontStyleAttrTokenMap( new SvXMLTokenMap(lcl_getFontStyleAttrTokenMap()) ),
eDfltEncoding( eDfltEnc )
{
}
XMLFontStylesContext::~XMLFontStylesContext()
{
delete pFamilyNameHdl;
delete pFamilyHdl;
delete pPitchHdl;
delete pEncHdl;
delete pFontStyleAttrTokenMap;
}
sal_Bool XMLFontStylesContext::FillProperties( const OUString& rName,
::std::vector< XMLPropertyState > &rProps,
sal_Int32 nFamilyNameIdx,
sal_Int32 nStyleNameIdx,
sal_Int32 nFamilyIdx,
sal_Int32 nPitchIdx,
sal_Int32 nCharsetIdx ) const
{
const SvXMLStyleContext* pStyle = FindStyleChildContext( XML_STYLE_FAMILY_FONT, rName, sal_True );
const XMLFontStyleContext_Impl *pFontStyle = PTR_CAST( XMLFontStyleContext_Impl,pStyle);// use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
if( pFontStyle )
pFontStyle->FillProperties( rProps, nFamilyNameIdx, nStyleNameIdx,
nFamilyIdx, nPitchIdx, nCharsetIdx );
return 0 != pFontStyle;
}
|