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 <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <sax/tools/converter.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include "PropType.hxx"
28 #include "DeepTContext.hxx"
29 #include "RenameElemTContext.hxx"
30 #include "ActionMapTypesOOo.hxx"
31 #include "MutableAttrList.hxx"
32 #include "TransformerActions.hxx"
33 #include "PropertyActionsOOo.hxx"
34 #include "TransformerBase.hxx"
36 #include "StyleOOoTContext.hxx"
37 #include <xmloff/xmluconv.hxx>
38 #include <rtl/math.hxx>
39 #include <rtl/ustrbuf.hxx>
40 #include <osl/diagnose.h>
41 #include <sal/log.hxx>
44 using namespace ::xmloff::token
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::xml::sax
;
48 const sal_uInt16 MAX_PROP_TYPES
= 4;
49 #define ENTRY4(a,b,c,d) \
51 #define ENTRY3(a,b,c) \
52 { a, b, c, XML_PROP_TYPE_END }
54 { a, b, XML_PROP_TYPE_END, XML_PROP_TYPE_END }
56 { a, XML_PROP_TYPE_END, XML_PROP_TYPE_END, XML_PROP_TYPE_END }
58 const std::array
<XMLPropType
,MAX_PROP_TYPES
> aPropTypes
[XML_FAMILY_TYPE_END
] =
60 ENTRY3( XML_PROP_TYPE_GRAPHIC
, XML_PROP_TYPE_PARAGRAPH
, XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_GRAPHIC,
61 ENTRY3( XML_PROP_TYPE_GRAPHIC
, XML_PROP_TYPE_PARAGRAPH
, XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_PRESENTATION,
62 ENTRY1( XML_PROP_TYPE_DRAWING_PAGE
), // XML_FAMILY_TYPE_DRAWING_PAGE,
63 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_MASTER_PAGE
64 ENTRY1( XML_PROP_TYPE_PAGE_LAYOUT
), // XML_FAMILY_TYPE_PAGE_LAYOUT,
65 ENTRY1( XML_PROP_TYPE_HEADER_FOOTER
), // XML_FAMILY_TYPE_HEADER_FOOTER
66 ENTRY1( XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_TEXT,
67 ENTRY2( XML_PROP_TYPE_PARAGRAPH
, XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_PARAGRAPH,
68 ENTRY1( XML_PROP_TYPE_RUBY
), // XML_FAMILY_TYPE_RUBY,
69 ENTRY1( XML_PROP_TYPE_SECTION
), // XML_FAMILY_TYPE_SECTION,
70 ENTRY1( XML_PROP_TYPE_TABLE
), // XML_FAMILY_TYPE_TABLE,
71 ENTRY1( XML_PROP_TYPE_TABLE_COLUMN
), // XML_FAMILY_TYPE_TABLE_COLUMN,
72 ENTRY1( XML_PROP_TYPE_TABLE_ROW
), // XML_FAMILY_TYPE_TABLE_ROW,
73 ENTRY3( XML_PROP_TYPE_TABLE_CELL
, XML_PROP_TYPE_PARAGRAPH
, XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_TABLE_CELL,
74 ENTRY1( XML_PROP_TYPE_LIST_LEVEL
), // XML_FAMILY_TYPE_LIST,
75 ENTRY4( XML_PROP_TYPE_CHART
, XML_PROP_TYPE_GRAPHIC
, XML_PROP_TYPE_PARAGRAPH
, XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_CHART,
76 ENTRY1( XML_PROP_TYPE_TEXT
), // XML_FAMILY_TYPE_DATA,
77 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_GRADIENT,
78 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_HATCH,
79 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_FILL_IMAGE,
80 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_STROKE_DASH,
81 ENTRY1( XML_PROP_TYPE_END
), // XML_FAMILY_TYPE_MARKER,
84 const XMLTokenEnum aPropTokens
[XML_PROP_TYPE_END
] =
86 XML_GRAPHIC_PROPERTIES
,
87 XML_DRAWING_PAGE_PROPERTIES
,
88 XML_PAGE_LAYOUT_PROPERTIES
,
89 XML_HEADER_FOOTER_PROPERTIES
,
91 XML_PARAGRAPH_PROPERTIES
,
93 XML_SECTION_PROPERTIES
,
95 XML_TABLE_COLUMN_PROPERTIES
,
96 XML_TABLE_ROW_PROPERTIES
,
97 XML_TABLE_CELL_PROPERTIES
,
98 XML_LIST_LEVEL_PROPERTIES
,
102 const sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
104 PROP_OOO_GRAPHIC_ATTR_ACTIONS
,
105 PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
106 PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
,
107 PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
,
108 PROP_OOO_TEXT_ATTR_ACTIONS
,
109 PROP_OOO_PARAGRAPH_ATTR_ACTIONS
,
110 MAX_OOO_PROP_ACTIONS
, // RUBY
111 PROP_OOO_SECTION_ATTR_ACTIONS
,
112 PROP_OOO_TABLE_ATTR_ACTIONS
,
113 PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
,
114 PROP_OOO_TABLE_ROW_ATTR_ACTIONS
,
115 PROP_OOO_TABLE_CELL_ATTR_ACTIONS
,
116 PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
,
117 PROP_OOO_CHART_ATTR_ACTIONS
120 const sal_uInt16 aElemActionMaps
[XML_PROP_TYPE_END
] =
122 PROP_OOO_GRAPHIC_ELEM_ACTIONS
,
123 MAX_OOO_PROP_ACTIONS
,
124 MAX_OOO_PROP_ACTIONS
,
125 MAX_OOO_PROP_ACTIONS
,
126 PROP_OOO_TEXT_ELEM_ACTIONS
,
127 PROP_OOO_PARAGRAPH_ELEM_ACTIONS
,
128 MAX_OOO_PROP_ACTIONS
,
129 MAX_OOO_PROP_ACTIONS
,
130 MAX_OOO_PROP_ACTIONS
,
131 MAX_OOO_PROP_ACTIONS
,
132 MAX_OOO_PROP_ACTIONS
,
133 PROP_OOO_TABLE_CELL_ELEM_ACTIONS
,
134 MAX_OOO_PROP_ACTIONS
,
135 PROP_OOO_CHART_ELEM_ACTIONS
140 class XMLTypedPropertiesOOoTContext_Impl
: public XMLPersElemContentTContext
142 css::uno::Reference
< css::xml::sax::XAttributeList
> m_xAttrList
;
145 XMLTypedPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
146 const OUString
& rQName
);
148 using XMLPersAttrListTContext::AddAttribute
;
149 void AddAttribute( const OUString
&sName
,
150 const OUString
&sValue
);
151 void AddAttribute( sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
152 const OUString
&sValue
);
154 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
156 virtual void Export() override
;
161 XMLTypedPropertiesOOoTContext_Impl::XMLTypedPropertiesOOoTContext_Impl(
162 XMLTransformerBase
& rImp
,
163 const OUString
& rQName
) :
164 XMLPersElemContentTContext( rImp
, rQName
),
165 m_xAttrList( new XMLMutableAttributeList() )
169 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
170 const OUString
&sName
,
171 const OUString
&sValue
)
173 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
174 ->AddAttribute( sName
, sValue
);
177 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
178 sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
179 const OUString
&sValue
)
182 GetTransformer().GetNamespaceMap().GetQNameByKey(
183 nPrefix
, ::xmloff::token::GetXMLToken( eToken
) ) );
184 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
185 ->AddAttribute( sName
, sValue
);
188 void XMLTypedPropertiesOOoTContext_Impl::StartElement(
189 const Reference
< XAttributeList
>& )
191 // empty, ignore even the attribute list
194 void XMLTypedPropertiesOOoTContext_Impl::Export()
196 if( m_xAttrList
->getLength() || HasElementContent() )
198 GetTransformer().GetDocHandler()->startElement( GetQName(), m_xAttrList
);
200 GetTransformer().GetDocHandler()->endElement( GetQName() );
206 class XMLPropertiesOOoTContext_Impl
: public XMLTransformerContext
208 ::rtl::Reference
< XMLTypedPropertiesOOoTContext_Impl
>
209 m_aPropContexts
[MAX_PROP_TYPES
];
211 using XMLPropTypes
= std::array
<XMLPropType
, MAX_PROP_TYPES
>;
213 XMLPropTypes
const & m_rPropTypes
;
215 bool const m_bPersistent
;
217 XMLTypedPropertiesOOoTContext_Impl
*GetPropContextAndAction(
218 TransformerAction_Impl
& rAction
,
219 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
222 XMLTypedPropertiesOOoTContext_Impl
*GetPropContext(
226 XMLPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
227 const OUString
& rQName
,
228 const XMLPropTypes
& rTypes
,
231 rtl::Reference
<XMLTransformerContext
> CreateChildContext(
233 const OUString
& rLocalName
,
234 const OUString
& rQName
,
235 const Reference
< XAttributeList
>& rAttrList
) override
;
237 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
239 virtual void EndElement() override
;
241 virtual void Characters( const OUString
& rChars
) override
;
243 virtual void Export() override
;
245 virtual bool IsPersistent() const override
;
250 XMLTypedPropertiesOOoTContext_Impl
251 *XMLPropertiesOOoTContext_Impl::GetPropContext(
254 sal_uInt16 nIndex
= MAX_PROP_TYPES
;
255 for( sal_uInt16 i
=0; i
< MAX_PROP_TYPES
; i
++ )
257 if( m_rPropTypes
[i
] == eType
)
263 if( MAX_PROP_TYPES
== nIndex
)
266 if( !m_aPropContexts
[nIndex
].is() )
268 m_aPropContexts
[nIndex
] =
269 new XMLTypedPropertiesOOoTContext_Impl(
271 GetTransformer().GetNamespaceMap().GetQNameByKey(
273 ::xmloff::token::GetXMLToken(
274 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
277 return m_aPropContexts
[nIndex
].get();
280 XMLTypedPropertiesOOoTContext_Impl
281 *XMLPropertiesOOoTContext_Impl::GetPropContextAndAction(
282 TransformerAction_Impl
& rAction
,
283 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
286 rAction
.m_nActionType
= XML_ATACTION_COPY
;
287 sal_uInt16 nIndex
= 0;
289 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
291 while( i
< MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
])
293 sal_uInt16 nActionMap
=
294 (bElem
? aElemActionMaps
: aAttrActionMaps
)[m_rPropTypes
[i
]];
295 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
297 XMLTransformerActions
*pActions
=
298 GetTransformer().GetUserDefinedActions( nActionMap
);
299 OSL_ENSURE( pActions
, "go no actions" );
302 XMLTransformerActions::const_iterator aIter
=
303 pActions
->find( aKey
);
305 if( aIter
!= pActions
->end() )
307 rAction
= (*aIter
).second
;
317 if( !( XML_NAMESPACE_NONE
== nPrefix
||
318 (XML_NAMESPACE_UNKNOWN_FLAG
& nPrefix
) ||
319 XML_PROP_TYPE_END
==m_rPropTypes
[1] ||
320 (i
<MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
]) ) )
322 SAL_WARN("xmloff", "Didn't find property: "
323 << GetTransformer().GetNamespaceMap().GetPrefixByKey( nPrefix
)
326 << ", assuming <style:"
327 << ::xmloff::token::GetXMLToken( aPropTokens
[m_rPropTypes
[0]] )
332 if( !m_aPropContexts
[nIndex
].is() )
334 m_aPropContexts
[nIndex
] =
335 new XMLTypedPropertiesOOoTContext_Impl(
337 GetTransformer().GetNamespaceMap().GetQNameByKey(
339 ::xmloff::token::GetXMLToken(
340 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
343 return m_aPropContexts
[nIndex
].get();
346 XMLPropertiesOOoTContext_Impl::XMLPropertiesOOoTContext_Impl(
347 XMLTransformerBase
& rImp
,
348 const OUString
& rQName
,
349 const XMLPropTypes
& rTypes
,
351 XMLTransformerContext( rImp
, rQName
),
352 // remember the types that belong to the attribute and element lists
353 m_rPropTypes(rTypes
),
354 m_bPersistent( bPersistent
)
358 rtl::Reference
<XMLTransformerContext
> XMLPropertiesOOoTContext_Impl::CreateChildContext(
360 const OUString
& rLocalName
,
361 const OUString
& rQName
,
362 const Reference
< XAttributeList
>& rAttrList
)
364 TransformerAction_Impl aAction
;
365 return GetPropContextAndAction( aAction
, nPrefix
, rLocalName
, true )
366 ->CreateChildContext( nPrefix
, rLocalName
, rQName
, rAttrList
);
369 void XMLPropertiesOOoTContext_Impl::StartElement(
370 const Reference
< XAttributeList
>& rAttrList
)
372 XMLTypedPropertiesOOoTContext_Impl
* pIntervalMinorDivisorContext
= nullptr;
373 double fIntervalMajor
= 0.0;
374 double fIntervalMinor
= 0.0;
375 bool bMoveProtect
= false;
376 bool bSizeProtect
= false;
377 OUString aProtectAttrValue
;
378 XMLTypedPropertiesOOoTContext_Impl
* pProtectContext
= nullptr;
380 /* Attribute <style:mirror> has to be priority over attribute <style:draw>.
381 The filter from OpenDocument file format to OpenOffice.org file format
382 produces styles with both attributes. (#i49139#)
384 bool bExistStyleMirror( false );
385 OUStringBuffer aStyleMirrorAttrValue
;
386 bool bExistDrawMirror( false );
387 OUString aDrawMirrorAttrValue
;
388 XMLTypedPropertiesOOoTContext_Impl
* pMirrorContext( nullptr );
390 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
391 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
393 const OUString sAttrName
= rAttrList
->getNameByIndex( i
);
394 const OUString sAttrValue
= rAttrList
->getValueByIndex( i
);
397 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
399 TransformerAction_Impl aAction
;
400 XMLTypedPropertiesOOoTContext_Impl
*pContext
=
401 GetPropContextAndAction( aAction
, nPrefix
, aLocalName
, false );
402 switch( aAction
.m_nActionType
)
404 case XML_ATACTION_REMOVE
:
406 case XML_ATACTION_COPY
:
407 pContext
->AddAttribute( sAttrName
, sAttrValue
);
409 case XML_ATACTION_COPY_DUPLICATE
:
411 pContext
->AddAttribute( sAttrName
, sAttrValue
);
412 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
413 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
415 pContext2
->AddAttribute( sAttrName
, sAttrValue
);
418 case XML_ATACTION_RENAME
:
420 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
421 aAction
.GetQNameTokenFromParam1(),
425 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
427 OUString
aAttrValue( sAttrValue
);
428 GetTransformer().EncodeStyleName(aAttrValue
);
429 pContext
->AddAttribute( sAttrName
, aAttrValue
);
432 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF
:
434 OUString
aAttrValue( sAttrValue
);
435 GetTransformer().EncodeStyleName(aAttrValue
);
436 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
437 aAction
.GetQNameTokenFromParam1(),
441 case XML_ATACTION_NEG_PERCENT
:
443 OUString
aAttrValue( sAttrValue
);
444 XMLTransformerBase::NegPercent(aAttrValue
);
445 pContext
->AddAttribute( sAttrName
, aAttrValue
);
448 case XML_ATACTION_RENAME_NEG_PERCENT
:
450 OUString
aAttrValue( sAttrValue
);
451 XMLTransformerBase::NegPercent(aAttrValue
);
452 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
453 aAction
.GetQNameTokenFromParam1(),
457 case XML_ATACTION_INCH2IN
:
459 OUString
aAttrValue( sAttrValue
);
460 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
461 pContext
->AddAttribute( sAttrName
, aAttrValue
);
464 case XML_ATACTION_INCH2IN_DUPLICATE
:
466 OUString
aAttrValue( sAttrValue
);
467 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
468 pContext
->AddAttribute( sAttrName
, aAttrValue
);
469 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
470 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
472 pContext2
->AddAttribute( sAttrName
, aAttrValue
);
475 case XML_ATACTION_INCHS2INS
:
477 OUString
aAttrValue( sAttrValue
);
478 XMLTransformerBase::ReplaceInchWithIn( aAttrValue
);
479 pContext
->AddAttribute( sAttrName
, aAttrValue
);
482 case XML_PTACTION_LINE_MODE
:
484 const OUString
& aAttrValue( GetXMLToken(
485 IsXMLToken( sAttrValue
, XML_TRUE
)
487 : XML_SKIP_WHITE_SPACE
) );
489 GetTransformer().GetNamespaceMap().GetQNameByKey(
491 GetXMLToken( XML_TEXT_UNDERLINE_MODE
) ) );
492 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
495 GetTransformer().GetNamespaceMap().GetQNameByKey(
497 GetXMLToken( XML_TEXT_LINE_THROUGH_MODE
) );
498 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
501 case XML_PTACTION_KEEP_WITH_NEXT
:
503 const OUString
& aAttrValue( GetXMLToken(
504 IsXMLToken( sAttrValue
, XML_TRUE
)
507 pContext
->AddAttribute( sAttrName
, aAttrValue
);
510 case XML_PTACTION_UNDERLINE
:
512 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
513 bool bBold
= false, bDouble
= false;
527 case XML_BOLD_DOTTED
:
535 case XML_BOLD_LONG_DASH
:
536 eToken
= XML_LONG_DASH
;
539 case XML_BOLD_DOT_DASH
:
540 eToken
= XML_DOT_DASH
;
543 case XML_BOLD_DOT_DOT_DASH
:
544 eToken
= XML_DOT_DOT_DASH
;
551 case XML_DOUBLE_WAVE
:
560 OSL_FAIL( "xmloff::XMLPropertiesOOoTContext_Impl::StartElement(), unknown underline token!" );
563 pContext
->AddAttribute(
564 GetTransformer().GetNamespaceMap().GetQNameByKey(
566 GetXMLToken( XML_TEXT_UNDERLINE_STYLE
) ),
567 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
570 pContext
->AddAttribute(
571 GetTransformer().GetNamespaceMap().GetQNameByKey(
573 GetXMLToken( XML_TEXT_UNDERLINE_TYPE
) ),
574 GetXMLToken( XML_DOUBLE
) );
576 pContext
->AddAttribute(
577 GetTransformer().GetNamespaceMap().GetQNameByKey(
579 GetXMLToken( XML_TEXT_UNDERLINE_WIDTH
) ),
580 GetXMLToken( XML_BOLD
) );
583 case XML_PTACTION_LINETHROUGH
:
585 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
586 bool bBold
= false, bDouble
= false;
590 case XML_SINGLE_LINE
:
593 case XML_DOUBLE_LINE
:
612 pContext
->AddAttribute(
613 GetTransformer().GetNamespaceMap().GetQNameByKey(
615 GetXMLToken( XML_TEXT_LINE_THROUGH_STYLE
) ),
616 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
619 pContext
->AddAttribute(
620 GetTransformer().GetNamespaceMap().GetQNameByKey(
622 GetXMLToken( XML_TEXT_LINE_THROUGH_TYPE
) ),
623 GetXMLToken( XML_DOUBLE
) );
625 pContext
->AddAttribute(
626 GetTransformer().GetNamespaceMap().GetQNameByKey(
628 GetXMLToken( XML_TEXT_LINE_THROUGH_WIDTH
) ),
629 GetXMLToken( XML_BOLD
) );
631 pContext
->AddAttribute(
632 GetTransformer().GetNamespaceMap().GetQNameByKey(
634 GetXMLToken( XML_TEXT_LINE_THROUGH_TEXT
) ),
638 case XML_PTACTION_SPLINES
:
640 sal_Int32 nSplineType
= sAttrValue
.toInt32();
641 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
642 XML_NAMESPACE_CHART
, GetXMLToken( XML_INTERPOLATION
) );
644 switch( nSplineType
)
648 pContext
->AddAttribute(
649 aNewAttrName
, GetXMLToken( XML_NONE
));
653 pContext
->AddAttribute(
654 aNewAttrName
, GetXMLToken( XML_CUBIC_SPLINE
));
658 pContext
->AddAttribute(
659 aNewAttrName
, GetXMLToken( XML_B_SPLINE
));
663 OSL_FAIL( "invalid spline type" );
664 pContext
->AddAttribute(
665 aNewAttrName
, GetXMLToken( XML_NONE
));
670 case XML_PTACTION_INTERVAL_MAJOR
:
671 pContext
->AddAttribute( sAttrName
, sAttrValue
);
672 ::sax::Converter::convertDouble( fIntervalMajor
, sAttrValue
);
674 case XML_PTACTION_INTERVAL_MINOR
:
675 ::sax::Converter::convertDouble( fIntervalMinor
, sAttrValue
);
676 pIntervalMinorDivisorContext
= pContext
;
678 case XML_PTACTION_SYMBOL
:
680 sal_Int32 nSymbolType
= sAttrValue
.toInt32();
681 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
682 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_TYPE
) );
684 if( nSymbolType
>= 0 )
686 pContext
->AddAttribute( aNewAttrName
, GetXMLToken( XML_NAMED_SYMBOL
));
687 enum XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
688 switch( nSymbolType
)
692 // "square" has an awkward token name
693 eToken
= XML_GRADIENTSTYLE_SQUARE
;
697 eToken
= XML_DIAMOND
;
701 eToken
= XML_ARROW_DOWN
;
705 eToken
= XML_ARROW_UP
;
709 eToken
= XML_ARROW_RIGHT
;
713 eToken
= XML_ARROW_LEFT
;
717 eToken
= XML_BOW_TIE
;
721 eToken
= XML_HOURGLASS
;
736 eToken
= XML_ASTERISK
;
739 eToken
= XML_HORIZONTAL_BAR
;
742 eToken
= XML_VERTICAL_BAR
;
745 OSL_FAIL( "invalid named symbol" );
749 if( eToken
!= XML_TOKEN_INVALID
)
751 pContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
752 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_NAME
)),
753 GetXMLToken( eToken
));
758 switch( nSymbolType
)
762 pContext
->AddAttribute(
763 aNewAttrName
, GetXMLToken( XML_NONE
));
767 pContext
->AddAttribute(
768 aNewAttrName
, GetXMLToken( XML_AUTOMATIC
));
772 pContext
->AddAttribute(
773 aNewAttrName
, GetXMLToken( XML_IMAGE
));
776 OSL_FAIL( "invalid symbol type" );
777 pContext
->AddAttribute(
778 aNewAttrName
, GetXMLToken( XML_NONE
));
784 case XML_PTACTION_SYMBOL_IMAGE_NAME
:
786 // create an xlink:href element for URI attribute
787 XMLPersAttrListTContext
*pSymbolImageContext
= new XMLPersAttrListTContext(
788 GetTransformer(), GetTransformer().GetNamespaceMap().GetQNameByKey(
789 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_IMAGE
)));
790 rtl::Reference
<XMLTransformerContext
> xSymbolImageContext(pSymbolImageContext
);
792 OUString
aAttrValue( sAttrValue
);
793 if( GetTransformer().ConvertURIToOASIS( aAttrValue
, true ))
795 pSymbolImageContext
->AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aAttrValue
);
796 pContext
->AddContent(xSymbolImageContext
);
802 case XML_PTACTION_TRANSPARENCY
:
804 OUString
aAttrValue( sAttrValue
);
805 XMLTransformerBase::NegPercent(aAttrValue
);
806 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
809 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
815 case XML_PTACTION_BREAK_INSIDE
:
817 pContext
->AddAttribute(
818 XML_NAMESPACE_FO
, XML_KEEP_TOGETHER
,
820 IsXMLToken( sAttrValue
, XML_COLUMNSPLIT_AVOID
)
825 case XML_ATACTION_CAPTION_ESCAPE_OOO
:
827 OUString
aAttrValue( sAttrValue
);
828 if( aAttrValue
.indexOf( '%' ) != -1 )
830 sal_Int32 nValue
= 0;
831 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
836 ::sax::Converter::convertPercent( aOut
, nValue
);
837 aAttrValue
= aOut
.makeStringAndClear();
842 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
845 pContext
->AddAttribute( sAttrName
, aAttrValue
);
848 case XML_ATACTION_MOVE_PROTECT
:
849 bMoveProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
850 pProtectContext
= pContext
;
852 case XML_ATACTION_SIZE_PROTECT
:
853 bSizeProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
854 pProtectContext
= pContext
;
856 case XML_ATACTION_PROTECT
:
857 aProtectAttrValue
= sAttrValue
;
858 pProtectContext
= pContext
;
860 case XML_ATACTION_DRAW_MIRROR_OOO
: // renames draw:mirror to style:mirror and adapts values
862 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
863 aDrawMirrorAttrValue
=
864 GetXMLToken( IsXMLToken( sAttrValue
, XML_TRUE
)
865 ? XML_HORIZONTAL
: XML_NONE
);
866 bExistDrawMirror
= true;
867 pMirrorContext
= pContext
;
870 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
871 case XML_ATACTION_STYLE_MIRROR_OOO
: // adapts style:mirror values
873 SvXMLTokenEnumerator
aTokenEnum( sAttrValue
);
874 std::u16string_view aToken
;
875 while( aTokenEnum
.getNextToken( aToken
) )
877 if ( !aStyleMirrorAttrValue
.isEmpty() )
879 aStyleMirrorAttrValue
.append(" ");
882 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_LEFT_PAGES
) )
884 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_EVEN
));
886 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_RIGHT_PAGES
) )
888 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_ODD
));
892 aStyleMirrorAttrValue
.append(aToken
);
895 bExistStyleMirror
= true;
896 pMirrorContext
= pContext
;
899 case XML_ATACTION_GAMMA_OOO
: // converts double value to percentage
901 double fValue
= sAttrValue
.toDouble();
902 sal_Int32 nValue
= static_cast<sal_Int32
>((fValue
* 100.0) + ( fValue
> 0 ? 0.5 : - 0.5 ) );
905 ::sax::Converter::convertPercent( aOut
, nValue
);
906 OUString
aAttrValue( aOut
.makeStringAndClear() );
907 pContext
->AddAttribute( sAttrName
, aAttrValue
);
910 case XML_ATACTION_OPACITY_FIX
:
913 if( sAttrValue
.indexOf( '%' ) != -1 )
915 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
919 nValue
= sal_Int32( sAttrValue
.toDouble() * 100.0 );
921 nValue
= 100 - nValue
;
924 ::sax::Converter::convertPercent( aOut
, nValue
);
925 pContext
->AddAttribute( sAttrName
, aOut
.makeStringAndClear() );
929 OSL_ENSURE( false, "unknown action" );
934 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
935 if ( bExistStyleMirror
)
937 pMirrorContext
->AddAttribute(
938 GetTransformer().GetNamespaceMap().GetQNameByKey(
939 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
940 aStyleMirrorAttrValue
.makeStringAndClear());
942 else if ( bExistDrawMirror
)
944 pMirrorContext
->AddAttribute(
945 GetTransformer().GetNamespaceMap().GetQNameByKey(
946 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
947 aDrawMirrorAttrValue
);
950 if (bMoveProtect
|| bSizeProtect
|| !aProtectAttrValue
.isEmpty())
952 if( (bMoveProtect
||bSizeProtect
) && IsXMLToken( aProtectAttrValue
, XML_NONE
) )
953 aProtectAttrValue
.clear();
955 const OUString
& rPosition
= GetXMLToken( XML_POSITION
);
956 if( bMoveProtect
&& -1 == aProtectAttrValue
.indexOf( rPosition
) )
958 if( !aProtectAttrValue
.isEmpty() )
959 aProtectAttrValue
+= " ";
960 aProtectAttrValue
+= rPosition
;
963 const OUString
& rSize
= GetXMLToken( XML_SIZE
);
964 if( bSizeProtect
&& -1 == aProtectAttrValue
.indexOf( rSize
) )
966 if( !aProtectAttrValue
.isEmpty() )
967 aProtectAttrValue
+= " ";
968 aProtectAttrValue
+= rSize
;
971 assert(pProtectContext
&& "coverity[var_deref_model] - pProtectContext should be assigned in a superset of the enclosing if condition entry logic");
972 pProtectContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_STYLE
, GetXMLToken( XML_PROTECT
) ), aProtectAttrValue
);
975 if( !pIntervalMinorDivisorContext
)
978 if( fIntervalMinor
!= 0.0 )
980 sal_Int32 nIntervalMinorDivisor
= static_cast< sal_Int32
>(
981 ::rtl::math::round( fIntervalMajor
/ fIntervalMinor
));
983 pIntervalMinorDivisorContext
->AddAttribute(
984 GetTransformer().GetNamespaceMap().GetQNameByKey(
986 GetXMLToken( XML_INTERVAL_MINOR_DIVISOR
)),
987 OUString::number( nIntervalMinorDivisor
));
991 void XMLPropertiesOOoTContext_Impl::EndElement()
997 void XMLPropertiesOOoTContext_Impl::Characters( const OUString
& )
1002 void XMLPropertiesOOoTContext_Impl::Export()
1005 for(rtl::Reference
<XMLTypedPropertiesOOoTContext_Impl
> & rPropContext
: m_aPropContexts
)
1007 if( rPropContext
.is() )
1008 rPropContext
->Export();
1012 bool XMLPropertiesOOoTContext_Impl::IsPersistent() const
1014 return m_bPersistent
;
1017 XMLStyleOOoTContext::XMLStyleOOoTContext( XMLTransformerBase
& rImp
,
1018 const OUString
& rQName
,
1020 bool bPersistent
) :
1021 XMLPersElemContentTContext( rImp
, rQName
),
1023 m_bPersistent( bPersistent
)
1027 XMLStyleOOoTContext::XMLStyleOOoTContext(
1028 XMLTransformerBase
& rImp
,
1029 const OUString
& rQName
,
1032 ::xmloff::token::XMLTokenEnum eToken
,
1033 bool bPersistent
) :
1034 XMLPersElemContentTContext( rImp
, rQName
, nPrefix
, eToken
),
1036 m_bPersistent( bPersistent
)
1040 XMLStyleOOoTContext::~XMLStyleOOoTContext()
1044 rtl::Reference
<XMLTransformerContext
> XMLStyleOOoTContext::CreateChildContext(
1046 const OUString
& rLocalName
,
1047 const OUString
& rQName
,
1048 const Reference
< XAttributeList
>& rAttrList
)
1050 rtl::Reference
<XMLTransformerContext
> pContext
;
1052 if( XML_NAMESPACE_STYLE
== nPrefix
&&
1053 IsXMLToken( rLocalName
, XML_PROPERTIES
) )
1055 if( aPropTypes
[m_eFamily
][0] == XML_PROP_TYPE_END
)
1057 OSL_ENSURE( false, "unexpected properties element" );
1058 pContext
= m_bPersistent
1059 ? XMLPersElemContentTContext::CreateChildContext(
1060 nPrefix
, rLocalName
, rQName
, rAttrList
)
1061 : XMLTransformerContext::CreateChildContext(
1062 nPrefix
, rLocalName
, rQName
, rAttrList
);
1064 else if( aPropTypes
[m_eFamily
][1] == XML_PROP_TYPE_END
)
1066 sal_uInt16 nActionMap
=
1067 aAttrActionMaps
[aPropTypes
[m_eFamily
][0]];
1068 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
1070 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1071 GetTransformer(), rQName
,
1072 aPropTypes
[m_eFamily
], m_bPersistent
));
1077 pContext
.set(new XMLPersElemContentTContext(
1078 GetTransformer(), rQName
,
1079 XML_NAMESPACE_STYLE
,
1080 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1082 pContext
.set(new XMLRenameElemTransformerContext(
1083 GetTransformer(), rQName
,
1084 XML_NAMESPACE_STYLE
,
1085 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1090 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1091 GetTransformer(), rQName
,
1092 aPropTypes
[m_eFamily
], m_bPersistent
));
1096 AddContent( pContext
);
1100 pContext
= m_bPersistent
1101 ? XMLPersElemContentTContext::CreateChildContext(
1102 nPrefix
, rLocalName
, rQName
, rAttrList
)
1103 : XMLTransformerContext::CreateChildContext(
1104 nPrefix
, rLocalName
, rQName
, rAttrList
);
1110 void XMLStyleOOoTContext::StartElement(
1111 const Reference
< XAttributeList
>& rAttrList
)
1113 XMLTransformerActions
*pActions
=
1114 GetTransformer().GetUserDefinedActions( OOO_STYLE_ACTIONS
);
1115 OSL_ENSURE( pActions
, "go no actions" );
1117 Reference
< XAttributeList
> xAttrList( rAttrList
);
1118 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
;
1119 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1120 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1122 const OUString sAttrName
= xAttrList
->getNameByIndex( i
);
1123 OUString aLocalName
;
1124 sal_uInt16 nPrefix
=
1125 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
1127 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
1128 XMLTransformerActions::const_iterator aIter
=
1129 pActions
->find( aKey
);
1130 if( aIter
!= pActions
->end() )
1132 if( !pMutableAttrList
)
1135 new XMLMutableAttributeList( xAttrList
);
1136 xAttrList
= pMutableAttrList
;
1138 const OUString sAttrValue
= xAttrList
->getValueByIndex( i
);
1139 switch( (*aIter
).second
.m_nActionType
)
1141 case XML_ATACTION_STYLE_FAMILY
:
1143 bool bControl
= false;
1144 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1146 if( IsXMLToken( sAttrValue
, XML_GRAPHICS
) )
1147 m_eFamily
= XML_FAMILY_TYPE_GRAPHIC
;
1148 else if( IsXMLToken( sAttrValue
, XML_PRESENTATION
) )
1149 m_eFamily
= XML_FAMILY_TYPE_PRESENTATION
;
1150 else if( IsXMLToken( sAttrValue
, XML_DRAWING_PAGE
) )
1151 m_eFamily
= XML_FAMILY_TYPE_DRAWING_PAGE
;
1152 else if( IsXMLToken( sAttrValue
, XML_TEXT
) )
1153 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1154 else if( IsXMLToken( sAttrValue
, XML_PARAGRAPH
) )
1155 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1156 else if( IsXMLToken( sAttrValue
, XML_RUBY
) )
1157 m_eFamily
= XML_FAMILY_TYPE_RUBY
;
1158 else if( IsXMLToken( sAttrValue
, XML_SECTION
) )
1159 m_eFamily
= XML_FAMILY_TYPE_SECTION
;
1160 else if( IsXMLToken( sAttrValue
, XML_TABLE
) )
1161 m_eFamily
= XML_FAMILY_TYPE_TABLE
;
1162 else if( IsXMLToken( sAttrValue
, XML_TABLE_COLUMN
) )
1163 m_eFamily
= XML_FAMILY_TYPE_TABLE_COLUMN
;
1164 else if( IsXMLToken( sAttrValue
, XML_TABLE_ROW
) )
1165 m_eFamily
= XML_FAMILY_TYPE_TABLE_ROW
;
1166 else if( IsXMLToken( sAttrValue
, XML_TABLE_CELL
) )
1167 m_eFamily
= XML_FAMILY_TYPE_TABLE_CELL
;
1168 else if( IsXMLToken( sAttrValue
, XML_CHART
) )
1169 m_eFamily
= XML_FAMILY_TYPE_CHART
;
1170 else if( IsXMLToken( sAttrValue
, XML_CONTROL
) )
1172 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1176 if( XML_FAMILY_TYPE_GRAPHIC
== m_eFamily
)
1178 pMutableAttrList
->SetValueByIndex( i
,
1179 GetXMLToken( XML_GRAPHIC
) );
1183 pMutableAttrList
->SetValueByIndex( i
,
1184 GetXMLToken( XML_PARAGRAPH
) );
1188 case XML_ATACTION_INCH2IN
:
1190 OUString
aAttrValue( sAttrValue
);
1191 if( XMLTransformerBase::ReplaceSingleInchWithIn(
1193 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1196 case XML_ATACTION_ENCODE_STYLE_NAME
:
1198 OUString
aAttrValue( sAttrValue
);
1199 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1201 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1202 OUString
aNewAttrQName(
1203 GetTransformer().GetNamespaceMap().
1205 nPrefix
, ::xmloff::token::GetXMLToken(
1206 XML_DISPLAY_NAME
) ) );
1207 pMutableAttrList
->AddAttribute( aNewAttrQName
,
1212 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
1214 OUString
aAttrValue( sAttrValue
);
1215 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1216 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1219 case XML_ATACTION_NEG_PERCENT
:
1221 OUString
aAttrValue( sAttrValue
);
1222 if( XMLTransformerBase::NegPercent(aAttrValue
) )
1223 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1226 case XML_ATACTION_URI_OOO
:
1228 OUString
aAttrValue( sAttrValue
);
1229 if( GetTransformer().ConvertURIToOASIS( aAttrValue
,
1230 static_cast< bool >((*aIter
).second
.m_nParam1
)))
1231 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1235 OSL_ENSURE( false, "unknown action" );
1240 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1241 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1243 XMLPersElemContentTContext::StartElement( xAttrList
);
1245 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList
);
1248 void XMLStyleOOoTContext::EndElement()
1251 XMLPersElemContentTContext::EndElement();
1253 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
1256 void XMLStyleOOoTContext::Characters( const OUString
& )
1258 // element content only:
1261 bool XMLStyleOOoTContext::IsPersistent() const
1263 return m_bPersistent
;
1266 XMLTransformerActions
*XMLStyleOOoTContext::CreateTransformerActions(
1269 XMLTransformerActionInit
const *pInit
= nullptr;
1273 case PROP_OOO_GRAPHIC_ATTR_ACTIONS
:
1274 pInit
= aGraphicPropertyOOoAttrActionTable
;
1276 case PROP_OOO_GRAPHIC_ELEM_ACTIONS
:
1277 pInit
= aGraphicPropertyOOoElemActionTable
;
1279 case PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
:
1280 pInit
= aDrawingPagePropertyOOoAttrActionTable
;
1282 case PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
:
1283 pInit
= aPageLayoutPropertyOOoAttrActionTable
;
1285 case PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
:
1286 pInit
= aHeaderFooterPropertyOOoAttrActionTable
;
1288 case PROP_OOO_TEXT_ATTR_ACTIONS
:
1289 pInit
= aTextPropertyOOoAttrActionTable
;
1291 case PROP_OOO_TEXT_ELEM_ACTIONS
:
1292 pInit
= aTextPropertyOOoElemActionTable
;
1294 case PROP_OOO_PARAGRAPH_ATTR_ACTIONS
:
1295 pInit
= aParagraphPropertyOOoAttrActionTable
;
1297 case PROP_OOO_PARAGRAPH_ELEM_ACTIONS
:
1298 pInit
= aParagraphPropertyOOoElemActionTable
;
1300 case PROP_OOO_SECTION_ATTR_ACTIONS
:
1301 pInit
= aSectionPropertyOOoAttrActionTable
;
1303 case PROP_OOO_TABLE_ATTR_ACTIONS
:
1304 pInit
= aTablePropertyOOoAttrActionTable
;
1306 case PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
:
1307 pInit
= aTableColumnPropertyOOoAttrActionTable
;
1309 case PROP_OOO_TABLE_ROW_ATTR_ACTIONS
:
1310 pInit
= aTableRowPropertyOOoAttrActionTable
;
1312 case PROP_OOO_TABLE_CELL_ATTR_ACTIONS
:
1313 pInit
= aTableCellPropertyOOoAttrActionTable
;
1315 case PROP_OOO_TABLE_CELL_ELEM_ACTIONS
:
1316 pInit
= aTableCellPropertyOOoElemActionTable
;
1318 case PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
:
1319 pInit
= aListLevelPropertyOOoAttrActionTable
;
1321 case PROP_OOO_CHART_ATTR_ACTIONS
:
1322 pInit
= aChartPropertyOOoAttrActionTable
;
1324 case PROP_OOO_CHART_ELEM_ACTIONS
:
1325 pInit
= aChartPropertyOOoElemActionTable
;
1329 XMLTransformerActions
*pActions
= nullptr;
1331 pActions
= new XMLTransformerActions( pInit
);
1336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */