Update ooo320-m1
[ooovba.git] / xmloff / source / transform / StyleOASISTContext.cxx
blob2dd8552b989e1f8973a607166824f0e5ed297095
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StyleOASISTContext.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/xml/sax/SAXParseException.hpp>
34 #include <com/sun/star/xml/sax/SAXException.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <rtl/ustrbuf.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include "xmlnmspe.hxx"
41 #include "PropType.hxx"
42 #include "DeepTContext.hxx"
43 #include "ProcAttrTContext.hxx"
44 #ifndef _XMLOFF_TRANSFOERMERBASE_HXX
45 #include "TransformerBase.hxx"
46 #endif
47 #include "TransformerActions.hxx"
48 #include "ActionMapTypesOASIS.hxx"
49 #include "MutableAttrList.hxx"
50 #include "PropertyActionsOASIS.hxx"
51 #include "StyleOASISTContext.hxx"
52 #include <xmloff/xmluconv.hxx>
53 #include <rtl/ustrbuf.hxx>
55 using ::rtl::OUString;
56 using namespace ::xmloff::token;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::xml::sax;
59 //------------------------------------------------------------------------------
61 static sal_uInt16 aAttrActionMaps[XML_PROP_TYPE_END] =
63 PROP_OASIS_GRAPHIC_ATTR_ACTIONS,
64 PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS, // DRAWING_PAGE
65 PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS,
66 PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS,
67 PROP_OASIS_TEXT_ATTR_ACTIONS,
68 PROP_OASIS_PARAGRAPH_ATTR_ACTIONS,
69 MAX_OASIS_PROP_ACTIONS, // RUBY
70 PROP_OASIS_SECTION_ATTR_ACTIONS,
71 PROP_OASIS_TABLE_ATTR_ACTIONS,
72 PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS,
73 PROP_OASIS_TABLE_ROW_ATTR_ACTIONS,
74 PROP_OASIS_TABLE_CELL_ATTR_ACTIONS,
75 PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS,
76 PROP_OASIS_CHART_ATTR_ACTIONS
79 //------------------------------------------------------------------------------
81 class XMLPropertiesTContext_Impl : public XMLPersElemContentTContext
83 ::com::sun::star::uno::Reference<
84 ::com::sun::star::xml::sax::XAttributeList > m_xAttrList;
86 XMLPropType m_ePropType;
87 sal_Bool m_bControlStyle;
88 ::rtl::OUString m_aStyleFamily;
90 public:
92 void SetQNameAndPropType( const ::rtl::OUString& rQName,
93 XMLPropType ePropType )
95 m_ePropType = ePropType;
96 XMLTransformerContext::SetQName( rQName );
99 TYPEINFO();
101 XMLPropertiesTContext_Impl( XMLTransformerBase& rTransformer,
102 const ::rtl::OUString& rQName,
103 XMLPropType eP,
104 const ::rtl::OUString& rStyleFamily,
105 sal_Bool _bControlStyle = sal_False );
107 virtual ~XMLPropertiesTContext_Impl();
109 virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
111 virtual void Export();
113 static XMLPropType GetPropType( const OUString& rLocalName );
115 static OUString MergeUnderline( XMLTokenEnum eUnderline,
116 sal_Bool bBold, sal_Bool bDouble );
117 static OUString MergeLineThrough( XMLTokenEnum eLineThrough,
118 sal_Bool bBold, sal_Bool bDouble,
119 sal_Unicode c );
122 TYPEINIT1( XMLPropertiesTContext_Impl, XMLPersElemContentTContext );
124 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
125 XMLTransformerBase& rImp, const OUString& rQName, XMLPropType eP,
126 const ::rtl::OUString& rStyleFamily, sal_Bool _bControlStyle ) :
127 XMLPersElemContentTContext( rImp, rQName, XML_NAMESPACE_STYLE,
128 XML_PROPERTIES),
129 m_ePropType( eP ),
130 m_bControlStyle( _bControlStyle ),
131 m_aStyleFamily( rStyleFamily )
135 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
139 void XMLPropertiesTContext_Impl::StartElement(
140 const Reference< XAttributeList >& rAttrList )
142 XMLTransformerActions *pActions = 0;
143 sal_uInt16 nActionMap = aAttrActionMaps[m_ePropType];
144 if( nActionMap < MAX_OASIS_PROP_ACTIONS )
146 pActions = GetTransformer().GetUserDefinedActions( nActionMap );
147 OSL_ENSURE( pActions, "go no actions" );
150 if( pActions )
152 XMLMutableAttributeList *pAttrList = 0;
153 if( !m_xAttrList.is() )
155 pAttrList = new XMLMutableAttributeList();
156 m_xAttrList = pAttrList;
158 else
160 pAttrList =
161 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
164 XMLTokenEnum eUnderline = XML_TOKEN_END;
165 sal_Bool bBoldUnderline = sal_False, bDoubleUnderline = sal_False;
166 XMLTokenEnum eLineThrough = XML_TOKEN_END;
167 sal_Bool bBoldLineThrough = sal_False, bDoubleLineThrough = sal_False;
168 sal_Unicode cLineThroughChar = 0;
170 bool bIntervalMinorFound = false;
171 double fIntervalMajor = 0.0;
172 sal_Int32 nIntervalMinorDivisor = 0;
174 // #i25616#
175 OUString aOpacityValueRemember;
176 OUString aImageOpacityValueRemember;
178 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
179 for( sal_Int16 i=0; i < nAttrCount; i++ )
181 const OUString& rAttrName = rAttrList->getNameByIndex( i );
182 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
183 OUString aLocalName;
184 sal_uInt16 nPrefix =
185 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
186 &aLocalName );
188 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
189 XMLTransformerActions::const_iterator aIter =
190 pActions->find( aKey );
191 if( !(aIter == pActions->end() ) )
193 switch( (*aIter).second.m_nActionType )
195 case XML_ATACTION_REMOVE:
196 break;
197 case XML_ATACTION_COPY:
198 pAttrList->AddAttribute( rAttrName, rAttrValue );
199 break;
200 case XML_ATACTION_RENAME:
202 OUString aNewAttrQName(
203 GetTransformer().GetNamespaceMap().GetQNameByKey(
204 (*aIter).second.GetQNamePrefixFromParam1(),
205 ::xmloff::token::GetXMLToken(
206 (*aIter).second.GetQNameTokenFromParam1()) ) );
207 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
209 break;
210 case XML_ATACTION_IN2INCH:
212 OUString aAttrValue( rAttrValue );
213 XMLTransformerBase::ReplaceSingleInWithInch(
214 aAttrValue );
215 pAttrList->AddAttribute( rAttrName, aAttrValue );
217 break;
218 case XML_ATACTION_INS2INCHS:
220 OUString aAttrValue( rAttrValue );
221 XMLTransformerBase::ReplaceInWithInch(
222 aAttrValue );
223 pAttrList->AddAttribute( rAttrName, aAttrValue );
225 break;
226 case XML_ATACTION_DECODE_STYLE_NAME_REF:
228 OUString aAttrValue( rAttrValue );
229 GetTransformer().DecodeStyleName(aAttrValue);
230 pAttrList->AddAttribute( rAttrName, aAttrValue );
232 break;
233 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
235 OUString aNewAttrQName(
236 GetTransformer().GetNamespaceMap().GetQNameByKey(
237 (*aIter).second.GetQNamePrefixFromParam1(),
238 ::xmloff::token::GetXMLToken(
239 (*aIter).second.GetQNameTokenFromParam1()) ) );
240 OUString aAttrValue( rAttrValue );
241 GetTransformer().DecodeStyleName(aAttrValue);
242 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
244 break;
245 case XML_ATACTION_NEG_PERCENT:
247 OUString aAttrValue( rAttrValue );
248 GetTransformer().NegPercent(aAttrValue);
249 pAttrList->AddAttribute( rAttrName, aAttrValue );
251 break;
252 case XML_ATACTION_RENAME_NEG_PERCENT:
254 OUString aNewAttrQName(
255 GetTransformer().GetNamespaceMap().GetQNameByKey(
256 (*aIter).second.GetQNamePrefixFromParam1(),
257 ::xmloff::token::GetXMLToken(
258 (*aIter).second.GetQNameTokenFromParam1()) ) );
259 OUString aAttrValue( rAttrValue );
260 GetTransformer().NegPercent(aAttrValue);
261 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
263 break;
264 case XML_OPTACTION_LINE_MODE:
266 sal_Bool bWordMode =
267 IsXMLToken( rAttrValue, XML_SKIP_WHITE_SPACE );
268 OUString aAttrQName(
269 GetTransformer().GetNamespaceMap().GetQNameByKey(
270 XML_NAMESPACE_FO,
271 GetXMLToken( XML_SCORE_SPACES ) ) );
272 sal_Int16 nIndex =
273 pAttrList->GetIndexByName( aAttrQName );
274 if( -1 != nIndex )
276 if( bWordMode )
278 const OUString& rOldValue =
279 pAttrList->getValueByIndex( nIndex );
280 if( !IsXMLToken( rOldValue, XML_TRUE ) )
282 pAttrList->SetValueByIndex( nIndex,
283 GetXMLToken( XML_TRUE ) );
287 else
289 OUString aAttrValue( GetXMLToken( bWordMode
290 ? XML_FALSE
291 : XML_TRUE ) );
292 pAttrList->AddAttribute( aAttrQName, aAttrValue );
295 break;
296 case XML_OPTACTION_KEEP_WITH_NEXT:
298 OUString aAttrValue( GetXMLToken(
299 IsXMLToken( rAttrValue, XML_ALWAYS )
300 ? XML_TRUE
301 : XML_FALSE) );
302 pAttrList->AddAttribute( rAttrName, aAttrValue );
304 break;
305 case XML_OPTACTION_UNDERLINE_WIDTH:
306 if( IsXMLToken( rAttrValue, XML_BOLD ) )
307 bBoldUnderline = sal_True;
308 break;
309 case XML_OPTACTION_UNDERLINE_TYPE:
310 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
311 bDoubleUnderline = sal_True;
312 break;
313 case XML_OPTACTION_UNDERLINE_STYLE:
314 eUnderline = GetTransformer().GetToken( rAttrValue );
315 break;
316 case XML_OPTACTION_LINETHROUGH_WIDTH:
317 if( IsXMLToken( rAttrValue, XML_BOLD ) )
318 bBoldLineThrough = sal_True;
319 break;
320 case XML_OPTACTION_LINETHROUGH_TYPE:
321 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
322 bDoubleLineThrough = sal_True;
323 break;
324 case XML_OPTACTION_LINETHROUGH_STYLE:
325 eLineThrough = GetTransformer().GetToken( rAttrValue );
326 break;
327 case XML_OPTACTION_LINETHROUGH_TEXT:
328 if( rAttrValue.getLength() )
329 cLineThroughChar = rAttrValue[0];
330 break;
331 case XML_OPTACTION_INTERPOLATION:
333 // 0: none
334 sal_Int32 nSplineType = 0;
335 if( IsXMLToken( rAttrValue, XML_CUBIC_SPLINE ))
336 nSplineType = 1;
337 else if( IsXMLToken( rAttrValue, XML_B_SPLINE ))
338 nSplineType = 2;
340 pAttrList->AddAttribute(
341 GetTransformer().GetNamespaceMap().GetQNameByKey(
342 XML_NAMESPACE_CHART,
343 GetXMLToken( XML_SPLINES )),
344 OUString::valueOf( nSplineType ));
346 break;
347 case XML_OPTACTION_INTERVAL_MAJOR:
348 pAttrList->AddAttribute( rAttrName, rAttrValue );
349 SvXMLUnitConverter::convertDouble( fIntervalMajor, rAttrValue );
350 break;
351 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR:
352 SvXMLUnitConverter::convertNumber( nIntervalMinorDivisor, rAttrValue );
353 bIntervalMinorFound = true;
354 break;
355 case XML_OPTACTION_SYMBOL_TYPE:
357 // if symbol_type is "named-symbol" the "symbol"
358 // property is set in the action XML_OPTACTION_SYMBOL_NAME
359 sal_Int32 nSymbolType = 0;
360 if( IsXMLToken( rAttrValue, XML_NONE ))
361 nSymbolType = -3;
362 else if( IsXMLToken( rAttrValue, XML_AUTOMATIC ))
363 nSymbolType = -2;
364 else if( IsXMLToken( rAttrValue, XML_IMAGE ))
365 nSymbolType = -1;
367 if( nSymbolType < 0 )
368 pAttrList->AddAttribute(
369 GetTransformer().GetNamespaceMap().GetQNameByKey(
370 XML_NAMESPACE_CHART,
371 GetXMLToken( XML_SYMBOL )),
372 OUString::valueOf( nSymbolType ));
374 break;
375 case XML_OPTACTION_SYMBOL_NAME:
377 // assume "symbol-type" == "named-symbol"
378 sal_Int32 nSymbolType = -3; // NONE
379 // "square" just has an awkward token-name
380 if( IsXMLToken( rAttrValue, XML_GRADIENTSTYLE_SQUARE ))
381 nSymbolType = 0;
382 else if( IsXMLToken( rAttrValue, XML_DIAMOND ))
383 nSymbolType = 1;
384 else if( IsXMLToken( rAttrValue, XML_ARROW_DOWN ))
385 nSymbolType = 2;
386 else if( IsXMLToken( rAttrValue, XML_ARROW_UP ))
387 nSymbolType = 3;
388 else if( IsXMLToken( rAttrValue, XML_ARROW_RIGHT ))
389 nSymbolType = 4;
390 else if( IsXMLToken( rAttrValue, XML_ARROW_LEFT ))
391 nSymbolType = 5;
392 else if( IsXMLToken( rAttrValue, XML_BOW_TIE ))
393 nSymbolType = 6;
394 else if( IsXMLToken( rAttrValue, XML_HOURGLASS ))
395 nSymbolType = 7;
397 if( nSymbolType >= 0 )
398 pAttrList->AddAttribute(
399 GetTransformer().GetNamespaceMap().GetQNameByKey(
400 XML_NAMESPACE_CHART,
401 GetXMLToken( XML_SYMBOL )),
402 OUString::valueOf( nSymbolType ));
404 break;
405 // #i25616#
406 case XML_OPTACTION_OPACITY:
407 aOpacityValueRemember = rAttrValue;
408 GetTransformer().NegPercent(aOpacityValueRemember);
409 break;
411 // #i25616#
412 case XML_OPTACTION_IMAGE_OPACITY:
413 aImageOpacityValueRemember = rAttrValue;
414 GetTransformer().NegPercent(aImageOpacityValueRemember);
415 break;
417 case XML_OPTACTION_KEEP_TOGETHER:
418 pAttrList->AddAttribute(
419 GetTransformer().GetNamespaceMap().GetQNameByKey(
420 XML_NAMESPACE_STYLE,GetXMLToken(XML_BREAK_INSIDE)),
421 GetXMLToken(
422 IsXMLToken( rAttrValue, XML_ALWAYS )
423 ? XML_COLUMNSPLIT_AVOID
424 : XML_COLUMNSPLIT_AUTO ) );
425 break;
427 case XML_OPTACTION_CONTROL_TEXT_ALIGN:
428 if ( m_bControlStyle )
430 OUString aNewAttrQName(
431 GetTransformer().GetNamespaceMap().GetQNameByKey(
432 XML_NAMESPACE_STYLE,
433 ::xmloff::token::GetXMLToken(
434 XML_TEXT_ALIGN ) ) );
435 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
437 else
439 OUString aNewAttrQName(
440 GetTransformer().GetNamespaceMap().GetQNameByKey(
441 XML_NAMESPACE_FO,
442 ::xmloff::token::GetXMLToken(
443 XML_TEXT_ALIGN ) ) );
444 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
446 break;
448 case XML_OPTACTION_DRAW_WRITING_MODE:
449 if( IsXMLToken( m_aStyleFamily, XML_GRAPHICS ) )
451 pAttrList->AddAttribute(
452 GetTransformer().GetNamespaceMap().GetQNameByKey(
453 XML_NAMESPACE_DRAW,
454 GetXMLToken( XML_WRITING_MODE ) ), rAttrValue );
456 pAttrList->AddAttribute( rAttrName, rAttrValue );
457 break;
459 case XML_ATACTION_CAPTION_ESCAPE_OASIS:
461 OUString aAttrValue( rAttrValue );
462 if( aAttrValue.indexOf( sal_Unicode('%') ) != -1 )
464 sal_Int32 nValue = 0;
465 SvXMLUnitConverter::convertPercent( nValue, rAttrValue );
466 if( nValue )
468 nValue *= 100;
469 rtl::OUStringBuffer aOut;
470 SvXMLUnitConverter::convertPercent( aOut, nValue );
471 aAttrValue = aOut.makeStringAndClear();
474 else
476 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
479 pAttrList->AddAttribute( rAttrName, aAttrValue );
481 break;
483 case XML_ATACTION_DECODE_PROTECT:
485 pAttrList->AddAttribute( rAttrName, rAttrValue );
487 if( rAttrValue.indexOf( GetXMLToken( XML_SIZE ) ) != -1 )
488 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
489 XML_NAMESPACE_DRAW,
490 GetXMLToken( XML_SIZE_PROTECT )), GetXMLToken( XML_TRUE ) );
492 if( rAttrValue.indexOf( GetXMLToken( XML_POSITION ) ) != -1 )
493 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
494 XML_NAMESPACE_DRAW,
495 GetXMLToken( XML_MOVE_PROTECT )), GetXMLToken( XML_TRUE ) );
497 break;
499 case XML_ATACTION_DRAW_MIRROR_OASIS: // renames style:mirror to draw:mirror and adapts values
501 // keep original for writer graphic objects
502 // --> OD 2005-05-12 #i49139# - adapts attribute values,
503 OUString aNewAttrValue;
504 SvXMLTokenEnumerator aTokenEnum( rAttrValue );
505 OUString aToken;
506 while( aTokenEnum.getNextToken( aToken ) )
508 if ( aNewAttrValue.getLength() > 0 )
510 aNewAttrValue += rtl::OUString::createFromAscii( " " );
513 if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_EVEN ) )
515 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES );
517 else if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_ODD ) )
519 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES );
521 else
523 aNewAttrValue += aToken;
526 pAttrList->AddAttribute( rAttrName, aNewAttrValue );
527 // <--
529 // create old draw:mirror for drawing graphic objects
530 OUString aAttrValue( GetXMLToken( IsXMLToken( rAttrValue, XML_HORIZONTAL ) ? XML_TRUE : XML_FALSE ) );
531 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
532 XML_NAMESPACE_DRAW,
533 GetXMLToken( XML_MIRROR )), aAttrValue );
535 break;
536 case XML_ATACTION_GAMMA_OASIS: // converts percentage value to double
538 sal_Int32 nValue;
539 SvXMLUnitConverter::convertPercent( nValue, rAttrValue );
540 const double fValue = ((double)nValue) / 100.0;
541 pAttrList->AddAttribute( rAttrName, OUString::valueOf( fValue ) );
543 break;
544 case XML_ATACTION_OPACITY_FIX:
546 sal_Int32 nValue;
547 if( rAttrValue.indexOf( sal_Unicode('%') ) != -1 )
549 SvXMLUnitConverter::convertPercent( nValue, rAttrValue );
551 else
553 nValue = sal_Int32( rAttrValue.toDouble() * 100.0 );
555 nValue = 100 - nValue;
557 rtl::OUStringBuffer aOut;
558 SvXMLUnitConverter::convertPercent( aOut, nValue );
559 pAttrList->AddAttribute( rAttrName, aOut.makeStringAndClear() );
561 break;
562 default:
563 OSL_ENSURE( !this, "unknown action" );
564 break;
567 else
569 pAttrList->AddAttribute( rAttrName, rAttrValue );
572 if( XML_TOKEN_END != eUnderline )
573 pAttrList->AddAttribute(
574 GetTransformer().GetNamespaceMap().GetQNameByKey(
575 XML_NAMESPACE_STYLE,
576 GetXMLToken( XML_TEXT_UNDERLINE ) ),
577 MergeUnderline( eUnderline, bBoldUnderline,
578 bDoubleUnderline ) );
579 if( XML_TOKEN_END != eLineThrough )
580 pAttrList->AddAttribute(
581 GetTransformer().GetNamespaceMap().GetQNameByKey(
582 XML_NAMESPACE_STYLE,
583 GetXMLToken( XML_TEXT_CROSSING_OUT ) ),
584 MergeLineThrough( eLineThrough, bBoldLineThrough,
585 bDoubleLineThrough, cLineThroughChar ) );
586 if( bIntervalMinorFound )
588 double fIntervalMinor = 0.0;
589 if( nIntervalMinorDivisor != 0)
590 fIntervalMinor = fIntervalMajor / static_cast< double >( nIntervalMinorDivisor );
592 ::rtl::OUStringBuffer aBuf;
593 SvXMLUnitConverter::convertDouble( aBuf, fIntervalMinor );
594 pAttrList->AddAttribute(
595 GetTransformer().GetNamespaceMap().GetQNameByKey(
596 XML_NAMESPACE_CHART,
597 GetXMLToken( XML_INTERVAL_MINOR )),
598 aBuf.makeStringAndClear());
601 // #i25616#
602 if(aOpacityValueRemember.getLength() || aImageOpacityValueRemember.getLength())
604 pAttrList->AddAttribute(
605 GetTransformer().GetNamespaceMap().GetQNameByKey(
606 XML_NAMESPACE_DRAW,
607 GetXMLToken( XML_TRANSPARENCY ) ),
608 aImageOpacityValueRemember.getLength()
609 ? aImageOpacityValueRemember : aOpacityValueRemember );
612 else
614 if( !m_xAttrList.is() )
616 m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
618 else
620 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
621 ->AppendAttributeList( rAttrList );
626 void XMLPropertiesTContext_Impl::Export()
628 OUString aNewQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
629 XML_NAMESPACE_STYLE,
630 ::xmloff::token::GetXMLToken( XML_PROPERTIES ) ) );
631 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
632 m_xAttrList );
633 ExportContent();
634 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
637 XMLPropType XMLPropertiesTContext_Impl::GetPropType( const OUString& rLocalName )
639 XMLPropType eProp = XML_PROP_TYPE_END;
640 if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
641 eProp = XML_PROP_TYPE_GRAPHIC;
642 else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
643 eProp = XML_PROP_TYPE_DRAWING_PAGE;
644 else if( IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES ) )
645 eProp = XML_PROP_TYPE_PAGE_LAYOUT;
646 else if( IsXMLToken( rLocalName, XML_HEADER_FOOTER_PROPERTIES ) )
647 eProp = XML_PROP_TYPE_HEADER_FOOTER;
648 else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
649 eProp = XML_PROP_TYPE_TEXT;
650 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
651 eProp = XML_PROP_TYPE_PARAGRAPH;
652 else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) )
653 eProp = XML_PROP_TYPE_RUBY;
654 else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
655 eProp = XML_PROP_TYPE_SECTION;
656 else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
657 eProp = XML_PROP_TYPE_TABLE;
658 else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) )
659 eProp = XML_PROP_TYPE_TABLE_COLUMN;
660 else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
661 eProp = XML_PROP_TYPE_TABLE_ROW;
662 else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
663 eProp = XML_PROP_TYPE_TABLE_CELL;
664 else if( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) )
665 eProp = XML_PROP_TYPE_LIST_LEVEL;
666 else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
667 eProp = XML_PROP_TYPE_CHART;
669 return eProp;
672 OUString XMLPropertiesTContext_Impl::MergeUnderline(
673 XMLTokenEnum eUnderline, sal_Bool bBold, sal_Bool bDouble )
675 if( bDouble )
677 switch( eUnderline )
679 case XML_WAVE:
680 eUnderline = XML_DOUBLE_WAVE;
681 break;
682 default:
683 eUnderline = XML_DOUBLE;
684 break;
687 else if( bBold )
689 switch( eUnderline )
691 case XML_NONE:
692 case XML_SOLID:
693 eUnderline = XML_BOLD;
694 break;
695 case XML_DOTTED:
696 eUnderline = XML_BOLD_DOTTED;
697 break;
698 case XML_DASH:
699 eUnderline = XML_BOLD_DASH;
700 break;
701 case XML_LONG_DASH:
702 eUnderline = XML_BOLD_LONG_DASH;
703 break;
704 case XML_DOT_DASH:
705 eUnderline = XML_BOLD_DOT_DASH;
706 break;
707 case XML_DOT_DOT_DASH:
708 eUnderline = XML_BOLD_DOT_DOT_DASH;
709 break;
710 case XML_WAVE:
711 eUnderline = XML_BOLD_WAVE;
712 break;
713 default:
714 OSL_ENSURE( false, "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
715 break;
718 else
720 switch( eUnderline )
722 case XML_SOLID:
723 eUnderline = XML_SINGLE;
724 break;
725 case XML_NONE:
726 eUnderline = XML_NONE;
727 break;
728 default:
729 OSL_ENSURE( false, "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
730 break;
734 return GetXMLToken( eUnderline );
737 OUString XMLPropertiesTContext_Impl::MergeLineThrough(
738 XMLTokenEnum eLineThrough, sal_Bool bBold, sal_Bool bDouble,
739 sal_Unicode c )
741 if( c )
742 eLineThrough = c=='/' ? XML_SLASH : XML_uX;
743 else if( bDouble )
744 eLineThrough = XML_DOUBLE_LINE;
745 else if( bBold )
746 eLineThrough = XML_THICK_LINE;
747 else if( XML_NONE != eLineThrough )
748 eLineThrough = XML_SINGLE_LINE;
750 return GetXMLToken( eLineThrough );
753 //------------------------------------------------------------------------------
755 TYPEINIT1( XMLStyleOASISTContext, XMLPersElemContentTContext );
757 XMLStyleOASISTContext::XMLStyleOASISTContext( XMLTransformerBase& rImp,
758 const OUString& rQName,
759 sal_Bool bPersistent ) :
760 XMLPersElemContentTContext ( rImp, rQName ),
761 m_bPersistent( bPersistent ),
762 m_bControlStyle( false )
766 XMLStyleOASISTContext::XMLStyleOASISTContext(
767 XMLTransformerBase& rImp,
768 const OUString& rQName,
769 sal_uInt16 nPrefix,
770 ::xmloff::token::XMLTokenEnum eToken,
771 sal_Bool bPersistent ) :
772 XMLPersElemContentTContext( rImp, rQName, nPrefix, eToken ),
773 m_bPersistent( bPersistent )
777 XMLStyleOASISTContext::~XMLStyleOASISTContext()
781 XMLTransformerContext *XMLStyleOASISTContext::CreateChildContext(
782 sal_uInt16 nPrefix,
783 const OUString& rLocalName,
784 const OUString& rQName,
785 const Reference< XAttributeList >& rAttrList )
787 XMLTransformerContext *pContext = 0;
789 if( XML_NAMESPACE_STYLE == nPrefix )
791 XMLPropType ePropType =
792 XMLPropertiesTContext_Impl::GetPropType( rLocalName );
793 if( XML_PROP_TYPE_END != ePropType )
795 // if no properties context exist start a new one.
796 if( !m_xPropContext.is() )
797 m_xPropContext = new XMLPropertiesTContext_Impl(
798 GetTransformer(), rQName, ePropType, m_aStyleFamily, m_bControlStyle );
799 else
800 m_xPropContext->SetQNameAndPropType( rQName, ePropType );
801 pContext = m_xPropContext.get();
804 if( !pContext )
806 // if a properties context exist close it
807 if( m_xPropContext.is() && !m_bPersistent )
809 m_xPropContext->Export();
810 m_xPropContext = 0;
813 pContext = m_bPersistent
814 ? XMLPersElemContentTContext::CreateChildContext(
815 nPrefix, rLocalName, rQName, rAttrList )
816 : XMLTransformerContext::CreateChildContext(
817 nPrefix, rLocalName, rQName, rAttrList );
820 return pContext;
823 void XMLStyleOASISTContext::StartElement(
824 const Reference< XAttributeList >& rAttrList )
826 XMLTransformerActions *pActions =
827 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS );
828 OSL_ENSURE( pActions, "go no actions" );
830 Reference< XAttributeList > xAttrList( rAttrList );
831 XMLMutableAttributeList *pMutableAttrList = 0;
832 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
833 sal_Int16 nFamilyAttr = -1;
834 m_bControlStyle = sal_False;
836 for( sal_Int16 i=0; i < nAttrCount; i++ )
838 const OUString& rAttrName = xAttrList->getNameByIndex( i );
839 OUString aLocalName;
840 sal_uInt16 nPrefix =
841 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
842 &aLocalName );
843 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
844 XMLTransformerActions::const_iterator aIter =
845 pActions->find( aKey );
846 if( !(aIter == pActions->end() ) )
848 if( !pMutableAttrList )
850 pMutableAttrList =
851 new XMLMutableAttributeList( xAttrList );
852 xAttrList = pMutableAttrList;
854 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
855 switch( (*aIter).second.m_nActionType )
857 case XML_ATACTION_STYLE_FAMILY:
858 if( IsXMLToken( rAttrValue, XML_GRAPHIC ) )
860 m_aStyleFamily = GetXMLToken( XML_GRAPHICS ) ;
861 pMutableAttrList->SetValueByIndex( i, m_aStyleFamily );
863 else
865 m_aStyleFamily = rAttrValue;
867 if( IsXMLToken( rAttrValue, XML_PARAGRAPH ) )
868 nFamilyAttr = i;
871 break;
872 case XML_ATACTION_STYLE_DISPLAY_NAME:
873 case XML_ATACTION_REMOVE:
874 pMutableAttrList->RemoveAttributeByIndex( i );
875 --i;
876 --nAttrCount;
877 break;
878 case XML_ATACTION_DECODE_STYLE_NAME:
879 m_bControlStyle = 0 == rAttrValue.compareToAscii( "ctrl", 4 );
880 case XML_ATACTION_DECODE_STYLE_NAME_REF:
882 OUString aAttrValue( rAttrValue );
883 if( GetTransformer().DecodeStyleName(aAttrValue) )
884 pMutableAttrList->SetValueByIndex( i, aAttrValue );
886 break;
887 case XML_ATACTION_IN2INCH:
889 OUString aAttrValue( rAttrValue );
890 if( XMLTransformerBase::ReplaceSingleInWithInch(
891 aAttrValue ) )
892 pMutableAttrList->SetValueByIndex( i, aAttrValue );
894 break;
895 case XML_ATACTION_NEG_PERCENT:
897 OUString aAttrValue( rAttrValue );
898 if( GetTransformer().NegPercent(aAttrValue) )
899 pMutableAttrList->SetValueByIndex( i, aAttrValue );
901 break;
902 case XML_ATACTION_URI_OASIS:
904 OUString aAttrValue( rAttrValue );
905 if( GetTransformer().ConvertURIToOOo( aAttrValue,
906 static_cast< sal_Bool >((*aIter).second.m_nParam1)))
907 pMutableAttrList->SetValueByIndex( i, aAttrValue );
909 break;
910 default:
911 OSL_ENSURE( !this, "unknown action" );
912 break;
917 if( m_bControlStyle && nFamilyAttr != -1 )
918 pMutableAttrList->SetValueByIndex( nFamilyAttr, GetXMLToken( XML_CONTROL ) );
921 if( m_bPersistent )
922 XMLPersElemContentTContext::StartElement( xAttrList );
923 else
924 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
925 xAttrList );
928 void XMLStyleOASISTContext::EndElement()
930 if( m_bPersistent )
932 XMLPersElemContentTContext::EndElement();
934 else
936 // if a properties context exist close it
937 if( m_xPropContext.is() )
939 m_xPropContext->Export();
940 m_xPropContext = 0;
942 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
946 void XMLStyleOASISTContext::Characters( const OUString& )
948 // element content only:
951 void XMLStyleOASISTContext::ExportContent()
953 if( m_xPropContext.is() )
954 m_xPropContext->Export();
955 XMLPersElemContentTContext::ExportContent();
958 sal_Bool XMLStyleOASISTContext::IsPersistent() const
960 return m_bPersistent;
963 XMLTransformerActions *XMLStyleOASISTContext::CreateTransformerActions(
964 sal_uInt16 nType )
966 XMLTransformerActionInit *pInit = 0;
968 switch( nType )
970 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS:
971 pInit = aGraphicPropertyOASISAttrActionTable;
972 break;
973 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS:
974 pInit = aDrawingPagePropertyOASISAttrActionTable;
975 break;
976 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS:
977 pInit = aPageLayoutPropertyOASISAttrActionTable;
978 break;
979 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS:
980 pInit = aHeaderFooterPropertyOASISAttrActionTable;
981 break;
982 case PROP_OASIS_TEXT_ATTR_ACTIONS:
983 pInit = aTextPropertyOASISAttrActionTable;
984 break;
985 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS:
986 pInit = aParagraphPropertyOASISAttrActionTable;
987 break;
988 case PROP_OASIS_SECTION_ATTR_ACTIONS:
989 pInit = aSectionPropertyOASISAttrActionTable;
990 break;
991 case PROP_OASIS_TABLE_ATTR_ACTIONS:
992 pInit = aTablePropertyOASISAttrActionTable;
993 break;
994 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS:
995 pInit = aTableColumnPropertyOASISAttrActionTable;
996 break;
997 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS:
998 pInit = aTableRowPropertyOASISAttrActionTable;
999 break;
1000 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS:
1001 pInit = aTableCellPropertyOASISAttrActionTable;
1002 break;
1003 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS:
1004 pInit = aListLevelPropertyOASISAttrActionTable;
1005 break;
1006 case PROP_OASIS_CHART_ATTR_ACTIONS:
1007 pInit = aChartPropertyOASISAttrActionTable;
1008 break;
1011 XMLTransformerActions *pActions = 0;
1012 if( pInit )
1013 pActions = new XMLTransformerActions( pInit );
1015 return pActions;