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/nmspmap.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnmspe.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/ustrbuf.hxx>
41 #include <osl/diagnose.h>
42 #include <sal/log.hxx>
45 using namespace ::xmloff::token
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::xml::sax
;
49 const sal_uInt16 MAX_PROP_TYPES
= 4;
50 #define ENTRY4(a,b,c,d) \
51 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
52 XML_PROP_TYPE_##c, XML_PROP_TYPE_##d }
53 #define ENTRY3(a,b,c) \
54 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
55 XML_PROP_TYPE_##c, XML_PROP_TYPE_END }
57 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##b, \
58 XML_PROP_TYPE_END, XML_PROP_TYPE_END }
60 { XML_PROP_TYPE_##a, XML_PROP_TYPE_##END, \
61 XML_PROP_TYPE_END, XML_PROP_TYPE_END }
63 static const std::array
<XMLPropType
,MAX_PROP_TYPES
> aPropTypes
[XML_FAMILY_TYPE_END
] =
65 ENTRY3( GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_GRAPHIC,
66 ENTRY3( GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_PRESENTATION,
67 ENTRY1( DRAWING_PAGE
), // XML_FAMILY_TYPE_DRAWING_PAGE,
68 ENTRY1( END
), // XML_FAMILY_TYPE_MASTER_PAGE
69 ENTRY1( PAGE_LAYOUT
), // XML_FAMILY_TYPE_PAGE_LAYOUT,
70 ENTRY1( HEADER_FOOTER
), // XML_FAMILY_TYPE_HEADER_FOOTER
71 ENTRY1( TEXT
), // XML_FAMILY_TYPE_TEXT,
72 ENTRY2( PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_PARAGRAPH,
73 ENTRY1( RUBY
), //XML_FAMILY_TYPE_RUBY,
74 ENTRY1( SECTION
), // XML_FAMILY_TYPE_SECTION,
75 ENTRY1( TABLE
), // XML_FAMILY_TYPE_TABLE,
76 ENTRY1( TABLE_COLUMN
), // XML_FAMILY_TYPE_TABLE_COLUMN,
77 ENTRY1( TABLE_ROW
), // XML_FAMILY_TYPE_TABLE_ROW,
78 ENTRY3( TABLE_CELL
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_TABLE_CELL,
79 ENTRY1( LIST_LEVEL
), // XML_FAMILY_TYPE_LIST,
80 ENTRY4( CHART
, GRAPHIC
, PARAGRAPH
, TEXT
), // XML_FAMILY_TYPE_CHART,
81 ENTRY1( TEXT
), // XML_FAMILY_TYPE_DATA,
82 ENTRY1( END
), // XML_FAMILY_TYPE_GRADIENT,
83 ENTRY1( END
), // XML_FAMILY_TYPE_HATCH,
84 ENTRY1( END
), // XML_FAMILY_TYPE_FILL_IMAGE,
85 ENTRY1( END
), // XML_FAMILY_TYPE_STROKE_DASH,
86 ENTRY1( END
), // XML_FAMILY_TYPE_MARKER,
89 static const XMLTokenEnum aPropTokens
[XML_PROP_TYPE_END
] =
91 XML_GRAPHIC_PROPERTIES
,
92 XML_DRAWING_PAGE_PROPERTIES
,
93 XML_PAGE_LAYOUT_PROPERTIES
,
94 XML_HEADER_FOOTER_PROPERTIES
,
96 XML_PARAGRAPH_PROPERTIES
,
98 XML_SECTION_PROPERTIES
,
100 XML_TABLE_COLUMN_PROPERTIES
,
101 XML_TABLE_ROW_PROPERTIES
,
102 XML_TABLE_CELL_PROPERTIES
,
103 XML_LIST_LEVEL_PROPERTIES
,
107 static const sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
109 PROP_OOO_GRAPHIC_ATTR_ACTIONS
,
110 PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
111 PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
,
112 PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
,
113 PROP_OOO_TEXT_ATTR_ACTIONS
,
114 PROP_OOO_PARAGRAPH_ATTR_ACTIONS
,
115 MAX_OOO_PROP_ACTIONS
, // RUBY
116 PROP_OOO_SECTION_ATTR_ACTIONS
,
117 PROP_OOO_TABLE_ATTR_ACTIONS
,
118 PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
,
119 PROP_OOO_TABLE_ROW_ATTR_ACTIONS
,
120 PROP_OOO_TABLE_CELL_ATTR_ACTIONS
,
121 PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
,
122 PROP_OOO_CHART_ATTR_ACTIONS
125 static const sal_uInt16 aElemActionMaps
[XML_PROP_TYPE_END
] =
127 PROP_OOO_GRAPHIC_ELEM_ACTIONS
,
128 MAX_OOO_PROP_ACTIONS
,
129 MAX_OOO_PROP_ACTIONS
,
130 MAX_OOO_PROP_ACTIONS
,
131 PROP_OOO_TEXT_ELEM_ACTIONS
,
132 PROP_OOO_PARAGRAPH_ELEM_ACTIONS
,
133 MAX_OOO_PROP_ACTIONS
,
134 MAX_OOO_PROP_ACTIONS
,
135 MAX_OOO_PROP_ACTIONS
,
136 MAX_OOO_PROP_ACTIONS
,
137 MAX_OOO_PROP_ACTIONS
,
138 PROP_OOO_TABLE_CELL_ELEM_ACTIONS
,
139 MAX_OOO_PROP_ACTIONS
,
140 PROP_OOO_CHART_ELEM_ACTIONS
143 class XMLTypedPropertiesOOoTContext_Impl
: public XMLPersElemContentTContext
145 css::uno::Reference
< css::xml::sax::XAttributeList
> m_xAttrList
;
148 XMLTypedPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
149 const OUString
& rQName
);
151 using XMLPersAttrListTContext::AddAttribute
;
152 void AddAttribute( const OUString
&sName
,
153 const OUString
&sValue
);
154 void AddAttribute( sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
155 const OUString
&sValue
);
157 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
159 virtual void Export() override
;
162 XMLTypedPropertiesOOoTContext_Impl::XMLTypedPropertiesOOoTContext_Impl(
163 XMLTransformerBase
& rImp
,
164 const OUString
& rQName
) :
165 XMLPersElemContentTContext( rImp
, rQName
),
166 m_xAttrList( new XMLMutableAttributeList() )
170 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
171 const OUString
&sName
,
172 const OUString
&sValue
)
174 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
175 ->AddAttribute( sName
, sValue
);
178 void XMLTypedPropertiesOOoTContext_Impl::AddAttribute(
179 sal_uInt16 nPrefix
, XMLTokenEnum eToken
,
180 const OUString
&sValue
)
183 GetTransformer().GetNamespaceMap().GetQNameByKey(
184 nPrefix
, ::xmloff::token::GetXMLToken( eToken
) ) );
185 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
186 ->AddAttribute( sName
, sValue
);
189 void XMLTypedPropertiesOOoTContext_Impl::StartElement(
190 const Reference
< XAttributeList
>& )
192 // empty, ignore even the attribute list
195 void XMLTypedPropertiesOOoTContext_Impl::Export()
197 if( m_xAttrList
->getLength() || HasElementContent() )
199 GetTransformer().GetDocHandler()->startElement( GetQName(), m_xAttrList
);
201 GetTransformer().GetDocHandler()->endElement( GetQName() );
205 class XMLPropertiesOOoTContext_Impl
: public XMLTransformerContext
207 ::rtl::Reference
< XMLTypedPropertiesOOoTContext_Impl
>
208 m_aPropContexts
[MAX_PROP_TYPES
];
210 using XMLPropTypes
= std::array
<XMLPropType
, MAX_PROP_TYPES
>;
212 XMLPropTypes
const & m_rPropTypes
;
214 bool const m_bPersistent
;
216 XMLTypedPropertiesOOoTContext_Impl
*GetPropContextAndAction(
217 TransformerAction_Impl
& rAction
,
218 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
221 XMLTypedPropertiesOOoTContext_Impl
*GetPropContext(
225 XMLPropertiesOOoTContext_Impl( XMLTransformerBase
& rTransformer
,
226 const OUString
& rQName
,
227 const XMLPropTypes
& rTypes
,
230 rtl::Reference
<XMLTransformerContext
> CreateChildContext(
232 const OUString
& rLocalName
,
233 const OUString
& rQName
,
234 const Reference
< XAttributeList
>& rAttrList
) override
;
236 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
) override
;
238 virtual void EndElement() override
;
240 virtual void Characters( const OUString
& rChars
) override
;
242 virtual void Export() override
;
244 virtual bool IsPersistent() const override
;
247 XMLTypedPropertiesOOoTContext_Impl
248 *XMLPropertiesOOoTContext_Impl::GetPropContext(
251 sal_uInt16 nIndex
= MAX_PROP_TYPES
;
252 for( sal_uInt16 i
=0; i
< MAX_PROP_TYPES
; i
++ )
254 if( m_rPropTypes
[i
] == eType
)
260 if( MAX_PROP_TYPES
== nIndex
)
263 if( !m_aPropContexts
[nIndex
].is() )
265 m_aPropContexts
[nIndex
] =
266 new XMLTypedPropertiesOOoTContext_Impl(
268 GetTransformer().GetNamespaceMap().GetQNameByKey(
270 ::xmloff::token::GetXMLToken(
271 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
274 return m_aPropContexts
[nIndex
].get();
277 XMLTypedPropertiesOOoTContext_Impl
278 *XMLPropertiesOOoTContext_Impl::GetPropContextAndAction(
279 TransformerAction_Impl
& rAction
,
280 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
283 rAction
.m_nActionType
= XML_ATACTION_COPY
;
284 sal_uInt16 nIndex
= 0;
286 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
288 while( i
< MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
])
290 sal_uInt16 nActionMap
=
291 (bElem
? aElemActionMaps
: aAttrActionMaps
)[m_rPropTypes
[i
]];
292 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
294 XMLTransformerActions
*pActions
=
295 GetTransformer().GetUserDefinedActions( nActionMap
);
296 OSL_ENSURE( pActions
, "go no actions" );
299 XMLTransformerActions::const_iterator aIter
=
300 pActions
->find( aKey
);
302 if( aIter
!= pActions
->end() )
304 rAction
= (*aIter
).second
;
314 if( !( XML_NAMESPACE_NONE
== nPrefix
||
315 (XML_NAMESPACE_UNKNOWN_FLAG
& nPrefix
) ||
316 XML_PROP_TYPE_END
==m_rPropTypes
[1] ||
317 (i
<MAX_PROP_TYPES
&& XML_PROP_TYPE_END
!=m_rPropTypes
[i
]) ) )
319 SAL_WARN("xmloff", "Didn't find property: "
320 << GetTransformer().GetNamespaceMap().GetPrefixByKey( nPrefix
)
323 << ", assuming <style:"
324 << ::xmloff::token::GetXMLToken( aPropTokens
[m_rPropTypes
[0]] )
329 if( !m_aPropContexts
[nIndex
].is() )
331 m_aPropContexts
[nIndex
] =
332 new XMLTypedPropertiesOOoTContext_Impl(
334 GetTransformer().GetNamespaceMap().GetQNameByKey(
336 ::xmloff::token::GetXMLToken(
337 aPropTokens
[m_rPropTypes
[nIndex
]] ) ));
340 return m_aPropContexts
[nIndex
].get();
343 XMLPropertiesOOoTContext_Impl::XMLPropertiesOOoTContext_Impl(
344 XMLTransformerBase
& rImp
,
345 const OUString
& rQName
,
346 const XMLPropTypes
& rTypes
,
348 XMLTransformerContext( rImp
, rQName
),
349 // remember the types that belong to the attribute and element lists
350 m_rPropTypes(rTypes
),
351 m_bPersistent( bPersistent
)
355 rtl::Reference
<XMLTransformerContext
> XMLPropertiesOOoTContext_Impl::CreateChildContext(
357 const OUString
& rLocalName
,
358 const OUString
& rQName
,
359 const Reference
< XAttributeList
>& rAttrList
)
361 TransformerAction_Impl aAction
;
362 return GetPropContextAndAction( aAction
, nPrefix
, rLocalName
, true )
363 ->CreateChildContext( nPrefix
, rLocalName
, rQName
, rAttrList
);
366 void XMLPropertiesOOoTContext_Impl::StartElement(
367 const Reference
< XAttributeList
>& rAttrList
)
369 XMLTypedPropertiesOOoTContext_Impl
* pIntervalMinorDivisorContext
= nullptr;
370 double fIntervalMajor
= 0.0;
371 double fIntervalMinor
= 0.0;
372 bool bMoveProtect
= false;
373 bool bSizeProtect
= false;
374 OUString aProtectAttrValue
;
375 XMLTypedPropertiesOOoTContext_Impl
* pProtectContext
= nullptr;
377 /* Attribute <style:mirror> has to be priority over attribute <style:draw>.
378 The filter from OpenDocument file format to OpenOffice.org file format
379 produces styles with both attributes. (#i49139#)
381 bool bExistStyleMirror( false );
382 OUStringBuffer aStyleMirrorAttrValue
;
383 bool bExistDrawMirror( false );
384 OUString aDrawMirrorAttrValue
;
385 XMLTypedPropertiesOOoTContext_Impl
* pMirrorContext( nullptr );
387 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
388 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
390 const OUString sAttrName
= rAttrList
->getNameByIndex( i
);
391 const OUString sAttrValue
= rAttrList
->getValueByIndex( i
);
394 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
396 TransformerAction_Impl aAction
;
397 XMLTypedPropertiesOOoTContext_Impl
*pContext
=
398 GetPropContextAndAction( aAction
, nPrefix
, aLocalName
, false );
399 switch( aAction
.m_nActionType
)
401 case XML_ATACTION_REMOVE
:
403 case XML_ATACTION_COPY
:
404 pContext
->AddAttribute( sAttrName
, sAttrValue
);
406 case XML_ATACTION_COPY_DUPLICATE
:
408 pContext
->AddAttribute( sAttrName
, sAttrValue
);
409 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
410 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
412 pContext2
->AddAttribute( sAttrName
, sAttrValue
);
415 case XML_ATACTION_RENAME
:
417 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
418 aAction
.GetQNameTokenFromParam1(),
422 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
424 OUString
aAttrValue( sAttrValue
);
425 GetTransformer().EncodeStyleName(aAttrValue
);
426 pContext
->AddAttribute( sAttrName
, aAttrValue
);
429 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF
:
431 OUString
aAttrValue( sAttrValue
);
432 GetTransformer().EncodeStyleName(aAttrValue
);
433 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
434 aAction
.GetQNameTokenFromParam1(),
438 case XML_ATACTION_NEG_PERCENT
:
440 OUString
aAttrValue( sAttrValue
);
441 XMLTransformerBase::NegPercent(aAttrValue
);
442 pContext
->AddAttribute( sAttrName
, aAttrValue
);
445 case XML_ATACTION_RENAME_NEG_PERCENT
:
447 OUString
aAttrValue( sAttrValue
);
448 XMLTransformerBase::NegPercent(aAttrValue
);
449 pContext
->AddAttribute( aAction
.GetQNamePrefixFromParam1(),
450 aAction
.GetQNameTokenFromParam1(),
454 case XML_ATACTION_INCH2IN
:
456 OUString
aAttrValue( sAttrValue
);
457 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
458 pContext
->AddAttribute( sAttrName
, aAttrValue
);
461 case XML_ATACTION_INCH2IN_DUPLICATE
:
463 OUString
aAttrValue( sAttrValue
);
464 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
465 pContext
->AddAttribute( sAttrName
, aAttrValue
);
466 XMLTypedPropertiesOOoTContext_Impl
*pContext2
=
467 GetPropContext( static_cast<XMLPropType
>(aAction
.m_nParam1
) );
469 pContext2
->AddAttribute( sAttrName
, aAttrValue
);
472 case XML_ATACTION_INCHS2INS
:
474 OUString
aAttrValue( sAttrValue
);
475 XMLTransformerBase::ReplaceInchWithIn( aAttrValue
);
476 pContext
->AddAttribute( sAttrName
, aAttrValue
);
479 case XML_PTACTION_LINE_MODE
:
481 const OUString
& aAttrValue( GetXMLToken(
482 IsXMLToken( sAttrValue
, XML_TRUE
)
484 : XML_SKIP_WHITE_SPACE
) );
486 GetTransformer().GetNamespaceMap().GetQNameByKey(
488 GetXMLToken( XML_TEXT_UNDERLINE_MODE
) ) );
489 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
492 GetTransformer().GetNamespaceMap().GetQNameByKey(
494 GetXMLToken( XML_TEXT_LINE_THROUGH_MODE
) );
495 pContext
->AddAttribute( aAttrQName
, aAttrValue
);
498 case XML_PTACTION_KEEP_WITH_NEXT
:
500 const OUString
& aAttrValue( GetXMLToken(
501 IsXMLToken( sAttrValue
, XML_TRUE
)
504 pContext
->AddAttribute( sAttrName
, aAttrValue
);
507 case XML_PTACTION_UNDERLINE
:
509 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
510 bool bBold
= false, bDouble
= false;
524 case XML_BOLD_DOTTED
:
532 case XML_BOLD_LONG_DASH
:
533 eToken
= XML_LONG_DASH
;
536 case XML_BOLD_DOT_DASH
:
537 eToken
= XML_DOT_DASH
;
540 case XML_BOLD_DOT_DOT_DASH
:
541 eToken
= XML_DOT_DOT_DASH
;
548 case XML_DOUBLE_WAVE
:
557 OSL_FAIL( "xmloff::XMLPropertiesOOoTContext_Impl::StartElement(), unknown underline token!" );
560 pContext
->AddAttribute(
561 GetTransformer().GetNamespaceMap().GetQNameByKey(
563 GetXMLToken( XML_TEXT_UNDERLINE_STYLE
) ),
564 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
567 pContext
->AddAttribute(
568 GetTransformer().GetNamespaceMap().GetQNameByKey(
570 GetXMLToken( XML_TEXT_UNDERLINE_TYPE
) ),
571 GetXMLToken( XML_DOUBLE
) );
573 pContext
->AddAttribute(
574 GetTransformer().GetNamespaceMap().GetQNameByKey(
576 GetXMLToken( XML_TEXT_UNDERLINE_WIDTH
) ),
577 GetXMLToken( XML_BOLD
) );
580 case XML_PTACTION_LINETHROUGH
:
582 XMLTokenEnum eToken
= GetTransformer().GetToken( sAttrValue
);
583 bool bBold
= false, bDouble
= false;
587 case XML_SINGLE_LINE
:
590 case XML_DOUBLE_LINE
:
609 pContext
->AddAttribute(
610 GetTransformer().GetNamespaceMap().GetQNameByKey(
612 GetXMLToken( XML_TEXT_LINE_THROUGH_STYLE
) ),
613 eToken
!= XML_TOKEN_END
? GetXMLToken( eToken
)
616 pContext
->AddAttribute(
617 GetTransformer().GetNamespaceMap().GetQNameByKey(
619 GetXMLToken( XML_TEXT_LINE_THROUGH_TYPE
) ),
620 GetXMLToken( XML_DOUBLE
) );
622 pContext
->AddAttribute(
623 GetTransformer().GetNamespaceMap().GetQNameByKey(
625 GetXMLToken( XML_TEXT_LINE_THROUGH_WIDTH
) ),
626 GetXMLToken( XML_BOLD
) );
628 pContext
->AddAttribute(
629 GetTransformer().GetNamespaceMap().GetQNameByKey(
631 GetXMLToken( XML_TEXT_LINE_THROUGH_TEXT
) ),
635 case XML_PTACTION_SPLINES
:
637 sal_Int32 nSplineType
= sAttrValue
.toInt32();
638 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
639 XML_NAMESPACE_CHART
, GetXMLToken( XML_INTERPOLATION
) );
641 switch( nSplineType
)
645 pContext
->AddAttribute(
646 aNewAttrName
, GetXMLToken( XML_NONE
));
650 pContext
->AddAttribute(
651 aNewAttrName
, GetXMLToken( XML_CUBIC_SPLINE
));
655 pContext
->AddAttribute(
656 aNewAttrName
, GetXMLToken( XML_B_SPLINE
));
660 OSL_FAIL( "invalid spline type" );
661 pContext
->AddAttribute(
662 aNewAttrName
, GetXMLToken( XML_NONE
));
667 case XML_PTACTION_INTERVAL_MAJOR
:
668 pContext
->AddAttribute( sAttrName
, sAttrValue
);
669 ::sax::Converter::convertDouble( fIntervalMajor
, sAttrValue
);
671 case XML_PTACTION_INTERVAL_MINOR
:
672 ::sax::Converter::convertDouble( fIntervalMinor
, sAttrValue
);
673 pIntervalMinorDivisorContext
= pContext
;
675 case XML_PTACTION_SYMBOL
:
677 sal_Int32 nSymbolType
= sAttrValue
.toInt32();
678 OUString aNewAttrName
= GetTransformer().GetNamespaceMap().GetQNameByKey(
679 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_TYPE
) );
681 if( nSymbolType
>= 0 )
683 pContext
->AddAttribute( aNewAttrName
, GetXMLToken( XML_NAMED_SYMBOL
));
684 enum XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
685 switch( nSymbolType
)
689 // "square" has an awkward token name
690 eToken
= XML_GRADIENTSTYLE_SQUARE
;
694 eToken
= XML_DIAMOND
;
698 eToken
= XML_ARROW_DOWN
;
702 eToken
= XML_ARROW_UP
;
706 eToken
= XML_ARROW_RIGHT
;
710 eToken
= XML_ARROW_LEFT
;
714 eToken
= XML_BOW_TIE
;
718 eToken
= XML_HOURGLASS
;
733 eToken
= XML_ASTERISK
;
736 eToken
= XML_HORIZONTAL_BAR
;
739 eToken
= XML_VERTICAL_BAR
;
742 OSL_FAIL( "invalid named symbol" );
746 if( eToken
!= XML_TOKEN_INVALID
)
748 pContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
749 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_NAME
)),
750 GetXMLToken( eToken
));
755 switch( nSymbolType
)
759 pContext
->AddAttribute(
760 aNewAttrName
, GetXMLToken( XML_NONE
));
764 pContext
->AddAttribute(
765 aNewAttrName
, GetXMLToken( XML_AUTOMATIC
));
769 pContext
->AddAttribute(
770 aNewAttrName
, GetXMLToken( XML_IMAGE
));
773 OSL_FAIL( "invalid symbol type" );
774 pContext
->AddAttribute(
775 aNewAttrName
, GetXMLToken( XML_NONE
));
781 case XML_PTACTION_SYMBOL_IMAGE_NAME
:
783 // create an xlink:href element for URI attribute
784 XMLPersAttrListTContext
*pSymbolImageContext
= new XMLPersAttrListTContext(
785 GetTransformer(), GetTransformer().GetNamespaceMap().GetQNameByKey(
786 XML_NAMESPACE_CHART
, GetXMLToken( XML_SYMBOL_IMAGE
)));
787 rtl::Reference
<XMLTransformerContext
> xSymbolImageContext(pSymbolImageContext
);
789 OUString
aAttrValue( sAttrValue
);
790 if( GetTransformer().ConvertURIToOASIS( aAttrValue
, true ))
792 pSymbolImageContext
->AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aAttrValue
);
793 pContext
->AddContent(xSymbolImageContext
);
799 case XML_PTACTION_TRANSPARENCY
:
801 OUString
aAttrValue( sAttrValue
);
802 XMLTransformerBase::NegPercent(aAttrValue
);
803 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
806 pContext
->AddAttribute( XML_NAMESPACE_DRAW
,
812 case XML_PTACTION_BREAK_INSIDE
:
814 pContext
->AddAttribute(
815 XML_NAMESPACE_FO
, XML_KEEP_TOGETHER
,
817 IsXMLToken( sAttrValue
, XML_COLUMNSPLIT_AVOID
)
822 case XML_ATACTION_CAPTION_ESCAPE_OOO
:
824 OUString
aAttrValue( sAttrValue
);
825 if( aAttrValue
.indexOf( '%' ) != -1 )
827 sal_Int32 nValue
= 0;
828 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
833 ::sax::Converter::convertPercent( aOut
, nValue
);
834 aAttrValue
= aOut
.makeStringAndClear();
839 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue
);
842 pContext
->AddAttribute( sAttrName
, aAttrValue
);
845 case XML_ATACTION_MOVE_PROTECT
:
846 bMoveProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
847 pProtectContext
= pContext
;
849 case XML_ATACTION_SIZE_PROTECT
:
850 bSizeProtect
= IsXMLToken( sAttrValue
, XML_TRUE
);
851 pProtectContext
= pContext
;
853 case XML_ATACTION_PROTECT
:
854 aProtectAttrValue
= sAttrValue
;
855 pProtectContext
= pContext
;
857 case XML_ATACTION_DRAW_MIRROR_OOO
: // renames draw:mirror to style:mirror and adapts values
859 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
860 aDrawMirrorAttrValue
=
861 GetXMLToken( IsXMLToken( sAttrValue
, XML_TRUE
)
862 ? XML_HORIZONTAL
: XML_NONE
);
863 bExistDrawMirror
= true;
864 pMirrorContext
= pContext
;
867 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
868 case XML_ATACTION_STYLE_MIRROR_OOO
: // adapts style:mirror values
870 SvXMLTokenEnumerator
aTokenEnum( sAttrValue
);
872 while( aTokenEnum
.getNextToken( aToken
) )
874 if ( !aStyleMirrorAttrValue
.isEmpty() )
876 aStyleMirrorAttrValue
.append(" ");
879 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_LEFT_PAGES
) )
881 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_EVEN
));
883 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_RIGHT_PAGES
) )
885 aStyleMirrorAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_ODD
));
889 aStyleMirrorAttrValue
.append(aToken
);
892 bExistStyleMirror
= true;
893 pMirrorContext
= pContext
;
896 case XML_ATACTION_GAMMA_OOO
: // converts double value to percentage
898 double fValue
= sAttrValue
.toDouble();
899 sal_Int32 nValue
= static_cast<sal_Int32
>((fValue
* 100.0) + ( fValue
> 0 ? 0.5 : - 0.5 ) );
902 ::sax::Converter::convertPercent( aOut
, nValue
);
903 OUString
aAttrValue( aOut
.makeStringAndClear() );
904 pContext
->AddAttribute( sAttrName
, aAttrValue
);
907 case XML_ATACTION_OPACITY_FIX
:
910 if( sAttrValue
.indexOf( '%' ) != -1 )
912 ::sax::Converter::convertPercent( nValue
, sAttrValue
);
916 nValue
= sal_Int32( sAttrValue
.toDouble() * 100.0 );
918 nValue
= 100 - nValue
;
921 ::sax::Converter::convertPercent( aOut
, nValue
);
922 pContext
->AddAttribute( sAttrName
, aOut
.makeStringAndClear() );
926 OSL_ENSURE( false, "unknown action" );
931 // OpenDocument file format: attribute value of <style:mirror> wrong (#i49139#)
932 if ( bExistStyleMirror
)
934 pMirrorContext
->AddAttribute(
935 GetTransformer().GetNamespaceMap().GetQNameByKey(
936 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
937 aStyleMirrorAttrValue
.makeStringAndClear());
939 else if ( bExistDrawMirror
)
941 pMirrorContext
->AddAttribute(
942 GetTransformer().GetNamespaceMap().GetQNameByKey(
943 XML_NAMESPACE_STYLE
, GetXMLToken( XML_MIRROR
) ),
944 aDrawMirrorAttrValue
);
947 if (bMoveProtect
|| bSizeProtect
|| !aProtectAttrValue
.isEmpty())
949 if( (bMoveProtect
||bSizeProtect
) && IsXMLToken( aProtectAttrValue
, XML_NONE
) )
950 aProtectAttrValue
.clear();
952 const OUString
& rPosition
= GetXMLToken( XML_POSITION
);
953 if( bMoveProtect
&& -1 == aProtectAttrValue
.indexOf( rPosition
) )
955 if( !aProtectAttrValue
.isEmpty() )
956 aProtectAttrValue
+= " ";
957 aProtectAttrValue
+= rPosition
;
960 const OUString
& rSize
= GetXMLToken( XML_SIZE
);
961 if( bSizeProtect
&& -1 == aProtectAttrValue
.indexOf( rSize
) )
963 if( !aProtectAttrValue
.isEmpty() )
964 aProtectAttrValue
+= " ";
965 aProtectAttrValue
+= rSize
;
968 assert(pProtectContext
&& "coverity[var_deref_model] - pProtectContext should be assigned in a superset of the enclosing if condition entry logic");
969 pProtectContext
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_STYLE
, GetXMLToken( XML_PROTECT
) ), aProtectAttrValue
);
972 if( pIntervalMinorDivisorContext
)
974 if( fIntervalMinor
!= 0.0 )
976 sal_Int32 nIntervalMinorDivisor
= static_cast< sal_Int32
>(
977 ::rtl::math::round( fIntervalMajor
/ fIntervalMinor
));
979 pIntervalMinorDivisorContext
->AddAttribute(
980 GetTransformer().GetNamespaceMap().GetQNameByKey(
982 GetXMLToken( XML_INTERVAL_MINOR_DIVISOR
)),
983 OUString::number( nIntervalMinorDivisor
));
988 void XMLPropertiesOOoTContext_Impl::EndElement()
994 void XMLPropertiesOOoTContext_Impl::Characters( const OUString
& )
999 void XMLPropertiesOOoTContext_Impl::Export()
1002 for(rtl::Reference
<XMLTypedPropertiesOOoTContext_Impl
> & rPropContext
: m_aPropContexts
)
1004 if( rPropContext
.is() )
1005 rPropContext
->Export();
1009 bool XMLPropertiesOOoTContext_Impl::IsPersistent() const
1011 return m_bPersistent
;
1014 XMLStyleOOoTContext::XMLStyleOOoTContext( XMLTransformerBase
& rImp
,
1015 const OUString
& rQName
,
1017 bool bPersistent
) :
1018 XMLPersElemContentTContext( rImp
, rQName
),
1020 m_bPersistent( bPersistent
)
1024 XMLStyleOOoTContext::XMLStyleOOoTContext(
1025 XMLTransformerBase
& rImp
,
1026 const OUString
& rQName
,
1029 ::xmloff::token::XMLTokenEnum eToken
,
1030 bool bPersistent
) :
1031 XMLPersElemContentTContext( rImp
, rQName
, nPrefix
, eToken
),
1033 m_bPersistent( bPersistent
)
1037 XMLStyleOOoTContext::~XMLStyleOOoTContext()
1041 rtl::Reference
<XMLTransformerContext
> XMLStyleOOoTContext::CreateChildContext(
1043 const OUString
& rLocalName
,
1044 const OUString
& rQName
,
1045 const Reference
< XAttributeList
>& rAttrList
)
1047 rtl::Reference
<XMLTransformerContext
> pContext
;
1049 if( XML_NAMESPACE_STYLE
== nPrefix
&&
1050 IsXMLToken( rLocalName
, XML_PROPERTIES
) )
1052 if( aPropTypes
[m_eFamily
][0] == XML_PROP_TYPE_END
)
1054 OSL_ENSURE( false, "unexpected properties element" );
1055 pContext
= m_bPersistent
1056 ? XMLPersElemContentTContext::CreateChildContext(
1057 nPrefix
, rLocalName
, rQName
, rAttrList
)
1058 : XMLTransformerContext::CreateChildContext(
1059 nPrefix
, rLocalName
, rQName
, rAttrList
);
1061 else if( aPropTypes
[m_eFamily
][1] == XML_PROP_TYPE_END
)
1063 sal_uInt16 nActionMap
=
1064 aAttrActionMaps
[aPropTypes
[m_eFamily
][0]];
1065 if( nActionMap
< MAX_OOO_PROP_ACTIONS
)
1067 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1068 GetTransformer(), rQName
,
1069 aPropTypes
[m_eFamily
], m_bPersistent
));
1074 pContext
.set(new XMLPersElemContentTContext(
1075 GetTransformer(), rQName
,
1076 XML_NAMESPACE_STYLE
,
1077 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1079 pContext
.set(new XMLRenameElemTransformerContext(
1080 GetTransformer(), rQName
,
1081 XML_NAMESPACE_STYLE
,
1082 aPropTokens
[aPropTypes
[m_eFamily
][0]] ));
1087 pContext
.set(new XMLPropertiesOOoTContext_Impl(
1088 GetTransformer(), rQName
,
1089 aPropTypes
[m_eFamily
], m_bPersistent
));
1093 AddContent( pContext
);
1097 pContext
= m_bPersistent
1098 ? XMLPersElemContentTContext::CreateChildContext(
1099 nPrefix
, rLocalName
, rQName
, rAttrList
)
1100 : XMLTransformerContext::CreateChildContext(
1101 nPrefix
, rLocalName
, rQName
, rAttrList
);
1107 void XMLStyleOOoTContext::StartElement(
1108 const Reference
< XAttributeList
>& rAttrList
)
1110 XMLTransformerActions
*pActions
=
1111 GetTransformer().GetUserDefinedActions( OOO_STYLE_ACTIONS
);
1112 OSL_ENSURE( pActions
, "go no actions" );
1114 Reference
< XAttributeList
> xAttrList( rAttrList
);
1115 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
1116 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1117 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1119 const OUString sAttrName
= xAttrList
->getNameByIndex( i
);
1120 OUString aLocalName
;
1121 sal_uInt16 nPrefix
=
1122 GetTransformer().GetNamespaceMap().GetKeyByAttrName( sAttrName
,
1124 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
1125 XMLTransformerActions::const_iterator aIter
=
1126 pActions
->find( aKey
);
1127 if( aIter
!= pActions
->end() )
1129 if( !pMutableAttrList
)
1132 new XMLMutableAttributeList( xAttrList
);
1133 xAttrList
= pMutableAttrList
;
1135 const OUString sAttrValue
= xAttrList
->getValueByIndex( i
);
1136 switch( (*aIter
).second
.m_nActionType
)
1138 case XML_ATACTION_STYLE_FAMILY
:
1140 bool bControl
= false;
1141 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1143 if( IsXMLToken( sAttrValue
, XML_GRAPHICS
) )
1144 m_eFamily
= XML_FAMILY_TYPE_GRAPHIC
;
1145 else if( IsXMLToken( sAttrValue
, XML_PRESENTATION
) )
1146 m_eFamily
= XML_FAMILY_TYPE_PRESENTATION
;
1147 else if( IsXMLToken( sAttrValue
, XML_DRAWING_PAGE
) )
1148 m_eFamily
= XML_FAMILY_TYPE_DRAWING_PAGE
;
1149 else if( IsXMLToken( sAttrValue
, XML_TEXT
) )
1150 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1151 else if( IsXMLToken( sAttrValue
, XML_PARAGRAPH
) )
1152 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1153 else if( IsXMLToken( sAttrValue
, XML_RUBY
) )
1154 m_eFamily
= XML_FAMILY_TYPE_RUBY
;
1155 else if( IsXMLToken( sAttrValue
, XML_SECTION
) )
1156 m_eFamily
= XML_FAMILY_TYPE_SECTION
;
1157 else if( IsXMLToken( sAttrValue
, XML_TABLE
) )
1158 m_eFamily
= XML_FAMILY_TYPE_TABLE
;
1159 else if( IsXMLToken( sAttrValue
, XML_TABLE_COLUMN
) )
1160 m_eFamily
= XML_FAMILY_TYPE_TABLE_COLUMN
;
1161 else if( IsXMLToken( sAttrValue
, XML_TABLE_ROW
) )
1162 m_eFamily
= XML_FAMILY_TYPE_TABLE_ROW
;
1163 else if( IsXMLToken( sAttrValue
, XML_TABLE_CELL
) )
1164 m_eFamily
= XML_FAMILY_TYPE_TABLE_CELL
;
1165 else if( IsXMLToken( sAttrValue
, XML_CHART
) )
1166 m_eFamily
= XML_FAMILY_TYPE_CHART
;
1167 else if( IsXMLToken( sAttrValue
, XML_CONTROL
) )
1169 m_eFamily
= XML_FAMILY_TYPE_PARAGRAPH
;
1173 if( XML_FAMILY_TYPE_GRAPHIC
== m_eFamily
)
1175 pMutableAttrList
->SetValueByIndex( i
,
1176 GetXMLToken( XML_GRAPHIC
) );
1180 pMutableAttrList
->SetValueByIndex( i
,
1181 GetXMLToken( XML_PARAGRAPH
) );
1185 case XML_ATACTION_INCH2IN
:
1187 OUString
aAttrValue( sAttrValue
);
1188 if( XMLTransformerBase::ReplaceSingleInchWithIn(
1190 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1193 case XML_ATACTION_ENCODE_STYLE_NAME
:
1195 OUString
aAttrValue( sAttrValue
);
1196 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1198 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1199 OUString
aNewAttrQName(
1200 GetTransformer().GetNamespaceMap().
1202 nPrefix
, ::xmloff::token::GetXMLToken(
1203 XML_DISPLAY_NAME
) ) );
1204 pMutableAttrList
->AddAttribute( aNewAttrQName
,
1209 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
1211 OUString
aAttrValue( sAttrValue
);
1212 if( GetTransformer().EncodeStyleName(aAttrValue
) )
1213 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1216 case XML_ATACTION_NEG_PERCENT
:
1218 OUString
aAttrValue( sAttrValue
);
1219 if( XMLTransformerBase::NegPercent(aAttrValue
) )
1220 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1223 case XML_ATACTION_URI_OOO
:
1225 OUString
aAttrValue( sAttrValue
);
1226 if( GetTransformer().ConvertURIToOASIS( aAttrValue
,
1227 static_cast< bool >((*aIter
).second
.m_nParam1
)))
1228 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
1232 OSL_ENSURE( false, "unknown action" );
1237 if( XML_FAMILY_TYPE_END
== m_eFamily
)
1238 m_eFamily
= XML_FAMILY_TYPE_TEXT
;
1240 XMLPersElemContentTContext::StartElement( xAttrList
);
1242 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList
);
1245 void XMLStyleOOoTContext::EndElement()
1248 XMLPersElemContentTContext::EndElement();
1250 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
1253 void XMLStyleOOoTContext::Characters( const OUString
& )
1255 // element content only:
1258 bool XMLStyleOOoTContext::IsPersistent() const
1260 return m_bPersistent
;
1263 XMLTransformerActions
*XMLStyleOOoTContext::CreateTransformerActions(
1266 XMLTransformerActionInit
const *pInit
= nullptr;
1270 case PROP_OOO_GRAPHIC_ATTR_ACTIONS
:
1271 pInit
= aGraphicPropertyOOoAttrActionTable
;
1273 case PROP_OOO_GRAPHIC_ELEM_ACTIONS
:
1274 pInit
= aGraphicPropertyOOoElemActionTable
;
1276 case PROP_OOO_DRAWING_PAGE_ATTR_ACTIONS
:
1277 pInit
= aDrawingPagePropertyOOoAttrActionTable
;
1279 case PROP_OOO_PAGE_LAYOUT_ATTR_ACTIONS
:
1280 pInit
= aPageLayoutPropertyOOoAttrActionTable
;
1282 case PROP_OOO_HEADER_FOOTER_ATTR_ACTIONS
:
1283 pInit
= aHeaderFooterPropertyOOoAttrActionTable
;
1285 case PROP_OOO_TEXT_ATTR_ACTIONS
:
1286 pInit
= aTextPropertyOOoAttrActionTable
;
1288 case PROP_OOO_TEXT_ELEM_ACTIONS
:
1289 pInit
= aTextPropertyOOoElemActionTable
;
1291 case PROP_OOO_PARAGRAPH_ATTR_ACTIONS
:
1292 pInit
= aParagraphPropertyOOoAttrActionTable
;
1294 case PROP_OOO_PARAGRAPH_ELEM_ACTIONS
:
1295 pInit
= aParagraphPropertyOOoElemActionTable
;
1297 case PROP_OOO_SECTION_ATTR_ACTIONS
:
1298 pInit
= aSectionPropertyOOoAttrActionTable
;
1300 case PROP_OOO_TABLE_ATTR_ACTIONS
:
1301 pInit
= aTablePropertyOOoAttrActionTable
;
1303 case PROP_OOO_TABLE_COLUMN_ATTR_ACTIONS
:
1304 pInit
= aTableColumnPropertyOOoAttrActionTable
;
1306 case PROP_OOO_TABLE_ROW_ATTR_ACTIONS
:
1307 pInit
= aTableRowPropertyOOoAttrActionTable
;
1309 case PROP_OOO_TABLE_CELL_ATTR_ACTIONS
:
1310 pInit
= aTableCellPropertyOOoAttrActionTable
;
1312 case PROP_OOO_TABLE_CELL_ELEM_ACTIONS
:
1313 pInit
= aTableCellPropertyOOoElemActionTable
;
1315 case PROP_OOO_LIST_LEVEL_ATTR_ACTIONS
:
1316 pInit
= aListLevelPropertyOOoAttrActionTable
;
1318 case PROP_OOO_CHART_ATTR_ACTIONS
:
1319 pInit
= aChartPropertyOOoAttrActionTable
;
1321 case PROP_OOO_CHART_ELEM_ACTIONS
:
1322 pInit
= aChartPropertyOOoElemActionTable
;
1326 XMLTransformerActions
*pActions
= nullptr;
1328 pActions
= new XMLTransformerActions( pInit
);
1333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */