merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / xmlnume.cxx
blob2c86ee70f0977794f923db0f1542c092e887e8ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlnume.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <rtl/ustrbuf.hxx>
34 #include <tools/debug.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #ifndef _XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX
40 #include "fonthdl.hxx"
41 #endif
42 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
43 #include <com/sun/star/style/NumberingType.hpp>
44 #include <com/sun/star/style/XStyle.hpp>
45 #include <com/sun/star/container/XNameContainer.hpp>
46 #include <com/sun/star/container/XIndexReplace.hpp>
47 #include <com/sun/star/awt/XBitmap.hpp>
48 #include <com/sun/star/awt/FontDescriptor.hpp>
49 #include <com/sun/star/text/HoriOrientation.hpp>
50 #include <com/sun/star/text/VertOrientation.hpp>
51 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
52 // --> OD 2008-01-16 #newlistlevelattrs#
53 #include <com/sun/star/text/PositionAndSpaceMode.hpp>
54 #include <com/sun/star/text/LabelFollow.hpp>
55 // <--
56 #include <com/sun/star/beans/PropertyValue.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include "XMLTextListAutoStylePool.hxx"
59 #include <xmloff/xmlnume.hxx>
60 #include <xmloff/xmlexp.hxx>
61 #include <vcl/vclenum.hxx>
63 using ::rtl::OUString;
64 using ::rtl::OUStringBuffer;
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::style;
69 using namespace ::com::sun::star::text;
70 using namespace ::com::sun::star::container;
71 using namespace ::com::sun::star::beans;
72 using namespace ::xmloff::token;
74 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE[] = "SymbolTextDistance";
75 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_PARENT_NUMBERING[] = "ParentNumbering";
76 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_CHAR_STYLE_NAME[] = "CharStyleName";
77 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_BULLET_CHAR[] = "BulletChar";
78 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_BULLET_RELSIZE[] = "BulletRelSize";
79 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_BULLET_COLOR[] = "BulletColor";
80 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_GRAPHIC_BITMAP[] = "GraphicBitmap";
81 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_GRAPHIC_SIZE[] = "GraphicSize";
82 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_VERT_ORIENT[] = "VertOrient";
83 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_NUMBERINGTYPE[] = "NumberingType";
84 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_HEADING_STYLE_NAME[] = "HeadingStyleName";
85 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_PREFIX[] = "Prefix";
86 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_SUFFIX[] = "Suffix";
87 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_ADJUST[] = "Adjust";
88 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_LEFT_MARGIN[] = "LeftMargin";
89 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET[] = "FirstLineOffset";
90 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_BULLET_FONT[] = "BulletFont";
91 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_GRAPHICURL[] = "GraphicURL";
92 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_START_WITH[] = "StartWith";
93 // --> OD 2008-01-15 #newlistlevelattrs#
94 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE[] = "PositionAndSpaceMode";
95 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY[] = "LabelFollowedBy";
96 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION[] = "ListtabStopPosition";
97 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_FIRST_LINE_INDENT[] = "FirstLineIndent";
98 static sal_Char __READONLY_DATA XML_UNO_NAME_NRULE_INDENT_AT[] = "IndentAt";
99 // <--
101 void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< ::com::sun::star::container::XIndexReplace > & xNumRule,
102 sal_Bool bOutline )
104 sal_Int32 nCount = xNumRule ->getCount();
105 for( sal_Int32 i=0; i<nCount; i++ )
107 uno::Any aEntry( xNumRule->getByIndex( i ) );
108 uno::Sequence<beans::PropertyValue> aSeq;
109 if( aEntry >>= aSeq )
111 exportLevelStyle( i, aSeq, bOutline );
116 void SvxXMLNumRuleExport::exportLevelStyle( INT32 nLevel,
117 const uno::Sequence<beans::PropertyValue>& rProps,
118 BOOL bOutline )
120 sal_Int16 eType = NumberingType::CHAR_SPECIAL;
122 sal_Int16 eAdjust = HoriOrientation::LEFT;
123 OUString sPrefix, sSuffix;
124 OUString sTextStyleName;
125 sal_Bool bHasColor = sal_False;
126 sal_Int32 nColor = 0;
127 sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0;
129 sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0;
131 sal_Unicode cBullet = 0xf095;
132 OUString sBulletFontName, sBulletFontStyleName ;
133 sal_Int16 eBulletFontFamily = FAMILY_DONTKNOW;
134 sal_Int16 eBulletFontPitch = PITCH_DONTKNOW;
135 rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW;
137 OUString sImageURL;
138 uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap;
139 sal_Int32 nImageWidth = 0, nImageHeight = 0;
140 sal_Int16 eImageVertOrient = VertOrientation::LINE_CENTER;
142 // --> OD 2008-01-15 #newlistlevelattrs#
143 sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
144 sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB;
145 sal_Int32 nListtabStopPosition( 0 );
146 sal_Int32 nFirstLineIndent( 0 );
147 sal_Int32 nIndentAt( 0 );
148 // <--
150 const sal_Int32 nCount = rProps.getLength();
151 const beans::PropertyValue* pPropArray = rProps.getConstArray();
152 for( sal_Int32 i=0; i<nCount; i++ )
154 const beans::PropertyValue& rProp = pPropArray[i];
156 if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_NUMBERINGTYPE, sizeof(XML_UNO_NAME_NRULE_NUMBERINGTYPE)-1 ) )
158 rProp.Value >>= eType;
160 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PREFIX, sizeof(XML_UNO_NAME_NRULE_PREFIX)-1 ) )
162 rProp.Value >>= sPrefix;
164 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SUFFIX, sizeof(XML_UNO_NAME_NRULE_SUFFIX)-1 ) )
166 rProp.Value >>= sSuffix;
168 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_CHAR, sizeof(XML_UNO_NAME_NRULE_BULLET_CHAR)-1 ) )
170 OUString sValue;
171 rProp.Value >>= sValue;
172 if( sValue.getLength() > 0 )
174 cBullet = (sal_Unicode)sValue[0];
177 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_RELSIZE, sizeof(XML_UNO_NAME_NRULE_BULLET_RELSIZE)-1 ) )
179 rProp.Value >>= nBullRelSize;
181 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_ADJUST, sizeof(XML_UNO_NAME_NRULE_ADJUST)-1 ) )
183 sal_Int16 nValue = 0;
184 rProp.Value >>= nValue;
185 eAdjust = nValue;
187 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_FONT, sizeof(XML_UNO_NAME_NRULE_BULLET_FONT)-1 ) )
189 awt::FontDescriptor rFDesc;
190 if( rProp.Value >>= rFDesc )
192 sBulletFontName = rFDesc.Name;
193 sBulletFontStyleName = rFDesc.StyleName;
194 eBulletFontFamily = (sal_Int16)rFDesc.Family;
195 eBulletFontPitch = (sal_Int16)rFDesc.Pitch;
196 eBulletFontEncoding = (rtl_TextEncoding)rFDesc.CharSet;
199 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHICURL, sizeof(XML_UNO_NAME_NRULE_GRAPHICURL)-1 ) )
201 rProp.Value >>= sImageURL;
203 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_BITMAP, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_BITMAP)-1 ) )
205 rProp.Value >>= xBitmap;
207 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_COLOR, sizeof(XML_UNO_NAME_NRULE_BULLET_COLOR)-1 ) )
209 rProp.Value >>= nColor;
210 bHasColor = sal_True;
212 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_START_WITH, sizeof(XML_UNO_NAME_NRULE_START_WITH)-1 ) )
214 rProp.Value >>= nStartValue;
216 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LEFT_MARGIN, sizeof(XML_UNO_NAME_NRULE_LEFT_MARGIN)-1 ) )
218 rProp.Value >>= nSpaceBefore;
220 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET, sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET)-1 ) )
222 rProp.Value >>= nMinLabelWidth;
224 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE, sizeof(XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE)-1 ) )
226 rProp.Value >>= nMinLabelDist;
228 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PARENT_NUMBERING, sizeof(XML_UNO_NAME_NRULE_PARENT_NUMBERING)-1 ) )
230 rProp.Value >>= nDisplayLevels;
231 if( nDisplayLevels > nLevel+1 )
232 nDisplayLevels = static_cast<sal_Int16>( nLevel )+1;
234 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_CHAR_STYLE_NAME, sizeof(XML_UNO_NAME_NRULE_CHAR_STYLE_NAME)-1 ) )
236 rProp.Value >>= sTextStyleName;
238 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_SIZE, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_SIZE)-1 ) )
240 awt::Size aSize;
241 if( rProp.Value >>= aSize )
243 nImageWidth = aSize.Width;
244 nImageHeight = aSize.Height;
247 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_VERT_ORIENT, sizeof(XML_UNO_NAME_NRULE_VERT_ORIENT)-1 ) )
249 sal_Int16 nValue = 0;
250 rProp.Value >>= nValue;
251 eImageVertOrient = nValue;
253 // --> OD 2008-01-16 #newlistlevelattrs#
254 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE,
255 sizeof(XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE)-1 ) )
257 sal_Int16 nValue = 0;
258 rProp.Value >>= nValue;
259 ePosAndSpaceMode = nValue;
261 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY,
262 sizeof(XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY)-1 ) )
264 sal_Int16 nValue = 0;
265 rProp.Value >>= nValue;
266 eLabelFollowedBy = nValue;
268 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION,
269 sizeof(XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION)-1 ) )
271 rProp.Value >>= nListtabStopPosition;
273 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_INDENT,
274 sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_INDENT)-1 ) )
276 rProp.Value >>= nFirstLineIndent;
278 else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_INDENT_AT,
279 sizeof(XML_UNO_NAME_NRULE_INDENT_AT)-1 ) )
281 rProp.Value >>= nIndentAt;
283 // <--
286 if( bOutline && (NumberingType::CHAR_SPECIAL == eType ||
287 NumberingType::BITMAP == eType) )
289 DBG_ASSERT( !bOutline,
290 "SvxXMLNumRuleExport::exportLevelStyle: invalid style for outline" );
291 return;
294 GetExport().CheckAttrList();
296 // text:level
297 OUStringBuffer sTmp;
298 sTmp.append( nLevel + 1 );
299 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, sTmp.makeStringAndClear() );
300 if( sTextStyleName.getLength() > 0 )
301 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
302 GetExport().EncodeStyleName( sTextStyleName ) );
303 if( sPrefix.getLength() > 0 )
304 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX, sPrefix );
305 if( sSuffix.getLength() > 0 )
306 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, sSuffix );
308 enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER;
309 if( NumberingType::CHAR_SPECIAL == eType )
311 // <text:list-level-style-bullet>
312 eElem = XML_LIST_LEVEL_STYLE_BULLET;
314 if( cBullet )
316 if( cBullet < ' ' )
318 cBullet = 0xF000 + 149;
320 // text:bullet-char="..."
321 sTmp.append( cBullet );
322 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR,
323 sTmp.makeStringAndClear() );
327 else if( NumberingType::BITMAP == eType )
329 // <text:list-level-style-image>
331 eElem = XML_LIST_LEVEL_STYLE_IMAGE;
334 if( sImageURL.getLength() )
336 OUString sURL( GetExport().AddEmbeddedGraphicObject( sImageURL ) );
337 if( sURL.getLength() )
339 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL );
341 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
342 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
343 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
346 else
348 DBG_ASSERT( !xBitmap.is(),
349 "embedded images are not supported by now" );
352 else
354 // <text:list-level-style-number> or <text:outline-level-style>
355 if( bOutline )
356 eElem = XML_OUTLINE_LEVEL_STYLE;
357 else
358 eElem = XML_LIST_LEVEL_STYLE_NUMBER;
360 GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType );
361 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
362 sTmp.makeStringAndClear() );
363 GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp, eType );
364 if( sTmp.getLength() )
365 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
366 XML_NUM_LETTER_SYNC,
367 sTmp.makeStringAndClear() );
369 if( nStartValue != 1 )
371 sTmp.append( (sal_Int32)nStartValue );
372 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
373 sTmp.makeStringAndClear() );
375 if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType )
377 sTmp.append( (sal_Int32)nDisplayLevels );
378 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS,
379 sTmp.makeStringAndClear() );
384 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
385 sal_True, sal_True );
387 // --> OD 2008-01-16 #newlistlevelattrs#
388 OUStringBuffer sBuffer;
389 if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
391 // --> OD 2008-06-05 #i89178#
392 // optimization of XML stream size:
393 // suppress export of property list-level-position-and-space-mode,
394 // if its value is "label-width-and-position" - its the default value
395 // GetExport().AddAttribute( XML_NAMESPACE_TEXT,
396 // XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
397 // XML_LABEL_WIDTH_AND_POSITION );
398 // <--
400 nSpaceBefore += nMinLabelWidth;
401 nMinLabelWidth = -nMinLabelWidth;
402 if( nSpaceBefore != 0 )
404 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nSpaceBefore );
405 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE,
406 sBuffer.makeStringAndClear() );
408 if( nMinLabelWidth != 0 )
410 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nMinLabelWidth );
411 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH,
412 sBuffer.makeStringAndClear() );
414 if( nMinLabelDist > 0 )
416 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nMinLabelDist );
417 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE,
418 sBuffer.makeStringAndClear() );
421 // --> OD 2008-06-06 #i89178#
422 // check, if properties for position-and-space-mode LABEL_ALIGNMENT
423 // are allowed to be exported.
424 else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
425 mbExportPositionAndSpaceModeLabelAlignment )
426 // <--
428 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
429 XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
430 XML_LABEL_ALIGNMENT );
432 // <--
433 if( HoriOrientation::LEFT != eAdjust )
435 enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
436 switch( eAdjust )
438 case HoriOrientation::RIGHT: eValue = XML_END; break;
439 case HoriOrientation::CENTER: eValue = XML_CENTER; break;
441 if( eValue != XML_TOKEN_INVALID )
442 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue );
445 if( NumberingType::BITMAP == eType )
447 enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
448 switch( eImageVertOrient )
450 case VertOrientation::BOTTOM: // yes, its OK: BOTTOM means that the baseline
451 // hits the frame at its topmost position
452 case VertOrientation::LINE_TOP:
453 case VertOrientation::CHAR_TOP:
454 eValue = XML_TOP;
455 break;
456 case VertOrientation::CENTER:
457 case VertOrientation::LINE_CENTER:
458 case VertOrientation::CHAR_CENTER:
459 eValue = XML_MIDDLE;
460 break;
461 case VertOrientation::TOP: // yes, its OK: TOP means that the baseline
462 // hits the frame at its bottommost position
463 case VertOrientation::LINE_BOTTOM:
464 case VertOrientation::CHAR_BOTTOM:
465 eValue = XML_BOTTOM;
466 break;
468 if( eValue != XML_TOKEN_INVALID )
469 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue );
471 eValue = XML_TOKEN_INVALID;
472 switch( eImageVertOrient )
474 case VertOrientation::TOP:
475 case VertOrientation::CENTER:
476 case VertOrientation::BOTTOM:
477 eValue = XML_BASELINE;
478 break;
479 case VertOrientation::LINE_TOP:
480 case VertOrientation::LINE_CENTER:
481 case VertOrientation::LINE_BOTTOM:
482 eValue = XML_LINE;
483 break;
484 case VertOrientation::CHAR_TOP:
485 case VertOrientation::CHAR_CENTER:
486 case VertOrientation::CHAR_BOTTOM:
487 eValue = XML_CHAR;
488 break;
490 if( eValue != XML_TOKEN_INVALID )
491 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue );
493 if( nImageWidth > 0 )
495 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nImageWidth );
496 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH,
497 sBuffer.makeStringAndClear() );
500 if( nImageHeight > 0 )
502 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nImageHeight );
503 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT,
504 sBuffer.makeStringAndClear() );
508 // --> OD 2008-01-16 #newlistlevelattrs#
509 // if( GetExport().GetAttrList().getLength() > 0 )
511 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
512 XML_LIST_LEVEL_PROPERTIES, sal_True, sal_True );
514 // --> OD 2008-06-06 #i89178#
515 // check, if properties for position-and-space-mode LABEL_ALIGNMENT
516 // are allowed to be exported.
517 if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
518 mbExportPositionAndSpaceModeLabelAlignment )
519 // <--
521 enum XMLTokenEnum eValue = XML_LISTTAB;
522 if ( eLabelFollowedBy == LabelFollow::SPACE )
524 eValue = XML_SPACE;
526 else if ( eLabelFollowedBy == LabelFollow::NOTHING )
528 eValue = XML_NOTHING;
530 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
531 XML_LABEL_FOLLOWED_BY, eValue );
533 if ( eLabelFollowedBy == LabelFollow::LISTTAB &&
534 nListtabStopPosition > 0 )
536 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nListtabStopPosition );
537 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
538 XML_LIST_TAB_STOP_POSITION,
539 sBuffer.makeStringAndClear() );
542 if ( nFirstLineIndent != 0 )
544 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nFirstLineIndent );
545 GetExport().AddAttribute( XML_NAMESPACE_FO,
546 XML_TEXT_INDENT,
547 sBuffer.makeStringAndClear() );
550 if ( nIndentAt != 0 )
552 GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nIndentAt );
553 GetExport().AddAttribute( XML_NAMESPACE_FO,
554 XML_MARGIN_LEFT,
555 sBuffer.makeStringAndClear() );
558 SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE,
559 XML_LIST_LEVEL_LABEL_ALIGNMENT,
560 sal_True, sal_True );
563 // <--
565 if( NumberingType::CHAR_SPECIAL == eType )
567 if( sBulletFontName.getLength() )
569 OUString sStyleName =
570 GetExport().GetFontAutoStylePool()->Find(
571 sBulletFontName, sBulletFontStyleName,
572 eBulletFontFamily, eBulletFontPitch,
573 eBulletFontEncoding );
575 if( sStyleName.getLength() )
577 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
578 XML_FONT_NAME,
579 sStyleName );
581 else
583 Any aAny;
584 OUString sTemp;
586 const SvXMLUnitConverter& rUnitConv =
587 GetExport().GetMM100UnitConverter();
588 XMLFontFamilyNamePropHdl aFamilyNameHdl;
589 aAny <<= sBulletFontName;
590 if( aFamilyNameHdl.exportXML( sTemp, aAny, rUnitConv ) )
591 GetExport().AddAttribute( XML_NAMESPACE_FO,
592 XML_FONT_FAMILY, sTemp );
594 if( sBulletFontStyleName.getLength() )
595 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
596 XML_FONT_STYLE_NAME,
597 sBulletFontStyleName );
599 XMLFontFamilyPropHdl aFamilyHdl;
600 aAny <<= (sal_Int16)eBulletFontFamily;
601 if( aFamilyHdl.exportXML( sTemp, aAny, rUnitConv ) )
602 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
603 XML_FONT_FAMILY_GENERIC,
604 sTemp );
606 XMLFontPitchPropHdl aPitchHdl;
607 aAny <<= (sal_Int16)eBulletFontPitch;
608 if( aPitchHdl.exportXML( sTemp, aAny, rUnitConv ) )
609 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
610 XML_FONT_PITCH, sTemp );
612 XMLFontEncodingPropHdl aEncHdl;
613 aAny <<= (sal_Int16)eBulletFontEncoding;
614 if( aEncHdl.exportXML( sTemp, aAny, rUnitConv ) )
615 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
616 XML_FONT_CHARSET, sTemp );
620 if( NumberingType::BITMAP != eType )
622 // fo:color = "#..."
623 if( bHasColor )
625 const Color aColor( nColor );
626 if( aColor.GetColor() == 0xffffffff )
628 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE );
630 else
632 SvXMLUnitConverter::convertColor( sBuffer, aColor );
633 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR,
634 sBuffer.makeStringAndClear() );
637 // fo:height="...%"
638 if( nBullRelSize )
640 GetExport().GetMM100UnitConverter().convertPercent( sTmp, nBullRelSize );
641 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE,
642 sTmp.makeStringAndClear() );
645 if( GetExport().GetAttrList().getLength() > 0 )
647 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
648 XML_TEXT_PROPERTIES, sal_True, sal_True );
650 if( NumberingType::BITMAP == eType && sImageURL.getLength() )
652 // optional office:binary-data
653 GetExport().AddEmbeddedGraphicObjectAsBase64( sImageURL );
659 uno::Reference< ::com::sun::star::container::XIndexReplace > SvxXMLNumRuleExport::GetUNONumRule() const
661 return uno::Reference< ::com::sun::star::container::XIndexReplace > ();
664 void SvxXMLNumRuleExport::AddListStyleAttributes()
669 SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) :
670 rExport( rExp ),
671 sNumberingRules( RTL_CONSTASCII_USTRINGPARAM( "NumberingRules" ) ),
672 sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
673 sIsContinuousNumbering( RTL_CONSTASCII_USTRINGPARAM( "IsContinuousNumbering" ) ),
674 // --> OD 2008-06-06 #i89178#
675 mbExportPositionAndSpaceModeLabelAlignment( true )
676 // <--
678 switch ( GetExport().getDefaultVersion() )
680 case SvtSaveOptions::ODFVER_010:
681 case SvtSaveOptions::ODFVER_011:
683 mbExportPositionAndSpaceModeLabelAlignment = false;
685 break;
686 default: // ODFVER_UNKNOWN or ODFVER_012
688 mbExportPositionAndSpaceModeLabelAlignment = true;
693 SvxXMLNumRuleExport::~SvxXMLNumRuleExport()
697 // --> OD 2008-06-17 #i90780#
698 // refactoring: removing unused methods
699 //void SvxXMLNumRuleExport::Export( const OUString& rName,
700 // sal_Bool bContNumbering )
702 // GetExport().CheckAttrList();
704 // // style:name="..."
705 // if( rName.getLength() )
706 // {
707 // sal_Bool bEncoded = sal_False;
708 // GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
709 // GetExport().EncodeStyleName( rName, &bEncoded ) );
710 // if( bEncoded )
711 // GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
712 // rName);
713 // }
715 // // text:consecutive-numbering="..."
716 // if( bContNumbering )
717 // GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_CONSECUTIVE_NUMBERING,
718 // XML_TRUE );
720 // // other application specific attributes
721 // AddListStyleAttributes();
723 // OUString sElem = GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TEXT,
724 // GetXMLToken(XML_LIST_STYLE) );
725 // GetExport().IgnorableWhitespace();
726 // GetExport().StartElement( XML_NAMESPACE_TEXT, XML_LIST_STYLE, sal_False );
728 // uno::Reference< ::com::sun::star::container::XIndexReplace > xNumRule = GetUNONumRule();
729 // if( xNumRule.is() )
730 // exportLevelStyles( xNumRule );
732 // GetExport().EndElement( XML_NAMESPACE_TEXT, XML_LIST_STYLE, sal_True );
735 //void SvxXMLNumRuleExport::ExportOutline()
737 // GetExport().IgnorableWhitespace( );
738 // GetExport().StartElement( XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, sal_False );
740 // uno::Reference< ::com::sun::star::container::XIndexReplace > xNumRule = GetUNONumRule();
741 // if( xNumRule.is() )
742 // exportLevelStyles( xNumRule, sal_True );
744 // GetExport().EndElement( XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, sal_True );
746 // <--
748 void SvxXMLNumRuleExport::exportNumberingRule(
749 const OUString& rName,
750 const Reference< XIndexReplace >& rNumRule )
752 Reference< XPropertySet > xPropSet( rNumRule, UNO_QUERY );
753 Reference< XPropertySetInfo > xPropSetInfo;
754 if( xPropSet.is() )
755 xPropSetInfo = xPropSet->getPropertySetInfo();
757 GetExport().CheckAttrList();
759 // style:name="..."
760 if( rName.getLength() )
762 sal_Bool bEncoded = sal_False;
763 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
764 GetExport().EncodeStyleName( rName, &bEncoded ) );
765 if( bEncoded )
766 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
767 rName);
770 // text:consecutive-numbering="..."
771 sal_Bool bContNumbering = sal_False;
772 if( xPropSetInfo.is() &&
773 xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) )
775 Any aAny( xPropSet->getPropertyValue( sIsContinuousNumbering ) );
776 bContNumbering = *(sal_Bool *)aAny.getValue();
778 if( bContNumbering )
779 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
780 XML_CONSECUTIVE_NUMBERING, XML_TRUE );
782 // other application specific attributes
783 AddListStyleAttributes();
786 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE ,
787 sal_True, sal_True );
788 exportLevelStyles( rNumRule );
792 sal_Bool SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle )
794 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
795 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
797 Any aAny;
799 // Don't export styles that aren't existing really. This may be the
800 // case for StarOffice Writer's pool styles.
801 if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
803 aAny = xPropSet->getPropertyValue( sIsPhysical );
804 if( !*(sal_Bool *)aAny.getValue() )
805 return sal_False;
808 aAny = xPropSet->getPropertyValue( sNumberingRules );
809 Reference<XIndexReplace> xNumRule;
810 aAny >>= xNumRule;
812 OUString sName = rStyle->getName();
814 exportNumberingRule( sName, xNumRule );
816 return sal_True;
819 void SvxXMLNumRuleExport::exportOutline()
821 Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(),
822 UNO_QUERY );
823 DBG_ASSERT( xCNSupplier.is(), "no chapter numbering supplier" );
825 if( xCNSupplier.is() )
827 Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() );
828 DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
830 if( xNumRule.is() )
832 // --> OD 2008-06-17 #i90780#
833 // Outline style has property style:name since ODF 1.2
834 // Thus, export this property and adjust fix for issue #i69627#
835 OUString sOutlineStyleName;
837 Reference<XPropertySet> xNumRulePropSet(
838 xCNSupplier->getChapterNumberingRules(), UNO_QUERY );
839 if (xNumRulePropSet.is())
841 const OUString sName( RTL_CONSTASCII_USTRINGPARAM("Name") );
842 xNumRulePropSet->getPropertyValue( sName ) >>= sOutlineStyleName;
845 const SvtSaveOptions::ODFDefaultVersion nODFVersion =
846 GetExport().getDefaultVersion();
847 if ( ( nODFVersion == SvtSaveOptions::ODFVER_010 ||
848 nODFVersion == SvtSaveOptions::ODFVER_011 ) &&
849 GetExport().writeOutlineStyleAsNormalListStyle() )
851 exportNumberingRule( sOutlineStyleName, xNumRule );
853 else
855 if ( nODFVersion != SvtSaveOptions::ODFVER_010 &&
856 nODFVersion != SvtSaveOptions::ODFVER_011 )
858 // style:name="..."
859 GetExport().CheckAttrList();
860 if ( sOutlineStyleName.getLength() > 0 )
862 sal_Bool bEncoded = sal_False;
863 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
864 GetExport().EncodeStyleName( sOutlineStyleName,
865 &bEncoded ) );
866 if( bEncoded )
867 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
868 XML_DISPLAY_NAME,
869 sOutlineStyleName );
872 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
873 XML_OUTLINE_STYLE, sal_True, sal_True );
874 exportLevelStyles( xNumRule, sal_True );
880 void SvxXMLNumRuleExport::exportStyles( sal_Bool bUsed,
881 XMLTextListAutoStylePool *pPool,
882 sal_Bool bExportChapterNumbering )
884 if( bExportChapterNumbering )
885 exportOutline();
887 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
888 DBG_ASSERT( xFamiliesSupp.is(), "No XStyleFamiliesSupplier from XModel for export!" );
889 if( xFamiliesSupp.is() )
891 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
892 DBG_ASSERT( xFamiliesSupp.is(), "getStyleFamilies() from XModel failed for export!" );
894 if( xFamilies.is() )
896 const OUString aNumberStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyles" ));
898 Reference< XIndexAccess > xStyles;
899 if( xFamilies->hasByName( aNumberStyleName ) )
901 xFamilies->getByName( aNumberStyleName ) >>= xStyles;
903 DBG_ASSERT( xStyles.is(), "Style not found for export!" );
905 if( xStyles.is() )
907 const sal_Int32 nStyles = xStyles->getCount();
909 for( sal_Int32 i=0; i < nStyles; i++ )
911 Reference< XStyle > xStyle;
912 xStyles->getByIndex( i ) >>= xStyle;
914 if( !bUsed || xStyle->isInUse() )
916 exportStyle( xStyle );
917 if( pPool )
918 pPool->RegisterName( xStyle->getName() );
927 sal_Bool SvxXMLNumRuleExport::GetOutlineStyles( XMLStringVector& rStyleNames,
928 const ::com::sun::star::uno::Reference<
929 ::com::sun::star::frame::XModel > & rModel )
931 Reference< XChapterNumberingSupplier > xCNSupplier( rModel,
932 UNO_QUERY );
933 sal_Int32 nLevels = 0;
934 Reference< XIndexReplace > xNumRule;
935 if( xCNSupplier.is() )
937 xNumRule = xCNSupplier->getChapterNumberingRules();
938 if( xNumRule.is() )
939 nLevels = xNumRule->getCount();
942 rStyleNames.resize( nLevels );
943 for( sal_Int32 i=0; i<nLevels; i++ )
945 uno::Any aEntry( xNumRule->getByIndex( i ) );
946 uno::Sequence<beans::PropertyValue> aSeq;
947 if( aEntry >>= aSeq )
949 const sal_Int32 nCount = aSeq.getLength();
950 const beans::PropertyValue* pPropArray = aSeq.getConstArray();
951 for( sal_Int32 j=0; j<nCount; j++ )
953 const beans::PropertyValue& rProp = pPropArray[j];
955 if( rProp.Name.equalsAsciiL(
956 XML_UNO_NAME_NRULE_HEADING_STYLE_NAME,
957 sizeof(XML_UNO_NAME_NRULE_HEADING_STYLE_NAME)-1 ) )
959 rProp.Value >>= rStyleNames[i];
960 break;
966 return nLevels != 0;