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