Update git submodules
[LibreOffice.git] / xmloff / source / style / xmlnume.cxx
blob74f7abc366f66283168dce5f4f543b3e0af381c9
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 <sal/config.h>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
24 #include <com/sun/star/style/NumberingType.hpp>
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/container/XIndexReplace.hpp>
27 #include <com/sun/star/awt/XBitmap.hpp>
28 #include <com/sun/star/graphic/XGraphic.hpp>
29 #include <com/sun/star/awt/FontDescriptor.hpp>
30 #include <com/sun/star/text/HoriOrientation.hpp>
31 #include <com/sun/star/text/VertOrientation.hpp>
32 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
33 #include <com/sun/star/text/PositionAndSpaceMode.hpp>
34 #include <com/sun/star/text/LabelFollow.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <o3tl/any.hxx>
39 #include <o3tl/temporary.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <sal/log.hxx>
43 #include <sax/tools/converter.hxx>
45 #include <xmloff/xmlnamespace.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include "fonthdl.hxx"
49 #include <xmloff/xmlnume.hxx>
50 #include <xmloff/xmlexp.hxx>
51 #include <tools/fontenum.hxx>
52 #include <vcl/vclenum.hxx>
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::style;
57 using namespace ::com::sun::star::text;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::beans;
60 using namespace ::xmloff::token;
62 void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< css::container::XIndexReplace > & xNumRule,
63 bool bOutline )
65 sal_Int32 nCount = xNumRule ->getCount();
66 for( sal_Int32 i=0; i<nCount; i++ )
68 uno::Any aEntry( xNumRule->getByIndex( i ) );
69 uno::Sequence<beans::PropertyValue> aSeq;
70 if( aEntry >>= aSeq )
72 exportLevelStyle( i, aSeq, bOutline );
77 void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel,
78 const uno::Sequence<beans::PropertyValue>& rProps,
79 bool bOutline )
81 sal_Int16 eType = NumberingType::CHAR_SPECIAL;
83 sal_Int16 eAdjust = HoriOrientation::LEFT;
84 OUString sPrefix, sSuffix, sListFormat;
85 OUString sTextStyleName;
86 bool bIsLegal = false;
87 bool bHasColor = false;
88 sal_Int32 nColor = 0;
89 sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0;
91 sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0;
93 sal_UCS4 cBullet = 0xf095;
94 OUString sBulletFontName, sBulletFontStyleName ;
95 FontFamily eBulletFontFamily = FAMILY_DONTKNOW;
96 FontPitch eBulletFontPitch = PITCH_DONTKNOW;
97 rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW;
99 uno::Reference<graphic::XGraphic> xGraphic;
101 sal_Int32 nImageWidth = 0, nImageHeight = 0;
102 sal_Int16 eImageVertOrient = VertOrientation::LINE_CENTER;
104 sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
105 sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB;
106 sal_Int32 nListtabStopPosition( 0 );
107 sal_Int32 nFirstLineIndent( 0 );
108 sal_Int32 nIndentAt( 0 );
110 for( const beans::PropertyValue& rProp : rProps )
112 if( rProp.Name == "NumberingType" )
114 rProp.Value >>= eType;
116 else if( rProp.Name == "Prefix" )
118 rProp.Value >>= sPrefix;
120 else if( rProp.Name == "Suffix" )
122 rProp.Value >>= sSuffix;
124 else if (rProp.Name == "ListFormat")
126 rProp.Value >>= sListFormat;
128 else if (rProp.Name == "IsLegal")
130 rProp.Value >>= bIsLegal;
132 else if (rProp.Name == "BulletChar")
134 OUString sValue;
135 rProp.Value >>= sValue;
136 if( !sValue.isEmpty() )
138 cBullet = sValue.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
141 else if( rProp.Name == "BulletRelSize" )
143 rProp.Value >>= nBullRelSize;
145 else if( rProp.Name == "Adjust" )
147 sal_Int16 nValue = 0;
148 rProp.Value >>= nValue;
149 eAdjust = nValue;
151 else if( rProp.Name == "BulletFont" )
153 awt::FontDescriptor rFDesc;
154 if( rProp.Value >>= rFDesc )
156 sBulletFontName = rFDesc.Name;
157 sBulletFontStyleName = rFDesc.StyleName;
158 eBulletFontFamily = static_cast< FontFamily >( rFDesc.Family );
159 eBulletFontPitch = static_cast< FontPitch >( rFDesc.Pitch );
160 eBulletFontEncoding = static_cast<rtl_TextEncoding>(rFDesc.CharSet);
163 else if( rProp.Name == "GraphicBitmap" )
165 uno::Reference<awt::XBitmap> xBitmap;
166 rProp.Value >>= xBitmap;
167 xGraphic.set(xBitmap, uno::UNO_QUERY);
169 else if( rProp.Name == "BulletColor" )
171 rProp.Value >>= nColor;
172 bHasColor = true;
174 else if( rProp.Name == "StartWith" )
176 rProp.Value >>= nStartValue;
178 else if( rProp.Name == "LeftMargin" )
180 rProp.Value >>= nSpaceBefore;
182 else if( rProp.Name == "FirstLineOffset" )
184 rProp.Value >>= nMinLabelWidth;
186 else if( rProp.Name == "SymbolTextDistance" )
188 rProp.Value >>= nMinLabelDist;
190 else if( rProp.Name == "ParentNumbering" )
192 rProp.Value >>= nDisplayLevels;
193 if( nDisplayLevels > nLevel+1 )
194 nDisplayLevels = static_cast<sal_Int16>( nLevel )+1;
196 else if( rProp.Name == "CharStyleName" )
198 rProp.Value >>= sTextStyleName;
200 else if( rProp.Name == "GraphicSize" )
202 awt::Size aSize;
203 if( rProp.Value >>= aSize )
205 nImageWidth = aSize.Width;
206 nImageHeight = aSize.Height;
209 else if( rProp.Name == "VertOrient" )
211 sal_Int16 nValue = 0;
212 rProp.Value >>= nValue;
213 eImageVertOrient = nValue;
215 else if( rProp.Name == "PositionAndSpaceMode" )
217 sal_Int16 nValue = 0;
218 rProp.Value >>= nValue;
219 ePosAndSpaceMode = nValue;
221 else if( rProp.Name == "LabelFollowedBy" )
223 sal_Int16 nValue = 0;
224 rProp.Value >>= nValue;
225 eLabelFollowedBy = nValue;
227 else if( rProp.Name == "ListtabStopPosition" )
229 rProp.Value >>= nListtabStopPosition;
231 else if( rProp.Name == "FirstLineIndent" )
233 rProp.Value >>= nFirstLineIndent;
235 else if( rProp.Name == "IndentAt" )
237 rProp.Value >>= nIndentAt;
241 if( bOutline && (NumberingType::CHAR_SPECIAL == eType ||
242 NumberingType::BITMAP == eType) )
244 SAL_WARN_IF( bOutline, "xmloff",
245 "SvxXMLNumRuleExport::exportLevelStyle: invalid style for outline" );
246 return;
249 GetExport().CheckAttrList();
251 // text:level
252 OUStringBuffer sTmp;
253 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, OUString::number( nLevel + 1 ) );
254 // #i110694#: no style-name on list-level-style-image
255 // #i116149#: neither prefix/suffix
256 if (NumberingType::BITMAP != eType)
258 if (!sTextStyleName.isEmpty())
260 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
261 GetExport().EncodeStyleName( sTextStyleName ) );
263 if (bIsLegal)
265 if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
266 GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_IS_LEGAL, u"true"_ustr);
268 if (!sListFormat.isEmpty())
270 if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
272 // Write only in extended mode: in ODF 1.3 we write only prefix/suffix,
273 // no list format yet available. Praying we did not lost some formatting.
274 GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_NUM_LIST_FORMAT, sListFormat);
277 if (!sPrefix.isEmpty())
279 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
280 sPrefix );
282 if (!sSuffix.isEmpty())
284 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
285 sSuffix );
289 enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER;
290 if( NumberingType::CHAR_SPECIAL == eType )
292 // <text:list-level-style-bullet>
293 eElem = XML_LIST_LEVEL_STYLE_BULLET;
295 if( cBullet )
297 if( cBullet < ' ' )
299 cBullet = 0xF000 + 149;
301 // text:bullet-char="..."
302 sTmp.append(OUString(&cBullet, 1));
303 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR,
304 sTmp.makeStringAndClear() );
306 else
308 // If 'cBullet' is zero, XML_BULLET_CHAR must exist with blank.
309 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR, u""_ustr);
312 else if( NumberingType::BITMAP == eType )
314 // <text:list-level-style-image>
316 eElem = XML_LIST_LEVEL_STYLE_IMAGE;
318 if (xGraphic.is())
320 OUString sUsedMimeType;
321 OUString sInternalURL = GetExport().AddEmbeddedXGraphic(xGraphic, sUsedMimeType);
322 if (!sInternalURL.isEmpty())
324 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sInternalURL);
325 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
326 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
327 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
330 else
332 SAL_WARN_IF(xGraphic.is(), "xmloff", "embedded images are not supported by now");
335 else
337 // <text:list-level-style-number> or <text:outline-level-style>
338 if( bOutline )
339 eElem = XML_OUTLINE_LEVEL_STYLE;
340 else
341 eElem = XML_LIST_LEVEL_STYLE_NUMBER;
343 GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType );
344 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
345 sTmp.makeStringAndClear() );
346 SvXMLUnitConverter::convertNumLetterSync( sTmp, eType );
347 if( !sTmp.isEmpty() )
348 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
349 XML_NUM_LETTER_SYNC,
350 sTmp.makeStringAndClear() );
352 if( nStartValue != 1 )
354 sTmp.append( static_cast<sal_Int32>(nStartValue) );
355 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
356 sTmp.makeStringAndClear() );
358 if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType )
360 sTmp.append( static_cast<sal_Int32>(nDisplayLevels) );
361 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS,
362 sTmp.makeStringAndClear() );
367 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
368 true, true );
370 if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
372 nSpaceBefore += nMinLabelWidth;
373 nMinLabelWidth = -nMinLabelWidth;
374 if( nSpaceBefore != 0 )
376 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
377 nSpaceBefore );
378 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE, sAttr );
380 if( nMinLabelWidth != 0 )
382 OUString s = GetExport().GetMM100UnitConverter().convertMeasureToXML( nMinLabelWidth );
383 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH, s);
385 if( nMinLabelDist > 0 )
387 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
388 nMinLabelDist );
389 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE, sAttr);
392 /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
393 are allowed to be exported. (#i89178#)
395 else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
396 mbExportPositionAndSpaceModeLabelAlignment )
398 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
399 XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
400 XML_LABEL_ALIGNMENT );
402 if( HoriOrientation::LEFT != eAdjust )
404 enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
405 switch( eAdjust )
407 case HoriOrientation::RIGHT: eValue = XML_END; break;
408 case HoriOrientation::CENTER: eValue = XML_CENTER; break;
410 if( eValue != XML_TOKEN_INVALID )
411 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue );
414 if( NumberingType::BITMAP == eType )
416 enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
417 switch( eImageVertOrient )
419 case VertOrientation::BOTTOM: // yes, it's OK: BOTTOM means that the baseline
420 // hits the frame at its topmost position
421 case VertOrientation::LINE_TOP:
422 case VertOrientation::CHAR_TOP:
423 eValue = XML_TOP;
424 break;
425 case VertOrientation::CENTER:
426 case VertOrientation::LINE_CENTER:
427 case VertOrientation::CHAR_CENTER:
428 eValue = XML_MIDDLE;
429 break;
430 case VertOrientation::TOP: // yes, it's OK: TOP means that the baseline
431 // hits the frame at its bottommost position
432 case VertOrientation::LINE_BOTTOM:
433 case VertOrientation::CHAR_BOTTOM:
434 eValue = XML_BOTTOM;
435 break;
437 if( eValue != XML_TOKEN_INVALID )
438 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue );
440 eValue = XML_TOKEN_INVALID;
441 switch( eImageVertOrient )
443 case VertOrientation::TOP:
444 case VertOrientation::CENTER:
445 case VertOrientation::BOTTOM:
446 eValue = XML_BASELINE;
447 break;
448 case VertOrientation::LINE_TOP:
449 case VertOrientation::LINE_CENTER:
450 case VertOrientation::LINE_BOTTOM:
451 eValue = XML_LINE;
452 break;
453 case VertOrientation::CHAR_TOP:
454 case VertOrientation::CHAR_CENTER:
455 case VertOrientation::CHAR_BOTTOM:
456 eValue = XML_CHAR;
457 break;
459 if( eValue != XML_TOKEN_INVALID )
460 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue );
462 if( nImageWidth > 0 )
464 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
465 nImageWidth );
466 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH, sAttr );
469 if( nImageHeight > 0 )
471 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
472 nImageHeight );
473 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT, sAttr );
478 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
479 XML_LIST_LEVEL_PROPERTIES, true, true );
481 /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
482 are allowed to be exported. (#i89178#)
484 if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
485 mbExportPositionAndSpaceModeLabelAlignment )
487 enum XMLTokenEnum eValue = XML_LISTTAB;
488 if ( eLabelFollowedBy == LabelFollow::SPACE )
490 eValue = XML_SPACE;
492 else if ( eLabelFollowedBy == LabelFollow::NOTHING )
494 eValue = XML_NOTHING;
496 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
497 XML_LABEL_FOLLOWED_BY, eValue );
499 if (eLabelFollowedBy == LabelFollow::NEWLINE)
501 eValue = XML_NEWLINE;
502 GetExport().AddAttribute( XML_NAMESPACE_LO_EXT,
503 XML_LABEL_FOLLOWED_BY, eValue );
506 if ( eLabelFollowedBy == LabelFollow::LISTTAB &&
507 nListtabStopPosition > 0 )
509 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
510 nListtabStopPosition );
511 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
512 XML_LIST_TAB_STOP_POSITION,
513 sAttr );
516 if ( nFirstLineIndent != 0 )
518 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
519 nFirstLineIndent );
520 GetExport().AddAttribute( XML_NAMESPACE_FO,
521 XML_TEXT_INDENT,
522 sAttr );
525 if ( nIndentAt != 0 )
527 OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML(
528 nIndentAt );
529 GetExport().AddAttribute( XML_NAMESPACE_FO,
530 XML_MARGIN_LEFT,
531 sAttr );
534 SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE,
535 XML_LIST_LEVEL_LABEL_ALIGNMENT,
536 true, true );
540 if( NumberingType::CHAR_SPECIAL == eType )
542 if( !sBulletFontName.isEmpty() )
544 OUString sStyleName =
545 GetExport().GetFontAutoStylePool()->Find(
546 sBulletFontName, sBulletFontStyleName,
547 eBulletFontFamily, eBulletFontPitch,
548 eBulletFontEncoding );
550 if( !sStyleName.isEmpty() )
552 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
553 XML_FONT_NAME,
554 sStyleName );
556 else
558 OUString sTemp;
560 const SvXMLUnitConverter& rUnitConv =
561 GetExport().GetMM100UnitConverter();
562 XMLFontFamilyNamePropHdl aFamilyNameHdl;
563 if( aFamilyNameHdl.exportXML( sTemp, Any(sBulletFontName), rUnitConv ) )
564 GetExport().AddAttribute( XML_NAMESPACE_FO,
565 XML_FONT_FAMILY, sTemp );
567 if( !sBulletFontStyleName.isEmpty() )
568 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
569 XML_FONT_STYLE_NAME,
570 sBulletFontStyleName );
572 XMLFontFamilyPropHdl aFamilyHdl;
573 if( aFamilyHdl.exportXML( sTemp, Any(static_cast<sal_Int16>(eBulletFontFamily)), rUnitConv ) )
574 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
575 XML_FONT_FAMILY_GENERIC,
576 sTemp );
578 XMLFontPitchPropHdl aPitchHdl;
579 if( aPitchHdl.exportXML( sTemp, Any(static_cast<sal_Int16>(eBulletFontPitch)), rUnitConv ) )
580 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
581 XML_FONT_PITCH, sTemp );
583 XMLFontEncodingPropHdl aEncHdl;
584 if( aEncHdl.exportXML( sTemp, Any(static_cast<sal_Int16>(eBulletFontEncoding)), rUnitConv ) )
585 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
586 XML_FONT_CHARSET, sTemp );
590 if( NumberingType::BITMAP != eType )
592 // fo:color = "#..."
593 if( bHasColor )
595 if (0xffffffff == static_cast<sal_uInt32>(nColor))
597 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE );
599 else
601 OUStringBuffer sBuffer;
602 ::sax::Converter::convertColor( sBuffer, nColor );
603 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR,
604 sBuffer.makeStringAndClear() );
607 // fo:height="...%"
608 if( nBullRelSize )
610 ::sax::Converter::convertPercent( sTmp, nBullRelSize );
611 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE,
612 sTmp.makeStringAndClear() );
615 if( GetExport().GetAttrList().getLength() > 0 )
617 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
618 XML_TEXT_PROPERTIES, true, true );
620 if (xGraphic.is() && NumberingType::BITMAP == eType)
622 // optional office:binary-data
623 GetExport().AddEmbeddedXGraphicAsBase64(xGraphic);
629 constexpr OUStringLiteral gsNumberingRules( u"NumberingRules" );
630 constexpr OUString gsIsPhysical( u"IsPhysical"_ustr );
631 constexpr OUString gsIsContinuousNumbering( u"IsContinuousNumbering"_ustr );
633 SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) :
634 m_rExport( rExp ),
635 // Let list style creation depend on Load/Save option "ODF format version" (#i89178#)
636 mbExportPositionAndSpaceModeLabelAlignment( true )
638 switch (GetExport().getSaneDefaultVersion())
640 case SvtSaveOptions::ODFSVER_010:
641 case SvtSaveOptions::ODFSVER_011:
643 mbExportPositionAndSpaceModeLabelAlignment = false;
645 break;
646 default: // >= ODFSVER_012
648 mbExportPositionAndSpaceModeLabelAlignment = true;
653 void SvxXMLNumRuleExport::exportNumberingRule(
654 const OUString& rName, bool bIsHidden,
655 const Reference< XIndexReplace >& rNumRule )
657 Reference< XPropertySet > xPropSet( rNumRule, UNO_QUERY );
658 Reference< XPropertySetInfo > xPropSetInfo;
659 if( xPropSet.is() )
660 xPropSetInfo = xPropSet->getPropertySetInfo();
662 GetExport().CheckAttrList();
664 // style:name="..."
665 if( !rName.isEmpty() )
667 bool bEncoded = false;
668 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
669 GetExport().EncodeStyleName( rName, &bEncoded ) );
670 if( bEncoded )
671 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
672 rName);
675 // style:hidden="..."
676 if (bIsHidden
677 && GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
679 GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDDEN, u"true"_ustr);
680 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_HIDDEN, u"true"_ustr); // FIXME for compatibility
683 // text:consecutive-numbering="..."
684 bool bContNumbering = false;
685 if( xPropSetInfo.is() &&
686 xPropSetInfo->hasPropertyByName( gsIsContinuousNumbering ) )
688 Any aAny( xPropSet->getPropertyValue( gsIsContinuousNumbering ) );
689 bContNumbering = *o3tl::doAccess<bool>(aAny);
691 if( bContNumbering )
692 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
693 XML_CONSECUTIVE_NUMBERING, XML_TRUE );
696 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE ,
697 true, true );
698 exportLevelStyles( rNumRule );
702 void SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle )
704 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
705 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
707 Any aAny;
709 // Don't export styles that aren't existing really. This may be the
710 // case for StarOffice Writer's pool styles.
711 if( xPropSetInfo->hasPropertyByName( gsIsPhysical ) )
713 aAny = xPropSet->getPropertyValue( gsIsPhysical );
714 if( !*o3tl::doAccess<bool>(aAny) )
715 return;
718 aAny = xPropSet->getPropertyValue( gsNumberingRules );
719 Reference<XIndexReplace> xNumRule;
720 aAny >>= xNumRule;
722 OUString sName = rStyle->getName();
724 bool bHidden = false;
725 if ( xPropSetInfo->hasPropertyByName( u"Hidden"_ustr ) )
727 aAny = xPropSet->getPropertyValue( u"Hidden"_ustr );
728 aAny >>= bHidden;
731 exportNumberingRule( sName, bHidden, xNumRule );
734 void SvxXMLNumRuleExport::exportOutline()
736 Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(),
737 UNO_QUERY );
738 SAL_WARN_IF( !xCNSupplier.is(), "xmloff", "no chapter numbering supplier" );
740 if( !xCNSupplier.is() )
741 return;
743 Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() );
744 SAL_WARN_IF( !xNumRule.is(), "xmloff", "no chapter numbering rules" );
746 if( !xNumRule.is() )
747 return;
749 /* Outline style has property style:name since ODF 1.2
750 Thus, export this property and adjust fix for issue #i69627# (#i90780#)
752 OUString sOutlineStyleName;
754 Reference<XPropertySet> xNumRulePropSet(
755 xCNSupplier->getChapterNumberingRules(), UNO_QUERY );
756 if (xNumRulePropSet.is())
758 xNumRulePropSet->getPropertyValue( u"Name"_ustr ) >>= sOutlineStyleName;
761 const SvtSaveOptions::ODFSaneDefaultVersion nODFVersion =
762 GetExport().getSaneDefaultVersion();
763 if ((nODFVersion == SvtSaveOptions::ODFSVER_010 ||
764 nODFVersion == SvtSaveOptions::ODFSVER_011)
765 && GetExport().writeOutlineStyleAsNormalListStyle())
767 exportNumberingRule( sOutlineStyleName, false, xNumRule );
769 else
771 if (nODFVersion != SvtSaveOptions::ODFSVER_010 &&
772 nODFVersion != SvtSaveOptions::ODFSVER_011)
774 // style:name="..."
775 GetExport().CheckAttrList();
776 if ( !sOutlineStyleName.isEmpty() )
778 bool bEncoded = false;
779 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
780 GetExport().EncodeStyleName( sOutlineStyleName,
781 &bEncoded ) );
782 if( bEncoded )
783 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
784 XML_DISPLAY_NAME,
785 sOutlineStyleName );
788 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
789 XML_OUTLINE_STYLE, true, true );
790 exportLevelStyles( xNumRule, true );
794 void SvxXMLNumRuleExport::exportStyles( bool bUsed, bool bExportChapterNumbering )
796 if( bExportChapterNumbering )
797 exportOutline();
799 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
800 SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff", "No XStyleFamiliesSupplier from XModel for export!" );
801 if( !xFamiliesSupp.is() )
802 return;
804 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
805 SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff", "getStyleFamilies() from XModel failed for export!" );
807 if( !xFamilies.is() )
808 return;
810 static constexpr OUString aNumberStyleName( u"NumberingStyles"_ustr );
812 Reference< XIndexAccess > xStyles;
813 if( !xFamilies->hasByName( aNumberStyleName ) )
814 return;
816 xFamilies->getByName( aNumberStyleName ) >>= xStyles;
818 SAL_WARN_IF( !xStyles.is(), "xmloff", "Style not found for export!" );
820 if( !xStyles.is() )
821 return;
823 const sal_Int32 nStyles = xStyles->getCount();
825 for( sal_Int32 i=0; i < nStyles; i++ )
827 Reference< XStyle > xStyle;
828 xStyles->getByIndex( i ) >>= xStyle;
830 if( !bUsed || xStyle->isInUse() )
831 exportStyle( xStyle );
836 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */