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"
59 #include <xmloff/XMLComplexColorHandler.hxx>
63 using namespace ::com::sun::star
;
64 using namespace ::xmloff::token
;
66 SvXMLEnumMapEntry
<drawing::ColorMode
> const aXML_ColorMode_EnumMap
[] =
68 { XML_GREYSCALE
, drawing::ColorMode_GREYS
},
69 { XML_MONO
, drawing::ColorMode_MONO
},
70 { XML_WATERMARK
, drawing::ColorMode_WATERMARK
},
71 { XML_STANDARD
, drawing::ColorMode_STANDARD
},
72 { XML_TOKEN_INVALID
, drawing::ColorMode(0) }
75 SvXMLEnumMapEntry
<text::HorizontalAdjust
> const aXML_HorizontalAdjust_Enum
[] =
77 { XML_LEFT
, text::HorizontalAdjust_LEFT
},
78 { XML_CENTER
, text::HorizontalAdjust_CENTER
},
79 { XML_RIGHT
, text::HorizontalAdjust_RIGHT
},
80 { XML_TOKEN_INVALID
, text::HorizontalAdjust(0) }
83 // aXML_WritingDirection_Enum is used with and without 'page'
84 // attribute, so you'll find uses of aXML_WritingDirection_Enum
85 // directly, as well as &(aXML_WritingDirection_Enum[1])
86 SvXMLEnumMapEntry
<sal_uInt16
> const aXML_WritingDirection_Enum
[] =
88 // aXML_WritingDirection_Enum
89 { XML_PAGE
, text::WritingMode2::PAGE
},
91 // &(aXML_WritingDirection_Enum[1])
92 { XML_LR_TB
, text::WritingMode2::LR_TB
},
93 { XML_RL_TB
, text::WritingMode2::RL_TB
},
94 { XML_TB_RL
, text::WritingMode2::TB_RL
},
95 { XML_TB_LR
, text::WritingMode2::TB_LR
},
96 { XML_BT_LR
, text::WritingMode2::BT_LR
},
98 // alternative names of the above, as accepted by XSL
99 { XML_LR
, text::WritingMode2::LR_TB
},
100 { XML_RL
, text::WritingMode2::RL_TB
},
101 { XML_TB
, text::WritingMode2::TB_RL
},
103 // vertical as clockwise 90deg rotation, for OOXML vert="vert"
104 { XML_TB_RL90
, text::WritingMode2::TB_RL90
},
106 { XML_TOKEN_INVALID
, 0 }
109 SvXMLEnumMapEntry
<sal_uInt16
> const pXML_VertPos_Enum
[] =
111 { XML_FROM_TOP
, text::VertOrientation::NONE
},
112 { XML_TOP
, text::VertOrientation::TOP
},
113 { XML_TOP
, text::VertOrientation::CHAR_TOP
}, // export only
114 { XML_TOP
, text::VertOrientation::LINE_TOP
}, // export only
115 { XML_MIDDLE
, text::VertOrientation::CENTER
},
116 { XML_MIDDLE
, text::VertOrientation::CHAR_CENTER
}, // export only
117 { XML_MIDDLE
, text::VertOrientation::LINE_CENTER
}, // export only
118 { XML_BOTTOM
, text::VertOrientation::BOTTOM
},
119 { XML_BOTTOM
, text::VertOrientation::CHAR_BOTTOM
}, // export only
120 { XML_BOTTOM
, text::VertOrientation::LINE_BOTTOM
}, // export only
121 { XML_BELOW
, text::VertOrientation::CHAR_BOTTOM
}, // import only
122 { XML_TOKEN_INVALID
, 0 }
125 typedef std::map
<sal_Int32
, const XMLPropertyHandler
*> CacheMap
;
127 struct XMLPropertyHandlerFactory::Impl
129 mutable CacheMap maHandlerCache
;
132 XMLPropertyHandlerFactory::XMLPropertyHandlerFactory() :
135 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
137 for( const auto& rCacheEntry
: mpImpl
->maHandlerCache
)
138 delete rCacheEntry
.second
;
142 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType
) const
144 SAL_WARN_IF( (nType
& ~(sal_uInt32(MID_FLAG_MASK
))) != 0, "xmloff",
145 "GetPropertyHandler called with flags in type" );
146 return GetBasicHandler( nType
);
149 // Helper-methods to create and cache PropertyHandler
150 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType
) const
152 const XMLPropertyHandler
* pRet
= nullptr;
154 if( mpImpl
->maHandlerCache
.find( nType
) != mpImpl
->maHandlerCache
.end() )
155 pRet
= mpImpl
->maHandlerCache
.find( nType
)->second
;
160 void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType
, const XMLPropertyHandler
* pHdl
) const
162 mpImpl
->maHandlerCache
[nType
] = pHdl
;
165 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType
) const
167 const XMLPropertyHandler
* pPropHdl
= GetHdlCache( nType
);
171 std::unique_ptr
<XMLPropertyHandler
> pNewPropHdl
= CreatePropertyHandler( nType
);
173 PutHdlCache( nType
, pNewPropHdl
.get() );
174 return pNewPropHdl
.release();
177 std::unique_ptr
<XMLPropertyHandler
> XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType
)
179 std::unique_ptr
<XMLPropertyHandler
> pPropHdl
;
184 pPropHdl
.reset(new XMLBoolPropHdl
);
186 case XML_TYPE_BOOL_FALSE
:
187 pPropHdl
.reset(new XMLBoolFalsePropHdl
);
189 case XML_TYPE_MEASURE
:
190 pPropHdl
.reset(new XMLMeasurePropHdl( 4 ));
192 case XML_TYPE_MEASURE8
:
193 pPropHdl
.reset(new XMLMeasurePropHdl( 1 ));
195 case XML_TYPE_MEASURE16
:
196 pPropHdl
.reset(new XMLMeasurePropHdl( 2 ));
198 case XML_TYPE_UNIT_MEASURE
:
199 pPropHdl
= std::make_unique
<XMLUnitMeasurePropHdl
>();
201 case XML_TYPE_PERCENT
:
202 pPropHdl
.reset(new XMLPercentPropHdl( 4 ));
204 case XML_TYPE_PERCENT8
:
205 pPropHdl
.reset(new XMLPercentPropHdl( 1 ));
207 case XML_TYPE_PERCENT16
:
208 pPropHdl
.reset(new XMLPercentPropHdl( 2 ));
210 case XML_TYPE_PERCENT100
:
211 pPropHdl
.reset(new XML100thPercentPropHdl
);
213 case XML_TYPE_DOUBLE_PERCENT
:
214 pPropHdl
.reset(new XMLDoublePercentPropHdl
);
216 case XML_TYPE_NEG_PERCENT
:
217 pPropHdl
.reset(new XMLNegPercentPropHdl( 4 ));
219 case XML_TYPE_NEG_PERCENT8
:
220 pPropHdl
.reset(new XMLNegPercentPropHdl( 1 ));
222 case XML_TYPE_NEG_PERCENT16
:
223 pPropHdl
.reset(new XMLNegPercentPropHdl( 2 ));
225 case XML_TYPE_MEASURE_PX
:
226 pPropHdl
.reset(new XMLMeasurePxPropHdl( 4 ));
228 case XML_TYPE_STRING
:
229 pPropHdl
.reset(new XMLStringPropHdl
);
231 case XML_TYPE_COLOR
:
232 pPropHdl
.reset(new XMLColorPropHdl
);
235 pPropHdl
.reset(new XMLHexPropHdl
);
237 case XML_TYPE_NUMBER
:
238 pPropHdl
.reset(new XMLNumberPropHdl( 4 ));
240 case XML_TYPE_NUMBER8
:
241 pPropHdl
.reset(new XMLNumberPropHdl( 1 ));
243 case XML_TYPE_NUMBER16
:
244 pPropHdl
.reset(new XMLNumberPropHdl( 2 ));
246 case XML_TYPE_NUMBER_NONE
:
247 pPropHdl
.reset(new XMLNumberNonePropHdl
);
249 case XML_TYPE_NUMBER8_NONE
:
250 pPropHdl
.reset(new XMLNumberNonePropHdl( 1 ));
252 case XML_TYPE_NUMBER16_NONE
:
253 pPropHdl
.reset(new XMLNumberNonePropHdl( 2 ));
255 case XML_TYPE_DOUBLE
:
256 pPropHdl
.reset(new XMLDoublePropHdl
);
258 case XML_TYPE_NBOOL
:
259 pPropHdl
.reset(new XMLNBoolPropHdl
);
261 case XML_TYPE_COLORTRANSPARENT
:
262 pPropHdl
.reset(new XMLColorTransparentPropHdl
);
264 case XML_TYPE_ISTRANSPARENT
:
265 pPropHdl
.reset(new XMLIsTransparentPropHdl
);
267 case XML_TYPE_COLORAUTO
:
268 pPropHdl
.reset(new XMLColorAutoPropHdl
);
270 case XML_TYPE_ISAUTOCOLOR
:
271 pPropHdl
.reset(new XMLIsAutoColorPropHdl
);
273 case XML_TYPE_BUILDIN_CMP_ONLY
:
274 pPropHdl
.reset(new XMLCompareOnlyPropHdl
);
277 case XML_TYPE_RECTANGLE_LEFT
:
278 case XML_TYPE_RECTANGLE_TOP
:
279 case XML_TYPE_RECTANGLE_WIDTH
:
280 case XML_TYPE_RECTANGLE_HEIGHT
:
281 pPropHdl
.reset(new XMLRectangleMembersHdl( nType
));
284 case XML_TYPE_TEXT_CROSSEDOUT_TYPE
:
285 pPropHdl
.reset(new XMLCrossedOutTypePropHdl
) ;
287 case XML_TYPE_TEXT_CROSSEDOUT_STYLE
:
288 pPropHdl
.reset(new XMLCrossedOutStylePropHdl
) ;
290 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH
:
291 pPropHdl
.reset(new XMLCrossedOutWidthPropHdl
) ;
293 case XML_TYPE_TEXT_CROSSEDOUT_TEXT
:
294 pPropHdl
.reset(new XMLCrossedOutTextPropHdl
) ;
296 case XML_TYPE_TEXT_BOOLCROSSEDOUT
:
297 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
298 GetXMLToken(XML_SOLID
),
299 GetXMLToken(XML_NONE
) ));
301 case XML_TYPE_TEXT_ESCAPEMENT
:
302 pPropHdl
.reset(new XMLEscapementPropHdl
);
304 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT
:
305 pPropHdl
.reset(new XMLEscapementHeightPropHdl
);
307 case XML_TYPE_TEXT_CASEMAP
:
308 pPropHdl
.reset(new XMLCaseMapPropHdl
);
310 case XML_TYPE_TEXT_CASEMAP_VAR
:
311 pPropHdl
.reset(new XMLCaseMapVariantHdl
);
313 case XML_TYPE_TEXT_FONTFAMILYNAME
:
314 pPropHdl
.reset(new XMLFontFamilyNamePropHdl
);
316 case XML_TYPE_TEXT_FONTFAMILY
:
317 pPropHdl
.reset(new XMLFontFamilyPropHdl
);
319 case XML_TYPE_TEXT_FONTENCODING
:
320 pPropHdl
.reset(new XMLFontEncodingPropHdl
);
322 case XML_TYPE_TEXT_FONTPITCH
:
323 pPropHdl
.reset(new XMLFontPitchPropHdl
);
325 case XML_TYPE_TEXT_KERNING
:
326 pPropHdl
.reset(new XMLKerningPropHdl
);
328 case XML_TYPE_TEXT_POSTURE
:
329 pPropHdl
.reset(new XMLPosturePropHdl
);
331 case XML_TYPE_TEXT_SHADOWED
:
332 pPropHdl
.reset(new XMLShadowedPropHdl
);
334 case XML_TYPE_TEXT_UNDERLINE_TYPE
:
335 pPropHdl
.reset(new XMLUnderlineTypePropHdl
);
337 case XML_TYPE_TEXT_UNDERLINE_STYLE
:
338 pPropHdl
.reset(new XMLUnderlineStylePropHdl
);
340 case XML_TYPE_TEXT_UNDERLINE_WIDTH
:
341 pPropHdl
.reset(new XMLUnderlineWidthPropHdl
);
343 case XML_TYPE_TEXT_UNDERLINE_COLOR
:
344 pPropHdl
.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR
));
346 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR
:
347 pPropHdl
.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
350 case XML_TYPE_TEXT_OVERLINE_TYPE
:
351 pPropHdl
.reset(new XMLUnderlineTypePropHdl
);
353 case XML_TYPE_TEXT_OVERLINE_STYLE
:
354 pPropHdl
.reset(new XMLUnderlineStylePropHdl
);
356 case XML_TYPE_TEXT_OVERLINE_WIDTH
:
357 pPropHdl
.reset(new XMLUnderlineWidthPropHdl
);
359 case XML_TYPE_TEXT_OVERLINE_COLOR
:
360 pPropHdl
.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR
));
362 case XML_TYPE_TEXT_OVERLINE_HASCOLOR
:
363 pPropHdl
.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
366 case XML_TYPE_TEXT_WEIGHT
:
367 pPropHdl
.reset(new XMLFontWeightPropHdl
);
369 case XML_TYPE_TEXT_SPLIT
:
370 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
371 GetXMLToken(XML_AUTO
),
372 GetXMLToken(XML_ALWAYS
) ));
374 case XML_TYPE_TEXT_BREAKBEFORE
:
375 pPropHdl
.reset(new XMLFmtBreakBeforePropHdl
);
377 case XML_TYPE_TEXT_BREAKAFTER
:
378 pPropHdl
.reset(new XMLFmtBreakAfterPropHdl
);
380 case XML_TYPE_TEXT_SHADOW
:
381 pPropHdl
.reset(new XMLShadowPropHdl
);
383 case XML_TYPE_TEXT_ADJUST
:
384 pPropHdl
.reset(new XMLParaAdjustPropHdl
);
386 case XML_TYPE_TEXT_ADJUSTLAST
:
387 pPropHdl
.reset(new XMLLastLineAdjustPropHdl
);
389 case XML_TYPE_CHAR_HEIGHT
:
390 pPropHdl
.reset(new XMLCharHeightHdl
);
392 case XML_TYPE_CHAR_HEIGHT_PROP
:
393 pPropHdl
.reset(new XMLCharHeightPropHdl
);
395 case XML_TYPE_CHAR_HEIGHT_DIFF
:
396 pPropHdl
.reset(new XMLCharHeightDiffHdl
);
398 case XML_TYPE_CHAR_RFC_LANGUAGE_TAG
:
399 pPropHdl
.reset(new XMLCharRfcLanguageTagHdl
);
401 case XML_TYPE_CHAR_LANGUAGE
:
402 pPropHdl
.reset(new XMLCharLanguageHdl
);
404 case XML_TYPE_CHAR_SCRIPT
:
405 pPropHdl
.reset(new XMLCharScriptHdl
);
407 case XML_TYPE_CHAR_COUNTRY
:
408 pPropHdl
.reset(new XMLCharCountryHdl
);
410 case XML_TYPE_LINE_SPACE_FIXED
:
411 pPropHdl
.reset(new XMLLineHeightHdl
);
413 case XML_TYPE_LINE_SPACE_MINIMUM
:
414 pPropHdl
.reset(new XMLLineHeightAtLeastHdl
);
416 case XML_TYPE_LINE_SPACE_DISTANCE
:
417 pPropHdl
.reset(new XMLLineSpacingHdl
);
419 case XML_TYPE_BORDER_WIDTH
:
420 pPropHdl
.reset(new XMLBorderWidthHdl
);
422 case XML_TYPE_BORDER
:
423 pPropHdl
.reset(new XMLBorderHdl
);
425 case XML_TYPE_TEXT_TABSTOP
:
426 pPropHdl
.reset(new XMLTabStopPropHdl
);
428 case XML_TYPE_ATTRIBUTE_CONTAINER
:
429 pPropHdl
.reset(new XMLAttributeContainerHandler
);
431 case XML_TYPE_COLOR_MODE
:
432 pPropHdl
.reset(new XMLEnumPropertyHdl(aXML_ColorMode_EnumMap
));
434 case XML_TYPE_DURATION16_MS
:
435 pPropHdl
.reset(new XMLDurationMS16PropHdl_Impl
);
437 case XML_TYPE_TEXT_HORIZONTAL_ADJUST
:
438 pPropHdl
.reset(new XMLEnumPropertyHdl(aXML_HorizontalAdjust_Enum
));
440 case XML_TYPE_TEXT_DRAW_ASPECT
:
441 pPropHdl
.reset(new DrawAspectHdl
);
443 case XML_TYPE_TEXT_WRITING_MODE
:
444 pPropHdl
.reset(new XMLConstantsPropertyHandler(
445 &(aXML_WritingDirection_Enum
[1]),
448 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT
:
449 pPropHdl
.reset(new XMLConstantsPropertyHandler(
450 aXML_WritingDirection_Enum
,
453 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY
:
454 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(
455 GetXMLToken(XML_NONE
),
456 GetXMLToken(XML_TRUE
) ));
458 case XML_TYPE_STYLENAME
:
459 pPropHdl
.reset(new XMLStyleNamePropHdl
);
461 case XML_TYPE_NUMBER_NO_ZERO
:
462 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 4 ));
464 case XML_TYPE_NUMBER8_NO_ZERO
:
465 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 1 ));
467 case XML_TYPE_NUMBER16_NO_ZERO
:
468 pPropHdl
.reset(new XMLNumberWithoutZeroPropHdl( 2 ));
470 case XML_TYPE_NUMBER16_AUTO
:
471 pPropHdl
.reset(new XMLNumberWithAutoForVoidPropHdl
);
473 case XML_TYPE_TEXT_VERTICAL_POS
:
474 pPropHdl
.reset(new XMLConstantsPropertyHandler( pXML_VertPos_Enum
, XML_TOKEN_INVALID
));
476 case XML_TYPE_TEXT_OVERFLOW_BEHAVIOR
:
477 // auto-create-new-frame isn't properly implemented yet. It just means don't clip.
478 pPropHdl
.reset(new XMLNamedBoolPropertyHdl(GetXMLToken(XML_CLIP
),
479 GetXMLToken(XML_AUTO_CREATE_NEW_FRAME
)));
481 case XML_TYPE_COMPLEX_COLOR
:
482 pPropHdl
.reset(new XMLComplexColorHandler
);
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */