Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <xmloff/prhdlfac.hxx>
21 :
22 : #include <com/sun/star/drawing/ColorMode.hpp>
23 : #include <com/sun/star/text/HorizontalAdjust.hpp>
24 : #include <com/sun/star/text/WritingMode2.hpp>
25 :
26 : #include <tools/debug.hxx>
27 :
28 : #include <xmloff/xmltypes.hxx>
29 : #include <xmloff/xmltoken.hxx>
30 : #include <xmloff/xmlprhdl.hxx>
31 : #include "xmlbahdl.hxx"
32 : #include <xmloff/NamedBoolPropertyHdl.hxx>
33 : #include <xmloff/XMLConstantsPropertyHandler.hxx>
34 : #include "cdouthdl.hxx"
35 : #include "csmaphdl.hxx"
36 : #include "fonthdl.hxx"
37 : #include "kernihdl.hxx"
38 : #include <postuhdl.hxx>
39 : #include "shadwhdl.hxx"
40 : #include "shdwdhdl.hxx"
41 : #include "undlihdl.hxx"
42 : #include "weighhdl.hxx"
43 : #include "breakhdl.hxx"
44 : #include <adjushdl.hxx>
45 : #include <escphdl.hxx>
46 : #include <chrhghdl.hxx>
47 : #include <chrlohdl.hxx>
48 : #include <lspachdl.hxx>
49 : #include <bordrhdl.hxx>
50 : #include <tabsthdl.hxx>
51 : #include <xmloff/EnumPropertyHdl.hxx>
52 : #include "AttributeContainerHandler.hxx"
53 : #include "durationhdl.hxx"
54 : #include "XMLRectangleMembersHandler.hxx"
55 : #include "DrawAspectHdl.hxx"
56 :
57 : #include <map>
58 :
59 : using namespace ::com::sun::star;
60 : using namespace ::xmloff::token;
61 :
62 : static SvXMLEnumMapEntry const aXML_ColorMode_EnumMap[] =
63 : {
64 : { XML_GREYSCALE, drawing::ColorMode_GREYS },
65 : { XML_MONO, drawing::ColorMode_MONO },
66 : { XML_WATERMARK, drawing::ColorMode_WATERMARK },
67 : { XML_STANDARD, drawing::ColorMode_STANDARD },
68 : { XML_TOKEN_INVALID, 0 }
69 : };
70 :
71 : static SvXMLEnumMapEntry const aXML_HorizontalAdjust_Enum[] =
72 : {
73 : { XML_LEFT, text::HorizontalAdjust_LEFT },
74 : { XML_CENTER, text::HorizontalAdjust_CENTER },
75 : { XML_RIGHT, text::HorizontalAdjust_RIGHT },
76 : { XML_TOKEN_INVALID, 0 }
77 : };
78 :
79 : // aXML_WritingDirection_Enum is used with and without 'page'
80 : // attribute, so you'll find uses of aXML_WritingDirection_Enum
81 : // directly, as well as &(aXML_WritingDirection_Enum[1])
82 : static SvXMLEnumMapEntry const aXML_WritingDirection_Enum[] =
83 : {
84 : // aXML_WritingDirection_Enum
85 : { XML_PAGE, text::WritingMode2::PAGE },
86 :
87 : // &(aXML_WritingDirection_Enum[1])
88 : { XML_LR_TB, text::WritingMode2::LR_TB },
89 : { XML_RL_TB, text::WritingMode2::RL_TB },
90 : { XML_TB_RL, text::WritingMode2::TB_RL },
91 : { XML_TB_LR, text::WritingMode2::TB_LR },
92 :
93 : // alternative names of the above, as accepted by XSL
94 : { XML_LR, text::WritingMode2::LR_TB },
95 : { XML_RL, text::WritingMode2::RL_TB },
96 : { XML_TB, text::WritingMode2::TB_RL },
97 :
98 : { XML_TOKEN_INVALID, 0 }
99 : };
100 :
101 : typedef std::map<sal_Int32, const XMLPropertyHandler*> CacheMap;
102 :
103 94884 : struct XMLPropertyHandlerFactory::Impl
104 : {
105 : mutable CacheMap maHandlerCache;
106 : };
107 :
108 47452 : XMLPropertyHandlerFactory::XMLPropertyHandlerFactory() :
109 47452 : mpImpl(new Impl) {}
110 :
111 94864 : XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
112 : {
113 2306208 : for( CacheMap::iterator pPos = mpImpl->maHandlerCache.begin(); pPos != mpImpl->maHandlerCache.end(); ++pPos )
114 2258776 : delete pPos->second;
115 :
116 47432 : delete mpImpl;
117 47432 : }
118 :
119 : // Interface
120 4938010 : const XMLPropertyHandler* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType ) const
121 : {
122 : DBG_ASSERT( (nType & ~((sal_uInt32)MID_FLAG_MASK)) == 0,
123 : "GetPropertyHandler called with flags in type" );
124 4938010 : return GetBasicHandler( nType );
125 : }
126 :
127 : // Helper-methods to create and cache PropertyHandler
128 4938010 : const XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const
129 : {
130 4938010 : const XMLPropertyHandler* pRet = NULL;
131 :
132 4938010 : if( mpImpl->maHandlerCache.find( nType ) != mpImpl->maHandlerCache.end() )
133 2677594 : pRet = mpImpl->maHandlerCache.find( nType )->second;
134 :
135 4938010 : return pRet;
136 : }
137 :
138 2260416 : void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const
139 : {
140 2260416 : mpImpl->maHandlerCache[nType] = pHdl;
141 2260416 : }
142 :
143 4938010 : const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const
144 : {
145 4938010 : const XMLPropertyHandler* pPropHdl = GetHdlCache( nType );
146 :
147 4938010 : if( !pPropHdl )
148 : {
149 2260416 : pPropHdl = CreatePropertyHandler( nType );
150 :
151 2260416 : if( pPropHdl )
152 1373698 : PutHdlCache( nType, pPropHdl );
153 : }
154 :
155 4938010 : return pPropHdl;
156 : }
157 :
158 2260450 : const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType )
159 : {
160 2260450 : XMLPropertyHandler* pPropHdl = NULL;
161 :
162 2260450 : switch( nType )
163 : {
164 : case XML_TYPE_BOOL :
165 39542 : pPropHdl = new XMLBoolPropHdl;
166 39542 : break;
167 : case XML_TYPE_BOOL_FALSE :
168 4 : pPropHdl = new XMLBoolFalsePropHdl;
169 4 : break;
170 : case XML_TYPE_MEASURE :
171 37856 : pPropHdl = new XMLMeasurePropHdl( 4 );
172 37856 : break;
173 : case XML_TYPE_MEASURE8 :
174 0 : pPropHdl = new XMLMeasurePropHdl( 1 );
175 0 : break;
176 : case XML_TYPE_MEASURE16:
177 2564 : pPropHdl = new XMLMeasurePropHdl( 2 );
178 2564 : break;
179 : case XML_TYPE_PERCENT :
180 25184 : pPropHdl = new XMLPercentPropHdl( 4 );
181 25184 : break;
182 : case XML_TYPE_PERCENT8 :
183 7858 : pPropHdl = new XMLPercentPropHdl( 1 );
184 7858 : break;
185 : case XML_TYPE_PERCENT16 :
186 29528 : pPropHdl = new XMLPercentPropHdl( 2 );
187 29528 : break;
188 : case XML_TYPE_DOUBLE_PERCENT :
189 12674 : pPropHdl = new XMLDoublePercentPropHdl();
190 12674 : break;
191 : case XML_TYPE_NEG_PERCENT :
192 12674 : pPropHdl = new XMLNegPercentPropHdl( 4 );
193 12674 : break;
194 : case XML_TYPE_NEG_PERCENT8 :
195 0 : pPropHdl = new XMLNegPercentPropHdl( 1 );
196 0 : break;
197 : case XML_TYPE_NEG_PERCENT16 :
198 17878 : pPropHdl = new XMLNegPercentPropHdl( 2 );
199 17878 : break;
200 : case XML_TYPE_MEASURE_PX :
201 12674 : pPropHdl = new XMLMeasurePxPropHdl( 4 );
202 12674 : break;
203 : case XML_TYPE_STRING :
204 37504 : pPropHdl = new XMLStringPropHdl;
205 37504 : break;
206 : case XML_TYPE_COLOR :
207 31940 : pPropHdl = new XMLColorPropHdl;
208 31940 : break;
209 : case XML_TYPE_HEX :
210 15946 : pPropHdl = new XMLHexPropHdl;
211 15946 : break;
212 : case XML_TYPE_NUMBER :
213 25214 : pPropHdl = new XMLNumberPropHdl( 4 );
214 25214 : break;
215 : case XML_TYPE_NUMBER8 :
216 11602 : pPropHdl = new XMLNumberPropHdl( 1 );
217 11602 : break;
218 : case XML_TYPE_NUMBER16:
219 23966 : pPropHdl = new XMLNumberPropHdl( 2 );
220 23966 : break;
221 : case XML_TYPE_NUMBER_NONE :
222 0 : pPropHdl = new XMLNumberNonePropHdl;
223 0 : break;
224 : case XML_TYPE_NUMBER8_NONE :
225 0 : pPropHdl = new XMLNumberNonePropHdl( 1 );
226 0 : break;
227 : case XML_TYPE_NUMBER16_NONE :
228 11602 : pPropHdl = new XMLNumberNonePropHdl( 2 );
229 11602 : break;
230 : case XML_TYPE_DOUBLE :
231 1888 : pPropHdl = new XMLDoublePropHdl;
232 1888 : break;
233 : case XML_TYPE_NBOOL :
234 136 : pPropHdl = new XMLNBoolPropHdl;
235 136 : break;
236 : case XML_TYPE_COLORTRANSPARENT :
237 29368 : pPropHdl = new XMLColorTransparentPropHdl;
238 29368 : break;
239 : case XML_TYPE_ISTRANSPARENT :
240 29368 : pPropHdl = new XMLIsTransparentPropHdl;
241 29368 : break;
242 : case XML_TYPE_COLORAUTO :
243 17214 : pPropHdl = new XMLColorAutoPropHdl;
244 17214 : break;
245 : case XML_TYPE_ISAUTOCOLOR :
246 15946 : pPropHdl = new XMLIsAutoColorPropHdl;
247 15946 : break;
248 : case XML_TYPE_BUILDIN_CMP_ONLY :
249 30748 : pPropHdl = new XMLCompareOnlyPropHdl;
250 30748 : break;
251 :
252 : case XML_TYPE_RECTANGLE_LEFT :
253 : case XML_TYPE_RECTANGLE_TOP :
254 : case XML_TYPE_RECTANGLE_WIDTH :
255 : case XML_TYPE_RECTANGLE_HEIGHT :
256 22896 : pPropHdl = new XMLRectangleMembersHdl( nType );
257 22896 : break;
258 :
259 : case XML_TYPE_TEXT_CROSSEDOUT_TYPE:
260 16470 : pPropHdl = new XMLCrossedOutTypePropHdl ;
261 16470 : break;
262 : case XML_TYPE_TEXT_CROSSEDOUT_STYLE:
263 16470 : pPropHdl = new XMLCrossedOutStylePropHdl ;
264 16470 : break;
265 : case XML_TYPE_TEXT_CROSSEDOUT_WIDTH:
266 16470 : pPropHdl = new XMLCrossedOutWidthPropHdl ;
267 16470 : break;
268 : case XML_TYPE_TEXT_CROSSEDOUT_TEXT:
269 16470 : pPropHdl = new XMLCrossedOutTextPropHdl ;
270 16470 : break;
271 : case XML_TYPE_TEXT_BOOLCROSSEDOUT:
272 : pPropHdl = new XMLNamedBoolPropertyHdl(
273 : GetXMLToken(XML_SOLID),
274 0 : GetXMLToken(XML_NONE) );
275 0 : break;
276 : case XML_TYPE_TEXT_ESCAPEMENT:
277 15946 : pPropHdl = new XMLEscapementPropHdl;
278 15946 : break;
279 : case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT:
280 15946 : pPropHdl = new XMLEscapementHeightPropHdl;
281 15946 : break;
282 : case XML_TYPE_TEXT_CASEMAP:
283 15946 : pPropHdl = new XMLCaseMapPropHdl;
284 15946 : break;
285 : case XML_TYPE_TEXT_CASEMAP_VAR:
286 15946 : pPropHdl = new XMLCaseMapVariantHdl;
287 15946 : break;
288 : case XML_TYPE_TEXT_FONTFAMILYNAME:
289 15946 : pPropHdl = new XMLFontFamilyNamePropHdl;
290 15946 : break;
291 : case XML_TYPE_TEXT_FONTFAMILY:
292 16470 : pPropHdl = new XMLFontFamilyPropHdl;
293 16470 : break;
294 : case XML_TYPE_TEXT_FONTENCODING:
295 16470 : pPropHdl = new XMLFontEncodingPropHdl;
296 16470 : break;
297 : case XML_TYPE_TEXT_FONTPITCH:
298 16470 : pPropHdl = new XMLFontPitchPropHdl;
299 16470 : break;
300 : case XML_TYPE_TEXT_KERNING:
301 15946 : pPropHdl = new XMLKerningPropHdl;
302 15946 : break;
303 : case XML_TYPE_TEXT_POSTURE:
304 16470 : pPropHdl = new XMLPosturePropHdl;
305 16470 : break;
306 : case XML_TYPE_TEXT_SHADOWED:
307 15946 : pPropHdl = new XMLShadowedPropHdl;
308 15946 : break;
309 : case XML_TYPE_TEXT_UNDERLINE_TYPE:
310 16470 : pPropHdl = new XMLUnderlineTypePropHdl;
311 16470 : break;
312 : case XML_TYPE_TEXT_UNDERLINE_STYLE:
313 16470 : pPropHdl = new XMLUnderlineStylePropHdl;
314 16470 : break;
315 : case XML_TYPE_TEXT_UNDERLINE_WIDTH:
316 16470 : pPropHdl = new XMLUnderlineWidthPropHdl;
317 16470 : break;
318 : case XML_TYPE_TEXT_UNDERLINE_COLOR:
319 16470 : pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
320 16470 : break;
321 : case XML_TYPE_TEXT_UNDERLINE_HASCOLOR:
322 : pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
323 16334 : false );
324 16334 : break;
325 : case XML_TYPE_TEXT_OVERLINE_TYPE:
326 15946 : pPropHdl = new XMLUnderlineTypePropHdl;
327 15946 : break;
328 : case XML_TYPE_TEXT_OVERLINE_STYLE:
329 15946 : pPropHdl = new XMLUnderlineStylePropHdl;
330 15946 : break;
331 : case XML_TYPE_TEXT_OVERLINE_WIDTH:
332 15946 : pPropHdl = new XMLUnderlineWidthPropHdl;
333 15946 : break;
334 : case XML_TYPE_TEXT_OVERLINE_COLOR:
335 15946 : pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
336 15946 : break;
337 : case XML_TYPE_TEXT_OVERLINE_HASCOLOR:
338 : pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
339 15946 : false );
340 15946 : break;
341 : case XML_TYPE_TEXT_WEIGHT:
342 16470 : pPropHdl = new XMLFontWeightPropHdl;
343 16470 : break;
344 : case XML_TYPE_TEXT_SPLIT:
345 : pPropHdl = new XMLNamedBoolPropertyHdl(
346 : GetXMLToken(XML_AUTO),
347 11602 : GetXMLToken(XML_ALWAYS) );
348 11602 : break;
349 : case XML_TYPE_TEXT_BREAKBEFORE:
350 11602 : pPropHdl = new XMLFmtBreakBeforePropHdl;
351 11602 : break;
352 : case XML_TYPE_TEXT_BREAKAFTER:
353 11602 : pPropHdl = new XMLFmtBreakAfterPropHdl;
354 11602 : break;
355 : case XML_TYPE_TEXT_SHADOW:
356 25072 : pPropHdl = new XMLShadowPropHdl;
357 25072 : break;
358 : case XML_TYPE_TEXT_ADJUST:
359 11602 : pPropHdl = new XMLParaAdjustPropHdl;
360 11602 : break;
361 : case XML_TYPE_TEXT_ADJUSTLAST:
362 11602 : pPropHdl = new XMLLastLineAdjustPropHdl;
363 11602 : break;
364 : case XML_TYPE_CHAR_HEIGHT:
365 16082 : pPropHdl = new XMLCharHeightHdl;
366 16082 : break;
367 : case XML_TYPE_CHAR_HEIGHT_PROP:
368 15946 : pPropHdl = new XMLCharHeightPropHdl;
369 15946 : break;
370 : case XML_TYPE_CHAR_HEIGHT_DIFF:
371 15946 : pPropHdl = new XMLCharHeightDiffHdl;
372 15946 : break;
373 : case XML_TYPE_CHAR_RFC_LANGUAGE_TAG:
374 15946 : pPropHdl = new XMLCharRfcLanguageTagHdl;
375 15946 : break;
376 : case XML_TYPE_CHAR_LANGUAGE:
377 15946 : pPropHdl = new XMLCharLanguageHdl;
378 15946 : break;
379 : case XML_TYPE_CHAR_SCRIPT:
380 15946 : pPropHdl = new XMLCharScriptHdl;
381 15946 : break;
382 : case XML_TYPE_CHAR_COUNTRY:
383 15946 : pPropHdl = new XMLCharCountryHdl;
384 15946 : break;
385 : case XML_TYPE_LINE_SPACE_FIXED:
386 11602 : pPropHdl = new XMLLineHeightHdl;
387 11602 : break;
388 : case XML_TYPE_LINE_SPACE_MINIMUM:
389 11602 : pPropHdl = new XMLLineHeightAtLeastHdl;
390 11602 : break;
391 : case XML_TYPE_LINE_SPACE_DISTANCE:
392 11602 : pPropHdl = new XMLLineSpacingHdl;
393 11602 : break;
394 : case XML_TYPE_BORDER_WIDTH:
395 25072 : pPropHdl = new XMLBorderWidthHdl;
396 25072 : break;
397 : case XML_TYPE_BORDER:
398 25072 : pPropHdl = new XMLBorderHdl;
399 25072 : break;
400 : case XML_TYPE_TEXT_TABSTOP:
401 11602 : pPropHdl = new XMLTabStopPropHdl;
402 11602 : break;
403 : case XML_TYPE_ATTRIBUTE_CONTAINER:
404 29674 : pPropHdl = new XMLAttributeContainerHandler;
405 29674 : break;
406 : case XML_TYPE_COLOR_MODE:
407 : pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap,
408 12674 : cppu::UnoType<drawing::ColorMode>::get());
409 12674 : break;
410 : case XML_TYPE_DURATION16_MS:
411 5724 : pPropHdl = new XMLDurationMS16PropHdl_Impl;
412 5724 : break;
413 : case XML_TYPE_TEXT_HORIZONTAL_ADJUST:
414 : pPropHdl = new XMLEnumPropertyHdl(
415 : aXML_HorizontalAdjust_Enum,
416 908 : cppu::UnoType<text::HorizontalAdjust>::get());
417 908 : break;
418 : case XML_TYPE_TEXT_DRAW_ASPECT:
419 12674 : pPropHdl = new DrawAspectHdl;
420 12674 : break;
421 : case XML_TYPE_TEXT_WRITING_MODE:
422 : pPropHdl = new XMLConstantsPropertyHandler(
423 : &(aXML_WritingDirection_Enum[1]),
424 2176 : XML_LR_TB);
425 2176 : break;
426 : case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT:
427 : pPropHdl = new XMLConstantsPropertyHandler(
428 : aXML_WritingDirection_Enum,
429 28606 : XML_PAGE);
430 28606 : break;
431 : case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY:
432 : pPropHdl = new XMLNamedBoolPropertyHdl(
433 : GetXMLToken(XML_NONE),
434 15946 : GetXMLToken(XML_TRUE) );
435 15946 : break;
436 : case XML_TYPE_STYLENAME :
437 25184 : pPropHdl = new XMLStyleNamePropHdl;
438 25184 : break;
439 : case XML_TYPE_NUMBER_NO_ZERO:
440 0 : pPropHdl = new XMLNumberWithoutZeroPropHdl( 4 );
441 0 : break;
442 : case XML_TYPE_NUMBER8_NO_ZERO:
443 0 : pPropHdl = new XMLNumberWithoutZeroPropHdl( 1 );
444 0 : break;
445 : case XML_TYPE_NUMBER16_NO_ZERO:
446 11602 : pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 );
447 11602 : break;
448 : case XML_TYPE_NUMBER16_AUTO:
449 11602 : pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl();
450 11602 : break;
451 : }
452 :
453 2260450 : return pPropHdl;
454 : }
455 :
456 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|