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/SAXException.hpp>
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <sax/tools/converter.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include "PropType.hxx"
30 #include "DeepTContext.hxx"
31 #include "RenameElemTContext.hxx"
32 #include "ActionMapTypesOOo.hxx"
33 #include "MutableAttrList.hxx"
34 #include "TransformerActions.hxx"
35 #include "PropertyActionsOOo.hxx"
36 #include "TransformerBase.hxx"
38 #include "StyleOOoTContext.hxx"
39 #include <xmloff/xmluconv.hxx>
40 #include <rtl/math.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <osl/diagnose.h>
43 #include <sal/log.hxx>
46 using namespace ::xmloff::token
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::xml::sax
;
50 const sal_uInt16 MAX_PROP_TYPES
= 4;
51 #define ENTRY4(a,b,c,d) \
52 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
53 XML_PROP_TYPE_##c, XML_PROP_TYPE_##d }
54 #define ENTRY3(a,b,c) \
55 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
56 XML_PROP_TYPE_##c, XML_PROP_TYPE_END }
58 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
59 XML_PROP_TYPE_END, XML_PROP_TYPE_END }
61 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##END, \
62 XML_PROP_TYPE_END, XML_PROP_TYPE_END }
64 const std::array
<XMLPropType
,MAX_PROP_TYPES
> aPropTypes
[XML_FAMILY_TYPE_END
] =
66 ENTRY3( GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_GRAPHIC,
67 ENTRY3( GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_PRESENTATION,
68 ENTRY1( DRAWING_PAGE
), // XML_FAMILY_TYPE_DRAWING_PAGE,
69 ENTRY1( END
), // XML_FAMILY_TYPE_MASTER_PAGE
70 ENTRY1( PAGE_LAYOUT
), // XML_FAMILY_TYPE_PAGE_LAYOUT,
71 ENTRY1( HEADER_FOOTER
), // XML_FAMILY_TYPE_HEADER_FOOTER
72 ENTRY1( TEXT
), // XML_FAMILY_TYPE_TEXT,
73 ENTRY2( PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_PARAGRAPH,
74 ENTRY1( RUBY
), //XML_FAMILY_TYPE_RUBY,
75 ENTRY1( SECTION
), // XML_FAMILY_TYPE_SECTION,
76 ENTRY1( TABLE
), // XML_FAMILY_TYPE_TABLE,
77 ENTRY1( TABLE_COLUMN
), // XML_FAMILY_TYPE_TABLE_COLUMN,
78 ENTRY1( TABLE_ROW
), // XML_FAMILY_TYPE_TABLE_ROW,
79 ENTRY3( TABLE_CELL
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_TABLE_CELL,
80 ENTRY1( LIST_LEVEL
), // XML_FAMILY_TYPE_LIST,
81 ENTRY4( CHART
, GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_CHART,
82 ENTRY1( TEXT
), // XML_FAMILY_TYPE_DATA,
83 ENTRY1( END
), // XML_FAMILY_TYPE_GRADIENT,
84 ENTRY1( END
), // XML_FAMILY_TYPE_HATCH,
85 ENTRY1( END
), // XML_FAMILY_TYPE_FILL_IMAGE,
86 ENTRY1( END
), // XML_FAMILY_TYPE_STROKE_DASH,
87 ENTRY1( END
), // XML_FAMILY_TYPE_MARKER,
90 const XMLTokenEnum aPropTokens
[XML_PROP_TYPE_END
] =
92 XML_GRAPHIC_PROPERTIES
,
93 XML_DRAWING_PAGE_PROPERTIES
,
94 XML_PAGE_LAYOUT_PROPERTIES
,
95 XML_HEADER_FOOTER_PROPERTIES
,
97 XML_PARAGRAPH_PROPERTIES
,
99 XML_SECTION_PROPERTIES
,
100 XML_TABLE_PROPERTIES
,
101 XML_TABLE_COLUMN_PROPERTIES
,
102 XML_TABLE_ROW_PROPERTIES
,
103 XML_TABLE_CELL_PROPERTIES
,
104 XML_LIST_LEVEL_PROPERTIES
,
108 const sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
110 PROP_OOO_GRAPHIC_ATTR_ACTIONS
,
111 PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
112 PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
,
113 PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
,
114 PROP_OOO_TEXT_ATTR_ACTIONS
,
115 PROP_OOO_PARAGRAPH_ATTR_ACTIONS
,
116 MAX_OOO_PROP_ACTIONS
, // RUBY
117 PROP_OOO_SECTION_ATTR_ACTIONS
,
118 PROP_OOO_TABLE_ATTR_ACTIONS
,
119 PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
,
120 PROP_OOO_TABLE_ROW_ATTR_ACTIONS
,
121 PROP_OOO_TABLE_CELL_ATTR_ACTIONS
,
122 PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
,
123 PROP_OOO_CHART_ATTR_ACTIONS
126 const sal_uInt16 aElemActionMaps
[XML_PROP_TYPE_END
] =
128 PROP_OOO_GRAPHIC_ELEM_ACTIONS
,
129 MAX_OOO_PROP_ACTIONS
,
130 MAX_OOO_PROP_ACTIONS
,
131 MAX_OOO_PROP_ACTIONS
,
132 PROP_OOO_TEXT_ELEM_ACTIONS
,
133 PROP_OOO_PARAGRAPH_ELEM_ACTIONS
,
134 MAX_OOO_PROP_ACTIONS
,
135 MAX_OOO_PROP_ACTIONS
,
136 MAX_OOO_PROP_ACTIONS
,
137 MAX_OOO_PROP_ACTIONS
,
138 MAX_OOO_PROP_ACTIONS
,
139 PROP_OOO_TABLE_CELL_ELEM_ACTIONS
,
140 MAX_OOO_PROP_ACTIONS
,
141 PROP_OOO_CHART_ELEM_ACTIONS
146 class XMLTypedPropertiesOOoTContext_Impl
: public XMLPersElemContentTContext
148 css::uno::Reference
< css::xml::sax::XAttributeList
> m_xAttrList
;
151 XMLTypedPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
152 const OUString
& rQName
);
154 using XMLPersAttrListTContext::AddAttribute
;
155 void AddAttribute( const OUString
&sName
,
156 const OUString
&sValue
);
157 void AddAttribute( sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
158 const OUString
&sValue
);
160 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
162 virtual void Export() override
;
167 XMLTypedPropertiesOOoTContext_Impl::XMLTypedPropertiesOOoTContext_Impl(
168 XMLTransformerBase
& rImp
,
169 const OUString
& rQName
) :
170 XMLPersElemContentTContext( rImp
, rQName
),
171 m_xAttrList( new XMLMutableAttributeList() )
175 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
176 const OUString
&sName
,
177 const OUString
&sValue
)
179 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
180 ->AddAttribute( sName
, sValue
);
183 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
184 sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
185 const OUString
&sValue
)
188 GetTransformer().GetNamespaceMap().GetQNameByKey(
189 nPrefix
, ::xmloff::token::GetXMLToken( eToken
) ) );
190 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
191 ->AddAttribute( sName
, sValue
);
194 void XMLTypedPropertiesOOoTContext_Impl::StartElement(
195 const Reference
< XAttributeList
>& )
197 // empty, ignore even the attribute list
200 void XMLTypedPropertiesOOoTContext_Impl::Export()
202 if( m_xAttrList
->getLength() || HasElementContent() )
204 GetTransformer().GetDocHandler()->startElement( GetQName(), m_xAttrList
);
206 GetTransformer().GetDocHandler()->endElement( GetQName() );
212 class XMLPropertiesOOoTContext_Impl
: public XMLTransformerContext
214 ::rtl::Reference
< XMLTypedPropertiesOOoTContext_Impl
>
215 m_aPropContexts
[MAX_PROP_TYPES
];
217 using XMLPropTypes
= std::array
<XMLPropType
, MAX_PROP_TYPES
>;
219 XMLPropTypes
const & m_rPropTypes
;
221 bool const m_bPersistent
;
223 XMLTypedPropertiesOOoTContext_Impl
*GetPropContextAndAction(
224 TransformerAction_Impl
& rAction
,
225 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
228 XMLTypedPropertiesOOoTContext_Impl
*GetPropContext(
232 XMLPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
233 const OUString
& rQName
,
234 const XMLPropTypes
& rTypes
,
237 rtl::Reference
<XMLTransformerContext
> CreateChildContext(
239 const OUString
& rLocalName
,
240 const OUString
& rQName
,
241 const Reference
< XAttributeList
>& rAttrList
) override
;
243 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
245 virtual void EndElement() override
;
247 virtual void Characters( const OUString
& rChars
) override
;
249 virtual void Export() override
;
251 virtual bool IsPersistent() const override
;
256 XMLTypedPropertiesOOoTContext_Impl
257 *XMLPropertiesOOoTContext_Impl::GetPropContext(
260 sal_uInt16 nIndex
= MAX_PROP_TYPES
;
261 for( sal_uInt16 i
=0; i
< MAX_PROP_TYPES
; i
++ )
263 if( m_rPropTypes
[i
] == eType
)
269 if( MAX_PROP_TYPES
== nIndex
)
272 if( !m_aPropContexts
[nIndex
].is() )
274 m_aPropContexts
[nIndex
] =
275 new XMLTypedPropertiesOOoTContext_Impl(
277 GetTransformer().GetNamespaceMap().GetQNameByKey(
279 ::xmloff::token::GetXMLToken(
280 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
283 return m_aPropContexts
[nIndex
].get();
286 XMLTypedPropertiesOOoTContext_Impl
287 *XMLPropertiesOOoTContext_Impl::GetPropContextAndAction(
288 TransformerAction_Impl
& rAction
,
289 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
292 rAction
.m_nActionType
= XML_ATACTION_COPY
;
293 sal_uInt16 nIndex
= 0;
295 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
297 while( i
< MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
])
299 sal_uInt16 nActionMap
=
300 (bElem
? aElemActionMaps
: aAttrActionMaps
)[m_rPropTypes
[i
]];
301 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
303 XMLTransformerActions
*pActions
=
304 GetTransformer().GetUserDefinedActions( nActionMap
);
305 OSL_ENSURE( pActions
, "go no actions" );
308 XMLTransformerActions::const_iterator aIter
=
309 pActions
->find( aKey
);
311 if( aIter
!= pActions
->end() )
313 rAction
= (*aIter
).second
;
323 if( !( XML_NAMESPACE_NONE
== nPrefix
||
324 (XML_NAMESPACE_UNKNOWN_FLAG
& nPrefix
) ||
325 XML_PROP_TYPE_END
==m_rPropTypes
[1] ||
326 (i
<MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
]) ) )
328 SAL_WARN("xmloff", "Didn't find property: "
329 << GetTransformer().GetNamespaceMap().GetPrefixByKey( nPrefix
)
332 << ", assuming <style:"
333 << ::xmloff::token::GetXMLToken( aPropTokens
[m_rPropTypes
[0]] )
338 if( !m_aPropContexts
[nIndex
].is() )
340 m_aPropContexts
[nIndex
] =
341 new XMLTypedPropertiesOOoTContext_Impl(
343 GetTransformer().GetNamespaceMap().GetQNameByKey(
345 ::xmloff::token::GetXMLToken(
346 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
349 return m_aPropContexts
[nIndex
].get();
352 XMLPropertiesOOoTContext_Impl::XMLPropertiesOOoTContext_Impl(
353 XMLTransformerBase
& rImp
,
354 const OUString
& rQName
,
355 const XMLPropTypes
& rTypes
,
357 XMLTransformerContext( rImp
, rQName
),
358 // remember the types that belong to the attribute and element lists
359 m_rPropTypes(rTypes
),
360 m_bPersistent( bPersistent
)
364 rtl::Reference
<XMLTransformerContext
> XMLPropertiesOOoTContext_Impl::CreateChildContext(
366 const OUString
& rLocalName
,
367 const OUString
& rQName
,
368 const Reference
< XAttributeList
>& rAttrList
)
370 TransformerAction_Impl aAction
;
371 return GetPropContextAndAction( aAction
, nPrefix
, rLocalName
, true )
372 ->CreateChildContext( nPrefix
, rLocalName
, rQName
, rAttrList
);
375 void XMLPropertiesOOoTContext_Impl::StartElement(
376 const Reference
< XAttributeList
>& rAttrList
)
378 XMLTypedPropertiesOOoTContext_Impl
* pIntervalMinorDivisorContext
= nullptr;
379 double fIntervalMajor
= 0.0;
380 double fIntervalMinor
= 0.0;
381 bool bMoveProtect
= false;
382 bool bSizeProtect
= false;
383 OUString aProtectAttrValue
;
384 XMLTypedPropertiesOOoTContext_Impl
* pProtectContext
= nullptr;
386 /* Attribute <style:mirror> has to be priority over attribute <style:draw>.
387 The filter from OpenDocument file format to OpenOffice.org file format
388 produces styles with both attributes. (#i49139#)
390 bool bExistStyleMirror( false );
391 OUStringBuffer aStyleMirrorAttrValue
;
392 bool bExistDrawMirror( false );
393 OUString aDrawMirrorAttrValue
;
394 XMLTypedPropertiesOOoTContext_Impl
* pMirrorContext( nullptr );
396 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
397 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
399 const OUString sAttrName
= rAttrList
->getNameByIndex( i
);
400 const OUString sAttrValue
= rAttrList
->getValueByIndex( i
);
403 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
405 TransformerAction_Impl aAction
;
406 XMLTypedPropertiesOOoTContext_Impl
*pContext
=
407 GetPropContextAndAction( aAction
, nPrefix
, aLocalName
, false );
408 switch( aAction
.m_nActionType
)
410 case XML_ATACTION_REMOVE
:
412 case XML_ATACTION_COPY
:
413 pContext
->AddAttribute( sAttrName
, sAttrValue
);
415 case XML_ATACTION_COPY_DUPLICATE
:
417 pContext
->AddAttribute( sAttrName
, sAttrValue
);
418 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
419 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
421 pContext2
->AddAttribute( sAttrName
, sAttrValue
);
424 case XML_ATACTION_RENAME
:
426 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
427 aAction
.GetQNameTokenFromParam1(),
431 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
433 OUString
aAttrValue( sAttrValue
);
434 GetTransformer().EncodeStyleName(aAttrValue
);
435 pContext
->AddAttribute( sAttrName
, aAttrValue
);
438 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF
:
440 OUString
aAttrValue( sAttrValue
);
441 GetTransformer().EncodeStyleName(aAttrValue
);
442 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
443 aAction
.GetQNameTokenFromParam1(),
447 case XML_ATACTION_NEG_PERCENT
:
449 OUString
aAttrValue( sAttrValue
);
450 XMLTransformerBase::NegPercent(aAttrValue
);
451 pContext
->AddAttribute( sAttrName
, aAttrValue
);
454 case XML_ATACTION_RENAME_NEG_PERCENT
:
456 OUString
aAttrValue( sAttrValue
);
457 XMLTransformerBase::NegPercent(aAttrValue
);
458 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
459 aAction
.GetQNameTokenFromParam1(),
463 case XML_ATACTION_INCH2IN
:
465 OUString
aAttrValue( sAttrValue
);
466 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
467 pContext
->AddAttribute( sAttrName
, aAttrValue
);
470 case XML_ATACTION_INCH2IN_DUPLICATE
:
472 OUString
aAttrValue( sAttrValue
);
473 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
474 pContext
->AddAttribute( sAttrName
, aAttrValue
);
475 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
476 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
478 pContext2
->AddAttribute( sAttrName
, aAttrValue
);
481 case XML_ATACTION_INCHS2INS
:
483 OUString
aAttrValue( sAttrValue
);
484 XMLTransformerBase::ReplaceInchWithIn( aAttrValue
);
485 pContext
->AddAttribute( sAttrName
, aAttrValue
);
488 case XML_PTACTION_LINE_MODE
:
490 const OUString
& aAttrValue( GetXMLToken(
491 IsXMLToken( sAttrValue
, XML_TRUE
)
493 : XML_SKIP_WHITE_SPACE
) );
495 GetTransformer().GetNamespaceMap().GetQNameByKey(
497 GetXMLToken( XML_TEXT_UNDERLINE_MODE
) ) );
498 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
501 GetTransformer().GetNamespaceMap().GetQNameByKey(
503 GetXMLToken( XML_TEXT_LINE_THROUGH_MODE
) );
504 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
507 case XML_PTACTION_KEEP_WITH_NEXT
:
509 const OUString
& aAttrValue( GetXMLToken(
510 IsXMLToken( sAttrValue
, XML_TRUE
)
513 pContext
->AddAttribute( sAttrName
, aAttrValue
);
516 case XML_PTACTION_UNDERLINE
:
518 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
519 bool bBold
= false, bDouble
= false;
533 case XML_BOLD_DOTTED
:
541 case XML_BOLD_LONG_DASH
:
542 eToken
= XML_LONG_DASH
;
545 case XML_BOLD_DOT_DASH
:
546 eToken
= XML_DOT_DASH
;
549 case XML_BOLD_DOT_DOT_DASH
:
550 eToken
= XML_DOT_DOT_DASH
;
557 case XML_DOUBLE_WAVE
:
566 OSL_FAIL( "xmloff::XMLPropertiesOOoTContext_Impl::StartElement(), unknown underline token!" );
569 pContext
->AddAttribute(
570 GetTransformer().GetNamespaceMap().GetQNameByKey(
572 GetXMLToken( XML_TEXT_UNDERLINE_STYLE
) ),
573 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
576 pContext
->AddAttribute(
577 GetTransformer().GetNamespaceMap().GetQNameByKey(
579 GetXMLToken( XML_TEXT_UNDERLINE_TYPE
) ),
580 GetXMLToken( XML_DOUBLE
) );
582 pContext
->AddAttribute(
583 GetTransformer().GetNamespaceMap().GetQNameByKey(
585 GetXMLToken( XML_TEXT_UNDERLINE_WIDTH
) ),
586 GetXMLToken( XML_BOLD
) );
589 case XML_PTACTION_LINETHROUGH
:
591 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
592 bool bBold
= false, bDouble
= false;
596 case XML_SINGLE_LINE
:
599 case XML_DOUBLE_LINE
:
618 pContext
->AddAttribute(
619 GetTransformer().GetNamespaceMap().GetQNameByKey(
621 GetXMLToken( XML_TEXT_LINE_THROUGH_STYLE
) ),
622 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
625 pContext
->AddAttribute(
626 GetTransformer().GetNamespaceMap().GetQNameByKey(
628 GetXMLToken( XML_TEXT_LINE_THROUGH_TYPE
) ),
629 GetXMLToken( XML_DOUBLE
) );
631 pContext
->AddAttribute(
632 GetTransformer().GetNamespaceMap().GetQNameByKey(
634 GetXMLToken( XML_TEXT_LINE_THROUGH_WIDTH
) ),
635 GetXMLToken( XML_BOLD
) );
637 pContext
->AddAttribute(
638 GetTransformer().GetNamespaceMap().GetQNameByKey(
640 GetXMLToken( XML_TEXT_LINE_THROUGH_TEXT
) ),
644 case XML_PTACTION_SPLINES
:
646 sal_Int32 nSplineType
= sAttrValue
.toInt32();
647 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
648 XML_NAMESPACE_CHART
, GetXMLToken( XML_INTERPOLATION
) );
650 switch( nSplineType
)
654 pContext
->AddAttribute(
655 aNewAttrName
, GetXMLToken( XML_NONE
));
659 pContext
->AddAttribute(
660 aNewAttrName
, GetXMLToken( XML_CUBIC_SPLINE
));
664 pContext
->AddAttribute(
665 aNewAttrName
, GetXMLToken( XML_B_SPLINE
));
669 OSL_FAIL( "invalid spline type" );
670 pContext
->AddAttribute(
671 aNewAttrName
, GetXMLToken( XML_NONE
));
676 case XML_PTACTION_INTERVAL_MAJOR
:
677 pContext
->AddAttribute( sAttrName
, sAttrValue
);
678 ::sax::Converter::convertDouble( fIntervalMajor
, sAttrValue
);
680 case XML_PTACTION_INTERVAL_MINOR
:
681 ::sax::Converter::convertDouble( fIntervalMinor
, sAttrValue
);
682 pIntervalMinorDivisorContext
= pContext
;
684 case XML_PTACTION_SYMBOL
:
686 sal_Int32 nSymbolType
= sAttrValue
.toInt32();
687 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
688 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_TYPE
) );
690 if( nSymbolType
>= 0 )
692 pContext
->AddAttribute( aNewAttrName
, GetXMLToken( XML_NAMED_SYMBOL
));
693 enum XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
694 switch( nSymbolType
)
698 // "square" has an awkward token name
699 eToken
= XML_GRADIENTSTYLE_SQUARE
;
703 eToken
= XML_DIAMOND
;
707 eToken
= XML_ARROW_DOWN
;
711 eToken
= XML_ARROW_UP
;
715 eToken
= XML_ARROW_RIGHT
;
719 eToken
= XML_ARROW_LEFT
;
723 eToken
= XML_BOW_TIE
;
727 eToken
= XML_HOURGLASS
;
742 eToken
= XML_ASTERISK
;
745 eToken
= XML_HORIZONTAL_BAR
;
748 eToken
= XML_VERTICAL_BAR
;
751 OSL_FAIL( "invalid named symbol" );
755 if( eToken
!= XML_TOKEN_INVALID
)
757 pContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
758 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_NAME
)),
759 GetXMLToken( eToken
));
764 switch( nSymbolType
)
768 pContext
->AddAttribute(
769 aNewAttrName
, GetXMLToken( XML_NONE
));
773 pContext
->AddAttribute(
774 aNewAttrName
, GetXMLToken( XML_AUTOMATIC
));
778 pContext
->AddAttribute(
779 aNewAttrName
, GetXMLToken( XML_IMAGE
));
782 OSL_FAIL( "invalid symbol type" );
783 pContext
->AddAttribute(
784 aNewAttrName
, GetXMLToken( XML_NONE
));
790 case XML_PTACTION_SYMBOL_IMAGE_NAME
:
792 // create an xlink:href element for URI attribute
793 XMLPersAttrListTContext
*pSymbolImageContext
= new XMLPersAttrListTContext(
794 GetTransformer(), GetTransformer().GetNamespaceMap().GetQNameByKey(
795 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_IMAGE
)));
796 rtl::Reference
<XMLTransformerContext
> xSymbolImageContext(pSymbolImageContext
);
798 OUString
aAttrValue( sAttrValue
);
799 if( GetTransformer().ConvertURIToOASIS( aAttrValue
, true ))
801 pSymbolImageContext
->AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aAttrValue
);
802 pContext
->AddContent(xSymbolImageContext
);
808 case XML_PTACTION_TRANSPARENCY
:
810 OUString
aAttrValue( sAttrValue
);
811 XMLTransformerBase::NegPercent(aAttrValue
);
812 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
815 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
821 case XML_PTACTION_BREAK_INSIDE
:
823 pContext
->AddAttribute(
824 XML_NAMESPACE_FO
, XML_KEEP_TOGETHER
,
826 IsXMLToken( sAttrValue
, XML_COLUMNSPLIT_AVOID
)
831 case XML_ATACTION_CAPTION_ESCAPE_OOO
:
833 OUString
aAttrValue( sAttrValue
);
834 if( aAttrValue
.indexOf( '%' ) != -1 )
836 sal_Int32 nValue
= 0;
837 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
842 ::sax::Converter::convertPercent( aOut
, nValue
);
843 aAttrValue
= aOut
.makeStringAndClear();
848 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
851 pContext
->AddAttribute( sAttrName
, aAttrValue
);
854 case XML_ATACTION_MOVE_PROTECT
:
855 bMoveProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
856 pProtectContext
= pContext
;
858 case XML_ATACTION_SIZE_PROTECT
:
859 bSizeProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
860 pProtectContext
= pContext
;
862 case XML_ATACTION_PROTECT
:
863 aProtectAttrValue
= sAttrValue
;
864 pProtectContext
= pContext
;
866 case XML_ATACTION_DRAW_MIRROR_OOO
: // renames draw:mirror to style:mirror and adapts values
868 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
869 aDrawMirrorAttrValue
=
870 GetXMLToken( IsXMLToken( sAttrValue
, XML_TRUE
)
871 ? XML_HORIZONTAL
: XML_NONE
);
872 bExistDrawMirror
= true;
873 pMirrorContext
= pContext
;
876 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
877 case XML_ATACTION_STYLE_MIRROR_OOO
: // adapts style:mirror values
879 SvXMLTokenEnumerator
aTokenEnum( sAttrValue
);
881 while( aTokenEnum
.getNextToken( aToken
) )
883 if ( !aStyleMirrorAttrValue
.isEmpty() )
885 aStyleMirrorAttrValue
.append(" ");
888 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_LEFT_PAGES
) )
890 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_EVEN
));
892 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_RIGHT_PAGES
) )
894 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_ODD
));
898 aStyleMirrorAttrValue
.append(aToken
);
901 bExistStyleMirror
= true;
902 pMirrorContext
= pContext
;
905 case XML_ATACTION_GAMMA_OOO
: // converts double value to percentage
907 double fValue
= sAttrValue
.toDouble();
908 sal_Int32 nValue
= static_cast<sal_Int32
>((fValue
* 100.0) + ( fValue
> 0 ? 0.5 : - 0.5 ) );
911 ::sax::Converter::convertPercent( aOut
, nValue
);
912 OUString
aAttrValue( aOut
.makeStringAndClear() );
913 pContext
->AddAttribute( sAttrName
, aAttrValue
);
916 case XML_ATACTION_OPACITY_FIX
:
919 if( sAttrValue
.indexOf( '%' ) != -1 )
921 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
925 nValue
= sal_Int32( sAttrValue
.toDouble() * 100.0 );
927 nValue
= 100 - nValue
;
930 ::sax::Converter::convertPercent( aOut
, nValue
);
931 pContext
->AddAttribute( sAttrName
, aOut
.makeStringAndClear() );
935 OSL_ENSURE( false, "unknown action" );
940 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
941 if ( bExistStyleMirror
)
943 pMirrorContext
->AddAttribute(
944 GetTransformer().GetNamespaceMap().GetQNameByKey(
945 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
946 aStyleMirrorAttrValue
.makeStringAndClear());
948 else if ( bExistDrawMirror
)
950 pMirrorContext
->AddAttribute(
951 GetTransformer().GetNamespaceMap().GetQNameByKey(
952 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
953 aDrawMirrorAttrValue
);
956 if (bMoveProtect
|| bSizeProtect
|| !aProtectAttrValue
.isEmpty())
958 if( (bMoveProtect
||bSizeProtect
) && IsXMLToken( aProtectAttrValue
, XML_NONE
) )
959 aProtectAttrValue
.clear();
961 const OUString
& rPosition
= GetXMLToken( XML_POSITION
);
962 if( bMoveProtect
&& -1 == aProtectAttrValue
.indexOf( rPosition
) )
964 if( !aProtectAttrValue
.isEmpty() )
965 aProtectAttrValue
+= " ";
966 aProtectAttrValue
+= rPosition
;
969 const OUString
& rSize
= GetXMLToken( XML_SIZE
);
970 if( bSizeProtect
&& -1 == aProtectAttrValue
.indexOf( rSize
) )
972 if( !aProtectAttrValue
.isEmpty() )
973 aProtectAttrValue
+= " ";
974 aProtectAttrValue
+= rSize
;
977 assert(pProtectContext
&& "coverity[var_deref_model] - pProtectContext should be assigned in a superset of the enclosing if condition entry logic");
978 pProtectContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_STYLE
, GetXMLToken( XML_PROTECT
) ), aProtectAttrValue
);
981 if( !pIntervalMinorDivisorContext
)
984 if( fIntervalMinor
!= 0.0 )
986 sal_Int32 nIntervalMinorDivisor
= static_cast< sal_Int32
>(
987 ::rtl::math::round( fIntervalMajor
/ fIntervalMinor
));
989 pIntervalMinorDivisorContext
->AddAttribute(
990 GetTransformer().GetNamespaceMap().GetQNameByKey(
992 GetXMLToken( XML_INTERVAL_MINOR_DIVISOR
)),
993 OUString::number( nIntervalMinorDivisor
));
997 void XMLPropertiesOOoTContext_Impl::EndElement()
1003 void XMLPropertiesOOoTContext_Impl::Characters( const OUString
& )
1008 void XMLPropertiesOOoTContext_Impl::Export()
1011 for(rtl::Reference
<XMLTypedPropertiesOOoTContext_Impl
> & rPropContext
: m_aPropContexts
)
1013 if( rPropContext
.is() )
1014 rPropContext
->Export();
1018 bool XMLPropertiesOOoTContext_Impl::IsPersistent() const
1020 return m_bPersistent
;
1023 XMLStyleOOoTContext::XMLStyleOOoTContext( XMLTransformerBase
& rImp
,
1024 const OUString
& rQName
,
1026 bool bPersistent
) :
1027 XMLPersElemContentTContext( rImp
, rQName
),
1029 m_bPersistent( bPersistent
)
1033 XMLStyleOOoTContext::XMLStyleOOoTContext(
1034 XMLTransformerBase
& rImp
,
1035 const OUString
& rQName
,
1038 ::xmloff::token::XMLTokenEnum eToken
,
1039 bool bPersistent
) :
1040 XMLPersElemContentTContext( rImp
, rQName
, nPrefix
, eToken
),
1042 m_bPersistent( bPersistent
)
1046 XMLStyleOOoTContext::~XMLStyleOOoTContext()
1050 rtl::Reference
<XMLTransformerContext
> XMLStyleOOoTContext::CreateChildContext(
1052 const OUString
& rLocalName
,
1053 const OUString
& rQName
,
1054 const Reference
< XAttributeList
>& rAttrList
)
1056 rtl::Reference
<XMLTransformerContext
> pContext
;
1058 if( XML_NAMESPACE_STYLE
== nPrefix
&&
1059 IsXMLToken( rLocalName
, XML_PROPERTIES
) )
1061 if( aPropTypes
[m_eFamily
][0] == XML_PROP_TYPE_END
)
1063 OSL_ENSURE( false, "unexpected properties element" );
1064 pContext
= m_bPersistent
1065 ? XMLPersElemContentTContext::CreateChildContext(
1066 nPrefix
, rLocalName
, rQName
, rAttrList
)
1067 : XMLTransformerContext::CreateChildContext(
1068 nPrefix
, rLocalName
, rQName
, rAttrList
);
1070 else if( aPropTypes
[m_eFamily
][1] == XML_PROP_TYPE_END
)
1072 sal_uInt16 nActionMap
=
1073 aAttrActionMaps
[aPropTypes
[m_eFamily
][0]];
1074 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
1076 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1077 GetTransformer(), rQName
,
1078 aPropTypes
[m_eFamily
], m_bPersistent
));
1083 pContext
.set(new XMLPersElemContentTContext(
1084 GetTransformer(), rQName
,
1085 XML_NAMESPACE_STYLE
,
1086 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1088 pContext
.set(new XMLRenameElemTransformerContext(
1089 GetTransformer(), rQName
,
1090 XML_NAMESPACE_STYLE
,
1091 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1096 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1097 GetTransformer(), rQName
,
1098 aPropTypes
[m_eFamily
], m_bPersistent
));
1102 AddContent( pContext
);
1106 pContext
= m_bPersistent
1107 ? XMLPersElemContentTContext::CreateChildContext(
1108 nPrefix
, rLocalName
, rQName
, rAttrList
)
1109 : XMLTransformerContext::CreateChildContext(
1110 nPrefix
, rLocalName
, rQName
, rAttrList
);
1116 void XMLStyleOOoTContext::StartElement(
1117 const Reference
< XAttributeList
>& rAttrList
)
1119 XMLTransformerActions
*pActions
=
1120 GetTransformer().GetUserDefinedActions( OOO_STYLE_ACTIONS
);
1121 OSL_ENSURE( pActions
, "go no actions" );
1123 Reference
< XAttributeList
> xAttrList( rAttrList
);
1124 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
1125 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1126 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1128 const OUString sAttrName
= xAttrList
->getNameByIndex( i
);
1129 OUString aLocalName
;
1130 sal_uInt16 nPrefix
=
1131 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
1133 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
1134 XMLTransformerActions::const_iterator aIter
=
1135 pActions
->find( aKey
);
1136 if( aIter
!= pActions
->end() )
1138 if( !pMutableAttrList
)
1141 new XMLMutableAttributeList( xAttrList
);
1142 xAttrList
= pMutableAttrList
;
1144 const OUString sAttrValue
= xAttrList
->getValueByIndex( i
);
1145 switch( (*aIter
).second
.m_nActionType
)
1147 case XML_ATACTION_STYLE_FAMILY
:
1149 bool bControl
= false;
1150 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1152 if( IsXMLToken( sAttrValue
, XML_GRAPHICS
) )
1153 m_eFamily
= XML_FAMILY_TYPE_GRAPHIC
;
1154 else if( IsXMLToken( sAttrValue
, XML_PRESENTATION
) )
1155 m_eFamily
= XML_FAMILY_TYPE_PRESENTATION
;
1156 else if( IsXMLToken( sAttrValue
, XML_DRAWING_PAGE
) )
1157 m_eFamily
= XML_FAMILY_TYPE_DRAWING_PAGE
;
1158 else if( IsXMLToken( sAttrValue
, XML_TEXT
) )
1159 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1160 else if( IsXMLToken( sAttrValue
, XML_PARAGRAPH
) )
1161 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1162 else if( IsXMLToken( sAttrValue
, XML_RUBY
) )
1163 m_eFamily
= XML_FAMILY_TYPE_RUBY
;
1164 else if( IsXMLToken( sAttrValue
, XML_SECTION
) )
1165 m_eFamily
= XML_FAMILY_TYPE_SECTION
;
1166 else if( IsXMLToken( sAttrValue
, XML_TABLE
) )
1167 m_eFamily
= XML_FAMILY_TYPE_TABLE
;
1168 else if( IsXMLToken( sAttrValue
, XML_TABLE_COLUMN
) )
1169 m_eFamily
= XML_FAMILY_TYPE_TABLE_COLUMN
;
1170 else if( IsXMLToken( sAttrValue
, XML_TABLE_ROW
) )
1171 m_eFamily
= XML_FAMILY_TYPE_TABLE_ROW
;
1172 else if( IsXMLToken( sAttrValue
, XML_TABLE_CELL
) )
1173 m_eFamily
= XML_FAMILY_TYPE_TABLE_CELL
;
1174 else if( IsXMLToken( sAttrValue
, XML_CHART
) )
1175 m_eFamily
= XML_FAMILY_TYPE_CHART
;
1176 else if( IsXMLToken( sAttrValue
, XML_CONTROL
) )
1178 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1182 if( XML_FAMILY_TYPE_GRAPHIC
== m_eFamily
)
1184 pMutableAttrList
->SetValueByIndex( i
,
1185 GetXMLToken( XML_GRAPHIC
) );
1189 pMutableAttrList
->SetValueByIndex( i
,
1190 GetXMLToken( XML_PARAGRAPH
) );
1194 case XML_ATACTION_INCH2IN
:
1196 OUString
aAttrValue( sAttrValue
);
1197 if( XMLTransformerBase::ReplaceSingleInchWithIn(
1199 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1202 case XML_ATACTION_ENCODE_STYLE_NAME
:
1204 OUString
aAttrValue( sAttrValue
);
1205 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1207 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1208 OUString
aNewAttrQName(
1209 GetTransformer().GetNamespaceMap().
1211 nPrefix
, ::xmloff::token::GetXMLToken(
1212 XML_DISPLAY_NAME
) ) );
1213 pMutableAttrList
->AddAttribute( aNewAttrQName
,
1218 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
1220 OUString
aAttrValue( sAttrValue
);
1221 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1222 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1225 case XML_ATACTION_NEG_PERCENT
:
1227 OUString
aAttrValue( sAttrValue
);
1228 if( XMLTransformerBase::NegPercent(aAttrValue
) )
1229 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1232 case XML_ATACTION_URI_OOO
:
1234 OUString
aAttrValue( sAttrValue
);
1235 if( GetTransformer().ConvertURIToOASIS( aAttrValue
,
1236 static_cast< bool >((*aIter
).second
.m_nParam1
)))
1237 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1241 OSL_ENSURE( false, "unknown action" );
1246 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1247 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1249 XMLPersElemContentTContext::StartElement( xAttrList
);
1251 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList
);
1254 void XMLStyleOOoTContext::EndElement()
1257 XMLPersElemContentTContext::EndElement();
1259 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
1262 void XMLStyleOOoTContext::Characters( const OUString
& )
1264 // element content only:
1267 bool XMLStyleOOoTContext::IsPersistent() const
1269 return m_bPersistent
;
1272 XMLTransformerActions
*XMLStyleOOoTContext::CreateTransformerActions(
1275 XMLTransformerActionInit
const *pInit
= nullptr;
1279 case PROP_OOO_GRAPHIC_ATTR_ACTIONS
:
1280 pInit
= aGraphicPropertyOOoAttrActionTable
;
1282 case PROP_OOO_GRAPHIC_ELEM_ACTIONS
:
1283 pInit
= aGraphicPropertyOOoElemActionTable
;
1285 case PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
:
1286 pInit
= aDrawingPagePropertyOOoAttrActionTable
;
1288 case PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
:
1289 pInit
= aPageLayoutPropertyOOoAttrActionTable
;
1291 case PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
:
1292 pInit
= aHeaderFooterPropertyOOoAttrActionTable
;
1294 case PROP_OOO_TEXT_ATTR_ACTIONS
:
1295 pInit
= aTextPropertyOOoAttrActionTable
;
1297 case PROP_OOO_TEXT_ELEM_ACTIONS
:
1298 pInit
= aTextPropertyOOoElemActionTable
;
1300 case PROP_OOO_PARAGRAPH_ATTR_ACTIONS
:
1301 pInit
= aParagraphPropertyOOoAttrActionTable
;
1303 case PROP_OOO_PARAGRAPH_ELEM_ACTIONS
:
1304 pInit
= aParagraphPropertyOOoElemActionTable
;
1306 case PROP_OOO_SECTION_ATTR_ACTIONS
:
1307 pInit
= aSectionPropertyOOoAttrActionTable
;
1309 case PROP_OOO_TABLE_ATTR_ACTIONS
:
1310 pInit
= aTablePropertyOOoAttrActionTable
;
1312 case PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
:
1313 pInit
= aTableColumnPropertyOOoAttrActionTable
;
1315 case PROP_OOO_TABLE_ROW_ATTR_ACTIONS
:
1316 pInit
= aTableRowPropertyOOoAttrActionTable
;
1318 case PROP_OOO_TABLE_CELL_ATTR_ACTIONS
:
1319 pInit
= aTableCellPropertyOOoAttrActionTable
;
1321 case PROP_OOO_TABLE_CELL_ELEM_ACTIONS
:
1322 pInit
= aTableCellPropertyOOoElemActionTable
;
1324 case PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
:
1325 pInit
= aListLevelPropertyOOoAttrActionTable
;
1327 case PROP_OOO_CHART_ATTR_ACTIONS
:
1328 pInit
= aChartPropertyOOoAttrActionTable
;
1330 case PROP_OOO_CHART_ELEM_ACTIONS
:
1331 pInit
= aChartPropertyOOoElemActionTable
;
1335 XMLTransformerActions
*pActions
= nullptr;
1337 pActions
= new XMLTransformerActions( pInit
);
1342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */