1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <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
,
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
;
72 exportLevelStyle( i
, aSeq
, bOutline
);
77 void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel
,
78 const uno::Sequence
<beans::PropertyValue
>& rProps
,
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;
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")
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
;
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
;
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" )
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" );
249 GetExport().CheckAttrList();
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
) );
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
,
282 if (!sSuffix
.isEmpty())
284 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_NUM_SUFFIX
,
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
;
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() );
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
;
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
);
332 SAL_WARN_IF(xGraphic
.is(), "xmloff", "embedded images are not supported by now");
337 // <text:list-level-style-number> or <text:outline-level-style>
339 eElem
= XML_OUTLINE_LEVEL_STYLE
;
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
,
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
,
370 if ( ePosAndSpaceMode
== PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION
)
372 nSpaceBefore
+= nMinLabelWidth
;
373 nMinLabelWidth
= -nMinLabelWidth
;
374 if( nSpaceBefore
!= 0 )
376 OUString sAttr
= GetExport().GetMM100UnitConverter().convertMeasureToXML(
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(
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
;
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
:
425 case VertOrientation::CENTER
:
426 case VertOrientation::LINE_CENTER
:
427 case VertOrientation::CHAR_CENTER
:
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
:
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
;
448 case VertOrientation::LINE_TOP
:
449 case VertOrientation::LINE_CENTER
:
450 case VertOrientation::LINE_BOTTOM
:
453 case VertOrientation::CHAR_TOP
:
454 case VertOrientation::CHAR_CENTER
:
455 case VertOrientation::CHAR_BOTTOM
:
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(
466 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_WIDTH
, sAttr
);
469 if( nImageHeight
> 0 )
471 OUString sAttr
= GetExport().GetMM100UnitConverter().convertMeasureToXML(
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
)
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
,
516 if ( nFirstLineIndent
!= 0 )
518 OUString sAttr
= GetExport().GetMM100UnitConverter().convertMeasureToXML(
520 GetExport().AddAttribute( XML_NAMESPACE_FO
,
525 if ( nIndentAt
!= 0 )
527 OUString sAttr
= GetExport().GetMM100UnitConverter().convertMeasureToXML(
529 GetExport().AddAttribute( XML_NAMESPACE_FO
,
534 SvXMLElementExport
aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE
,
535 XML_LIST_LEVEL_LABEL_ALIGNMENT
,
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
,
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
,
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
,
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
)
595 if (0xffffffff == static_cast<sal_uInt32
>(nColor
))
597 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_USE_WINDOW_FONT_COLOR
, XML_TRUE
);
601 OUStringBuffer sBuffer
;
602 ::sax::Converter::convertColor( sBuffer
, nColor
);
603 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_COLOR
,
604 sBuffer
.makeStringAndClear() );
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
) :
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;
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
;
660 xPropSetInfo
= xPropSet
->getPropertySetInfo();
662 GetExport().CheckAttrList();
665 if( !rName
.isEmpty() )
667 bool bEncoded
= false;
668 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_NAME
,
669 GetExport().EncodeStyleName( rName
, &bEncoded
) );
671 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_DISPLAY_NAME
,
675 // style:hidden="..."
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
);
692 GetExport().AddAttribute( XML_NAMESPACE_TEXT
,
693 XML_CONSECUTIVE_NUMBERING
, XML_TRUE
);
696 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_TEXT
, XML_LIST_STYLE
,
698 exportLevelStyles( rNumRule
);
702 void SvxXMLNumRuleExport::exportStyle( const Reference
< XStyle
>& rStyle
)
704 Reference
< XPropertySet
> xPropSet( rStyle
, UNO_QUERY
);
705 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropSet
->getPropertySetInfo();
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
) )
718 aAny
= xPropSet
->getPropertyValue( gsNumberingRules
);
719 Reference
<XIndexReplace
> xNumRule
;
722 OUString sName
= rStyle
->getName();
724 bool bHidden
= false;
725 if ( xPropSetInfo
->hasPropertyByName( u
"Hidden"_ustr
) )
727 aAny
= xPropSet
->getPropertyValue( u
"Hidden"_ustr
);
731 exportNumberingRule( sName
, bHidden
, xNumRule
);
734 void SvxXMLNumRuleExport::exportOutline()
736 Reference
< XChapterNumberingSupplier
> xCNSupplier( GetExport().GetModel(),
738 SAL_WARN_IF( !xCNSupplier
.is(), "xmloff", "no chapter numbering supplier" );
740 if( !xCNSupplier
.is() )
743 Reference
< XIndexReplace
> xNumRule( xCNSupplier
->getChapterNumberingRules() );
744 SAL_WARN_IF( !xNumRule
.is(), "xmloff", "no chapter numbering rules" );
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
);
771 if (nODFVersion
!= SvtSaveOptions::ODFSVER_010
&&
772 nODFVersion
!= SvtSaveOptions::ODFSVER_011
)
775 GetExport().CheckAttrList();
776 if ( !sOutlineStyleName
.isEmpty() )
778 bool bEncoded
= false;
779 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_NAME
,
780 GetExport().EncodeStyleName( sOutlineStyleName
,
783 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
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
)
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() )
804 Reference
< XNameAccess
> xFamilies( xFamiliesSupp
->getStyleFamilies() );
805 SAL_WARN_IF( !xFamiliesSupp
.is(), "xmloff", "getStyleFamilies() from XModel failed for export!" );
807 if( !xFamilies
.is() )
810 static constexpr OUString
aNumberStyleName( u
"NumberingStyles"_ustr
);
812 Reference
< XIndexAccess
> xStyles
;
813 if( !xFamilies
->hasByName( aNumberStyleName
) )
816 xFamilies
->getByName( aNumberStyleName
) >>= xStyles
;
818 SAL_WARN_IF( !xStyles
.is(), "xmloff", "Style not found for export!" );
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: */