1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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() :
131 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
133 for( const auto& rCacheEntry
: mpImpl
->maHandlerCache
)
134 delete rCacheEntry
.second
;
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
;
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
);
167 std::unique_ptr
<XMLPropertyHandler
> pNewPropHdl
= CreatePropertyHandler( nType
);
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
;
180 pPropHdl
.reset(new XMLBoolPropHdl
);
182 case XML_TYPE_BOOL_FALSE
:
183 pPropHdl
.reset(new XMLBoolFalsePropHdl
);
185 case XML_TYPE_MEASURE
:
186 pPropHdl
.reset(new XMLMeasurePropHdl( 4 ));
188 case XML_TYPE_MEASURE8
:
189 pPropHdl
.reset(new XMLMeasurePropHdl( 1 ));
191 case XML_TYPE_MEASURE16
:
192 pPropHdl
.reset(new XMLMeasurePropHdl( 2 ));
194 case XML_TYPE_PERCENT
:
195 pPropHdl
.reset(new XMLPercentPropHdl( 4 ));
197 case XML_TYPE_PERCENT8
:
198 pPropHdl
.reset(new XMLPercentPropHdl( 1 ));
200 case XML_TYPE_PERCENT16
:
201 pPropHdl
.reset(new XMLPercentPropHdl( 2 ));
203 case XML_TYPE_DOUBLE_PERCENT
:
204 pPropHdl
.reset(new XMLDoublePercentPropHdl
);
206 case XML_TYPE_NEG_PERCENT
:
207 pPropHdl
.reset(new XMLNegPercentPropHdl( 4 ));
209 case XML_TYPE_NEG_PERCENT8
:
210 pPropHdl
.reset(new XMLNegPercentPropHdl( 1 ));
212 case XML_TYPE_NEG_PERCENT16
:
213 pPropHdl
.reset(new XMLNegPercentPropHdl( 2 ));
215 case XML_TYPE_MEASURE_PX
:
216 pPropHdl
.reset(new XMLMeasurePxPropHdl( 4 ));
218 case XML_TYPE_STRING
:
219 pPropHdl
.reset(new XMLStringPropHdl
);
221 case XML_TYPE_COLOR
:
222 pPropHdl
.reset(new XMLColorPropHdl
);
225 pPropHdl
.reset(new XMLHexPropHdl
);
227 case XML_TYPE_NUMBER
:
228 pPropHdl
.reset(new XMLNumberPropHdl( 4 ));
230 case XML_TYPE_NUMBER8
:
231 pPropHdl
.reset(new XMLNumberPropHdl( 1 ));
233 case XML_TYPE_NUMBER16
:
234 pPropHdl
.reset(new XMLNumberPropHdl( 2 ));
236 case XML_TYPE_NUMBER_NONE
:
237 pPropHdl
.reset(new XMLNumberNonePropHdl
);
239 case XML_TYPE_NUMBER8_NONE
:
240 pPropHdl
.reset(new XMLNumberNonePropHdl( 1 ));
242 case XML_TYPE_NUMBER16_NONE
:
243 pPropHdl
.reset(new XMLNumberNonePropHdl( 2 ));
245 case XML_TYPE_DOUBLE
:
246 pPropHdl
.reset(new XMLDoublePropHdl
);
248 case XML_TYPE_NBOOL
:
249 pPropHdl
.reset(new XMLNBoolPropHdl
);
251 case XML_TYPE_COLORTRANSPARENT
:
252 pPropHdl
.reset(new XMLColorTransparentPropHdl
);
254 case XML_TYPE_ISTRANSPARENT
:
255 pPropHdl
.reset(new XMLIsTransparentPropHdl
);
257 case XML_TYPE_COLORAUTO
:
258 pPropHdl
.reset(new XMLColorAutoPropHdl
);
260 case XML_TYPE_ISAUTOCOLOR
:
261 pPropHdl
.reset(new XMLIsAutoColorPropHdl
);
263 case XML_TYPE_BUILDIN_CMP_ONLY
:
264 pPropHdl
.reset(new XMLCompareOnlyPropHdl
);
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
));
274 case XML_TYPE_TEXT_CROSSEDOUT_TYPE
:
275 pPropHdl
.reset(new XMLCrossedOutTypePropHdl
) ;
277 case XML_TYPE_TEXT_CROSSEDOUT_STYLE
:
278 pPropHdl
.reset(new XMLCrossedOutStylePropHdl
) ;
280 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH
:
281 pPropHdl
.reset(new XMLCrossedOutWidthPropHdl
) ;
283 case XML_TYPE_TEXT_CROSSEDOUT_TEXT
:
284 pPropHdl
.reset(new XMLCrossedOutTextPropHdl
) ;
286 case XML_TYPE_TEXT_BOOLCROSSEDOUT
:
287 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
288 GetXMLToken(XML_SOLID
),
289 GetXMLToken(XML_NONE
) ));
291 case XML_TYPE_TEXT_ESCAPEMENT
:
292 pPropHdl
.reset(new XMLEscapementPropHdl
);
294 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT
:
295 pPropHdl
.reset(new XMLEscapementHeightPropHdl
);
297 case XML_TYPE_TEXT_CASEMAP
:
298 pPropHdl
.reset(new XMLCaseMapPropHdl
);
300 case XML_TYPE_TEXT_CASEMAP_VAR
:
301 pPropHdl
.reset(new XMLCaseMapVariantHdl
);
303 case XML_TYPE_TEXT_FONTFAMILYNAME
:
304 pPropHdl
.reset(new XMLFontFamilyNamePropHdl
);
306 case XML_TYPE_TEXT_FONTFAMILY
:
307 pPropHdl
.reset(new XMLFontFamilyPropHdl
);
309 case XML_TYPE_TEXT_FONTENCODING
:
310 pPropHdl
.reset(new XMLFontEncodingPropHdl
);
312 case XML_TYPE_TEXT_FONTPITCH
:
313 pPropHdl
.reset(new XMLFontPitchPropHdl
);
315 case XML_TYPE_TEXT_KERNING
:
316 pPropHdl
.reset(new XMLKerningPropHdl
);
318 case XML_TYPE_TEXT_POSTURE
:
319 pPropHdl
.reset(new XMLPosturePropHdl
);
321 case XML_TYPE_TEXT_SHADOWED
:
322 pPropHdl
.reset(new XMLShadowedPropHdl
);
324 case XML_TYPE_TEXT_UNDERLINE_TYPE
:
325 pPropHdl
.reset(new XMLUnderlineTypePropHdl
);
327 case XML_TYPE_TEXT_UNDERLINE_STYLE
:
328 pPropHdl
.reset(new XMLUnderlineStylePropHdl
);
330 case XML_TYPE_TEXT_UNDERLINE_WIDTH
:
331 pPropHdl
.reset(new XMLUnderlineWidthPropHdl
);
333 case XML_TYPE_TEXT_UNDERLINE_COLOR
:
334 pPropHdl
.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR
));
336 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR
:
337 pPropHdl
.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
340 case XML_TYPE_TEXT_OVERLINE_TYPE
:
341 pPropHdl
.reset(new XMLUnderlineTypePropHdl
);
343 case XML_TYPE_TEXT_OVERLINE_STYLE
:
344 pPropHdl
.reset(new XMLUnderlineStylePropHdl
);
346 case XML_TYPE_TEXT_OVERLINE_WIDTH
:
347 pPropHdl
.reset(new XMLUnderlineWidthPropHdl
);
349 case XML_TYPE_TEXT_OVERLINE_COLOR
:
350 pPropHdl
.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR
));
352 case XML_TYPE_TEXT_OVERLINE_HASCOLOR
:
353 pPropHdl
.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
356 case XML_TYPE_TEXT_WEIGHT
:
357 pPropHdl
.reset(new XMLFontWeightPropHdl
);
359 case XML_TYPE_TEXT_SPLIT
:
360 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
361 GetXMLToken(XML_AUTO
),
362 GetXMLToken(XML_ALWAYS
) ));
364 case XML_TYPE_TEXT_BREAKBEFORE
:
365 pPropHdl
.reset(new XMLFmtBreakBeforePropHdl
);
367 case XML_TYPE_TEXT_BREAKAFTER
:
368 pPropHdl
.reset(new XMLFmtBreakAfterPropHdl
);
370 case XML_TYPE_TEXT_SHADOW
:
371 pPropHdl
.reset(new XMLShadowPropHdl
);
373 case XML_TYPE_TEXT_ADJUST
:
374 pPropHdl
.reset(new XMLParaAdjustPropHdl
);
376 case XML_TYPE_TEXT_ADJUSTLAST
:
377 pPropHdl
.reset(new XMLLastLineAdjustPropHdl
);
379 case XML_TYPE_CHAR_HEIGHT
:
380 pPropHdl
.reset(new XMLCharHeightHdl
);
382 case XML_TYPE_CHAR_HEIGHT_PROP
:
383 pPropHdl
.reset(new XMLCharHeightPropHdl
);
385 case XML_TYPE_CHAR_HEIGHT_DIFF
:
386 pPropHdl
.reset(new XMLCharHeightDiffHdl
);
388 case XML_TYPE_CHAR_RFC_LANGUAGE_TAG
:
389 pPropHdl
.reset(new XMLCharRfcLanguageTagHdl
);
391 case XML_TYPE_CHAR_LANGUAGE
:
392 pPropHdl
.reset(new XMLCharLanguageHdl
);
394 case XML_TYPE_CHAR_SCRIPT
:
395 pPropHdl
.reset(new XMLCharScriptHdl
);
397 case XML_TYPE_CHAR_COUNTRY
:
398 pPropHdl
.reset(new XMLCharCountryHdl
);
400 case XML_TYPE_LINE_SPACE_FIXED
:
401 pPropHdl
.reset(new XMLLineHeightHdl
);
403 case XML_TYPE_LINE_SPACE_MINIMUM
:
404 pPropHdl
.reset(new XMLLineHeightAtLeastHdl
);
406 case XML_TYPE_LINE_SPACE_DISTANCE
:
407 pPropHdl
.reset(new XMLLineSpacingHdl
);
409 case XML_TYPE_BORDER_WIDTH
:
410 pPropHdl
.reset(new XMLBorderWidthHdl
);
412 case XML_TYPE_BORDER
:
413 pPropHdl
.reset(new XMLBorderHdl
);
415 case XML_TYPE_TEXT_TABSTOP
:
416 pPropHdl
.reset(new XMLTabStopPropHdl
);
418 case XML_TYPE_ATTRIBUTE_CONTAINER
:
419 pPropHdl
.reset(new XMLAttributeContainerHandler
);
421 case XML_TYPE_COLOR_MODE
:
422 pPropHdl
.reset(new XMLEnumPropertyHdl(aXML_ColorMode_EnumMap
));
424 case XML_TYPE_DURATION16_MS
:
425 pPropHdl
.reset(new XMLDurationMS16PropHdl_Impl
);
427 case XML_TYPE_TEXT_HORIZONTAL_ADJUST
:
428 pPropHdl
.reset(new XMLEnumPropertyHdl(aXML_HorizontalAdjust_Enum
));
430 case XML_TYPE_TEXT_DRAW_ASPECT
:
431 pPropHdl
.reset(new DrawAspectHdl
);
433 case XML_TYPE_TEXT_WRITING_MODE
:
434 pPropHdl
.reset(new XMLConstantsPropertyHandler(
435 &(aXML_WritingDirection_Enum
[1]),
438 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT
:
439 pPropHdl
.reset(new XMLConstantsPropertyHandler(
440 aXML_WritingDirection_Enum
,
443 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY
:
444 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
445 GetXMLToken(XML_NONE
),
446 GetXMLToken(XML_TRUE
) ));
448 case XML_TYPE_STYLENAME
:
449 pPropHdl
.reset(new XMLStyleNamePropHdl
);
451 case XML_TYPE_NUMBER_NO_ZERO
:
452 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 4 ));
454 case XML_TYPE_NUMBER8_NO_ZERO
:
455 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 1 ));
457 case XML_TYPE_NUMBER16_NO_ZERO
:
458 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 2 ));
460 case XML_TYPE_NUMBER16_AUTO
:
461 pPropHdl
.reset(new XMLNumberWithAutoForVoidPropHdl
);
463 case XML_TYPE_TEXT_VERTICAL_POS
:
464 pPropHdl
.reset(new XMLConstantsPropertyHandler( pXML_VertPos_Enum
, XML_TOKEN_INVALID
));
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */