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>
23 #include <rtl/ustrbuf.hxx>
24 #include <osl/diagnose.h>
25 #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 "TransformerBase.hxx"
32 #include "TransformerActions.hxx"
33 #include "ActionMapTypesOASIS.hxx"
34 #include "MutableAttrList.hxx"
35 #include "PropertyActionsOASIS.hxx"
36 #include "StyleOASISTContext.hxx"
37 #include <xmloff/xmluconv.hxx>
39 using namespace ::xmloff::token
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::xml::sax
;
43 const sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
45 PROP_OASIS_GRAPHIC_ATTR_ACTIONS
,
46 PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
47 PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
,
48 PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
,
49 PROP_OASIS_TEXT_ATTR_ACTIONS
,
50 PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
,
51 MAX_OASIS_PROP_ACTIONS
, // RUBY
52 PROP_OASIS_SECTION_ATTR_ACTIONS
,
53 PROP_OASIS_TABLE_ATTR_ACTIONS
,
54 PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
,
55 PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
,
56 PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
,
57 PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
,
58 PROP_OASIS_CHART_ATTR_ACTIONS
61 class XMLPropertiesTContext_Impl
: public XMLPersElemContentTContext
63 css::uno::Reference
< css::xml::sax::XAttributeList
> m_xAttrList
;
65 XMLPropType m_ePropType
;
66 bool const m_bControlStyle
;
70 void SetQNameAndPropType( const OUString
& rQName
,
71 XMLPropType ePropType
)
73 m_ePropType
= ePropType
;
74 XMLTransformerContext::SetQName( rQName
);
77 XMLPropertiesTContext_Impl( XMLTransformerBase
& rTransformer
,
78 const OUString
& rQName
,
80 bool _bControlStyle
);
82 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
84 virtual void Export() override
;
86 static XMLPropType
GetPropType( const OUString
& rLocalName
);
88 static OUString
const & MergeUnderline( XMLTokenEnum eUnderline
,
89 bool bBold
, bool bDouble
);
90 static OUString
const & MergeLineThrough( XMLTokenEnum eLineThrough
,
91 bool bBold
, bool bDouble
,
95 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
96 XMLTransformerBase
& rImp
, const OUString
& rQName
, XMLPropType eP
,
97 bool _bControlStyle
) :
98 XMLPersElemContentTContext( rImp
, rQName
, XML_NAMESPACE_STYLE
,
101 m_bControlStyle( _bControlStyle
)
105 void XMLPropertiesTContext_Impl::StartElement(
106 const Reference
< XAttributeList
>& rAttrList
)
108 XMLTransformerActions
*pActions
= nullptr;
109 sal_uInt16 nActionMap
= aAttrActionMaps
[m_ePropType
];
110 if( nActionMap
< MAX_OASIS_PROP_ACTIONS
)
112 pActions
= GetTransformer().GetUserDefinedActions( nActionMap
);
113 OSL_ENSURE( pActions
, "go no actions" );
118 XMLMutableAttributeList
*pAttrList
= nullptr;
119 if( !m_xAttrList
.is() )
121 pAttrList
= new XMLMutableAttributeList();
122 m_xAttrList
= pAttrList
;
127 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
130 XMLTokenEnum eUnderline
= XML_TOKEN_END
;
131 bool bBoldUnderline
= false, bDoubleUnderline
= false;
132 XMLTokenEnum eLineThrough
= XML_TOKEN_END
;
133 bool bBoldLineThrough
= false, bDoubleLineThrough
= false;
134 sal_Unicode cLineThroughChar
= 0;
136 bool bIntervalMinorFound
= false;
137 double fIntervalMajor
= 0.0;
138 sal_Int32 nIntervalMinorDivisor
= 0;
141 OUString aOpacityValueRemember
;
142 OUString aImageOpacityValueRemember
;
144 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
145 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
147 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
148 const OUString
& rAttrValue
= rAttrList
->getValueByIndex( i
);
151 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
154 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
155 XMLTransformerActions::const_iterator aIter
=
156 pActions
->find( aKey
);
157 if( aIter
!= pActions
->end() )
159 switch( (*aIter
).second
.m_nActionType
)
161 case XML_ATACTION_REMOVE
:
163 case XML_ATACTION_COPY
:
164 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
166 case XML_ATACTION_RENAME
:
168 OUString
aNewAttrQName(
169 GetTransformer().GetNamespaceMap().GetQNameByKey(
170 (*aIter
).second
.GetQNamePrefixFromParam1(),
171 ::xmloff::token::GetXMLToken(
172 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
173 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
176 case XML_ATACTION_IN2INCH
:
178 OUString
aAttrValue( rAttrValue
);
179 XMLTransformerBase::ReplaceSingleInWithInch(
181 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
184 case XML_ATACTION_INS2INCHS
:
186 OUString
aAttrValue( rAttrValue
);
187 XMLTransformerBase::ReplaceInWithInch(
189 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
192 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
194 OUString
aAttrValue( rAttrValue
);
195 XMLTransformerBase::DecodeStyleName(aAttrValue
);
196 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
199 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF
:
201 OUString
aNewAttrQName(
202 GetTransformer().GetNamespaceMap().GetQNameByKey(
203 (*aIter
).second
.GetQNamePrefixFromParam1(),
204 ::xmloff::token::GetXMLToken(
205 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
206 OUString
aAttrValue( rAttrValue
);
207 XMLTransformerBase::DecodeStyleName(aAttrValue
);
208 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
211 case XML_ATACTION_NEG_PERCENT
:
213 OUString
aAttrValue( rAttrValue
);
214 XMLTransformerBase::NegPercent(aAttrValue
);
215 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
218 case XML_ATACTION_RENAME_NEG_PERCENT
:
220 OUString
aNewAttrQName(
221 GetTransformer().GetNamespaceMap().GetQNameByKey(
222 (*aIter
).second
.GetQNamePrefixFromParam1(),
223 ::xmloff::token::GetXMLToken(
224 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
225 OUString
aAttrValue( rAttrValue
);
226 XMLTransformerBase::NegPercent(aAttrValue
);
227 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
230 case XML_OPTACTION_LINE_MODE
:
233 IsXMLToken( rAttrValue
, XML_SKIP_WHITE_SPACE
);
235 GetTransformer().GetNamespaceMap().GetQNameByKey(
237 GetXMLToken( XML_SCORE_SPACES
) ) );
239 pAttrList
->GetIndexByName( aAttrQName
);
244 const OUString
& rOldValue
=
245 pAttrList
->getValueByIndex( nIndex
);
246 if( !IsXMLToken( rOldValue
, XML_TRUE
) )
248 pAttrList
->SetValueByIndex( nIndex
,
249 GetXMLToken( XML_TRUE
) );
255 const OUString
& aAttrValue( GetXMLToken( bWordMode
258 pAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
262 case XML_OPTACTION_KEEP_WITH_NEXT
:
264 const OUString
& aAttrValue( GetXMLToken(
265 IsXMLToken( rAttrValue
, XML_ALWAYS
)
268 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
271 case XML_OPTACTION_UNDERLINE_WIDTH
:
272 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
273 bBoldUnderline
= true;
275 case XML_OPTACTION_UNDERLINE_TYPE
:
276 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
277 bDoubleUnderline
= true;
279 case XML_OPTACTION_UNDERLINE_STYLE
:
280 eUnderline
= GetTransformer().GetToken( rAttrValue
);
282 case XML_OPTACTION_LINETHROUGH_WIDTH
:
283 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
284 bBoldLineThrough
= true;
286 case XML_OPTACTION_LINETHROUGH_TYPE
:
287 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
288 bDoubleLineThrough
= true;
290 case XML_OPTACTION_LINETHROUGH_STYLE
:
291 eLineThrough
= GetTransformer().GetToken( rAttrValue
);
293 case XML_OPTACTION_LINETHROUGH_TEXT
:
294 if( !rAttrValue
.isEmpty() )
295 cLineThroughChar
= rAttrValue
[0];
297 case XML_OPTACTION_INTERPOLATION
:
300 sal_Int32 nSplineType
= 0;
301 if( IsXMLToken( rAttrValue
, XML_CUBIC_SPLINE
))
303 else if( IsXMLToken( rAttrValue
, XML_B_SPLINE
))
306 pAttrList
->AddAttribute(
307 GetTransformer().GetNamespaceMap().GetQNameByKey(
309 GetXMLToken( XML_SPLINES
)),
310 OUString::number( nSplineType
));
313 case XML_OPTACTION_INTERVAL_MAJOR
:
314 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
315 ::sax::Converter::convertDouble(fIntervalMajor
, rAttrValue
);
317 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR
:
318 ::sax::Converter::convertNumber(nIntervalMinorDivisor
, rAttrValue
);
319 bIntervalMinorFound
= true;
321 case XML_OPTACTION_SYMBOL_TYPE
:
323 // if symbol_type is "named-symbol" the "symbol"
324 // property is set in the action XML_OPTACTION_SYMBOL_NAME
325 sal_Int32 nSymbolType
= 0;
326 if( IsXMLToken( rAttrValue
, XML_NONE
))
328 else if( IsXMLToken( rAttrValue
, XML_AUTOMATIC
))
330 else if( IsXMLToken( rAttrValue
, XML_IMAGE
))
333 if( nSymbolType
< 0 )
334 pAttrList
->AddAttribute(
335 GetTransformer().GetNamespaceMap().GetQNameByKey(
337 GetXMLToken( XML_SYMBOL
)),
338 OUString::number( nSymbolType
));
341 case XML_OPTACTION_SYMBOL_NAME
:
343 // assume "symbol-type" == "named-symbol"
344 sal_Int32 nSymbolType
= -3; // NONE
345 // "square" just has an awkward token-name
346 if( IsXMLToken( rAttrValue
, XML_GRADIENTSTYLE_SQUARE
))
348 else if( IsXMLToken( rAttrValue
, XML_DIAMOND
))
350 else if( IsXMLToken( rAttrValue
, XML_ARROW_DOWN
))
352 else if( IsXMLToken( rAttrValue
, XML_ARROW_UP
))
354 else if( IsXMLToken( rAttrValue
, XML_ARROW_RIGHT
))
356 else if( IsXMLToken( rAttrValue
, XML_ARROW_LEFT
))
358 else if( IsXMLToken( rAttrValue
, XML_BOW_TIE
))
360 else if( IsXMLToken( rAttrValue
, XML_HOURGLASS
))
362 else if( IsXMLToken( rAttrValue
, XML_CIRCLE
))
364 else if( IsXMLToken( rAttrValue
, XML_STAR
))
366 else if( IsXMLToken( rAttrValue
, XML_X
))
368 else if( IsXMLToken( rAttrValue
, XML_PLUS
))
370 else if( IsXMLToken( rAttrValue
, XML_ASTERISK
))
372 else if( IsXMLToken( rAttrValue
, XML_HORIZONTAL_BAR
))
374 else if( IsXMLToken( rAttrValue
, XML_VERTICAL_BAR
))
377 if( nSymbolType
>= 0 )
378 pAttrList
->AddAttribute(
379 GetTransformer().GetNamespaceMap().GetQNameByKey(
381 GetXMLToken( XML_SYMBOL
)),
382 OUString::number( nSymbolType
));
386 case XML_OPTACTION_OPACITY
:
387 aOpacityValueRemember
= rAttrValue
;
388 XMLTransformerBase::NegPercent(aOpacityValueRemember
);
392 case XML_OPTACTION_IMAGE_OPACITY
:
393 aImageOpacityValueRemember
= rAttrValue
;
394 XMLTransformerBase::NegPercent(aImageOpacityValueRemember
);
397 case XML_OPTACTION_KEEP_TOGETHER
:
398 pAttrList
->AddAttribute(
399 GetTransformer().GetNamespaceMap().GetQNameByKey(
400 XML_NAMESPACE_STYLE
,GetXMLToken(XML_BREAK_INSIDE
)),
402 IsXMLToken( rAttrValue
, XML_ALWAYS
)
403 ? XML_COLUMNSPLIT_AVOID
407 case XML_OPTACTION_CONTROL_TEXT_ALIGN
:
408 if ( m_bControlStyle
)
410 OUString
aNewAttrQName(
411 GetTransformer().GetNamespaceMap().GetQNameByKey(
413 ::xmloff::token::GetXMLToken(
414 XML_TEXT_ALIGN
) ) );
415 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
419 OUString
aNewAttrQName(
420 GetTransformer().GetNamespaceMap().GetQNameByKey(
422 ::xmloff::token::GetXMLToken(
423 XML_TEXT_ALIGN
) ) );
424 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
428 case XML_ATACTION_CAPTION_ESCAPE_OASIS
:
430 OUString
aAttrValue( rAttrValue
);
431 if( aAttrValue
.indexOf( '%' ) != -1 )
433 sal_Int32 nValue
= 0;
434 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
439 ::sax::Converter::convertPercent(aOut
, nValue
);
440 aAttrValue
= aOut
.makeStringAndClear();
445 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue
);
448 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
452 case XML_ATACTION_DECODE_PROTECT
:
454 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
456 if( rAttrValue
.indexOf( GetXMLToken( XML_SIZE
) ) != -1 )
457 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
459 GetXMLToken( XML_SIZE_PROTECT
)), GetXMLToken( XML_TRUE
) );
461 if( rAttrValue
.indexOf( GetXMLToken( XML_POSITION
) ) != -1 )
462 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
464 GetXMLToken( XML_MOVE_PROTECT
)), GetXMLToken( XML_TRUE
) );
468 case XML_ATACTION_DRAW_MIRROR_OASIS
: // renames style:mirror to draw:mirror and adapts values
470 // keep original for writer graphic objects
471 // Adapts attribute values (#i49139#)
472 OUStringBuffer aNewAttrValue
;
473 SvXMLTokenEnumerator
aTokenEnum( rAttrValue
);
475 while( aTokenEnum
.getNextToken( aToken
) )
477 if ( !aNewAttrValue
.isEmpty() )
479 aNewAttrValue
.append(" ");
482 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_EVEN
) )
484 aNewAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES
));
486 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_ODD
) )
488 aNewAttrValue
.append(GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES
));
492 aNewAttrValue
.append(aToken
);
495 pAttrList
->AddAttribute( rAttrName
, aNewAttrValue
.makeStringAndClear() );
497 // create old draw:mirror for drawing graphic objects
498 const OUString
& aAttrValue( GetXMLToken( IsXMLToken( rAttrValue
, XML_HORIZONTAL
) ? XML_TRUE
: XML_FALSE
) );
499 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
501 GetXMLToken( XML_MIRROR
)), aAttrValue
);
504 case XML_ATACTION_GAMMA_OASIS
: // converts percentage value to double
507 ::sax::Converter::convertPercent( nValue
, rAttrValue
);
508 const double fValue
= static_cast<double>(nValue
) / 100.0;
509 pAttrList
->AddAttribute( rAttrName
, OUString::number( fValue
) );
512 case XML_ATACTION_OPACITY_FIX
:
515 if( rAttrValue
.indexOf( '%' ) != -1 )
517 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
521 nValue
= sal_Int32( rAttrValue
.toDouble() * 100.0 );
523 nValue
= 100 - nValue
;
526 ::sax::Converter::convertPercent(aOut
, nValue
);
527 pAttrList
->AddAttribute( rAttrName
, aOut
.makeStringAndClear() );
531 OSL_ENSURE( false, "unknown action" );
537 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
540 if( XML_TOKEN_END
!= eUnderline
)
541 pAttrList
->AddAttribute(
542 GetTransformer().GetNamespaceMap().GetQNameByKey(
544 GetXMLToken( XML_TEXT_UNDERLINE
) ),
545 MergeUnderline( eUnderline
, bBoldUnderline
,
546 bDoubleUnderline
) );
547 if( XML_TOKEN_END
!= eLineThrough
)
548 pAttrList
->AddAttribute(
549 GetTransformer().GetNamespaceMap().GetQNameByKey(
551 GetXMLToken( XML_TEXT_CROSSING_OUT
) ),
552 MergeLineThrough( eLineThrough
, bBoldLineThrough
,
553 bDoubleLineThrough
, cLineThroughChar
) );
554 if( bIntervalMinorFound
)
556 double fIntervalMinor
= 0.0;
557 if( nIntervalMinorDivisor
!= 0)
558 fIntervalMinor
= fIntervalMajor
/ static_cast< double >( nIntervalMinorDivisor
);
561 ::sax::Converter::convertDouble( aBuf
, fIntervalMinor
);
562 pAttrList
->AddAttribute(
563 GetTransformer().GetNamespaceMap().GetQNameByKey(
565 GetXMLToken( XML_INTERVAL_MINOR
)),
566 aBuf
.makeStringAndClear());
570 if(!aOpacityValueRemember
.isEmpty() || !aImageOpacityValueRemember
.isEmpty())
572 pAttrList
->AddAttribute(
573 GetTransformer().GetNamespaceMap().GetQNameByKey(
575 GetXMLToken( XML_TRANSPARENCY
) ),
576 !aImageOpacityValueRemember
.isEmpty()
577 ? aImageOpacityValueRemember
: aOpacityValueRemember
);
582 if( !m_xAttrList
.is() )
584 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, true );
588 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
589 ->AppendAttributeList( rAttrList
);
594 void XMLPropertiesTContext_Impl::Export()
596 GetTransformer().GetDocHandler()->startElement( GetExportQName(), m_xAttrList
);
598 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
601 XMLPropType
XMLPropertiesTContext_Impl::GetPropType( const OUString
& rLocalName
)
603 XMLPropType eProp
= XML_PROP_TYPE_END
;
604 if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
605 eProp
= XML_PROP_TYPE_GRAPHIC
;
606 else if( IsXMLToken( rLocalName
, XML_DRAWING_PAGE_PROPERTIES
) )
607 eProp
= XML_PROP_TYPE_DRAWING_PAGE
;
608 else if( IsXMLToken( rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
609 eProp
= XML_PROP_TYPE_PAGE_LAYOUT
;
610 else if( IsXMLToken( rLocalName
, XML_HEADER_FOOTER_PROPERTIES
) )
611 eProp
= XML_PROP_TYPE_HEADER_FOOTER
;
612 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
613 eProp
= XML_PROP_TYPE_TEXT
;
614 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
615 eProp
= XML_PROP_TYPE_PARAGRAPH
;
616 else if( IsXMLToken( rLocalName
, XML_RUBY_PROPERTIES
) )
617 eProp
= XML_PROP_TYPE_RUBY
;
618 else if( IsXMLToken( rLocalName
, XML_SECTION_PROPERTIES
) )
619 eProp
= XML_PROP_TYPE_SECTION
;
620 else if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) )
621 eProp
= XML_PROP_TYPE_TABLE
;
622 else if( IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) )
623 eProp
= XML_PROP_TYPE_TABLE_COLUMN
;
624 else if( IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) )
625 eProp
= XML_PROP_TYPE_TABLE_ROW
;
626 else if( IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
627 eProp
= XML_PROP_TYPE_TABLE_CELL
;
628 else if( IsXMLToken( rLocalName
, XML_LIST_LEVEL_PROPERTIES
) )
629 eProp
= XML_PROP_TYPE_LIST_LEVEL
;
630 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
631 eProp
= XML_PROP_TYPE_CHART
;
636 OUString
const & XMLPropertiesTContext_Impl::MergeUnderline(
637 XMLTokenEnum eUnderline
, bool bBold
, bool bDouble
)
644 eUnderline
= XML_DOUBLE_WAVE
;
647 eUnderline
= XML_DOUBLE
;
657 eUnderline
= XML_BOLD
;
660 eUnderline
= XML_BOLD_DOTTED
;
663 eUnderline
= XML_BOLD_DASH
;
666 eUnderline
= XML_BOLD_LONG_DASH
;
669 eUnderline
= XML_BOLD_DOT_DASH
;
671 case XML_DOT_DOT_DASH
:
672 eUnderline
= XML_BOLD_DOT_DOT_DASH
;
675 eUnderline
= XML_BOLD_WAVE
;
678 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
687 eUnderline
= XML_SINGLE
;
690 eUnderline
= XML_NONE
;
693 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
698 return GetXMLToken( eUnderline
);
701 OUString
const & XMLPropertiesTContext_Impl::MergeLineThrough(
702 XMLTokenEnum eLineThrough
, bool bBold
, bool bDouble
,
706 eLineThrough
= c
=='/' ? XML_SLASH
: XML_uX
;
708 eLineThrough
= XML_DOUBLE_LINE
;
710 eLineThrough
= XML_THICK_LINE
;
711 else if( XML_NONE
!= eLineThrough
)
712 eLineThrough
= XML_SINGLE_LINE
;
714 return GetXMLToken( eLineThrough
);
717 XMLStyleOASISTContext::XMLStyleOASISTContext(XMLTransformerBase
& rImp
,
718 const OUString
& rQName
, bool bPersistent
)
719 : XMLPersElemContentTContext(rImp
, rQName
)
720 , m_bPersistent(bPersistent
)
721 , m_bControlStyle(false)
725 XMLStyleOASISTContext::XMLStyleOASISTContext(
726 XMLTransformerBase
& rImp
, const OUString
& rQName
,
727 sal_uInt16 nPrefix
, ::xmloff::token::XMLTokenEnum eToken
,
729 : XMLPersElemContentTContext(rImp
, rQName
, nPrefix
, eToken
)
730 , m_bPersistent(bPersistent
)
731 , m_bControlStyle(false)
735 XMLStyleOASISTContext::~XMLStyleOASISTContext()
739 rtl::Reference
<XMLTransformerContext
> XMLStyleOASISTContext::CreateChildContext(
741 const OUString
& rLocalName
,
742 const OUString
& rQName
,
743 const Reference
< XAttributeList
>& rAttrList
)
745 rtl::Reference
<XMLTransformerContext
> pContext
;
747 if( XML_NAMESPACE_STYLE
== nPrefix
|| XML_NAMESPACE_LO_EXT
== nPrefix
)
749 XMLPropType ePropType
=
750 XMLPropertiesTContext_Impl::GetPropType( rLocalName
);
751 if( XML_PROP_TYPE_END
!= ePropType
)
753 // if no properties context exist start a new one.
754 if( !m_xPropContext
.is() )
755 m_xPropContext
= new XMLPropertiesTContext_Impl(
756 GetTransformer(), rQName
, ePropType
, m_bControlStyle
);
758 m_xPropContext
->SetQNameAndPropType( rQName
, ePropType
);
759 pContext
.set(m_xPropContext
.get());
764 // if a properties context exist close it
765 if( m_xPropContext
.is() && !m_bPersistent
)
767 m_xPropContext
->Export();
768 m_xPropContext
= nullptr;
771 pContext
= m_bPersistent
772 ? XMLPersElemContentTContext::CreateChildContext(
773 nPrefix
, rLocalName
, rQName
, rAttrList
)
774 : XMLTransformerContext::CreateChildContext(
775 nPrefix
, rLocalName
, rQName
, rAttrList
);
781 void XMLStyleOASISTContext::StartElement(
782 const Reference
< XAttributeList
>& rAttrList
)
784 XMLTransformerActions
*pActions
=
785 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS
);
786 OSL_ENSURE( pActions
, "go no actions" );
788 Reference
< XAttributeList
> xAttrList( rAttrList
);
789 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
790 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
791 sal_Int16 nFamilyAttr
= -1;
792 m_bControlStyle
= false;
794 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
796 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
799 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
801 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
802 XMLTransformerActions::const_iterator aIter
=
803 pActions
->find( aKey
);
804 if( aIter
!= pActions
->end() )
806 if( !pMutableAttrList
)
809 new XMLMutableAttributeList( xAttrList
);
810 xAttrList
= pMutableAttrList
;
812 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
813 switch( (*aIter
).second
.m_nActionType
)
815 case XML_ATACTION_STYLE_FAMILY
:
816 if( IsXMLToken( rAttrValue
, XML_GRAPHIC
) )
818 pMutableAttrList
->SetValueByIndex(
819 i
, GetXMLToken(XML_GRAPHICS
) );
823 if( IsXMLToken( rAttrValue
, XML_PARAGRAPH
) )
828 case XML_ATACTION_STYLE_DISPLAY_NAME
:
829 case XML_ATACTION_REMOVE
:
830 pMutableAttrList
->RemoveAttributeByIndex( i
);
834 case XML_ATACTION_DECODE_STYLE_NAME
:
835 m_bControlStyle
= rAttrValue
.startsWith( "ctrl" );
837 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
839 OUString
aAttrValue( rAttrValue
);
840 if( XMLTransformerBase::DecodeStyleName(aAttrValue
) )
841 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
844 case XML_ATACTION_IN2INCH
:
846 OUString
aAttrValue( rAttrValue
);
847 if( XMLTransformerBase::ReplaceSingleInWithInch(
849 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
852 case XML_ATACTION_NEG_PERCENT
:
854 OUString
aAttrValue( rAttrValue
);
855 if( XMLTransformerBase::NegPercent(aAttrValue
) )
856 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
859 case XML_ATACTION_URI_OASIS
:
861 OUString
aAttrValue( rAttrValue
);
862 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
863 static_cast< bool >((*aIter
).second
.m_nParam1
)))
864 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
868 OSL_ENSURE( false, "unknown action" );
874 if( m_bControlStyle
&& nFamilyAttr
!= -1 )
875 pMutableAttrList
->SetValueByIndex( nFamilyAttr
, GetXMLToken( XML_CONTROL
) );
878 XMLPersElemContentTContext::StartElement( xAttrList
);
880 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList
);
883 void XMLStyleOASISTContext::EndElement()
887 XMLPersElemContentTContext::EndElement();
891 // if a properties context exist close it
892 if( m_xPropContext
.is() )
894 m_xPropContext
->Export();
895 m_xPropContext
= nullptr;
897 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
901 void XMLStyleOASISTContext::Characters( const OUString
& )
903 // element content only:
906 void XMLStyleOASISTContext::ExportContent()
908 if( m_xPropContext
.is() )
909 m_xPropContext
->Export();
910 XMLPersElemContentTContext::ExportContent();
913 bool XMLStyleOASISTContext::IsPersistent() const
915 return m_bPersistent
;
918 XMLTransformerActions
*XMLStyleOASISTContext::CreateTransformerActions(
921 XMLTransformerActionInit
const *pInit
= nullptr;
925 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS
:
926 pInit
= aGraphicPropertyOASISAttrActionTable
;
928 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
:
929 pInit
= aDrawingPagePropertyOASISAttrActionTable
;
931 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
:
932 pInit
= aPageLayoutPropertyOASISAttrActionTable
;
934 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
:
935 pInit
= aHeaderFooterPropertyOASISAttrActionTable
;
937 case PROP_OASIS_TEXT_ATTR_ACTIONS
:
938 pInit
= aTextPropertyOASISAttrActionTable
;
940 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
:
941 pInit
= aParagraphPropertyOASISAttrActionTable
;
943 case PROP_OASIS_SECTION_ATTR_ACTIONS
:
944 pInit
= aSectionPropertyOASISAttrActionTable
;
946 case PROP_OASIS_TABLE_ATTR_ACTIONS
:
947 pInit
= aTablePropertyOASISAttrActionTable
;
949 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
:
950 pInit
= aTableColumnPropertyOASISAttrActionTable
;
952 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
:
953 pInit
= aTableRowPropertyOASISAttrActionTable
;
955 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
:
956 pInit
= aTableCellPropertyOASISAttrActionTable
;
958 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
:
959 pInit
= aListLevelPropertyOASISAttrActionTable
;
961 case PROP_OASIS_CHART_ATTR_ACTIONS
:
962 pInit
= aChartPropertyOASISAttrActionTable
;
966 XMLTransformerActions
*pActions
= nullptr;
968 pActions
= new XMLTransformerActions( pInit
);
973 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */