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 62296 : struct XMLPropertyHandlerFactory::Impl
104 : {
105 : mutable CacheMap maHandlerCache;
106 : };
107 :
108 31153 : XMLPropertyHandlerFactory::XMLPropertyHandlerFactory() :
109 31153 : mpImpl(new Impl) {}
110 :
111 62286 : XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
112 : {
113 1495631 : for( CacheMap::iterator pPos = mpImpl->maHandlerCache.begin(); pPos != mpImpl->maHandlerCache.end(); ++pPos )
114 1464488 : delete pPos->second;
115 :
116 31143 : delete mpImpl;
117 31143 : }
118 :
119 : // Interface
120 3315886 : 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 3315886 : return GetBasicHandler( nType );
125 : }
126 :
127 : // Helper-methods to create and cache PropertyHandler
128 3315886 : const XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const
129 : {
130 3315886 : const XMLPropertyHandler* pRet = NULL;
131 :
132 3315886 : if( mpImpl->maHandlerCache.find( nType ) != mpImpl->maHandlerCache.end() )
133 1850584 : pRet = mpImpl->maHandlerCache.find( nType )->second;
134 :
135 3315886 : return pRet;
136 : }
137 :
138 1465308 : void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const
139 : {
140 1465308 : mpImpl->maHandlerCache[nType] = pHdl;
141 1465308 : }
142 :
143 3315886 : const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const
144 : {
145 3315886 : const XMLPropertyHandler* pPropHdl = GetHdlCache( nType );
146 :
147 3315886 : if( !pPropHdl )
148 : {
149 1465302 : pPropHdl = CreatePropertyHandler( nType );
150 :
151 1465302 : if( pPropHdl )
152 895139 : PutHdlCache( nType, pPropHdl );
153 : }
154 :
155 3315886 : return pPropHdl;
156 : }
157 :
158 1465338 : const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType )
159 : {
160 1465338 : XMLPropertyHandler* pPropHdl = NULL;
161 :
162 1465338 : switch( nType )
163 : {
164 : case XML_TYPE_BOOL :
165 25694 : pPropHdl = new XMLBoolPropHdl;
166 25694 : break;
167 : case XML_TYPE_BOOL_FALSE :
168 2 : pPropHdl = new XMLBoolFalsePropHdl;
169 2 : break;
170 : case XML_TYPE_MEASURE :
171 24350 : pPropHdl = new XMLMeasurePropHdl( 4 );
172 24350 : break;
173 : case XML_TYPE_MEASURE8 :
174 0 : pPropHdl = new XMLMeasurePropHdl( 1 );
175 0 : break;
176 : case XML_TYPE_MEASURE16:
177 1662 : pPropHdl = new XMLMeasurePropHdl( 2 );
178 1662 : break;
179 : case XML_TYPE_PERCENT :
180 16349 : pPropHdl = new XMLPercentPropHdl( 4 );
181 16349 : break;
182 : case XML_TYPE_PERCENT8 :
183 5243 : pPropHdl = new XMLPercentPropHdl( 1 );
184 5243 : break;
185 : case XML_TYPE_PERCENT16 :
186 19250 : pPropHdl = new XMLPercentPropHdl( 2 );
187 19250 : break;
188 : case XML_TYPE_DOUBLE_PERCENT :
189 8101 : pPropHdl = new XMLDoublePercentPropHdl();
190 8101 : break;
191 : case XML_TYPE_NEG_PERCENT :
192 8101 : pPropHdl = new XMLNegPercentPropHdl( 4 );
193 8101 : break;
194 : case XML_TYPE_NEG_PERCENT8 :
195 0 : pPropHdl = new XMLNegPercentPropHdl( 1 );
196 0 : break;
197 : case XML_TYPE_NEG_PERCENT16 :
198 11657 : pPropHdl = new XMLNegPercentPropHdl( 2 );
199 11657 : break;
200 : case XML_TYPE_MEASURE_PX :
201 8101 : pPropHdl = new XMLMeasurePxPropHdl( 4 );
202 8101 : break;
203 : case XML_TYPE_STRING :
204 24129 : pPropHdl = new XMLStringPropHdl;
205 24129 : break;
206 : case XML_TYPE_COLOR :
207 20476 : pPropHdl = new XMLColorPropHdl;
208 20476 : break;
209 : case XML_TYPE_HEX :
210 10471 : pPropHdl = new XMLHexPropHdl;
211 10471 : break;
212 : case XML_TYPE_NUMBER :
213 15896 : pPropHdl = new XMLNumberPropHdl( 4 );
214 15896 : break;
215 : case XML_TYPE_NUMBER8 :
216 7570 : pPropHdl = new XMLNumberPropHdl( 1 );
217 7570 : break;
218 : case XML_TYPE_NUMBER16:
219 15637 : pPropHdl = new XMLNumberPropHdl( 2 );
220 15637 : 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 7570 : pPropHdl = new XMLNumberNonePropHdl( 2 );
229 7570 : break;
230 : case XML_TYPE_DOUBLE :
231 899 : pPropHdl = new XMLDoublePropHdl;
232 899 : break;
233 : case XML_TYPE_NBOOL :
234 124 : pPropHdl = new XMLNBoolPropHdl;
235 124 : break;
236 : case XML_TYPE_COLORTRANSPARENT :
237 19379 : pPropHdl = new XMLColorTransparentPropHdl;
238 19379 : break;
239 : case XML_TYPE_ISTRANSPARENT :
240 19379 : pPropHdl = new XMLIsTransparentPropHdl;
241 19379 : break;
242 : case XML_TYPE_COLORAUTO :
243 11252 : pPropHdl = new XMLColorAutoPropHdl;
244 11252 : break;
245 : case XML_TYPE_ISAUTOCOLOR :
246 10471 : pPropHdl = new XMLIsAutoColorPropHdl;
247 10471 : break;
248 : case XML_TYPE_BUILDIN_CMP_ONLY :
249 20002 : pPropHdl = new XMLCompareOnlyPropHdl;
250 20002 : 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 14144 : pPropHdl = new XMLRectangleMembersHdl( nType );
257 14144 : break;
258 :
259 : case XML_TYPE_TEXT_CROSSEDOUT_TYPE:
260 10798 : pPropHdl = new XMLCrossedOutTypePropHdl ;
261 10798 : break;
262 : case XML_TYPE_TEXT_CROSSEDOUT_STYLE:
263 10798 : pPropHdl = new XMLCrossedOutStylePropHdl ;
264 10798 : break;
265 : case XML_TYPE_TEXT_CROSSEDOUT_WIDTH:
266 10798 : pPropHdl = new XMLCrossedOutWidthPropHdl ;
267 10798 : break;
268 : case XML_TYPE_TEXT_CROSSEDOUT_TEXT:
269 10798 : pPropHdl = new XMLCrossedOutTextPropHdl ;
270 10798 : 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 10471 : pPropHdl = new XMLEscapementPropHdl;
278 10471 : break;
279 : case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT:
280 10471 : pPropHdl = new XMLEscapementHeightPropHdl;
281 10471 : break;
282 : case XML_TYPE_TEXT_CASEMAP:
283 10471 : pPropHdl = new XMLCaseMapPropHdl;
284 10471 : break;
285 : case XML_TYPE_TEXT_CASEMAP_VAR:
286 10471 : pPropHdl = new XMLCaseMapVariantHdl;
287 10471 : break;
288 : case XML_TYPE_TEXT_FONTFAMILYNAME:
289 10471 : pPropHdl = new XMLFontFamilyNamePropHdl;
290 10471 : break;
291 : case XML_TYPE_TEXT_FONTFAMILY:
292 10798 : pPropHdl = new XMLFontFamilyPropHdl;
293 10798 : break;
294 : case XML_TYPE_TEXT_FONTENCODING:
295 10798 : pPropHdl = new XMLFontEncodingPropHdl;
296 10798 : break;
297 : case XML_TYPE_TEXT_FONTPITCH:
298 10798 : pPropHdl = new XMLFontPitchPropHdl;
299 10798 : break;
300 : case XML_TYPE_TEXT_KERNING:
301 10471 : pPropHdl = new XMLKerningPropHdl;
302 10471 : break;
303 : case XML_TYPE_TEXT_POSTURE:
304 10798 : pPropHdl = new XMLPosturePropHdl;
305 10798 : break;
306 : case XML_TYPE_TEXT_SHADOWED:
307 10471 : pPropHdl = new XMLShadowedPropHdl;
308 10471 : break;
309 : case XML_TYPE_TEXT_UNDERLINE_TYPE:
310 10798 : pPropHdl = new XMLUnderlineTypePropHdl;
311 10798 : break;
312 : case XML_TYPE_TEXT_UNDERLINE_STYLE:
313 10798 : pPropHdl = new XMLUnderlineStylePropHdl;
314 10798 : break;
315 : case XML_TYPE_TEXT_UNDERLINE_WIDTH:
316 10798 : pPropHdl = new XMLUnderlineWidthPropHdl;
317 10798 : break;
318 : case XML_TYPE_TEXT_UNDERLINE_COLOR:
319 10798 : pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
320 10798 : break;
321 : case XML_TYPE_TEXT_UNDERLINE_HASCOLOR:
322 : pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
323 10674 : false );
324 10674 : break;
325 : case XML_TYPE_TEXT_OVERLINE_TYPE:
326 10471 : pPropHdl = new XMLUnderlineTypePropHdl;
327 10471 : break;
328 : case XML_TYPE_TEXT_OVERLINE_STYLE:
329 10471 : pPropHdl = new XMLUnderlineStylePropHdl;
330 10471 : break;
331 : case XML_TYPE_TEXT_OVERLINE_WIDTH:
332 10471 : pPropHdl = new XMLUnderlineWidthPropHdl;
333 10471 : break;
334 : case XML_TYPE_TEXT_OVERLINE_COLOR:
335 10471 : pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
336 10471 : break;
337 : case XML_TYPE_TEXT_OVERLINE_HASCOLOR:
338 : pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
339 10471 : false );
340 10471 : break;
341 : case XML_TYPE_TEXT_WEIGHT:
342 10798 : pPropHdl = new XMLFontWeightPropHdl;
343 10798 : break;
344 : case XML_TYPE_TEXT_SPLIT:
345 : pPropHdl = new XMLNamedBoolPropertyHdl(
346 : GetXMLToken(XML_AUTO),
347 7570 : GetXMLToken(XML_ALWAYS) );
348 7570 : break;
349 : case XML_TYPE_TEXT_BREAKBEFORE:
350 7570 : pPropHdl = new XMLFmtBreakBeforePropHdl;
351 7570 : break;
352 : case XML_TYPE_TEXT_BREAKAFTER:
353 7570 : pPropHdl = new XMLFmtBreakAfterPropHdl;
354 7570 : break;
355 : case XML_TYPE_TEXT_SHADOW:
356 16495 : pPropHdl = new XMLShadowPropHdl;
357 16495 : break;
358 : case XML_TYPE_TEXT_ADJUST:
359 7570 : pPropHdl = new XMLParaAdjustPropHdl;
360 7570 : break;
361 : case XML_TYPE_TEXT_ADJUSTLAST:
362 7570 : pPropHdl = new XMLLastLineAdjustPropHdl;
363 7570 : break;
364 : case XML_TYPE_CHAR_HEIGHT:
365 10595 : pPropHdl = new XMLCharHeightHdl;
366 10595 : break;
367 : case XML_TYPE_CHAR_HEIGHT_PROP:
368 10471 : pPropHdl = new XMLCharHeightPropHdl;
369 10471 : break;
370 : case XML_TYPE_CHAR_HEIGHT_DIFF:
371 10471 : pPropHdl = new XMLCharHeightDiffHdl;
372 10471 : break;
373 : case XML_TYPE_CHAR_RFC_LANGUAGE_TAG:
374 10471 : pPropHdl = new XMLCharRfcLanguageTagHdl;
375 10471 : break;
376 : case XML_TYPE_CHAR_LANGUAGE:
377 10471 : pPropHdl = new XMLCharLanguageHdl;
378 10471 : break;
379 : case XML_TYPE_CHAR_SCRIPT:
380 10471 : pPropHdl = new XMLCharScriptHdl;
381 10471 : break;
382 : case XML_TYPE_CHAR_COUNTRY:
383 10471 : pPropHdl = new XMLCharCountryHdl;
384 10471 : break;
385 : case XML_TYPE_LINE_SPACE_FIXED:
386 7570 : pPropHdl = new XMLLineHeightHdl;
387 7570 : break;
388 : case XML_TYPE_LINE_SPACE_MINIMUM:
389 7570 : pPropHdl = new XMLLineHeightAtLeastHdl;
390 7570 : break;
391 : case XML_TYPE_LINE_SPACE_DISTANCE:
392 7570 : pPropHdl = new XMLLineSpacingHdl;
393 7570 : break;
394 : case XML_TYPE_BORDER_WIDTH:
395 16495 : pPropHdl = new XMLBorderWidthHdl;
396 16495 : break;
397 : case XML_TYPE_BORDER:
398 16501 : pPropHdl = new XMLBorderHdl;
399 16501 : break;
400 : case XML_TYPE_TEXT_TABSTOP:
401 7570 : pPropHdl = new XMLTabStopPropHdl;
402 7570 : break;
403 : case XML_TYPE_ATTRIBUTE_CONTAINER:
404 19110 : pPropHdl = new XMLAttributeContainerHandler;
405 19110 : break;
406 : case XML_TYPE_COLOR_MODE:
407 : pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap,
408 8101 : cppu::UnoType<drawing::ColorMode>::get());
409 8101 : break;
410 : case XML_TYPE_DURATION16_MS:
411 3536 : pPropHdl = new XMLDurationMS16PropHdl_Impl;
412 3536 : break;
413 : case XML_TYPE_TEXT_HORIZONTAL_ADJUST:
414 : pPropHdl = new XMLEnumPropertyHdl(
415 : aXML_HorizontalAdjust_Enum,
416 678 : cppu::UnoType<text::HorizontalAdjust>::get());
417 678 : break;
418 : case XML_TYPE_TEXT_DRAW_ASPECT:
419 8101 : pPropHdl = new DrawAspectHdl;
420 8101 : break;
421 : case XML_TYPE_TEXT_WRITING_MODE:
422 : pPropHdl = new XMLConstantsPropertyHandler(
423 : &(aXML_WritingDirection_Enum[1]),
424 1459 : XML_LR_TB);
425 1459 : break;
426 : case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT:
427 : pPropHdl = new XMLConstantsPropertyHandler(
428 : aXML_WritingDirection_Enum,
429 18579 : XML_PAGE);
430 18579 : break;
431 : case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY:
432 : pPropHdl = new XMLNamedBoolPropertyHdl(
433 : GetXMLToken(XML_NONE),
434 10471 : GetXMLToken(XML_TRUE) );
435 10471 : break;
436 : case XML_TYPE_STYLENAME :
437 16349 : pPropHdl = new XMLStyleNamePropHdl;
438 16349 : 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 7570 : pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 );
447 7570 : break;
448 : case XML_TYPE_NUMBER16_AUTO:
449 7570 : pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl();
450 7570 : break;
451 : }
452 :
453 1465338 : return pPropHdl;
454 : }
455 :
456 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|