Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
22 : #include <com/sun/star/style/NumberingType.hpp>
23 : #include <com/sun/star/style/XStyle.hpp>
24 : #include <com/sun/star/container/XNameContainer.hpp>
25 : #include <com/sun/star/container/XIndexReplace.hpp>
26 : #include <com/sun/star/awt/XBitmap.hpp>
27 : #include <com/sun/star/awt/FontDescriptor.hpp>
28 : #include <com/sun/star/text/HoriOrientation.hpp>
29 : #include <com/sun/star/text/VertOrientation.hpp>
30 : #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
31 : #include <com/sun/star/text/PositionAndSpaceMode.hpp>
32 : #include <com/sun/star/text/LabelFollow.hpp>
33 : #include <com/sun/star/beans/PropertyValue.hpp>
34 : #include <com/sun/star/beans/XPropertySet.hpp>
35 :
36 : #include <rtl/ustrbuf.hxx>
37 :
38 : #include <tools/debug.hxx>
39 :
40 : #include <sax/tools/converter.hxx>
41 :
42 : #include <xmloff/nmspmap.hxx>
43 : #include "xmloff/xmlnmspe.hxx"
44 : #include <xmloff/xmltoken.hxx>
45 : #include <xmloff/xmluconv.hxx>
46 : #include "fonthdl.hxx"
47 : #include "xmloff/XMLTextListAutoStylePool.hxx"
48 : #include <xmloff/xmlnume.hxx>
49 : #include <xmloff/xmlexp.hxx>
50 : #include <tools/fontenum.hxx>
51 :
52 :
53 : using ::rtl::OUString;
54 : using ::rtl::OUStringBuffer;
55 :
56 : using namespace ::com::sun::star;
57 : using namespace ::com::sun::star::uno;
58 : using namespace ::com::sun::star::style;
59 : using namespace ::com::sun::star::text;
60 : using namespace ::com::sun::star::container;
61 : using namespace ::com::sun::star::beans;
62 : using namespace ::xmloff::token;
63 :
64 : static sal_Char const XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE[] = "SymbolTextDistance";
65 : static sal_Char const XML_UNO_NAME_NRULE_PARENT_NUMBERING[] = "ParentNumbering";
66 : static sal_Char const XML_UNO_NAME_NRULE_CHAR_STYLE_NAME[] = "CharStyleName";
67 : static sal_Char const XML_UNO_NAME_NRULE_BULLET_CHAR[] = "BulletChar";
68 : static sal_Char const XML_UNO_NAME_NRULE_BULLET_RELSIZE[] = "BulletRelSize";
69 : static sal_Char const XML_UNO_NAME_NRULE_BULLET_COLOR[] = "BulletColor";
70 : static sal_Char const XML_UNO_NAME_NRULE_GRAPHIC_BITMAP[] = "GraphicBitmap";
71 : static sal_Char const XML_UNO_NAME_NRULE_GRAPHIC_SIZE[] = "GraphicSize";
72 : static sal_Char const XML_UNO_NAME_NRULE_VERT_ORIENT[] = "VertOrient";
73 : static sal_Char const XML_UNO_NAME_NRULE_NUMBERINGTYPE[] = "NumberingType";
74 : static sal_Char const XML_UNO_NAME_NRULE_HEADING_STYLE_NAME[] = "HeadingStyleName";
75 : static sal_Char const XML_UNO_NAME_NRULE_PREFIX[] = "Prefix";
76 : static sal_Char const XML_UNO_NAME_NRULE_SUFFIX[] = "Suffix";
77 : static sal_Char const XML_UNO_NAME_NRULE_ADJUST[] = "Adjust";
78 : static sal_Char const XML_UNO_NAME_NRULE_LEFT_MARGIN[] = "LeftMargin";
79 : static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET[] = "FirstLineOffset";
80 : static sal_Char const XML_UNO_NAME_NRULE_BULLET_FONT[] = "BulletFont";
81 : static sal_Char const XML_UNO_NAME_NRULE_GRAPHICURL[] = "GraphicURL";
82 : static sal_Char const XML_UNO_NAME_NRULE_START_WITH[] = "StartWith";
83 : static sal_Char const XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE[] = "PositionAndSpaceMode";
84 : static sal_Char const XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY[] = "LabelFollowedBy";
85 : static sal_Char const XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION[] = "ListtabStopPosition";
86 : static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_INDENT[] = "FirstLineIndent";
87 : static sal_Char const XML_UNO_NAME_NRULE_INDENT_AT[] = "IndentAt";
88 :
89 2 : void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< ::com::sun::star::container::XIndexReplace > & xNumRule,
90 : sal_Bool bOutline )
91 : {
92 2 : sal_Int32 nCount = xNumRule ->getCount();
93 22 : for( sal_Int32 i=0; i<nCount; i++ )
94 : {
95 20 : uno::Any aEntry( xNumRule->getByIndex( i ) );
96 20 : uno::Sequence<beans::PropertyValue> aSeq;
97 20 : if( aEntry >>= aSeq )
98 : {
99 20 : exportLevelStyle( i, aSeq, bOutline );
100 : }
101 20 : }
102 2 : }
103 :
104 20 : void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel,
105 : const uno::Sequence<beans::PropertyValue>& rProps,
106 : sal_Bool bOutline )
107 : {
108 20 : sal_Int16 eType = NumberingType::CHAR_SPECIAL;
109 :
110 20 : sal_Int16 eAdjust = HoriOrientation::LEFT;
111 20 : OUString sPrefix, sSuffix;
112 20 : OUString sTextStyleName;
113 20 : sal_Bool bHasColor = sal_False;
114 20 : sal_Int32 nColor = 0;
115 20 : sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0;
116 :
117 20 : sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0;
118 :
119 20 : sal_Unicode cBullet = 0xf095;
120 20 : OUString sBulletFontName, sBulletFontStyleName ;
121 20 : sal_Int16 eBulletFontFamily = FAMILY_DONTKNOW;
122 20 : sal_Int16 eBulletFontPitch = PITCH_DONTKNOW;
123 20 : rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW;
124 :
125 20 : OUString sImageURL;
126 20 : uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap;
127 20 : sal_Int32 nImageWidth = 0, nImageHeight = 0;
128 20 : sal_Int16 eImageVertOrient = VertOrientation::LINE_CENTER;
129 :
130 20 : sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
131 20 : sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB;
132 20 : sal_Int32 nListtabStopPosition( 0 );
133 20 : sal_Int32 nFirstLineIndent( 0 );
134 20 : sal_Int32 nIndentAt( 0 );
135 :
136 20 : const sal_Int32 nCount = rProps.getLength();
137 20 : const beans::PropertyValue* pPropArray = rProps.getConstArray();
138 280 : for( sal_Int32 i=0; i<nCount; i++ )
139 : {
140 260 : const beans::PropertyValue& rProp = pPropArray[i];
141 :
142 260 : if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_NUMBERINGTYPE, sizeof(XML_UNO_NAME_NRULE_NUMBERINGTYPE)-1 ) )
143 : {
144 20 : rProp.Value >>= eType;
145 : }
146 240 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PREFIX, sizeof(XML_UNO_NAME_NRULE_PREFIX)-1 ) )
147 : {
148 20 : rProp.Value >>= sPrefix;
149 : }
150 220 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SUFFIX, sizeof(XML_UNO_NAME_NRULE_SUFFIX)-1 ) )
151 : {
152 20 : rProp.Value >>= sSuffix;
153 : }
154 200 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_CHAR, sizeof(XML_UNO_NAME_NRULE_BULLET_CHAR)-1 ) )
155 : {
156 0 : OUString sValue;
157 0 : rProp.Value >>= sValue;
158 0 : if( !sValue.isEmpty() )
159 : {
160 0 : cBullet = (sal_Unicode)sValue[0];
161 0 : }
162 : }
163 200 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_RELSIZE, sizeof(XML_UNO_NAME_NRULE_BULLET_RELSIZE)-1 ) )
164 : {
165 0 : rProp.Value >>= nBullRelSize;
166 : }
167 200 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_ADJUST, sizeof(XML_UNO_NAME_NRULE_ADJUST)-1 ) )
168 : {
169 20 : sal_Int16 nValue = 0;
170 20 : rProp.Value >>= nValue;
171 20 : eAdjust = nValue;
172 : }
173 180 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_FONT, sizeof(XML_UNO_NAME_NRULE_BULLET_FONT)-1 ) )
174 : {
175 0 : awt::FontDescriptor rFDesc;
176 0 : if( rProp.Value >>= rFDesc )
177 : {
178 0 : sBulletFontName = rFDesc.Name;
179 0 : sBulletFontStyleName = rFDesc.StyleName;
180 0 : eBulletFontFamily = (sal_Int16)rFDesc.Family;
181 0 : eBulletFontPitch = (sal_Int16)rFDesc.Pitch;
182 0 : eBulletFontEncoding = (rtl_TextEncoding)rFDesc.CharSet;
183 0 : }
184 : }
185 180 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHICURL, sizeof(XML_UNO_NAME_NRULE_GRAPHICURL)-1 ) )
186 : {
187 0 : rProp.Value >>= sImageURL;
188 : }
189 180 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_BITMAP, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_BITMAP)-1 ) )
190 : {
191 0 : rProp.Value >>= xBitmap;
192 : }
193 180 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_COLOR, sizeof(XML_UNO_NAME_NRULE_BULLET_COLOR)-1 ) )
194 : {
195 0 : rProp.Value >>= nColor;
196 0 : bHasColor = sal_True;
197 : }
198 180 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_START_WITH, sizeof(XML_UNO_NAME_NRULE_START_WITH)-1 ) )
199 : {
200 20 : rProp.Value >>= nStartValue;
201 : }
202 160 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LEFT_MARGIN, sizeof(XML_UNO_NAME_NRULE_LEFT_MARGIN)-1 ) )
203 : {
204 0 : rProp.Value >>= nSpaceBefore;
205 : }
206 160 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET, sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET)-1 ) )
207 : {
208 0 : rProp.Value >>= nMinLabelWidth;
209 : }
210 160 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE, sizeof(XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE)-1 ) )
211 : {
212 0 : rProp.Value >>= nMinLabelDist;
213 : }
214 160 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PARENT_NUMBERING, sizeof(XML_UNO_NAME_NRULE_PARENT_NUMBERING)-1 ) )
215 : {
216 20 : rProp.Value >>= nDisplayLevels;
217 20 : if( nDisplayLevels > nLevel+1 )
218 0 : nDisplayLevels = static_cast<sal_Int16>( nLevel )+1;
219 : }
220 140 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_CHAR_STYLE_NAME, sizeof(XML_UNO_NAME_NRULE_CHAR_STYLE_NAME)-1 ) )
221 : {
222 20 : rProp.Value >>= sTextStyleName;
223 : }
224 120 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_SIZE, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_SIZE)-1 ) )
225 : {
226 0 : awt::Size aSize;
227 0 : if( rProp.Value >>= aSize )
228 : {
229 0 : nImageWidth = aSize.Width;
230 0 : nImageHeight = aSize.Height;
231 : }
232 : }
233 120 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_VERT_ORIENT, sizeof(XML_UNO_NAME_NRULE_VERT_ORIENT)-1 ) )
234 : {
235 0 : sal_Int16 nValue = 0;
236 0 : rProp.Value >>= nValue;
237 0 : eImageVertOrient = nValue;
238 : }
239 120 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE,
240 120 : sizeof(XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE)-1 ) )
241 : {
242 20 : sal_Int16 nValue = 0;
243 20 : rProp.Value >>= nValue;
244 20 : ePosAndSpaceMode = nValue;
245 : }
246 100 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY,
247 100 : sizeof(XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY)-1 ) )
248 : {
249 20 : sal_Int16 nValue = 0;
250 20 : rProp.Value >>= nValue;
251 20 : eLabelFollowedBy = nValue;
252 : }
253 80 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION,
254 80 : sizeof(XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION)-1 ) )
255 : {
256 20 : rProp.Value >>= nListtabStopPosition;
257 : }
258 60 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_INDENT,
259 60 : sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_INDENT)-1 ) )
260 : {
261 20 : rProp.Value >>= nFirstLineIndent;
262 : }
263 40 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_INDENT_AT,
264 40 : sizeof(XML_UNO_NAME_NRULE_INDENT_AT)-1 ) )
265 : {
266 20 : rProp.Value >>= nIndentAt;
267 : }
268 : }
269 :
270 20 : if( bOutline && (NumberingType::CHAR_SPECIAL == eType ||
271 : NumberingType::BITMAP == eType) )
272 : {
273 : DBG_ASSERT( !bOutline,
274 : "SvxXMLNumRuleExport::exportLevelStyle: invalid style for outline" );
275 20 : return;
276 : }
277 :
278 20 : GetExport().CheckAttrList();
279 :
280 : // text:level
281 20 : OUStringBuffer sTmp;
282 20 : sTmp.append( nLevel + 1 );
283 20 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, sTmp.makeStringAndClear() );
284 : // #i110694#: no style-name on list-level-style-image
285 : // #i116149#: neither prefix/suffix
286 20 : if (NumberingType::BITMAP != eType)
287 : {
288 20 : if (!sTextStyleName.isEmpty())
289 : {
290 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
291 0 : GetExport().EncodeStyleName( sTextStyleName ) );
292 : }
293 20 : if (!sPrefix.isEmpty())
294 : {
295 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
296 0 : sPrefix );
297 : }
298 20 : if (!sSuffix.isEmpty())
299 : {
300 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
301 0 : sSuffix );
302 : }
303 : }
304 :
305 20 : enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER;
306 20 : if( NumberingType::CHAR_SPECIAL == eType )
307 : {
308 : // <text:list-level-style-bullet>
309 0 : eElem = XML_LIST_LEVEL_STYLE_BULLET;
310 :
311 0 : if( cBullet )
312 : {
313 0 : if( cBullet < ' ' )
314 : {
315 0 : cBullet = 0xF000 + 149;
316 : }
317 : // text:bullet-char="..."
318 0 : sTmp.append( cBullet );
319 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR,
320 0 : sTmp.makeStringAndClear() );
321 : }
322 :
323 : }
324 20 : else if( NumberingType::BITMAP == eType )
325 : {
326 : // <text:list-level-style-image>
327 :
328 0 : eElem = XML_LIST_LEVEL_STYLE_IMAGE;
329 :
330 :
331 0 : if( !sImageURL.isEmpty() )
332 : {
333 0 : OUString sURL( GetExport().AddEmbeddedGraphicObject( sImageURL ) );
334 0 : if( !sURL.isEmpty() )
335 : {
336 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL );
337 :
338 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
339 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
340 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
341 0 : }
342 : }
343 : else
344 : {
345 : DBG_ASSERT( !xBitmap.is(),
346 : "embedded images are not supported by now" );
347 : }
348 : }
349 : else
350 : {
351 : // <text:list-level-style-number> or <text:outline-level-style>
352 20 : if( bOutline )
353 20 : eElem = XML_OUTLINE_LEVEL_STYLE;
354 : else
355 0 : eElem = XML_LIST_LEVEL_STYLE_NUMBER;
356 :
357 20 : GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType );
358 20 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
359 40 : sTmp.makeStringAndClear() );
360 20 : GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp, eType );
361 20 : if( sTmp.getLength() )
362 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
363 : XML_NUM_LETTER_SYNC,
364 0 : sTmp.makeStringAndClear() );
365 :
366 20 : if( nStartValue != 1 )
367 : {
368 0 : sTmp.append( (sal_Int32)nStartValue );
369 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
370 0 : sTmp.makeStringAndClear() );
371 : }
372 20 : if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType )
373 : {
374 0 : sTmp.append( (sal_Int32)nDisplayLevels );
375 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS,
376 0 : sTmp.makeStringAndClear() );
377 : }
378 : }
379 :
380 : {
381 20 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
382 20 : sal_True, sal_True );
383 :
384 20 : OUStringBuffer sBuffer;
385 20 : if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
386 : {
387 0 : nSpaceBefore += nMinLabelWidth;
388 0 : nMinLabelWidth = -nMinLabelWidth;
389 0 : if( nSpaceBefore != 0 )
390 : {
391 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
392 0 : sBuffer, nSpaceBefore );
393 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE,
394 0 : sBuffer.makeStringAndClear() );
395 : }
396 0 : if( nMinLabelWidth != 0 )
397 : {
398 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
399 0 : sBuffer, nMinLabelWidth );
400 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH,
401 0 : sBuffer.makeStringAndClear() );
402 : }
403 0 : if( nMinLabelDist > 0 )
404 : {
405 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
406 0 : sBuffer, nMinLabelDist );
407 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE,
408 0 : sBuffer.makeStringAndClear() );
409 : }
410 : }
411 : /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
412 : are allowed to be exported. (#i89178#)
413 : */
414 20 : else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
415 : mbExportPositionAndSpaceModeLabelAlignment )
416 : {
417 20 : GetExport().AddAttribute( XML_NAMESPACE_TEXT,
418 : XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
419 20 : XML_LABEL_ALIGNMENT );
420 : }
421 20 : if( HoriOrientation::LEFT != eAdjust )
422 : {
423 0 : enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
424 0 : switch( eAdjust )
425 : {
426 0 : case HoriOrientation::RIGHT: eValue = XML_END; break;
427 0 : case HoriOrientation::CENTER: eValue = XML_CENTER; break;
428 : }
429 0 : if( eValue != XML_TOKEN_INVALID )
430 0 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue );
431 : }
432 :
433 20 : if( NumberingType::BITMAP == eType )
434 : {
435 0 : enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
436 0 : switch( eImageVertOrient )
437 : {
438 : case VertOrientation::BOTTOM: // yes, its OK: BOTTOM means that the baseline
439 : // hits the frame at its topmost position
440 : case VertOrientation::LINE_TOP:
441 : case VertOrientation::CHAR_TOP:
442 0 : eValue = XML_TOP;
443 0 : break;
444 : case VertOrientation::CENTER:
445 : case VertOrientation::LINE_CENTER:
446 : case VertOrientation::CHAR_CENTER:
447 0 : eValue = XML_MIDDLE;
448 0 : break;
449 : case VertOrientation::TOP: // yes, its OK: TOP means that the baseline
450 : // hits the frame at its bottommost position
451 : case VertOrientation::LINE_BOTTOM:
452 : case VertOrientation::CHAR_BOTTOM:
453 0 : eValue = XML_BOTTOM;
454 0 : break;
455 : }
456 0 : if( eValue != XML_TOKEN_INVALID )
457 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue );
458 :
459 0 : eValue = XML_TOKEN_INVALID;
460 0 : switch( eImageVertOrient )
461 : {
462 : case VertOrientation::TOP:
463 : case VertOrientation::CENTER:
464 : case VertOrientation::BOTTOM:
465 0 : eValue = XML_BASELINE;
466 0 : break;
467 : case VertOrientation::LINE_TOP:
468 : case VertOrientation::LINE_CENTER:
469 : case VertOrientation::LINE_BOTTOM:
470 0 : eValue = XML_LINE;
471 0 : break;
472 : case VertOrientation::CHAR_TOP:
473 : case VertOrientation::CHAR_CENTER:
474 : case VertOrientation::CHAR_BOTTOM:
475 0 : eValue = XML_CHAR;
476 0 : break;
477 : }
478 0 : if( eValue != XML_TOKEN_INVALID )
479 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue );
480 :
481 0 : if( nImageWidth > 0 )
482 : {
483 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
484 0 : sBuffer, nImageWidth );
485 0 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH,
486 0 : sBuffer.makeStringAndClear() );
487 : }
488 :
489 0 : if( nImageHeight > 0 )
490 : {
491 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
492 0 : sBuffer, nImageHeight );
493 0 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT,
494 0 : sBuffer.makeStringAndClear() );
495 : }
496 : }
497 :
498 : {
499 20 : SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
500 20 : XML_LIST_LEVEL_PROPERTIES, sal_True, sal_True );
501 :
502 : /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
503 : are allowed to be exported. (#i89178#)
504 : */
505 20 : if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
506 : mbExportPositionAndSpaceModeLabelAlignment )
507 : {
508 20 : enum XMLTokenEnum eValue = XML_LISTTAB;
509 20 : if ( eLabelFollowedBy == LabelFollow::SPACE )
510 : {
511 0 : eValue = XML_SPACE;
512 : }
513 20 : else if ( eLabelFollowedBy == LabelFollow::NOTHING )
514 : {
515 0 : eValue = XML_NOTHING;
516 : }
517 20 : GetExport().AddAttribute( XML_NAMESPACE_TEXT,
518 20 : XML_LABEL_FOLLOWED_BY, eValue );
519 :
520 20 : if ( eLabelFollowedBy == LabelFollow::LISTTAB &&
521 : nListtabStopPosition > 0 )
522 : {
523 20 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
524 40 : sBuffer, nListtabStopPosition );
525 20 : GetExport().AddAttribute( XML_NAMESPACE_TEXT,
526 : XML_LIST_TAB_STOP_POSITION,
527 40 : sBuffer.makeStringAndClear() );
528 : }
529 :
530 20 : if ( nFirstLineIndent != 0 )
531 : {
532 20 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
533 40 : sBuffer, nFirstLineIndent );
534 20 : GetExport().AddAttribute( XML_NAMESPACE_FO,
535 : XML_TEXT_INDENT,
536 40 : sBuffer.makeStringAndClear() );
537 : }
538 :
539 20 : if ( nIndentAt != 0 )
540 : {
541 20 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
542 40 : sBuffer, nIndentAt );
543 20 : GetExport().AddAttribute( XML_NAMESPACE_FO,
544 : XML_MARGIN_LEFT,
545 40 : sBuffer.makeStringAndClear() );
546 : }
547 :
548 20 : SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE,
549 : XML_LIST_LEVEL_LABEL_ALIGNMENT,
550 20 : sal_True, sal_True );
551 20 : }
552 : }
553 :
554 20 : if( NumberingType::CHAR_SPECIAL == eType )
555 : {
556 0 : if( !sBulletFontName.isEmpty() )
557 : {
558 : OUString sStyleName =
559 0 : GetExport().GetFontAutoStylePool()->Find(
560 : sBulletFontName, sBulletFontStyleName,
561 : eBulletFontFamily, eBulletFontPitch,
562 0 : eBulletFontEncoding );
563 :
564 0 : if( !sStyleName.isEmpty() )
565 : {
566 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
567 : XML_FONT_NAME,
568 0 : sStyleName );
569 : }
570 : else
571 : {
572 0 : Any aAny;
573 0 : OUString sTemp;
574 :
575 : const SvXMLUnitConverter& rUnitConv =
576 0 : GetExport().GetMM100UnitConverter();
577 0 : XMLFontFamilyNamePropHdl aFamilyNameHdl;
578 0 : aAny <<= sBulletFontName;
579 0 : if( aFamilyNameHdl.exportXML( sTemp, aAny, rUnitConv ) )
580 0 : GetExport().AddAttribute( XML_NAMESPACE_FO,
581 0 : XML_FONT_FAMILY, sTemp );
582 :
583 0 : if( !sBulletFontStyleName.isEmpty() )
584 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
585 : XML_FONT_STYLE_NAME,
586 0 : sBulletFontStyleName );
587 :
588 0 : XMLFontFamilyPropHdl aFamilyHdl;
589 0 : aAny <<= (sal_Int16)eBulletFontFamily;
590 0 : if( aFamilyHdl.exportXML( sTemp, aAny, rUnitConv ) )
591 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
592 : XML_FONT_FAMILY_GENERIC,
593 0 : sTemp );
594 :
595 0 : XMLFontPitchPropHdl aPitchHdl;
596 0 : aAny <<= (sal_Int16)eBulletFontPitch;
597 0 : if( aPitchHdl.exportXML( sTemp, aAny, rUnitConv ) )
598 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
599 0 : XML_FONT_PITCH, sTemp );
600 :
601 0 : XMLFontEncodingPropHdl aEncHdl;
602 0 : aAny <<= (sal_Int16)eBulletFontEncoding;
603 0 : if( aEncHdl.exportXML( sTemp, aAny, rUnitConv ) )
604 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
605 0 : XML_FONT_CHARSET, sTemp );
606 0 : }
607 : }
608 : }
609 20 : if( NumberingType::BITMAP != eType )
610 : {
611 : // fo:color = "#..."
612 20 : if( bHasColor )
613 : {
614 0 : if (0xffffffff == static_cast<sal_uInt32>(nColor))
615 : {
616 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE );
617 : }
618 : else
619 : {
620 0 : ::sax::Converter::convertColor( sBuffer, nColor );
621 0 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR,
622 0 : sBuffer.makeStringAndClear() );
623 : }
624 : }
625 : // fo:height="...%"
626 20 : if( nBullRelSize )
627 : {
628 0 : ::sax::Converter::convertPercent( sTmp, nBullRelSize );
629 0 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE,
630 0 : sTmp.makeStringAndClear() );
631 : }
632 : }
633 20 : if( GetExport().GetAttrList().getLength() > 0 )
634 : {
635 0 : SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
636 0 : XML_TEXT_PROPERTIES, sal_True, sal_True );
637 : }
638 20 : if( NumberingType::BITMAP == eType && !sImageURL.isEmpty() )
639 : {
640 : // optional office:binary-data
641 0 : GetExport().AddEmbeddedGraphicObjectAsBase64( sImageURL );
642 20 : }
643 20 : }
644 : }
645 :
646 :
647 0 : uno::Reference< ::com::sun::star::container::XIndexReplace > SvxXMLNumRuleExport::GetUNONumRule() const
648 : {
649 0 : return uno::Reference< ::com::sun::star::container::XIndexReplace > ();
650 : }
651 :
652 0 : void SvxXMLNumRuleExport::AddListStyleAttributes()
653 : {
654 0 : }
655 :
656 :
657 22 : SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) :
658 : rExport( rExp ),
659 : sNumberingRules( RTL_CONSTASCII_USTRINGPARAM( "NumberingRules" ) ),
660 : sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
661 : sIsContinuousNumbering( RTL_CONSTASCII_USTRINGPARAM( "IsContinuousNumbering" ) ),
662 : // Let list style creation depend on Load/Save option "ODF format version" (#i89178#)
663 22 : mbExportPositionAndSpaceModeLabelAlignment( true )
664 : {
665 22 : switch ( GetExport().getDefaultVersion() )
666 : {
667 : case SvtSaveOptions::ODFVER_010:
668 : case SvtSaveOptions::ODFVER_011:
669 : {
670 0 : mbExportPositionAndSpaceModeLabelAlignment = false;
671 : }
672 0 : break;
673 : default: // ODFVER_UNKNOWN or ODFVER_012
674 : {
675 22 : mbExportPositionAndSpaceModeLabelAlignment = true;
676 : }
677 : }
678 22 : }
679 :
680 22 : SvxXMLNumRuleExport::~SvxXMLNumRuleExport()
681 : {
682 22 : }
683 :
684 0 : void SvxXMLNumRuleExport::exportNumberingRule(
685 : const OUString& rName, sal_Bool bIsHidden,
686 : const Reference< XIndexReplace >& rNumRule )
687 : {
688 0 : Reference< XPropertySet > xPropSet( rNumRule, UNO_QUERY );
689 0 : Reference< XPropertySetInfo > xPropSetInfo;
690 0 : if( xPropSet.is() )
691 0 : xPropSetInfo = xPropSet->getPropertySetInfo();
692 :
693 0 : GetExport().CheckAttrList();
694 :
695 : // style:name="..."
696 0 : if( !rName.isEmpty() )
697 : {
698 0 : sal_Bool bEncoded = sal_False;
699 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
700 0 : GetExport().EncodeStyleName( rName, &bEncoded ) );
701 0 : if( bEncoded )
702 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
703 0 : rName);
704 : }
705 :
706 : // style:hidden="..."
707 0 : if ( bIsHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
708 0 : GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
709 :
710 : // text:consecutive-numbering="..."
711 0 : sal_Bool bContNumbering = sal_False;
712 0 : if( xPropSetInfo.is() &&
713 0 : xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) )
714 : {
715 0 : Any aAny( xPropSet->getPropertyValue( sIsContinuousNumbering ) );
716 0 : bContNumbering = *(sal_Bool *)aAny.getValue();
717 : }
718 0 : if( bContNumbering )
719 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT,
720 0 : XML_CONSECUTIVE_NUMBERING, XML_TRUE );
721 :
722 : // other application specific attributes
723 0 : AddListStyleAttributes();
724 :
725 : {
726 0 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE ,
727 0 : sal_True, sal_True );
728 0 : exportLevelStyles( rNumRule );
729 0 : }
730 0 : }
731 :
732 20 : sal_Bool SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle )
733 : {
734 20 : Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
735 20 : Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
736 :
737 20 : Any aAny;
738 :
739 : // Don't export styles that aren't existing really. This may be the
740 : // case for StarOffice Writer's pool styles.
741 20 : if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
742 : {
743 20 : aAny = xPropSet->getPropertyValue( sIsPhysical );
744 20 : if( !*(sal_Bool *)aAny.getValue() )
745 20 : return sal_False;
746 : }
747 :
748 0 : aAny = xPropSet->getPropertyValue( sNumberingRules );
749 0 : Reference<XIndexReplace> xNumRule;
750 0 : aAny >>= xNumRule;
751 :
752 0 : OUString sName = rStyle->getName();
753 :
754 0 : sal_Bool bHidden = sal_False;
755 0 : if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
756 : {
757 0 : aAny = xPropSet->getPropertyValue( "Hidden" );
758 0 : aAny >>= bHidden;
759 : }
760 :
761 0 : exportNumberingRule( sName, bHidden, xNumRule );
762 :
763 0 : return sal_True;
764 : }
765 :
766 2 : void SvxXMLNumRuleExport::exportOutline()
767 : {
768 2 : Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(),
769 2 : UNO_QUERY );
770 : DBG_ASSERT( xCNSupplier.is(), "no chapter numbering supplier" );
771 :
772 2 : if( xCNSupplier.is() )
773 : {
774 2 : Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() );
775 : DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
776 :
777 2 : if( xNumRule.is() )
778 : {
779 : /* Outline style has property style:name since ODF 1.2
780 : Thus, export this property and adjust fix for issue #i69627# (#i90780#)
781 : */
782 2 : OUString sOutlineStyleName;
783 : {
784 : Reference<XPropertySet> xNumRulePropSet(
785 2 : xCNSupplier->getChapterNumberingRules(), UNO_QUERY );
786 2 : if (xNumRulePropSet.is())
787 : {
788 2 : const OUString sName( RTL_CONSTASCII_USTRINGPARAM("Name") );
789 2 : xNumRulePropSet->getPropertyValue( sName ) >>= sOutlineStyleName;
790 2 : }
791 : }
792 : const SvtSaveOptions::ODFDefaultVersion nODFVersion =
793 2 : GetExport().getDefaultVersion();
794 2 : if ( ( nODFVersion == SvtSaveOptions::ODFVER_010 ||
795 : nODFVersion == SvtSaveOptions::ODFVER_011 ) &&
796 0 : GetExport().writeOutlineStyleAsNormalListStyle() )
797 : {
798 0 : exportNumberingRule( sOutlineStyleName, sal_False, xNumRule );
799 : }
800 : else
801 : {
802 2 : if ( nODFVersion != SvtSaveOptions::ODFVER_010 &&
803 : nODFVersion != SvtSaveOptions::ODFVER_011 )
804 : {
805 : // style:name="..."
806 2 : GetExport().CheckAttrList();
807 2 : if ( !sOutlineStyleName.isEmpty() )
808 : {
809 2 : sal_Bool bEncoded = sal_False;
810 2 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
811 2 : GetExport().EncodeStyleName( sOutlineStyleName,
812 4 : &bEncoded ) );
813 2 : if( bEncoded )
814 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
815 : XML_DISPLAY_NAME,
816 0 : sOutlineStyleName );
817 : }
818 : }
819 2 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
820 2 : XML_OUTLINE_STYLE, sal_True, sal_True );
821 2 : exportLevelStyles( xNumRule, sal_True );
822 2 : }
823 2 : }
824 2 : }
825 2 : }
826 :
827 2 : void SvxXMLNumRuleExport::exportStyles( sal_Bool bUsed,
828 : XMLTextListAutoStylePool *pPool,
829 : sal_Bool bExportChapterNumbering )
830 : {
831 2 : if( bExportChapterNumbering )
832 2 : exportOutline();
833 :
834 2 : Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
835 : DBG_ASSERT( xFamiliesSupp.is(), "No XStyleFamiliesSupplier from XModel for export!" );
836 2 : if( xFamiliesSupp.is() )
837 : {
838 2 : Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
839 : DBG_ASSERT( xFamiliesSupp.is(), "getStyleFamilies() from XModel failed for export!" );
840 :
841 2 : if( xFamilies.is() )
842 : {
843 2 : const OUString aNumberStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyles" ));
844 :
845 2 : Reference< XIndexAccess > xStyles;
846 2 : if( xFamilies->hasByName( aNumberStyleName ) )
847 : {
848 2 : xFamilies->getByName( aNumberStyleName ) >>= xStyles;
849 :
850 : DBG_ASSERT( xStyles.is(), "Style not found for export!" );
851 :
852 2 : if( xStyles.is() )
853 : {
854 2 : const sal_Int32 nStyles = xStyles->getCount();
855 :
856 22 : for( sal_Int32 i=0; i < nStyles; i++ )
857 : {
858 20 : Reference< XStyle > xStyle;
859 20 : xStyles->getByIndex( i ) >>= xStyle;
860 :
861 20 : if( !bUsed || xStyle->isInUse() )
862 : {
863 20 : exportStyle( xStyle );
864 20 : if( pPool )
865 20 : pPool->RegisterName( xStyle->getName() );
866 : }
867 20 : }
868 : }
869 2 : }
870 2 : }
871 2 : }
872 2 : }
873 :
874 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|