bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / StyleOASISTContext.cxx
blob26200f62596229ae23d4f64d68efeb4ab09f45b7
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 <osl/diagnose.h>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include "PropType.hxx"
31 #include "DeepTContext.hxx"
32 #include "ProcAttrTContext.hxx"
33 #include "TransformerBase.hxx"
34 #include "TransformerActions.hxx"
35 #include "ActionMapTypesOASIS.hxx"
36 #include "MutableAttrList.hxx"
37 #include "PropertyActionsOASIS.hxx"
38 #include "StyleOASISTContext.hxx"
39 #include <xmloff/xmluconv.hxx>
41 using namespace ::xmloff::token;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::xml::sax;
45 static const 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 class XMLPropertiesTContext_Impl : public XMLPersElemContentTContext
65 ::com::sun::star::uno::Reference<
66 ::com::sun::star::xml::sax::XAttributeList > m_xAttrList;
68 XMLPropType m_ePropType;
69 bool m_bControlStyle;
70 OUString m_aStyleFamily;
72 public:
74 void SetQNameAndPropType( const OUString& rQName,
75 XMLPropType ePropType )
77 m_ePropType = ePropType;
78 XMLTransformerContext::SetQName( rQName );
81 TYPEINFO_OVERRIDE();
83 XMLPropertiesTContext_Impl( XMLTransformerBase& rTransformer,
84 const OUString& rQName,
85 XMLPropType eP,
86 const OUString& rStyleFamily,
87 bool _bControlStyle = false );
89 virtual ~XMLPropertiesTContext_Impl();
91 virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
93 virtual void Export() SAL_OVERRIDE;
95 static XMLPropType GetPropType( const OUString& rLocalName );
97 static OUString MergeUnderline( XMLTokenEnum eUnderline,
98 bool bBold, bool bDouble );
99 static OUString MergeLineThrough( XMLTokenEnum eLineThrough,
100 bool bBold, bool bDouble,
101 sal_Unicode c );
104 TYPEINIT1( XMLPropertiesTContext_Impl, XMLPersElemContentTContext );
106 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
107 XMLTransformerBase& rImp, const OUString& rQName, XMLPropType eP,
108 const OUString& rStyleFamily, bool _bControlStyle ) :
109 XMLPersElemContentTContext( rImp, rQName, XML_NAMESPACE_STYLE,
110 XML_PROPERTIES),
111 m_ePropType( eP ),
112 m_bControlStyle( _bControlStyle ),
113 m_aStyleFamily( rStyleFamily )
117 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
121 void XMLPropertiesTContext_Impl::StartElement(
122 const Reference< XAttributeList >& rAttrList )
124 XMLTransformerActions *pActions = 0;
125 sal_uInt16 nActionMap = aAttrActionMaps[m_ePropType];
126 if( nActionMap < MAX_OASIS_PROP_ACTIONS )
128 pActions = GetTransformer().GetUserDefinedActions( nActionMap );
129 OSL_ENSURE( pActions, "go no actions" );
132 if( pActions )
134 XMLMutableAttributeList *pAttrList = 0;
135 if( !m_xAttrList.is() )
137 pAttrList = new XMLMutableAttributeList();
138 m_xAttrList = pAttrList;
140 else
142 pAttrList =
143 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
146 XMLTokenEnum eUnderline = XML_TOKEN_END;
147 bool bBoldUnderline = false, bDoubleUnderline = false;
148 XMLTokenEnum eLineThrough = XML_TOKEN_END;
149 bool bBoldLineThrough = false, bDoubleLineThrough = false;
150 sal_Unicode cLineThroughChar = 0;
152 bool bIntervalMinorFound = false;
153 double fIntervalMajor = 0.0;
154 sal_Int32 nIntervalMinorDivisor = 0;
156 // #i25616#
157 OUString aOpacityValueRemember;
158 OUString aImageOpacityValueRemember;
160 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
161 for( sal_Int16 i=0; i < nAttrCount; i++ )
163 const OUString& rAttrName = rAttrList->getNameByIndex( i );
164 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
165 OUString aLocalName;
166 sal_uInt16 nPrefix =
167 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
168 &aLocalName );
170 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
171 XMLTransformerActions::const_iterator aIter =
172 pActions->find( aKey );
173 if( !(aIter == pActions->end() ) )
175 switch( (*aIter).second.m_nActionType )
177 case XML_ATACTION_REMOVE:
178 break;
179 case XML_ATACTION_COPY:
180 pAttrList->AddAttribute( rAttrName, rAttrValue );
181 break;
182 case XML_ATACTION_RENAME:
184 OUString aNewAttrQName(
185 GetTransformer().GetNamespaceMap().GetQNameByKey(
186 (*aIter).second.GetQNamePrefixFromParam1(),
187 ::xmloff::token::GetXMLToken(
188 (*aIter).second.GetQNameTokenFromParam1()) ) );
189 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
191 break;
192 case XML_ATACTION_IN2INCH:
194 OUString aAttrValue( rAttrValue );
195 XMLTransformerBase::ReplaceSingleInWithInch(
196 aAttrValue );
197 pAttrList->AddAttribute( rAttrName, aAttrValue );
199 break;
200 case XML_ATACTION_INS2INCHS:
202 OUString aAttrValue( rAttrValue );
203 XMLTransformerBase::ReplaceInWithInch(
204 aAttrValue );
205 pAttrList->AddAttribute( rAttrName, aAttrValue );
207 break;
208 case XML_ATACTION_DECODE_STYLE_NAME_REF:
210 OUString aAttrValue( rAttrValue );
211 XMLTransformerBase::DecodeStyleName(aAttrValue);
212 pAttrList->AddAttribute( rAttrName, aAttrValue );
214 break;
215 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
217 OUString aNewAttrQName(
218 GetTransformer().GetNamespaceMap().GetQNameByKey(
219 (*aIter).second.GetQNamePrefixFromParam1(),
220 ::xmloff::token::GetXMLToken(
221 (*aIter).second.GetQNameTokenFromParam1()) ) );
222 OUString aAttrValue( rAttrValue );
223 XMLTransformerBase::DecodeStyleName(aAttrValue);
224 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
226 break;
227 case XML_ATACTION_NEG_PERCENT:
229 OUString aAttrValue( rAttrValue );
230 XMLTransformerBase::NegPercent(aAttrValue);
231 pAttrList->AddAttribute( rAttrName, aAttrValue );
233 break;
234 case XML_ATACTION_RENAME_NEG_PERCENT:
236 OUString aNewAttrQName(
237 GetTransformer().GetNamespaceMap().GetQNameByKey(
238 (*aIter).second.GetQNamePrefixFromParam1(),
239 ::xmloff::token::GetXMLToken(
240 (*aIter).second.GetQNameTokenFromParam1()) ) );
241 OUString aAttrValue( rAttrValue );
242 XMLTransformerBase::NegPercent(aAttrValue);
243 pAttrList->AddAttribute( aNewAttrQName, aAttrValue );
245 break;
246 case XML_OPTACTION_LINE_MODE:
248 bool bWordMode =
249 IsXMLToken( rAttrValue, XML_SKIP_WHITE_SPACE );
250 OUString aAttrQName(
251 GetTransformer().GetNamespaceMap().GetQNameByKey(
252 XML_NAMESPACE_FO,
253 GetXMLToken( XML_SCORE_SPACES ) ) );
254 sal_Int16 nIndex =
255 pAttrList->GetIndexByName( aAttrQName );
256 if( -1 != nIndex )
258 if( bWordMode )
260 const OUString& rOldValue =
261 pAttrList->getValueByIndex( nIndex );
262 if( !IsXMLToken( rOldValue, XML_TRUE ) )
264 pAttrList->SetValueByIndex( nIndex,
265 GetXMLToken( XML_TRUE ) );
269 else
271 OUString aAttrValue( GetXMLToken( bWordMode
272 ? XML_FALSE
273 : XML_TRUE ) );
274 pAttrList->AddAttribute( aAttrQName, aAttrValue );
277 break;
278 case XML_OPTACTION_KEEP_WITH_NEXT:
280 OUString aAttrValue( GetXMLToken(
281 IsXMLToken( rAttrValue, XML_ALWAYS )
282 ? XML_TRUE
283 : XML_FALSE) );
284 pAttrList->AddAttribute( rAttrName, aAttrValue );
286 break;
287 case XML_OPTACTION_UNDERLINE_WIDTH:
288 if( IsXMLToken( rAttrValue, XML_BOLD ) )
289 bBoldUnderline = true;
290 break;
291 case XML_OPTACTION_UNDERLINE_TYPE:
292 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
293 bDoubleUnderline = true;
294 break;
295 case XML_OPTACTION_UNDERLINE_STYLE:
296 eUnderline = GetTransformer().GetToken( rAttrValue );
297 break;
298 case XML_OPTACTION_LINETHROUGH_WIDTH:
299 if( IsXMLToken( rAttrValue, XML_BOLD ) )
300 bBoldLineThrough = true;
301 break;
302 case XML_OPTACTION_LINETHROUGH_TYPE:
303 if( IsXMLToken( rAttrValue, XML_DOUBLE ) )
304 bDoubleLineThrough = true;
305 break;
306 case XML_OPTACTION_LINETHROUGH_STYLE:
307 eLineThrough = GetTransformer().GetToken( rAttrValue );
308 break;
309 case XML_OPTACTION_LINETHROUGH_TEXT:
310 if( !rAttrValue.isEmpty() )
311 cLineThroughChar = rAttrValue[0];
312 break;
313 case XML_OPTACTION_INTERPOLATION:
315 // 0: none (default)
316 sal_Int32 nSplineType = 0;
317 if( IsXMLToken( rAttrValue, XML_CUBIC_SPLINE ))
318 nSplineType = 1;
319 else if( IsXMLToken( rAttrValue, XML_B_SPLINE ))
320 nSplineType = 2;
322 pAttrList->AddAttribute(
323 GetTransformer().GetNamespaceMap().GetQNameByKey(
324 XML_NAMESPACE_CHART,
325 GetXMLToken( XML_SPLINES )),
326 OUString::number( nSplineType ));
328 break;
329 case XML_OPTACTION_INTERVAL_MAJOR:
330 pAttrList->AddAttribute( rAttrName, rAttrValue );
331 ::sax::Converter::convertDouble(fIntervalMajor, rAttrValue);
332 break;
333 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR:
334 ::sax::Converter::convertNumber(nIntervalMinorDivisor, rAttrValue);
335 bIntervalMinorFound = true;
336 break;
337 case XML_OPTACTION_SYMBOL_TYPE:
339 // if symbol_type is "named-symbol" the "symbol"
340 // property is set in the action XML_OPTACTION_SYMBOL_NAME
341 sal_Int32 nSymbolType = 0;
342 if( IsXMLToken( rAttrValue, XML_NONE ))
343 nSymbolType = -3;
344 else if( IsXMLToken( rAttrValue, XML_AUTOMATIC ))
345 nSymbolType = -2;
346 else if( IsXMLToken( rAttrValue, XML_IMAGE ))
347 nSymbolType = -1;
349 if( nSymbolType < 0 )
350 pAttrList->AddAttribute(
351 GetTransformer().GetNamespaceMap().GetQNameByKey(
352 XML_NAMESPACE_CHART,
353 GetXMLToken( XML_SYMBOL )),
354 OUString::number( nSymbolType ));
356 break;
357 case XML_OPTACTION_SYMBOL_NAME:
359 // assume "symbol-type" == "named-symbol"
360 sal_Int32 nSymbolType = -3; // NONE
361 // "square" just has an awkward token-name
362 if( IsXMLToken( rAttrValue, XML_GRADIENTSTYLE_SQUARE ))
363 nSymbolType = 0;
364 else if( IsXMLToken( rAttrValue, XML_DIAMOND ))
365 nSymbolType = 1;
366 else if( IsXMLToken( rAttrValue, XML_ARROW_DOWN ))
367 nSymbolType = 2;
368 else if( IsXMLToken( rAttrValue, XML_ARROW_UP ))
369 nSymbolType = 3;
370 else if( IsXMLToken( rAttrValue, XML_ARROW_RIGHT ))
371 nSymbolType = 4;
372 else if( IsXMLToken( rAttrValue, XML_ARROW_LEFT ))
373 nSymbolType = 5;
374 else if( IsXMLToken( rAttrValue, XML_BOW_TIE ))
375 nSymbolType = 6;
376 else if( IsXMLToken( rAttrValue, XML_HOURGLASS ))
377 nSymbolType = 7;
378 else if( IsXMLToken( rAttrValue, XML_CIRCLE ))
379 nSymbolType = 8;
380 else if( IsXMLToken( rAttrValue, XML_STAR ))
381 nSymbolType = 9;
382 else if( IsXMLToken( rAttrValue, XML_X ))
383 nSymbolType = 10;
384 else if( IsXMLToken( rAttrValue, XML_PLUS ))
385 nSymbolType = 11;
386 else if( IsXMLToken( rAttrValue, XML_ASTERISK ))
387 nSymbolType = 12;
388 else if( IsXMLToken( rAttrValue, XML_HORIZONTAL_BAR ))
389 nSymbolType = 13;
390 else if( IsXMLToken( rAttrValue, XML_VERTICAL_BAR ))
391 nSymbolType = 14;
393 if( nSymbolType >= 0 )
394 pAttrList->AddAttribute(
395 GetTransformer().GetNamespaceMap().GetQNameByKey(
396 XML_NAMESPACE_CHART,
397 GetXMLToken( XML_SYMBOL )),
398 OUString::number( nSymbolType ));
400 break;
401 // #i25616#
402 case XML_OPTACTION_OPACITY:
403 aOpacityValueRemember = rAttrValue;
404 XMLTransformerBase::NegPercent(aOpacityValueRemember);
405 break;
407 // #i25616#
408 case XML_OPTACTION_IMAGE_OPACITY:
409 aImageOpacityValueRemember = rAttrValue;
410 XMLTransformerBase::NegPercent(aImageOpacityValueRemember);
411 break;
413 case XML_OPTACTION_KEEP_TOGETHER:
414 pAttrList->AddAttribute(
415 GetTransformer().GetNamespaceMap().GetQNameByKey(
416 XML_NAMESPACE_STYLE,GetXMLToken(XML_BREAK_INSIDE)),
417 GetXMLToken(
418 IsXMLToken( rAttrValue, XML_ALWAYS )
419 ? XML_COLUMNSPLIT_AVOID
420 : XML_COLUMNSPLIT_AUTO ) );
421 break;
423 case XML_OPTACTION_CONTROL_TEXT_ALIGN:
424 if ( m_bControlStyle )
426 OUString aNewAttrQName(
427 GetTransformer().GetNamespaceMap().GetQNameByKey(
428 XML_NAMESPACE_STYLE,
429 ::xmloff::token::GetXMLToken(
430 XML_TEXT_ALIGN ) ) );
431 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
433 else
435 OUString aNewAttrQName(
436 GetTransformer().GetNamespaceMap().GetQNameByKey(
437 XML_NAMESPACE_FO,
438 ::xmloff::token::GetXMLToken(
439 XML_TEXT_ALIGN ) ) );
440 pAttrList->AddAttribute( aNewAttrQName, rAttrValue );
442 break;
444 case XML_OPTACTION_DRAW_WRITING_MODE:
445 if( IsXMLToken( m_aStyleFamily, XML_GRAPHICS ) )
447 pAttrList->AddAttribute(
448 GetTransformer().GetNamespaceMap().GetQNameByKey(
449 XML_NAMESPACE_DRAW,
450 GetXMLToken( XML_WRITING_MODE ) ), rAttrValue );
452 pAttrList->AddAttribute( rAttrName, rAttrValue );
453 break;
455 case XML_ATACTION_CAPTION_ESCAPE_OASIS:
457 OUString aAttrValue( rAttrValue );
458 if( aAttrValue.indexOf( '%' ) != -1 )
460 sal_Int32 nValue = 0;
461 ::sax::Converter::convertPercent(nValue, rAttrValue);
462 if( nValue )
464 nValue *= 100;
465 OUStringBuffer aOut;
466 ::sax::Converter::convertPercent(aOut, nValue);
467 aAttrValue = aOut.makeStringAndClear();
470 else
472 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
475 pAttrList->AddAttribute( rAttrName, aAttrValue );
477 break;
479 case XML_ATACTION_DECODE_PROTECT:
481 pAttrList->AddAttribute( rAttrName, rAttrValue );
483 if( rAttrValue.indexOf( GetXMLToken( XML_SIZE ) ) != -1 )
484 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
485 XML_NAMESPACE_DRAW,
486 GetXMLToken( XML_SIZE_PROTECT )), GetXMLToken( XML_TRUE ) );
488 if( rAttrValue.indexOf( GetXMLToken( XML_POSITION ) ) != -1 )
489 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
490 XML_NAMESPACE_DRAW,
491 GetXMLToken( XML_MOVE_PROTECT )), GetXMLToken( XML_TRUE ) );
493 break;
495 case XML_ATACTION_DRAW_MIRROR_OASIS: // renames style:mirror to draw:mirror and adapts values
497 // keep original for writer graphic objects
498 // Adapts attribute values (#i49139#)
499 OUString aNewAttrValue;
500 SvXMLTokenEnumerator aTokenEnum( rAttrValue );
501 OUString aToken;
502 while( aTokenEnum.getNextToken( aToken ) )
504 if ( !aNewAttrValue.isEmpty() )
506 aNewAttrValue += " ";
509 if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_EVEN ) )
511 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES );
513 else if ( IsXMLToken( aToken, XML_HORIZONTAL_ON_ODD ) )
515 aNewAttrValue += GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES );
517 else
519 aNewAttrValue += aToken;
522 pAttrList->AddAttribute( rAttrName, aNewAttrValue );
524 // create old draw:mirror for drawing graphic objects
525 OUString aAttrValue( GetXMLToken( IsXMLToken( rAttrValue, XML_HORIZONTAL ) ? XML_TRUE : XML_FALSE ) );
526 pAttrList->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
527 XML_NAMESPACE_DRAW,
528 GetXMLToken( XML_MIRROR )), aAttrValue );
530 break;
531 case XML_ATACTION_GAMMA_OASIS: // converts percentage value to double
533 sal_Int32 nValue;
534 ::sax::Converter::convertPercent( nValue, rAttrValue );
535 const double fValue = ((double)nValue) / 100.0;
536 pAttrList->AddAttribute( rAttrName, OUString::number( fValue ) );
538 break;
539 case XML_ATACTION_OPACITY_FIX:
541 sal_Int32 nValue;
542 if( rAttrValue.indexOf( '%' ) != -1 )
544 ::sax::Converter::convertPercent(nValue, rAttrValue);
546 else
548 nValue = sal_Int32( rAttrValue.toDouble() * 100.0 );
550 nValue = 100 - nValue;
552 OUStringBuffer aOut;
553 ::sax::Converter::convertPercent(aOut, nValue);
554 pAttrList->AddAttribute( rAttrName, aOut.makeStringAndClear() );
556 break;
557 default:
558 OSL_ENSURE( false, "unknown action" );
559 break;
562 else
564 pAttrList->AddAttribute( rAttrName, rAttrValue );
567 if( XML_TOKEN_END != eUnderline )
568 pAttrList->AddAttribute(
569 GetTransformer().GetNamespaceMap().GetQNameByKey(
570 XML_NAMESPACE_STYLE,
571 GetXMLToken( XML_TEXT_UNDERLINE ) ),
572 MergeUnderline( eUnderline, bBoldUnderline,
573 bDoubleUnderline ) );
574 if( XML_TOKEN_END != eLineThrough )
575 pAttrList->AddAttribute(
576 GetTransformer().GetNamespaceMap().GetQNameByKey(
577 XML_NAMESPACE_STYLE,
578 GetXMLToken( XML_TEXT_CROSSING_OUT ) ),
579 MergeLineThrough( eLineThrough, bBoldLineThrough,
580 bDoubleLineThrough, cLineThroughChar ) );
581 if( bIntervalMinorFound )
583 double fIntervalMinor = 0.0;
584 if( nIntervalMinorDivisor != 0)
585 fIntervalMinor = fIntervalMajor / static_cast< double >( nIntervalMinorDivisor );
587 OUStringBuffer aBuf;
588 ::sax::Converter::convertDouble( aBuf, fIntervalMinor );
589 pAttrList->AddAttribute(
590 GetTransformer().GetNamespaceMap().GetQNameByKey(
591 XML_NAMESPACE_CHART,
592 GetXMLToken( XML_INTERVAL_MINOR )),
593 aBuf.makeStringAndClear());
596 // #i25616#
597 if(!aOpacityValueRemember.isEmpty() || !aImageOpacityValueRemember.isEmpty())
599 pAttrList->AddAttribute(
600 GetTransformer().GetNamespaceMap().GetQNameByKey(
601 XML_NAMESPACE_DRAW,
602 GetXMLToken( XML_TRANSPARENCY ) ),
603 !aImageOpacityValueRemember.isEmpty()
604 ? aImageOpacityValueRemember : aOpacityValueRemember );
607 else
609 if( !m_xAttrList.is() )
611 m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
613 else
615 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
616 ->AppendAttributeList( rAttrList );
621 void XMLPropertiesTContext_Impl::Export()
623 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
624 m_xAttrList );
625 ExportContent();
626 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
629 XMLPropType XMLPropertiesTContext_Impl::GetPropType( const OUString& rLocalName )
631 XMLPropType eProp = XML_PROP_TYPE_END;
632 if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
633 eProp = XML_PROP_TYPE_GRAPHIC;
634 else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
635 eProp = XML_PROP_TYPE_DRAWING_PAGE;
636 else if( IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES ) )
637 eProp = XML_PROP_TYPE_PAGE_LAYOUT;
638 else if( IsXMLToken( rLocalName, XML_HEADER_FOOTER_PROPERTIES ) )
639 eProp = XML_PROP_TYPE_HEADER_FOOTER;
640 else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
641 eProp = XML_PROP_TYPE_TEXT;
642 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
643 eProp = XML_PROP_TYPE_PARAGRAPH;
644 else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) )
645 eProp = XML_PROP_TYPE_RUBY;
646 else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
647 eProp = XML_PROP_TYPE_SECTION;
648 else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
649 eProp = XML_PROP_TYPE_TABLE;
650 else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) )
651 eProp = XML_PROP_TYPE_TABLE_COLUMN;
652 else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
653 eProp = XML_PROP_TYPE_TABLE_ROW;
654 else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
655 eProp = XML_PROP_TYPE_TABLE_CELL;
656 else if( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) )
657 eProp = XML_PROP_TYPE_LIST_LEVEL;
658 else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
659 eProp = XML_PROP_TYPE_CHART;
661 return eProp;
664 OUString XMLPropertiesTContext_Impl::MergeUnderline(
665 XMLTokenEnum eUnderline, bool bBold, bool bDouble )
667 if( bDouble )
669 switch( eUnderline )
671 case XML_WAVE:
672 eUnderline = XML_DOUBLE_WAVE;
673 break;
674 default:
675 eUnderline = XML_DOUBLE;
676 break;
679 else if( bBold )
681 switch( eUnderline )
683 case XML_NONE:
684 case XML_SOLID:
685 eUnderline = XML_BOLD;
686 break;
687 case XML_DOTTED:
688 eUnderline = XML_BOLD_DOTTED;
689 break;
690 case XML_DASH:
691 eUnderline = XML_BOLD_DASH;
692 break;
693 case XML_LONG_DASH:
694 eUnderline = XML_BOLD_LONG_DASH;
695 break;
696 case XML_DOT_DASH:
697 eUnderline = XML_BOLD_DOT_DASH;
698 break;
699 case XML_DOT_DOT_DASH:
700 eUnderline = XML_BOLD_DOT_DOT_DASH;
701 break;
702 case XML_WAVE:
703 eUnderline = XML_BOLD_WAVE;
704 break;
705 default:
706 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
707 break;
710 else
712 switch( eUnderline )
714 case XML_SOLID:
715 eUnderline = XML_SINGLE;
716 break;
717 case XML_NONE:
718 eUnderline = XML_NONE;
719 break;
720 default:
721 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
722 break;
726 return GetXMLToken( eUnderline );
729 OUString XMLPropertiesTContext_Impl::MergeLineThrough(
730 XMLTokenEnum eLineThrough, bool bBold, bool bDouble,
731 sal_Unicode c )
733 if( c )
734 eLineThrough = c=='/' ? XML_SLASH : XML_uX;
735 else if( bDouble )
736 eLineThrough = XML_DOUBLE_LINE;
737 else if( bBold )
738 eLineThrough = XML_THICK_LINE;
739 else if( XML_NONE != eLineThrough )
740 eLineThrough = XML_SINGLE_LINE;
742 return GetXMLToken( eLineThrough );
745 TYPEINIT1( XMLStyleOASISTContext, XMLPersElemContentTContext );
747 XMLStyleOASISTContext::XMLStyleOASISTContext(XMLTransformerBase& rImp,
748 const OUString& rQName, bool bPersistent)
749 : XMLPersElemContentTContext(rImp, rQName)
750 , m_bPersistent(bPersistent)
751 , m_bControlStyle(false)
755 XMLStyleOASISTContext::XMLStyleOASISTContext(
756 XMLTransformerBase& rImp, const OUString& rQName,
757 sal_uInt16 nPrefix, ::xmloff::token::XMLTokenEnum eToken,
758 bool bPersistent)
759 : XMLPersElemContentTContext(rImp, rQName, nPrefix, eToken)
760 , m_bPersistent(bPersistent)
761 , m_bControlStyle(false)
765 XMLStyleOASISTContext::~XMLStyleOASISTContext()
769 XMLTransformerContext *XMLStyleOASISTContext::CreateChildContext(
770 sal_uInt16 nPrefix,
771 const OUString& rLocalName,
772 const OUString& rQName,
773 const Reference< XAttributeList >& rAttrList )
775 XMLTransformerContext *pContext = 0;
777 if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
779 XMLPropType ePropType =
780 XMLPropertiesTContext_Impl::GetPropType( rLocalName );
781 if( XML_PROP_TYPE_END != ePropType )
783 // if no properties context exist start a new one.
784 if( !m_xPropContext.is() )
785 m_xPropContext = new XMLPropertiesTContext_Impl(
786 GetTransformer(), rQName, ePropType, m_aStyleFamily, m_bControlStyle );
787 else
788 m_xPropContext->SetQNameAndPropType( rQName, ePropType );
789 pContext = m_xPropContext.get();
792 if( !pContext )
794 // if a properties context exist close it
795 if( m_xPropContext.is() && !m_bPersistent )
797 m_xPropContext->Export();
798 m_xPropContext = 0;
801 pContext = m_bPersistent
802 ? XMLPersElemContentTContext::CreateChildContext(
803 nPrefix, rLocalName, rQName, rAttrList )
804 : XMLTransformerContext::CreateChildContext(
805 nPrefix, rLocalName, rQName, rAttrList );
808 return pContext;
811 void XMLStyleOASISTContext::StartElement(
812 const Reference< XAttributeList >& rAttrList )
814 XMLTransformerActions *pActions =
815 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS );
816 OSL_ENSURE( pActions, "go no actions" );
818 Reference< XAttributeList > xAttrList( rAttrList );
819 XMLMutableAttributeList *pMutableAttrList = 0;
820 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
821 sal_Int16 nFamilyAttr = -1;
822 m_bControlStyle = false;
824 for( sal_Int16 i=0; i < nAttrCount; i++ )
826 const OUString& rAttrName = xAttrList->getNameByIndex( i );
827 OUString aLocalName;
828 sal_uInt16 nPrefix =
829 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
830 &aLocalName );
831 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
832 XMLTransformerActions::const_iterator aIter =
833 pActions->find( aKey );
834 if( !(aIter == pActions->end() ) )
836 if( !pMutableAttrList )
838 pMutableAttrList =
839 new XMLMutableAttributeList( xAttrList );
840 xAttrList = pMutableAttrList;
842 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
843 switch( (*aIter).second.m_nActionType )
845 case XML_ATACTION_STYLE_FAMILY:
846 if( IsXMLToken( rAttrValue, XML_GRAPHIC ) )
848 m_aStyleFamily = GetXMLToken( XML_GRAPHICS ) ;
849 pMutableAttrList->SetValueByIndex( i, m_aStyleFamily );
851 else
853 m_aStyleFamily = rAttrValue;
855 if( IsXMLToken( rAttrValue, XML_PARAGRAPH ) )
856 nFamilyAttr = i;
859 break;
860 case XML_ATACTION_STYLE_DISPLAY_NAME:
861 case XML_ATACTION_REMOVE:
862 pMutableAttrList->RemoveAttributeByIndex( i );
863 --i;
864 --nAttrCount;
865 break;
866 case XML_ATACTION_DECODE_STYLE_NAME:
867 m_bControlStyle = rAttrValue.startsWith( "ctrl" );
868 // fall-through
869 case XML_ATACTION_DECODE_STYLE_NAME_REF:
871 OUString aAttrValue( rAttrValue );
872 if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
873 pMutableAttrList->SetValueByIndex( i, aAttrValue );
875 break;
876 case XML_ATACTION_IN2INCH:
878 OUString aAttrValue( rAttrValue );
879 if( XMLTransformerBase::ReplaceSingleInWithInch(
880 aAttrValue ) )
881 pMutableAttrList->SetValueByIndex( i, aAttrValue );
883 break;
884 case XML_ATACTION_NEG_PERCENT:
886 OUString aAttrValue( rAttrValue );
887 if( XMLTransformerBase::NegPercent(aAttrValue) )
888 pMutableAttrList->SetValueByIndex( i, aAttrValue );
890 break;
891 case XML_ATACTION_URI_OASIS:
893 OUString aAttrValue( rAttrValue );
894 if( GetTransformer().ConvertURIToOOo( aAttrValue,
895 static_cast< bool >((*aIter).second.m_nParam1)))
896 pMutableAttrList->SetValueByIndex( i, aAttrValue );
898 break;
899 default:
900 OSL_ENSURE( false, "unknown action" );
901 break;
906 if( m_bControlStyle && nFamilyAttr != -1 )
907 pMutableAttrList->SetValueByIndex( nFamilyAttr, GetXMLToken( XML_CONTROL ) );
909 if( m_bPersistent )
910 XMLPersElemContentTContext::StartElement( xAttrList );
911 else
912 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
913 xAttrList );
916 void XMLStyleOASISTContext::EndElement()
918 if( m_bPersistent )
920 XMLPersElemContentTContext::EndElement();
922 else
924 // if a properties context exist close it
925 if( m_xPropContext.is() )
927 m_xPropContext->Export();
928 m_xPropContext = 0;
930 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
934 void XMLStyleOASISTContext::Characters( const OUString& )
936 // element content only:
939 void XMLStyleOASISTContext::ExportContent()
941 if( m_xPropContext.is() )
942 m_xPropContext->Export();
943 XMLPersElemContentTContext::ExportContent();
946 bool XMLStyleOASISTContext::IsPersistent() const
948 return m_bPersistent;
951 XMLTransformerActions *XMLStyleOASISTContext::CreateTransformerActions(
952 sal_uInt16 nType )
954 XMLTransformerActionInit *pInit = 0;
956 switch( nType )
958 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS:
959 pInit = aGraphicPropertyOASISAttrActionTable;
960 break;
961 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS:
962 pInit = aDrawingPagePropertyOASISAttrActionTable;
963 break;
964 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS:
965 pInit = aPageLayoutPropertyOASISAttrActionTable;
966 break;
967 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS:
968 pInit = aHeaderFooterPropertyOASISAttrActionTable;
969 break;
970 case PROP_OASIS_TEXT_ATTR_ACTIONS:
971 pInit = aTextPropertyOASISAttrActionTable;
972 break;
973 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS:
974 pInit = aParagraphPropertyOASISAttrActionTable;
975 break;
976 case PROP_OASIS_SECTION_ATTR_ACTIONS:
977 pInit = aSectionPropertyOASISAttrActionTable;
978 break;
979 case PROP_OASIS_TABLE_ATTR_ACTIONS:
980 pInit = aTablePropertyOASISAttrActionTable;
981 break;
982 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS:
983 pInit = aTableColumnPropertyOASISAttrActionTable;
984 break;
985 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS:
986 pInit = aTableRowPropertyOASISAttrActionTable;
987 break;
988 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS:
989 pInit = aTableCellPropertyOASISAttrActionTable;
990 break;
991 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS:
992 pInit = aListLevelPropertyOASISAttrActionTable;
993 break;
994 case PROP_OASIS_CHART_ATTR_ACTIONS:
995 pInit = aChartPropertyOASISAttrActionTable;
996 break;
999 XMLTransformerActions *pActions = 0;
1000 if( pInit )
1001 pActions = new XMLTransformerActions( pInit );
1003 return pActions;
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */