fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / transform / StyleOASISTContext.cxx
blobbadf7df3af6d1cb2cbbf59f567fd16d19273cf0c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/SAXParseException.hpp>
21 #include <com/sun/star/xml/sax/SAXException.hpp>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <rtl/ustrbuf.hxx>
25 #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 "ProcAttrTContext.hxx"
32 #include "TransformerBase.hxx"
33 #include "TransformerActions.hxx"
34 #include "ActionMapTypesOASIS.hxx"
35 #include "MutableAttrList.hxx"
36 #include "PropertyActionsOASIS.hxx"
37 #include "StyleOASISTContext.hxx"
38 #include <xmloff/xmluconv.hxx>
40 using namespace ::xmloff::token;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::xml::sax;
43 //------------------------------------------------------------------------------
45 static sal_uInt16 aAttrActionMaps[XML_PROP_TYPE_END] =
47 PROP_OASIS_GRAPHIC_ATTR_ACTIONS,
48 PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS, // DRAWING_PAGE
49 PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS,
50 PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS,
51 PROP_OASIS_TEXT_ATTR_ACTIONS,
52 PROP_OASIS_PARAGRAPH_ATTR_ACTIONS,
53 MAX_OASIS_PROP_ACTIONS, // RUBY
54 PROP_OASIS_SECTION_ATTR_ACTIONS,
55 PROP_OASIS_TABLE_ATTR_ACTIONS,
56 PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS,
57 PROP_OASIS_TABLE_ROW_ATTR_ACTIONS,
58 PROP_OASIS_TABLE_CELL_ATTR_ACTIONS,
59 PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS,
60 PROP_OASIS_CHART_ATTR_ACTIONS
63 //------------------------------------------------------------------------------
65 class XMLPropertiesTContext_Impl : public XMLPersElemContentTContext
67 ::com::sun::star::uno::Reference<
68 ::com::sun::star::xml::sax::XAttributeList > m_xAttrList;
70 XMLPropType m_ePropType;
71 sal_Bool m_bControlStyle;
72 OUString m_aStyleFamily;
74 public:
76 void SetQNameAndPropType( const OUString& rQName,
77 XMLPropType ePropType )
79 m_ePropType = ePropType;
80 XMLTransformerContext::SetQName( rQName );
83 TYPEINFO();
85 XMLPropertiesTContext_Impl( XMLTransformerBase& rTransformer,
86 const OUString& rQName,
87 XMLPropType eP,
88 const OUString& rStyleFamily,
89 sal_Bool _bControlStyle = sal_False );
91 virtual ~XMLPropertiesTContext_Impl();
93 virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
95 virtual void Export();
97 static XMLPropType GetPropType( const OUString& rLocalName );
99 static OUString MergeUnderline( XMLTokenEnum eUnderline,
100 sal_Bool bBold, sal_Bool bDouble );
101 static OUString MergeLineThrough( XMLTokenEnum eLineThrough,
102 sal_Bool bBold, sal_Bool bDouble,
103 sal_Unicode c );
106 TYPEINIT1( XMLPropertiesTContext_Impl, XMLPersElemContentTContext );
108 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
109 XMLTransformerBase& rImp, const OUString& rQName, XMLPropType eP,
110 const OUString& rStyleFamily, sal_Bool _bControlStyle ) :
111 XMLPersElemContentTContext( rImp, rQName, XML_NAMESPACE_STYLE,
112 XML_PROPERTIES),
113 m_ePropType( eP ),
114 m_bControlStyle( _bControlStyle ),
115 m_aStyleFamily( rStyleFamily )
119 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
123 void XMLPropertiesTContext_Impl::StartElement(
124 const Reference< XAttributeList >& rAttrList )
126 XMLTransformerActions *pActions = 0;
127 sal_uInt16 nActionMap = aAttrActionMaps[m_ePropType];
128 if( nActionMap < MAX_OASIS_PROP_ACTIONS )
130 pActions = GetTransformer().GetUserDefinedActions( nActionMap );
131 OSL_ENSURE( pActions, "go no actions" );
134 if( pActions )
136 XMLMutableAttributeList *pAttrList = 0;
137 if( !m_xAttrList.is() )
139 pAttrList = new XMLMutableAttributeList();
140 m_xAttrList = pAttrList;
142 else
144 pAttrList =
145 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
148 XMLTokenEnum eUnderline = XML_TOKEN_END;
149 sal_Bool bBoldUnderline = sal_False, bDoubleUnderline = sal_False;
150 XMLTokenEnum eLineThrough = XML_TOKEN_END;
151 sal_Bool bBoldLineThrough = sal_False, bDoubleLineThrough = sal_False;
152 sal_Unicode cLineThroughChar = 0;
154 bool bIntervalMinorFound = false;
155 double fIntervalMajor = 0.0;
156 sal_Int32 nIntervalMinorDivisor = 0;
158 // #i25616#
159 OUString aOpacityValueRemember;
160 OUString aImageOpacityValueRemember;
162 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
163 for( sal_Int16 i=0; i < nAttrCount; i++ )
165 const OUString& rAttrName = rAttrList->getNameByIndex( i );
166 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
167 OUString aLocalName;
168 sal_uInt16 nPrefix =
169 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
170 &aLocalName );
172 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
173 XMLTransformerActions::const_iterator aIter =
174 pActions->find( aKey );
175 if( !(aIter == pActions->end() ) )
177 switch( (*aIter).second.m_nActionType )
179 case XML_ATACTION_REMOVE:
180 break;
181 case XML_ATACTION_COPY:
182 pAttrList->AddAttribute( rAttrName, rAttrValue );
183 break;
184 case XML_ATACTION_RENAME:
186 OUString aNewAttrQName(
187 GetTransformer().GetNamespaceMap().GetQNameByKey(
188 (*aIter).second.GetQNamePrefixFromParam1(),
189 ::xmloff::token::GetXMLToken(
190 (*aIter).second.GetQNameTokenFromParam1()) ) );
191 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
193 break;
194 case XML_ATACTION_IN2INCH:
196 OUString aAttrValue( rAttrValue );
197 XMLTransformerBase::ReplaceSingleInWithInch(
198 aAttrValue );
199 pAttrList->AddAttribute( rAttrName, aAttrValue );
201 break;
202 case XML_ATACTION_INS2INCHS:
204 OUString aAttrValue( rAttrValue );
205 XMLTransformerBase::ReplaceInWithInch(
206 aAttrValue );
207 pAttrList->AddAttribute( rAttrName, aAttrValue );
209 break;
210 case XML_ATACTION_DECODE_STYLE_NAME_REF:
212 OUString aAttrValue( rAttrValue );
213 GetTransformer().DecodeStyleName(aAttrValue);
214 pAttrList->AddAttribute( rAttrName, aAttrValue );
216 break;
217 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
219 OUString aNewAttrQName(
220 GetTransformer().GetNamespaceMap().GetQNameByKey(
221 (*aIter).second.GetQNamePrefixFromParam1(),
222 ::xmloff::token::GetXMLToken(
223 (*aIter).second.GetQNameTokenFromParam1()) ) );
224 OUString aAttrValue( rAttrValue );
225 GetTransformer().DecodeStyleName(aAttrValue);
226 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
228 break;
229 case XML_ATACTION_NEG_PERCENT:
231 OUString aAttrValue( rAttrValue );
232 GetTransformer().NegPercent(aAttrValue);
233 pAttrList->AddAttribute( rAttrName, aAttrValue );
235 break;
236 case XML_ATACTION_RENAME_NEG_PERCENT:
238 OUString aNewAttrQName(
239 GetTransformer().GetNamespaceMap().GetQNameByKey(
240 (*aIter).second.GetQNamePrefixFromParam1(),
241 ::xmloff::token::GetXMLToken(
242 (*aIter).second.GetQNameTokenFromParam1()) ) );
243 OUString aAttrValue( rAttrValue );
244 GetTransformer().NegPercent(aAttrValue);
245 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
247 break;
248 case XML_OPTACTION_LINE_MODE:
250 sal_Bool bWordMode =
251 IsXMLToken( rAttrValue, XML_SKIP_WHITE_SPACE );
252 OUString aAttrQName(
253 GetTransformer().GetNamespaceMap().GetQNameByKey(
254 XML_NAMESPACE_FO,
255 GetXMLToken( XML_SCORE_SPACES ) ) );
256 sal_Int16 nIndex =
257 pAttrList->GetIndexByName( aAttrQName );
258 if( -1 != nIndex )
260 if( bWordMode )
262 const OUString& rOldValue =
263 pAttrList->getValueByIndex( nIndex );
264 if( !IsXMLToken( rOldValue, XML_TRUE ) )
266 pAttrList->SetValueByIndex( nIndex,
267 GetXMLToken( XML_TRUE ) );
271 else
273 OUString aAttrValue( GetXMLToken( bWordMode
274 ? XML_FALSE
275 : XML_TRUE ) );
276 pAttrList->AddAttribute( aAttrQName, aAttrValue );
279 break;
280 case XML_OPTACTION_KEEP_WITH_NEXT:
282 OUString aAttrValue( GetXMLToken(
283 IsXMLToken( rAttrValue, XML_ALWAYS )
284 ? XML_TRUE
285 : XML_FALSE) );
286 pAttrList->AddAttribute( rAttrName, aAttrValue );
288 break;
289 case XML_OPTACTION_UNDERLINE_WIDTH:
290 if( IsXMLToken( rAttrValue, XML_BOLD ) )
291 bBoldUnderline = sal_True;
292 break;
293 case XML_OPTACTION_UNDERLINE_TYPE:
294 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
295 bDoubleUnderline = sal_True;
296 break;
297 case XML_OPTACTION_UNDERLINE_STYLE:
298 eUnderline = GetTransformer().GetToken( rAttrValue );
299 break;
300 case XML_OPTACTION_LINETHROUGH_WIDTH:
301 if( IsXMLToken( rAttrValue, XML_BOLD ) )
302 bBoldLineThrough = sal_True;
303 break;
304 case XML_OPTACTION_LINETHROUGH_TYPE:
305 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
306 bDoubleLineThrough = sal_True;
307 break;
308 case XML_OPTACTION_LINETHROUGH_STYLE:
309 eLineThrough = GetTransformer().GetToken( rAttrValue );
310 break;
311 case XML_OPTACTION_LINETHROUGH_TEXT:
312 if( !rAttrValue.isEmpty() )
313 cLineThroughChar = rAttrValue[0];
314 break;
315 case XML_OPTACTION_INTERPOLATION:
317 // 0: none (default)
318 sal_Int32 nSplineType = 0;
319 if( IsXMLToken( rAttrValue, XML_CUBIC_SPLINE ))
320 nSplineType = 1;
321 else if( IsXMLToken( rAttrValue, XML_B_SPLINE ))
322 nSplineType = 2;
324 pAttrList->AddAttribute(
325 GetTransformer().GetNamespaceMap().GetQNameByKey(
326 XML_NAMESPACE_CHART,
327 GetXMLToken( XML_SPLINES )),
328 OUString::valueOf( nSplineType ));
330 break;
331 case XML_OPTACTION_INTERVAL_MAJOR:
332 pAttrList->AddAttribute( rAttrName, rAttrValue );
333 ::sax::Converter::convertDouble(fIntervalMajor, rAttrValue);
334 break;
335 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR:
336 ::sax::Converter::convertNumber(nIntervalMinorDivisor, rAttrValue);
337 bIntervalMinorFound = true;
338 break;
339 case XML_OPTACTION_SYMBOL_TYPE:
341 // if symbol_type is "named-symbol" the "symbol"
342 // property is set in the action XML_OPTACTION_SYMBOL_NAME
343 sal_Int32 nSymbolType = 0;
344 if( IsXMLToken( rAttrValue, XML_NONE ))
345 nSymbolType = -3;
346 else if( IsXMLToken( rAttrValue, XML_AUTOMATIC ))
347 nSymbolType = -2;
348 else if( IsXMLToken( rAttrValue, XML_IMAGE ))
349 nSymbolType = -1;
351 if( nSymbolType < 0 )
352 pAttrList->AddAttribute(
353 GetTransformer().GetNamespaceMap().GetQNameByKey(
354 XML_NAMESPACE_CHART,
355 GetXMLToken( XML_SYMBOL )),
356 OUString::valueOf( nSymbolType ));
358 break;
359 case XML_OPTACTION_SYMBOL_NAME:
361 // assume "symbol-type" == "named-symbol"
362 sal_Int32 nSymbolType = -3; // NONE
363 // "square" just has an awkward token-name
364 if( IsXMLToken( rAttrValue, XML_GRADIENTSTYLE_SQUARE ))
365 nSymbolType = 0;
366 else if( IsXMLToken( rAttrValue, XML_DIAMOND ))
367 nSymbolType = 1;
368 else if( IsXMLToken( rAttrValue, XML_ARROW_DOWN ))
369 nSymbolType = 2;
370 else if( IsXMLToken( rAttrValue, XML_ARROW_UP ))
371 nSymbolType = 3;
372 else if( IsXMLToken( rAttrValue, XML_ARROW_RIGHT ))
373 nSymbolType = 4;
374 else if( IsXMLToken( rAttrValue, XML_ARROW_LEFT ))
375 nSymbolType = 5;
376 else if( IsXMLToken( rAttrValue, XML_BOW_TIE ))
377 nSymbolType = 6;
378 else if( IsXMLToken( rAttrValue, XML_HOURGLASS ))
379 nSymbolType = 7;
380 else if( IsXMLToken( rAttrValue, XML_CIRCLE ))
381 nSymbolType = 8;
382 else if( IsXMLToken( rAttrValue, XML_STAR ))
383 nSymbolType = 9;
384 else if( IsXMLToken( rAttrValue, XML_X ))
385 nSymbolType = 10;
386 else if( IsXMLToken( rAttrValue, XML_PLUS ))
387 nSymbolType = 11;
388 else if( IsXMLToken( rAttrValue, XML_ASTERISK ))
389 nSymbolType = 12;
390 else if( IsXMLToken( rAttrValue, XML_HORIZONTAL_BAR ))
391 nSymbolType = 13;
392 else if( IsXMLToken( rAttrValue, XML_VERTICAL_BAR ))
393 nSymbolType = 14;
395 if( nSymbolType >= 0 )
396 pAttrList->AddAttribute(
397 GetTransformer().GetNamespaceMap().GetQNameByKey(
398 XML_NAMESPACE_CHART,
399 GetXMLToken( XML_SYMBOL )),
400 OUString::valueOf( nSymbolType ));
402 break;
403 // #i25616#
404 case XML_OPTACTION_OPACITY:
405 aOpacityValueRemember = rAttrValue;
406 GetTransformer().NegPercent(aOpacityValueRemember);
407 break;
409 // #i25616#
410 case XML_OPTACTION_IMAGE_OPACITY:
411 aImageOpacityValueRemember = rAttrValue;
412 GetTransformer().NegPercent(aImageOpacityValueRemember);
413 break;
415 case XML_OPTACTION_KEEP_TOGETHER:
416 pAttrList->AddAttribute(
417 GetTransformer().GetNamespaceMap().GetQNameByKey(
418 XML_NAMESPACE_STYLE,GetXMLToken(XML_BREAK_INSIDE)),
419 GetXMLToken(
420 IsXMLToken( rAttrValue, XML_ALWAYS )
421 ? XML_COLUMNSPLIT_AVOID
422 : XML_COLUMNSPLIT_AUTO ) );
423 break;
425 case XML_OPTACTION_CONTROL_TEXT_ALIGN:
426 if ( m_bControlStyle )
428 OUString aNewAttrQName(
429 GetTransformer().GetNamespaceMap().GetQNameByKey(
430 XML_NAMESPACE_STYLE,
431 ::xmloff::token::GetXMLToken(
432 XML_TEXT_ALIGN ) ) );
433 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
435 else
437 OUString aNewAttrQName(
438 GetTransformer().GetNamespaceMap().GetQNameByKey(
439 XML_NAMESPACE_FO,
440 ::xmloff::token::GetXMLToken(
441 XML_TEXT_ALIGN ) ) );
442 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
444 break;
446 case XML_OPTACTION_DRAW_WRITING_MODE:
447 if( IsXMLToken( m_aStyleFamily, XML_GRAPHICS ) )
449 pAttrList->AddAttribute(
450 GetTransformer().GetNamespaceMap().GetQNameByKey(
451 XML_NAMESPACE_DRAW,
452 GetXMLToken( XML_WRITING_MODE ) ), rAttrValue );
454 pAttrList->AddAttribute( rAttrName, rAttrValue );
455 break;
457 case XML_ATACTION_CAPTION_ESCAPE_OASIS:
459 OUString aAttrValue( rAttrValue );
460 if( aAttrValue.indexOf( sal_Unicode('%') ) != -1 )
462 sal_Int32 nValue = 0;
463 ::sax::Converter::convertPercent(nValue, rAttrValue);
464 if( nValue )
466 nValue *= 100;
467 OUStringBuffer aOut;
468 ::sax::Converter::convertPercent(aOut, nValue);
469 aAttrValue = aOut.makeStringAndClear();
472 else
474 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
477 pAttrList->AddAttribute( rAttrName, aAttrValue );
479 break;
481 case XML_ATACTION_DECODE_PROTECT:
483 pAttrList->AddAttribute( rAttrName, rAttrValue );
485 if( rAttrValue.indexOf( GetXMLToken( XML_SIZE ) ) != -1 )
486 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
487 XML_NAMESPACE_DRAW,
488 GetXMLToken( XML_SIZE_PROTECT )), GetXMLToken( XML_TRUE ) );
490 if( rAttrValue.indexOf( GetXMLToken( XML_POSITION ) ) != -1 )
491 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
492 XML_NAMESPACE_DRAW,
493 GetXMLToken( XML_MOVE_PROTECT )), GetXMLToken( XML_TRUE ) );
495 break;
497 case XML_ATACTION_DRAW_MIRROR_OASIS: // renames style:mirror to draw:mirror and adapts values
499 // keep original for writer graphic objects
500 // Adapts attribute values (#i49139#)
501 OUString aNewAttrValue;
502 SvXMLTokenEnumerator aTokenEnum( rAttrValue );
503 OUString aToken;
504 while( aTokenEnum.getNextToken( aToken ) )
506 if ( !aNewAttrValue.isEmpty() )
508 aNewAttrValue += OUString(" " );
511 if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_EVEN ) )
513 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES );
515 else if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_ODD ) )
517 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES );
519 else
521 aNewAttrValue += aToken;
524 pAttrList->AddAttribute( rAttrName, aNewAttrValue );
526 // create old draw:mirror for drawing graphic objects
527 OUString aAttrValue( GetXMLToken( IsXMLToken( rAttrValue, XML_HORIZONTAL ) ? XML_TRUE : XML_FALSE ) );
528 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
529 XML_NAMESPACE_DRAW,
530 GetXMLToken( XML_MIRROR )), aAttrValue );
532 break;
533 case XML_ATACTION_GAMMA_OASIS: // converts percentage value to double
535 sal_Int32 nValue;
536 ::sax::Converter::convertPercent( nValue, rAttrValue );
537 const double fValue = ((double)nValue) / 100.0;
538 pAttrList->AddAttribute( rAttrName, OUString::valueOf( fValue ) );
540 break;
541 case XML_ATACTION_OPACITY_FIX:
543 sal_Int32 nValue;
544 if( rAttrValue.indexOf( sal_Unicode('%') ) != -1 )
546 ::sax::Converter::convertPercent(nValue, rAttrValue);
548 else
550 nValue = sal_Int32( rAttrValue.toDouble() * 100.0 );
552 nValue = 100 - nValue;
554 OUStringBuffer aOut;
555 ::sax::Converter::convertPercent(aOut, nValue);
556 pAttrList->AddAttribute( rAttrName, aOut.makeStringAndClear() );
558 break;
559 default:
560 OSL_ENSURE( !this, "unknown action" );
561 break;
564 else
566 pAttrList->AddAttribute( rAttrName, rAttrValue );
569 if( XML_TOKEN_END != eUnderline )
570 pAttrList->AddAttribute(
571 GetTransformer().GetNamespaceMap().GetQNameByKey(
572 XML_NAMESPACE_STYLE,
573 GetXMLToken( XML_TEXT_UNDERLINE ) ),
574 MergeUnderline( eUnderline, bBoldUnderline,
575 bDoubleUnderline ) );
576 if( XML_TOKEN_END != eLineThrough )
577 pAttrList->AddAttribute(
578 GetTransformer().GetNamespaceMap().GetQNameByKey(
579 XML_NAMESPACE_STYLE,
580 GetXMLToken( XML_TEXT_CROSSING_OUT ) ),
581 MergeLineThrough( eLineThrough, bBoldLineThrough,
582 bDoubleLineThrough, cLineThroughChar ) );
583 if( bIntervalMinorFound )
585 double fIntervalMinor = 0.0;
586 if( nIntervalMinorDivisor != 0)
587 fIntervalMinor = fIntervalMajor / static_cast< double >( nIntervalMinorDivisor );
589 OUStringBuffer aBuf;
590 ::sax::Converter::convertDouble( aBuf, fIntervalMinor );
591 pAttrList->AddAttribute(
592 GetTransformer().GetNamespaceMap().GetQNameByKey(
593 XML_NAMESPACE_CHART,
594 GetXMLToken( XML_INTERVAL_MINOR )),
595 aBuf.makeStringAndClear());
598 // #i25616#
599 if(!aOpacityValueRemember.isEmpty() || !aImageOpacityValueRemember.isEmpty())
601 pAttrList->AddAttribute(
602 GetTransformer().GetNamespaceMap().GetQNameByKey(
603 XML_NAMESPACE_DRAW,
604 GetXMLToken( XML_TRANSPARENCY ) ),
605 !aImageOpacityValueRemember.isEmpty()
606 ? aImageOpacityValueRemember : aOpacityValueRemember );
609 else
611 if( !m_xAttrList.is() )
613 m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
615 else
617 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
618 ->AppendAttributeList( rAttrList );
623 void XMLPropertiesTContext_Impl::Export()
625 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
626 m_xAttrList );
627 ExportContent();
628 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
631 XMLPropType XMLPropertiesTContext_Impl::GetPropType( const OUString& rLocalName )
633 XMLPropType eProp = XML_PROP_TYPE_END;
634 if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
635 eProp = XML_PROP_TYPE_GRAPHIC;
636 else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
637 eProp = XML_PROP_TYPE_DRAWING_PAGE;
638 else if( IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES ) )
639 eProp = XML_PROP_TYPE_PAGE_LAYOUT;
640 else if( IsXMLToken( rLocalName, XML_HEADER_FOOTER_PROPERTIES ) )
641 eProp = XML_PROP_TYPE_HEADER_FOOTER;
642 else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
643 eProp = XML_PROP_TYPE_TEXT;
644 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
645 eProp = XML_PROP_TYPE_PARAGRAPH;
646 else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) )
647 eProp = XML_PROP_TYPE_RUBY;
648 else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
649 eProp = XML_PROP_TYPE_SECTION;
650 else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
651 eProp = XML_PROP_TYPE_TABLE;
652 else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) )
653 eProp = XML_PROP_TYPE_TABLE_COLUMN;
654 else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
655 eProp = XML_PROP_TYPE_TABLE_ROW;
656 else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
657 eProp = XML_PROP_TYPE_TABLE_CELL;
658 else if( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) )
659 eProp = XML_PROP_TYPE_LIST_LEVEL;
660 else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
661 eProp = XML_PROP_TYPE_CHART;
663 return eProp;
666 OUString XMLPropertiesTContext_Impl::MergeUnderline(
667 XMLTokenEnum eUnderline, sal_Bool bBold, sal_Bool bDouble )
669 if( bDouble )
671 switch( eUnderline )
673 case XML_WAVE:
674 eUnderline = XML_DOUBLE_WAVE;
675 break;
676 default:
677 eUnderline = XML_DOUBLE;
678 break;
681 else if( bBold )
683 switch( eUnderline )
685 case XML_NONE:
686 case XML_SOLID:
687 eUnderline = XML_BOLD;
688 break;
689 case XML_DOTTED:
690 eUnderline = XML_BOLD_DOTTED;
691 break;
692 case XML_DASH:
693 eUnderline = XML_BOLD_DASH;
694 break;
695 case XML_LONG_DASH:
696 eUnderline = XML_BOLD_LONG_DASH;
697 break;
698 case XML_DOT_DASH:
699 eUnderline = XML_BOLD_DOT_DASH;
700 break;
701 case XML_DOT_DOT_DASH:
702 eUnderline = XML_BOLD_DOT_DOT_DASH;
703 break;
704 case XML_WAVE:
705 eUnderline = XML_BOLD_WAVE;
706 break;
707 default:
708 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
709 break;
712 else
714 switch( eUnderline )
716 case XML_SOLID:
717 eUnderline = XML_SINGLE;
718 break;
719 case XML_NONE:
720 eUnderline = XML_NONE;
721 break;
722 default:
723 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
724 break;
728 return GetXMLToken( eUnderline );
731 OUString XMLPropertiesTContext_Impl::MergeLineThrough(
732 XMLTokenEnum eLineThrough, sal_Bool bBold, sal_Bool bDouble,
733 sal_Unicode c )
735 if( c )
736 eLineThrough = c=='/' ? XML_SLASH : XML_uX;
737 else if( bDouble )
738 eLineThrough = XML_DOUBLE_LINE;
739 else if( bBold )
740 eLineThrough = XML_THICK_LINE;
741 else if( XML_NONE != eLineThrough )
742 eLineThrough = XML_SINGLE_LINE;
744 return GetXMLToken( eLineThrough );
747 //------------------------------------------------------------------------------
749 TYPEINIT1( XMLStyleOASISTContext, XMLPersElemContentTContext );
751 XMLStyleOASISTContext::XMLStyleOASISTContext( XMLTransformerBase& rImp,
752 const OUString& rQName,
753 sal_Bool bPersistent ) :
754 XMLPersElemContentTContext ( rImp, rQName ),
755 m_bPersistent( bPersistent ),
756 m_bControlStyle( false )
760 XMLStyleOASISTContext::XMLStyleOASISTContext(
761 XMLTransformerBase& rImp,
762 const OUString& rQName,
763 sal_uInt16 nPrefix,
764 ::xmloff::token::XMLTokenEnum eToken,
765 sal_Bool bPersistent ) :
766 XMLPersElemContentTContext( rImp, rQName, nPrefix, eToken ),
767 m_bPersistent( bPersistent )
771 XMLStyleOASISTContext::~XMLStyleOASISTContext()
775 XMLTransformerContext *XMLStyleOASISTContext::CreateChildContext(
776 sal_uInt16 nPrefix,
777 const OUString& rLocalName,
778 const OUString& rQName,
779 const Reference< XAttributeList >& rAttrList )
781 XMLTransformerContext *pContext = 0;
783 if( XML_NAMESPACE_STYLE == nPrefix )
785 XMLPropType ePropType =
786 XMLPropertiesTContext_Impl::GetPropType( rLocalName );
787 if( XML_PROP_TYPE_END != ePropType )
789 // if no properties context exist start a new one.
790 if( !m_xPropContext.is() )
791 m_xPropContext = new XMLPropertiesTContext_Impl(
792 GetTransformer(), rQName, ePropType, m_aStyleFamily, m_bControlStyle );
793 else
794 m_xPropContext->SetQNameAndPropType( rQName, ePropType );
795 pContext = m_xPropContext.get();
798 if( !pContext )
800 // if a properties context exist close it
801 if( m_xPropContext.is() && !m_bPersistent )
803 m_xPropContext->Export();
804 m_xPropContext = 0;
807 pContext = m_bPersistent
808 ? XMLPersElemContentTContext::CreateChildContext(
809 nPrefix, rLocalName, rQName, rAttrList )
810 : XMLTransformerContext::CreateChildContext(
811 nPrefix, rLocalName, rQName, rAttrList );
814 return pContext;
817 void XMLStyleOASISTContext::StartElement(
818 const Reference< XAttributeList >& rAttrList )
820 XMLTransformerActions *pActions =
821 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS );
822 OSL_ENSURE( pActions, "go no actions" );
824 Reference< XAttributeList > xAttrList( rAttrList );
825 XMLMutableAttributeList *pMutableAttrList = 0;
826 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
827 sal_Int16 nFamilyAttr = -1;
828 m_bControlStyle = sal_False;
830 for( sal_Int16 i=0; i < nAttrCount; i++ )
832 const OUString& rAttrName = xAttrList->getNameByIndex( i );
833 OUString aLocalName;
834 sal_uInt16 nPrefix =
835 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
836 &aLocalName );
837 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
838 XMLTransformerActions::const_iterator aIter =
839 pActions->find( aKey );
840 if( !(aIter == pActions->end() ) )
842 if( !pMutableAttrList )
844 pMutableAttrList =
845 new XMLMutableAttributeList( xAttrList );
846 xAttrList = pMutableAttrList;
848 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
849 switch( (*aIter).second.m_nActionType )
851 case XML_ATACTION_STYLE_FAMILY:
852 if( IsXMLToken( rAttrValue, XML_GRAPHIC ) )
854 m_aStyleFamily = GetXMLToken( XML_GRAPHICS ) ;
855 pMutableAttrList->SetValueByIndex( i, m_aStyleFamily );
857 else
859 m_aStyleFamily = rAttrValue;
861 if( IsXMLToken( rAttrValue, XML_PARAGRAPH ) )
862 nFamilyAttr = i;
865 break;
866 case XML_ATACTION_STYLE_DISPLAY_NAME:
867 case XML_ATACTION_REMOVE:
868 pMutableAttrList->RemoveAttributeByIndex( i );
869 --i;
870 --nAttrCount;
871 break;
872 case XML_ATACTION_DECODE_STYLE_NAME:
873 m_bControlStyle = rAttrValue.startsWith( "ctrl" );
874 case XML_ATACTION_DECODE_STYLE_NAME_REF:
876 OUString aAttrValue( rAttrValue );
877 if( GetTransformer().DecodeStyleName(aAttrValue) )
878 pMutableAttrList->SetValueByIndex( i, aAttrValue );
880 break;
881 case XML_ATACTION_IN2INCH:
883 OUString aAttrValue( rAttrValue );
884 if( XMLTransformerBase::ReplaceSingleInWithInch(
885 aAttrValue ) )
886 pMutableAttrList->SetValueByIndex( i, aAttrValue );
888 break;
889 case XML_ATACTION_NEG_PERCENT:
891 OUString aAttrValue( rAttrValue );
892 if( GetTransformer().NegPercent(aAttrValue) )
893 pMutableAttrList->SetValueByIndex( i, aAttrValue );
895 break;
896 case XML_ATACTION_URI_OASIS:
898 OUString aAttrValue( rAttrValue );
899 if( GetTransformer().ConvertURIToOOo( aAttrValue,
900 static_cast< sal_Bool >((*aIter).second.m_nParam1)))
901 pMutableAttrList->SetValueByIndex( i, aAttrValue );
903 break;
904 default:
905 OSL_ENSURE( !this, "unknown action" );
906 break;
911 if( m_bControlStyle && nFamilyAttr != -1 )
912 pMutableAttrList->SetValueByIndex( nFamilyAttr, GetXMLToken( XML_CONTROL ) );
915 if( m_bPersistent )
916 XMLPersElemContentTContext::StartElement( xAttrList );
917 else
918 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
919 xAttrList );
922 void XMLStyleOASISTContext::EndElement()
924 if( m_bPersistent )
926 XMLPersElemContentTContext::EndElement();
928 else
930 // if a properties context exist close it
931 if( m_xPropContext.is() )
933 m_xPropContext->Export();
934 m_xPropContext = 0;
936 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
940 void XMLStyleOASISTContext::Characters( const OUString& )
942 // element content only:
945 void XMLStyleOASISTContext::ExportContent()
947 if( m_xPropContext.is() )
948 m_xPropContext->Export();
949 XMLPersElemContentTContext::ExportContent();
952 sal_Bool XMLStyleOASISTContext::IsPersistent() const
954 return m_bPersistent;
957 XMLTransformerActions *XMLStyleOASISTContext::CreateTransformerActions(
958 sal_uInt16 nType )
960 XMLTransformerActionInit *pInit = 0;
962 switch( nType )
964 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS:
965 pInit = aGraphicPropertyOASISAttrActionTable;
966 break;
967 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS:
968 pInit = aDrawingPagePropertyOASISAttrActionTable;
969 break;
970 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS:
971 pInit = aPageLayoutPropertyOASISAttrActionTable;
972 break;
973 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS:
974 pInit = aHeaderFooterPropertyOASISAttrActionTable;
975 break;
976 case PROP_OASIS_TEXT_ATTR_ACTIONS:
977 pInit = aTextPropertyOASISAttrActionTable;
978 break;
979 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS:
980 pInit = aParagraphPropertyOASISAttrActionTable;
981 break;
982 case PROP_OASIS_SECTION_ATTR_ACTIONS:
983 pInit = aSectionPropertyOASISAttrActionTable;
984 break;
985 case PROP_OASIS_TABLE_ATTR_ACTIONS:
986 pInit = aTablePropertyOASISAttrActionTable;
987 break;
988 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS:
989 pInit = aTableColumnPropertyOASISAttrActionTable;
990 break;
991 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS:
992 pInit = aTableRowPropertyOASISAttrActionTable;
993 break;
994 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS:
995 pInit = aTableCellPropertyOASISAttrActionTable;
996 break;
997 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS:
998 pInit = aListLevelPropertyOASISAttrActionTable;
999 break;
1000 case PROP_OASIS_CHART_ATTR_ACTIONS:
1001 pInit = aChartPropertyOASISAttrActionTable;
1002 break;
1005 XMLTransformerActions *pActions = 0;
1006 if( pInit )
1007 pActions = new XMLTransformerActions( pInit );
1009 return pActions;
1012 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */