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 : #include <com/sun/star/beans/PropertyValue.hpp>
21 : #include <com/sun/star/beans/XPropertySet.hpp>
22 : #include <com/sun/star/awt/Size.hpp>
23 : #include <com/sun/star/awt/FontDescriptor.hpp>
24 : #include <com/sun/star/text/HoriOrientation.hpp>
25 : #include <com/sun/star/text/VertOrientation.hpp>
26 : #include <com/sun/star/text/PositionAndSpaceMode.hpp>
27 : #include <com/sun/star/text/LabelFollow.hpp>
28 : #include <com/sun/star/container/XNameContainer.hpp>
29 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 : #include <com/sun/star/style/XStyle.hpp>
31 : #include <com/sun/star/io/XOutputStream.hpp>
32 :
33 : #include <rtl/ustrbuf.hxx>
34 :
35 : #include <tools/debug.hxx>
36 : #include <tools/fontenum.hxx>
37 :
38 : #include <sax/tools/converter.hxx>
39 :
40 : #include <xmloff/xmltkmap.hxx>
41 : #include <xmloff/nmspmap.hxx>
42 : #include <xmloff/xmlnmspe.hxx>
43 : #include <xmloff/xmlimp.hxx>
44 : #include <xmloff/XMLBase64ImportContext.hxx>
45 : #include <xmloff/xmltoken.hxx>
46 :
47 : #include <xmloff/i18nmap.hxx>
48 : #include <xmloff/xmluconv.hxx>
49 : #include "fonthdl.hxx"
50 : #include <xmloff/XMLFontStylesContext.hxx>
51 : #include <xmloff/families.hxx>
52 : #include <xmloff/maptype.hxx>
53 :
54 : #include <xmloff/xmlnumi.hxx>
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::beans;
61 : using namespace ::com::sun::star::container;
62 : using namespace ::com::sun::star::lang;
63 : using namespace ::com::sun::star::frame;
64 : using namespace ::xmloff::token;
65 : using namespace ::com::sun::star::io;
66 :
67 : class SvxXMLListLevelStyleContext_Impl;
68 :
69 : class SvxXMLListLevelStyleAttrContext_Impl : public SvXMLImportContext
70 : {
71 : SvxXMLListLevelStyleContext_Impl& rListLevel;
72 :
73 : public:
74 :
75 : SvxXMLListLevelStyleAttrContext_Impl(
76 : SvXMLImport& rImport, sal_uInt16 nPrfx,
77 : const OUString& rLName,
78 : const Reference< xml::sax::XAttributeList >& xAttrList,
79 : SvxXMLListLevelStyleContext_Impl& rLLevel );
80 : virtual ~SvxXMLListLevelStyleAttrContext_Impl();
81 :
82 : virtual SvXMLImportContext *CreateChildContext(
83 : sal_uInt16 nPrefix, const OUString& rLocalName,
84 : const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
85 : };
86 :
87 : class SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl : public SvXMLImportContext
88 : {
89 : SvxXMLListLevelStyleContext_Impl& rListLevel;
90 :
91 : public:
92 :
93 : SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl(
94 : SvXMLImport& rImport, sal_uInt16 nPrfx,
95 : const OUString& rLName,
96 : const Reference< xml::sax::XAttributeList >& xAttrList,
97 : SvxXMLListLevelStyleContext_Impl& rLLevel );
98 : virtual ~SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl();
99 : };
100 :
101 : enum SvxXMLTextListLevelStyleAttrTokens
102 : {
103 : XML_TOK_TEXT_LEVEL_ATTR_LEVEL,
104 : XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME,
105 : XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR,
106 : XML_TOK_TEXT_LEVEL_ATTR_HREF,
107 : XML_TOK_TEXT_LEVEL_ATTR_TYPE,
108 : XML_TOK_TEXT_LEVEL_ATTR_SHOW,
109 : XML_TOK_TEXT_LEVEL_ATTR_ACTUATE,
110 : XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT,
111 : XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX,
112 : XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX,
113 : XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC,
114 : XML_TOK_TEXT_LEVEL_ATTR_START_VALUE,
115 : XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS,
116 :
117 : XML_TOK_TEXT_LEVEL_ATTR_END=XML_TOK_UNKNOWN
118 : };
119 :
120 0 : static const SvXMLTokenMapEntry* lcl_getLevelAttrTokenMap()
121 : {
122 : static const SvXMLTokenMapEntry aLevelAttrTokenMap[] =
123 : {
124 : { XML_NAMESPACE_TEXT, XML_LEVEL, XML_TOK_TEXT_LEVEL_ATTR_LEVEL },
125 : { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME },
126 : { XML_NAMESPACE_TEXT, XML_BULLET_CHAR, XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR },
127 : { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_TEXT_LEVEL_ATTR_HREF },
128 : { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_TEXT_LEVEL_ATTR_TYPE },
129 : { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_TEXT_LEVEL_ATTR_SHOW },
130 : { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_TEXT_LEVEL_ATTR_ACTUATE },
131 :
132 : { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT },
133 : { XML_NAMESPACE_STYLE, XML_NUM_PREFIX, XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX },
134 : { XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX },
135 : { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC },
136 : { XML_NAMESPACE_TEXT, XML_START_VALUE, XML_TOK_TEXT_LEVEL_ATTR_START_VALUE },
137 : { XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS, XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS },
138 :
139 : XML_TOKEN_MAP_END
140 : };
141 0 : return aLevelAttrTokenMap;
142 : }
143 :
144 : class SvxXMLListLevelStyleContext_Impl : public SvXMLImportContext
145 : {
146 : friend class SvxXMLListLevelStyleAttrContext_Impl;
147 : const OUString sStarBats;
148 : const OUString sStarMath;
149 :
150 : OUString sPrefix;
151 : OUString sSuffix;
152 : OUString sTextStyleName;
153 : OUString sNumFormat;
154 : OUString sNumLetterSync;
155 : OUString sBulletFontName;
156 : OUString sBulletFontStyleName;
157 : OUString sImageURL;
158 :
159 : Reference < XOutputStream > xBase64Stream;
160 :
161 : sal_Int32 nLevel;
162 : sal_Int32 nSpaceBefore;
163 : sal_Int32 nMinLabelWidth;
164 : sal_Int32 nMinLabelDist;
165 : sal_Int32 nImageWidth;
166 : sal_Int32 nImageHeight;
167 : sal_Int16 nNumStartValue;
168 : sal_Int16 nNumDisplayLevels;
169 :
170 : sal_Int16 eAdjust;
171 : sal_Int16 eBulletFontFamily;
172 : sal_Int16 eBulletFontPitch;
173 : rtl_TextEncoding eBulletFontEncoding;
174 : sal_Int16 eImageVertOrient;
175 :
176 : sal_Unicode cBullet;
177 :
178 : sal_Int16 nRelSize;
179 : sal_Int32 m_nColor;
180 :
181 : sal_Int16 ePosAndSpaceMode;
182 : sal_Int16 eLabelFollowedBy;
183 : sal_Int32 nListtabStopPosition;
184 : sal_Int32 nFirstLineIndent;
185 : sal_Int32 nIndentAt;
186 :
187 : sal_Bool bBullet : 1;
188 : sal_Bool bImage : 1;
189 : sal_Bool bNum : 1;
190 : sal_Bool bHasColor : 1;
191 :
192 0 : void SetRelSize( sal_Int16 nRel ) { nRelSize = nRel; }
193 0 : void SetColor( sal_Int32 nColor )
194 0 : { m_nColor = nColor; bHasColor = sal_True; }
195 0 : void SetSpaceBefore( sal_Int32 nSet ) { nSpaceBefore = nSet; }
196 0 : void SetMinLabelWidth( sal_Int32 nSet ) { nMinLabelWidth = nSet; }
197 0 : void SetMinLabelDist( sal_Int32 nSet ) { nMinLabelDist = nSet; }
198 0 : void SetAdjust( sal_Int16 eSet ) { eAdjust = eSet; }
199 :
200 0 : void SetBulletFontName( const OUString& rSet ) { sBulletFontName = rSet; }
201 0 : void SetBulletFontStyleName( const OUString& rSet )
202 0 : { sBulletFontStyleName = rSet; }
203 0 : void SetBulletFontFamily( sal_Int16 eSet ) { eBulletFontFamily = eSet; }
204 0 : void SetBulletFontPitch( sal_Int16 eSet ) { eBulletFontPitch = eSet; }
205 0 : void SetBulletFontEncoding( rtl_TextEncoding eSet )
206 0 : { eBulletFontEncoding = eSet; }
207 :
208 0 : void SetImageWidth( sal_Int32 nSet ) { nImageWidth = nSet; }
209 0 : void SetImageHeight( sal_Int32 nSet ) { nImageHeight = nSet; }
210 0 : void SetImageVertOrient( sal_Int16 eSet )
211 0 : { eImageVertOrient = eSet; }
212 :
213 : public:
214 :
215 : SvxXMLListLevelStyleContext_Impl(
216 : SvXMLImport& rImport, sal_uInt16 nPrfx,
217 : const OUString& rLName,
218 : const Reference< xml::sax::XAttributeList > & xAttrList );
219 : virtual ~SvxXMLListLevelStyleContext_Impl();
220 :
221 : virtual SvXMLImportContext *CreateChildContext(
222 : sal_uInt16 nPrefix, const OUString& rLocalName,
223 : const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
224 :
225 0 : sal_Int32 GetLevel() const { return nLevel; }
226 : Sequence<beans::PropertyValue> GetProperties(
227 : const SvI18NMap *pI18NMap=0 );
228 :
229 0 : inline void SetPosAndSpaceMode( sal_Int16 eValue )
230 : {
231 0 : ePosAndSpaceMode = eValue;
232 0 : }
233 0 : inline void SetLabelFollowedBy( sal_Int16 eValue )
234 : {
235 0 : eLabelFollowedBy = eValue;
236 0 : }
237 0 : inline void SetListtabStopPosition( sal_Int32 nValue )
238 : {
239 0 : nListtabStopPosition = nValue;
240 0 : }
241 0 : inline void SetFirstLineIndent( sal_Int32 nValue )
242 : {
243 0 : nFirstLineIndent = nValue;
244 0 : }
245 0 : inline void SetIndentAt( sal_Int32 nValue )
246 : {
247 0 : nIndentAt = nValue;
248 0 : }
249 : };
250 :
251 0 : SvxXMLListLevelStyleContext_Impl::SvxXMLListLevelStyleContext_Impl(
252 : SvXMLImport& rImport, sal_uInt16 nPrfx,
253 : const OUString& rLName,
254 : const Reference< xml::sax::XAttributeList > & xAttrList )
255 :
256 : : SvXMLImportContext( rImport, nPrfx, rLName )
257 : , sStarBats( "StarBats" )
258 : , sStarMath( "StarMath" )
259 : , sNumFormat( OUString("1") )
260 : , nLevel( -1L )
261 : , nSpaceBefore( 0L )
262 : , nMinLabelWidth( 0L )
263 : , nMinLabelDist( 0L )
264 : , nImageWidth( 0L )
265 : , nImageHeight( 0L )
266 : , nNumStartValue( 1 )
267 : , nNumDisplayLevels( 1 )
268 : , eAdjust( HoriOrientation::LEFT )
269 : , eBulletFontFamily( FAMILY_DONTKNOW )
270 : , eBulletFontPitch( PITCH_DONTKNOW )
271 : , eBulletFontEncoding( RTL_TEXTENCODING_DONTKNOW )
272 : , eImageVertOrient(0)
273 : , cBullet( 0 )
274 : , nRelSize(0)
275 : , m_nColor(0)
276 : , ePosAndSpaceMode( PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
277 : , eLabelFollowedBy( LabelFollow::LISTTAB )
278 : , nListtabStopPosition( 0 )
279 : , nFirstLineIndent( 0 )
280 : , nIndentAt( 0 )
281 : , bBullet( sal_False )
282 : , bImage( sal_False )
283 : , bNum( sal_False )
284 0 : , bHasColor( sal_False )
285 : {
286 0 : if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_NUMBER ) ||
287 0 : IsXMLToken( rLName, XML_OUTLINE_LEVEL_STYLE ) )
288 0 : bNum = sal_True;
289 0 : else if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_BULLET ) )
290 0 : bBullet = sal_True;
291 0 : else if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_IMAGE ) )
292 0 : bImage = sal_True;
293 :
294 0 : SvXMLTokenMap aTokenMap( lcl_getLevelAttrTokenMap() );
295 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
296 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
297 : {
298 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
299 0 : OUString aLocalName;
300 : sal_uInt16 nPrefix =
301 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
302 0 : &aLocalName );
303 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
304 :
305 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
306 : {
307 : case XML_TOK_TEXT_LEVEL_ATTR_LEVEL:
308 0 : nLevel = rValue.toInt32();
309 0 : if( nLevel >= 1L )
310 0 : nLevel--;
311 : else
312 0 : nLevel = 0;
313 0 : break;
314 : case XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME:
315 0 : sTextStyleName = rValue;
316 0 : break;
317 : case XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR:
318 0 : if (!rValue.isEmpty())
319 0 : cBullet = rValue[0];
320 0 : break;
321 : case XML_TOK_TEXT_LEVEL_ATTR_HREF:
322 0 : if( bImage )
323 0 : sImageURL = rValue;
324 0 : break;
325 : case XML_TOK_TEXT_LEVEL_ATTR_TYPE:
326 : case XML_TOK_TEXT_LEVEL_ATTR_SHOW:
327 : case XML_TOK_TEXT_LEVEL_ATTR_ACTUATE:
328 : // This properties will be ignored
329 0 : break;
330 : case XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT:
331 0 : if( bNum )
332 0 : sNumFormat = rValue;
333 0 : break;
334 : case XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX:
335 0 : sPrefix = rValue;
336 0 : break;
337 : case XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX:
338 0 : sSuffix = rValue;
339 0 : break;
340 : case XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC:
341 0 : if( bNum )
342 0 : sNumLetterSync = rValue;
343 0 : break;
344 : case XML_TOK_TEXT_LEVEL_ATTR_START_VALUE:
345 0 : if( bNum )
346 : {
347 0 : sal_Int32 nTmp = rValue.toInt32();
348 : nNumStartValue =
349 : (nTmp < 0L) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX
350 0 : : (sal_Int16)nTmp );
351 : }
352 0 : break;
353 : case XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS:
354 0 : if( bNum )
355 : {
356 0 : sal_Int32 nTmp = rValue.toInt32();
357 : nNumDisplayLevels =
358 : (nTmp < 1L) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX
359 0 : : (sal_Int16)nTmp );
360 : }
361 0 : break;
362 : }
363 0 : }
364 0 : }
365 :
366 0 : SvxXMLListLevelStyleContext_Impl::~SvxXMLListLevelStyleContext_Impl()
367 : {
368 0 : }
369 :
370 0 : SvXMLImportContext *SvxXMLListLevelStyleContext_Impl::CreateChildContext(
371 : sal_uInt16 nPrefix, const OUString& rLocalName,
372 : const Reference< xml::sax::XAttributeList > & xAttrList )
373 : {
374 0 : SvXMLImportContext *pContext = 0;
375 0 : if( XML_NAMESPACE_STYLE == nPrefix &&
376 0 : ( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) ||
377 0 : IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) )
378 : {
379 0 : pContext = new SvxXMLListLevelStyleAttrContext_Impl( GetImport(),
380 : nPrefix,
381 : rLocalName,
382 : xAttrList,
383 0 : *this );
384 : }
385 0 : else if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName,
386 0 : xmloff::token::XML_BINARY_DATA ) )
387 : {
388 0 : if( bImage && sImageURL.isEmpty() && !xBase64Stream.is() )
389 : {
390 0 : xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
391 0 : if( xBase64Stream.is() )
392 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
393 : rLocalName, xAttrList,
394 0 : xBase64Stream );
395 : }
396 : }
397 0 : if( !pContext )
398 : {
399 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
400 : }
401 :
402 0 : return pContext;
403 : }
404 :
405 0 : Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties(
406 : const SvI18NMap *pI18NMap )
407 : {
408 0 : sal_Int16 eType = NumberingType::NUMBER_NONE;
409 :
410 0 : sal_Int32 nCount = 0;
411 0 : if( bBullet )
412 : {
413 0 : eType = NumberingType::CHAR_SPECIAL;
414 0 : nCount = 15; // 'cBullet' will be written anyway if 'bBullet' is true
415 : }
416 0 : if( bImage )
417 : {
418 0 : eType = NumberingType::BITMAP;
419 0 : nCount = 15;
420 :
421 0 : if( !sImageURL.isEmpty() || xBase64Stream.is() )
422 0 : nCount++;
423 : }
424 0 : if( bNum )
425 : {
426 0 : eType = NumberingType::ARABIC;
427 0 : GetImport().GetMM100UnitConverter().convertNumFormat(
428 0 : eType, sNumFormat, sNumLetterSync, true );
429 0 : nCount = 15;
430 : }
431 :
432 0 : if( ( bBullet || bNum ) && nRelSize )
433 0 : nCount++;
434 :
435 0 : if( !bImage && bHasColor )
436 : {
437 0 : nCount++;
438 : }
439 :
440 0 : if (bBullet && !sSuffix.isEmpty())
441 : {
442 0 : sal_uInt16 const nVersion(GetImport().getGeneratorVersion());
443 : sal_Int32 nUPD;
444 : sal_Int32 nBuildId;
445 0 : if (GetImport().getBuildIds(nUPD, nBuildId)
446 0 : && ( (SvXMLImport::OOo_1x == nVersion)
447 0 : || (SvXMLImport::OOo_2x == nVersion)
448 0 : || (310 == nUPD) || (320 == nUPD) || (330 == nUPD)
449 0 : || ((300 == nUPD) && (nBuildId <= 9573))))
450 : {
451 : // #i93908# OOo < 3.4 wrote a bogus suffix for bullet chars
452 0 : sSuffix = OUString(); // clear it
453 : }
454 : }
455 :
456 0 : Sequence<beans::PropertyValue> aPropSeq( nCount );
457 0 : if( nCount > 0 )
458 : {
459 0 : beans::PropertyValue *pProps = aPropSeq.getArray();
460 0 : sal_Int32 nPos = 0;
461 0 : pProps[nPos].Name = "NumberingType";
462 0 : pProps[nPos++].Value <<= (sal_Int16)eType ;
463 :
464 0 : pProps[nPos].Name = "Prefix";
465 0 : pProps[nPos++].Value <<= sPrefix;
466 :
467 0 : pProps[nPos].Name = "Suffix";
468 0 : pProps[nPos++].Value <<= sSuffix;
469 :
470 0 : pProps[nPos].Name = "Adjust";
471 0 : pProps[nPos++].Value <<= eAdjust;
472 :
473 0 : sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth;
474 0 : pProps[nPos].Name = "LeftMargin";
475 0 : pProps[nPos++].Value <<= (sal_Int32)nLeftMargin;
476 :
477 0 : sal_Int32 nFirstLineOffset = -nMinLabelWidth;
478 :
479 0 : pProps[nPos].Name = "FirstLineOffset";
480 0 : pProps[nPos++].Value <<= (sal_Int32)nFirstLineOffset;
481 :
482 0 : pProps[nPos].Name = "SymbolTextDistance";
483 0 : pProps[nPos++].Value <<= (sal_Int16)nMinLabelDist;
484 :
485 0 : pProps[nPos].Name = "PositionAndSpaceMode";
486 0 : pProps[nPos++].Value <<= (sal_Int16)ePosAndSpaceMode;
487 0 : pProps[nPos].Name = "LabelFollowedBy";
488 0 : pProps[nPos++].Value <<= (sal_Int16)eLabelFollowedBy;
489 0 : pProps[nPos].Name = "ListtabStopPosition";
490 0 : pProps[nPos++].Value <<= (sal_Int32)nListtabStopPosition;
491 0 : pProps[nPos].Name = "FirstLineIndent";
492 0 : pProps[nPos++].Value <<= (sal_Int32)nFirstLineIndent;
493 0 : pProps[nPos].Name = "IndentAt";
494 0 : pProps[nPos++].Value <<= (sal_Int32)nIndentAt;
495 :
496 0 : OUString sDisplayTextStyleName = GetImport().GetStyleDisplayName(
497 0 : XML_STYLE_FAMILY_TEXT_TEXT, sTextStyleName );
498 0 : OUString sStyleName = sDisplayTextStyleName;
499 0 : if( !sStyleName.isEmpty() && pI18NMap )
500 0 : sStyleName = pI18NMap->Get( SFX_STYLE_FAMILY_CHAR, sStyleName );
501 0 : pProps[nPos].Name = "CharStyleName";
502 0 : pProps[nPos++].Value <<= sDisplayTextStyleName;
503 :
504 0 : if( bBullet )
505 : {
506 0 : awt::FontDescriptor aFDesc;
507 0 : aFDesc.Name = sBulletFontName;
508 0 : if( !sBulletFontName.isEmpty() )
509 : {
510 0 : aFDesc.StyleName = sBulletFontStyleName;
511 0 : aFDesc.Family = eBulletFontFamily;
512 0 : aFDesc.Pitch = eBulletFontPitch;
513 0 : aFDesc.CharSet = eBulletFontEncoding;
514 0 : aFDesc.Weight = WEIGHT_DONTKNOW;
515 0 : sal_Bool bStarSymbol = sal_False;
516 0 : if( aFDesc.Name.equalsIgnoreAsciiCase( sStarBats ) )
517 : {
518 0 : cBullet = GetImport().ConvStarBatsCharToStarSymbol( cBullet );
519 0 : bStarSymbol = sal_True;
520 : }
521 0 : else if( aFDesc.Name.equalsIgnoreAsciiCase( sStarMath ) )
522 : {
523 0 : cBullet = GetImport().ConvStarMathCharToStarSymbol( cBullet );
524 0 : bStarSymbol = sal_True;
525 : }
526 0 : if( bStarSymbol )
527 0 : aFDesc.Name = "StarSymbol" ;
528 : }
529 :
530 : // Must append 'cBullet' even if it is zero
531 : // if 'bBullet' is true and 'cBullet' is zero - BulletChar property must be 0.
532 0 : OUStringBuffer sTmp(1);
533 0 : sTmp.append( cBullet );
534 0 : pProps[nPos].Name = "BulletChar";
535 0 : pProps[nPos++].Value <<= sTmp.makeStringAndClear();
536 :
537 0 : pProps[nPos].Name = "BulletFont";
538 0 : pProps[nPos++].Value <<= aFDesc;
539 :
540 : }
541 :
542 0 : if( bImage )
543 : {
544 0 : OUString sStr( sImageURL );
545 0 : if( !sImageURL.isEmpty() )
546 : {
547 0 : sStr = GetImport().ResolveGraphicObjectURL( sImageURL, false );
548 : }
549 0 : else if( xBase64Stream.is() )
550 : {
551 0 : sStr = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
552 : }
553 :
554 0 : if( !sStr.isEmpty() )
555 : {
556 0 : pProps[nPos].Name = "GraphicURL";
557 0 : pProps[nPos++].Value <<= sStr;
558 : }
559 :
560 0 : awt::Size aSize( nImageWidth, nImageHeight );
561 0 : pProps[nPos].Name = "GraphicSize";
562 0 : pProps[nPos++].Value <<= aSize;
563 :
564 0 : pProps[nPos].Name = "VertOrient";
565 0 : pProps[nPos++].Value <<= (sal_Int16)eImageVertOrient;
566 : }
567 :
568 0 : if( bNum )
569 : {
570 0 : pProps[nPos].Name = "StartWith";
571 0 : pProps[nPos++].Value <<= (sal_Int16)nNumStartValue;
572 :
573 0 : pProps[nPos].Name = "ParentNumbering";
574 0 : pProps[nPos++].Value <<= (sal_Int16)nNumDisplayLevels;
575 : }
576 :
577 0 : if( ( bNum || bBullet ) && nRelSize )
578 : {
579 0 : pProps[nPos].Name = "BulletRelSize";
580 0 : pProps[nPos++].Value <<= nRelSize;
581 : }
582 :
583 0 : if( !bImage && bHasColor )
584 : {
585 0 : pProps[nPos].Name = "BulletColor";
586 0 : pProps[nPos++].Value <<= m_nColor;
587 : }
588 :
589 0 : DBG_ASSERT( nPos == nCount, "array under/overflow" );
590 : }
591 :
592 0 : return aPropSeq;
593 : }
594 :
595 : enum SvxXMLStyleAttributesAttrTokens
596 : {
597 : XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE,
598 : XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH,
599 : XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST,
600 : XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN,
601 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME,
602 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY,
603 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC,
604 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME,
605 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH,
606 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET,
607 : XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS,
608 : XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL,
609 : XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH,
610 : XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT,
611 : XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR,
612 : XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR,
613 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE,
614 : XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE,
615 : XML_TOK_STYLE_ATTRIBUTES_ATTR_END=XML_TOK_UNKNOWN
616 : };
617 0 : static const SvXMLTokenMapEntry* lcl_getStyleAttributesAttrTokenMap()
618 : {
619 : static const SvXMLTokenMapEntry aStyleAttributesAttrTokenMap[] =
620 : {
621 : { XML_NAMESPACE_TEXT, XML_SPACE_BEFORE,
622 : XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE },
623 : { XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH,
624 : XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH },
625 : { XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE,
626 : XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST },
627 : { XML_NAMESPACE_FO, XML_TEXT_ALIGN,
628 : XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN },
629 : { XML_NAMESPACE_STYLE, XML_FONT_NAME,
630 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME },
631 : { XML_NAMESPACE_FO, XML_FONT_FAMILY,
632 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY },
633 : { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC,
634 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC },
635 : { XML_NAMESPACE_STYLE, XML_FONT_STYLE_NAME,
636 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME },
637 : { XML_NAMESPACE_STYLE, XML_FONT_PITCH,
638 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH },
639 : { XML_NAMESPACE_STYLE, XML_FONT_CHARSET,
640 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET },
641 : { XML_NAMESPACE_STYLE, XML_VERTICAL_POS,
642 : XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS },
643 : { XML_NAMESPACE_STYLE, XML_VERTICAL_REL,
644 : XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL },
645 : { XML_NAMESPACE_FO, XML_WIDTH,
646 : XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH },
647 : { XML_NAMESPACE_FO, XML_HEIGHT,
648 : XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT },
649 : { XML_NAMESPACE_FO, XML_COLOR,
650 : XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR },
651 : { XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR,
652 : XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR },
653 : { XML_NAMESPACE_FO, XML_FONT_SIZE,
654 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE },
655 : { XML_NAMESPACE_TEXT, XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
656 : XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE },
657 : XML_TOKEN_MAP_END
658 : };
659 0 : return aStyleAttributesAttrTokenMap;
660 : }
661 0 : SvxXMLListLevelStyleAttrContext_Impl::SvxXMLListLevelStyleAttrContext_Impl(
662 : SvXMLImport& rImport, sal_uInt16 nPrfx,
663 : const OUString& rLName,
664 : const Reference< xml::sax::XAttributeList > & xAttrList,
665 : SvxXMLListLevelStyleContext_Impl& rLLevel ) :
666 : SvXMLImportContext( rImport, nPrfx, rLName ),
667 0 : rListLevel( rLLevel )
668 : {
669 0 : SvXMLTokenMap aTokenMap( lcl_getStyleAttributesAttrTokenMap() );
670 0 : SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
671 :
672 0 : OUString sFontName, sFontFamily, sFontStyleName, sFontFamilyGeneric,
673 0 : sFontPitch, sFontCharset;
674 0 : OUString sVerticalPos, sVerticalRel;
675 :
676 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
677 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
678 : {
679 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
680 0 : OUString aLocalName;
681 : sal_uInt16 nPrefix =
682 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
683 0 : &aLocalName );
684 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
685 :
686 : sal_Int32 nVal;
687 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
688 : {
689 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE:
690 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, SHRT_MIN, SHRT_MAX))
691 0 : rListLevel.SetSpaceBefore( nVal );
692 0 : break;
693 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH:
694 0 : if (rUnitConv.convertMeasureToCore( nVal, rValue, 0, SHRT_MAX ))
695 0 : rListLevel.SetMinLabelWidth( nVal );
696 0 : break;
697 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST:
698 0 : if (rUnitConv.convertMeasureToCore( nVal, rValue, 0, USHRT_MAX ))
699 0 : rListLevel.SetMinLabelDist( nVal );
700 0 : break;
701 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN:
702 0 : if( !rValue.isEmpty() )
703 : {
704 0 : sal_Int16 eAdjust = HoriOrientation::LEFT;
705 0 : if( IsXMLToken( rValue, XML_CENTER ) )
706 0 : eAdjust = HoriOrientation::CENTER;
707 0 : else if( IsXMLToken( rValue, XML_END ) )
708 0 : eAdjust = HoriOrientation::RIGHT;
709 0 : rListLevel.SetAdjust( eAdjust );
710 : }
711 0 : break;
712 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME:
713 0 : sFontName = rValue;
714 0 : break;
715 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY:
716 0 : sFontFamily = rValue;
717 0 : break;
718 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC:
719 0 : sFontFamilyGeneric = rValue;
720 0 : break;
721 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME:
722 0 : sFontStyleName = rValue;
723 0 : break;
724 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH:
725 0 : sFontPitch = rValue;
726 0 : break;
727 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET:
728 0 : sFontCharset = rValue;
729 0 : break;
730 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS:
731 0 : sVerticalPos = rValue;
732 0 : break;
733 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL:
734 0 : sVerticalRel = rValue;
735 0 : break;
736 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH:
737 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, 0, SAL_MAX_INT32))
738 0 : rListLevel.SetImageWidth( nVal );
739 0 : break;
740 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT:
741 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, 0, SAL_MAX_INT32))
742 0 : rListLevel.SetImageHeight( nVal );
743 0 : break;
744 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR:
745 : {
746 0 : sal_Int32 nColor(0);
747 0 : if (::sax::Converter::convertColor( nColor, rValue ))
748 : {
749 0 : rListLevel.SetColor( nColor );
750 : }
751 : }
752 0 : break;
753 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR:
754 : {
755 0 : if( IsXMLToken( rValue, XML_TRUE ) )
756 0 : rListLevel.SetColor( (sal_Int32)0xffffffff );
757 : }
758 0 : break;
759 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE:
760 0 : if (::sax::Converter::convertPercent( nVal, rValue ))
761 0 : rListLevel.SetRelSize( (sal_Int16)nVal );
762 0 : break;
763 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE:
764 : {
765 0 : sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
766 0 : if( IsXMLToken( rValue, XML_LABEL_ALIGNMENT ) )
767 0 : ePosAndSpaceMode = PositionAndSpaceMode::LABEL_ALIGNMENT;
768 0 : rListLevel.SetPosAndSpaceMode( ePosAndSpaceMode );
769 : }
770 0 : break;
771 : }
772 0 : }
773 :
774 0 : if( !sFontName.isEmpty() )
775 : {
776 : const XMLFontStylesContext *pFontDecls =
777 0 : GetImport().GetFontDecls();
778 0 : if( pFontDecls )
779 : {
780 0 : ::std::vector < XMLPropertyState > aProps;
781 0 : if( pFontDecls->FillProperties( sFontName, aProps, 0, 1, 2, 3, 4 ) )
782 : {
783 0 : OUString sTmp;
784 0 : sal_Int16 nTmp = 0;
785 0 : ::std::vector< XMLPropertyState >::iterator i;
786 0 : for( i = aProps.begin(); i != aProps.end(); ++i )
787 : {
788 0 : switch( i->mnIndex )
789 : {
790 : case 0:
791 0 : i->maValue >>= sTmp;
792 0 : rListLevel.SetBulletFontName( sTmp);
793 0 : break;
794 : case 1:
795 0 : i->maValue >>= sTmp;
796 0 : rListLevel.SetBulletFontStyleName( sTmp );
797 0 : break;
798 : case 2:
799 0 : i->maValue >>= nTmp;
800 0 : rListLevel.SetBulletFontFamily( nTmp );
801 0 : break;
802 : case 3:
803 0 : i->maValue >>= nTmp;
804 0 : rListLevel.SetBulletFontPitch( nTmp );
805 0 : break;
806 : case 4:
807 0 : i->maValue >>= nTmp;
808 0 : rListLevel.SetBulletFontEncoding( nTmp );
809 0 : break;
810 : }
811 0 : }
812 0 : }
813 : }
814 : }
815 0 : if( !sFontFamily.isEmpty() )
816 : {
817 0 : Any aAny;
818 :
819 0 : XMLFontFamilyNamePropHdl aFamilyNameHdl;
820 0 : if( aFamilyNameHdl.importXML( sFontFamily, aAny, rUnitConv ) )
821 : {
822 0 : OUString sTmp;
823 0 : aAny >>= sTmp;
824 0 : rListLevel.SetBulletFontName( sTmp);
825 : }
826 :
827 0 : XMLFontFamilyPropHdl aFamilyHdl;
828 0 : if( !sFontFamilyGeneric.isEmpty() &&
829 0 : aFamilyHdl.importXML( sFontFamilyGeneric, aAny, rUnitConv ) )
830 : {
831 0 : sal_Int16 nTmp = 0;
832 0 : aAny >>= nTmp;
833 0 : rListLevel.SetBulletFontFamily( nTmp );
834 : }
835 :
836 0 : if( !sFontStyleName.isEmpty() )
837 0 : rListLevel.SetBulletFontStyleName( sFontStyleName );
838 :
839 0 : XMLFontPitchPropHdl aPitchHdl;
840 0 : if( !sFontPitch.isEmpty() &&
841 0 : aPitchHdl.importXML( sFontPitch, aAny, rUnitConv ) )
842 : {
843 0 : sal_Int16 nTmp = 0;
844 0 : aAny >>= nTmp;
845 0 : rListLevel.SetBulletFontPitch( nTmp );
846 : }
847 :
848 0 : XMLFontEncodingPropHdl aEncHdl;
849 0 : if( !sFontCharset.isEmpty() &&
850 0 : aEncHdl.importXML( sFontCharset, aAny, rUnitConv ) )
851 : {
852 0 : sal_Int16 nTmp = 0;
853 0 : aAny >>= nTmp;
854 0 : rListLevel.SetBulletFontEncoding( nTmp );
855 0 : }
856 : }
857 :
858 0 : sal_Int16 eVertOrient = VertOrientation::LINE_CENTER;
859 0 : if( !sVerticalPos.isEmpty() )
860 : {
861 0 : if( IsXMLToken( sVerticalPos, XML_TOP ) )
862 0 : eVertOrient = VertOrientation::LINE_TOP;
863 0 : else if( IsXMLToken( sVerticalPos, XML_BOTTOM ) )
864 0 : eVertOrient = VertOrientation::LINE_BOTTOM;
865 : }
866 0 : if( !sVerticalRel.isEmpty() )
867 : {
868 0 : if( IsXMLToken( sVerticalRel, XML_BASELINE ) )
869 : {
870 : // TOP and BOTTOM are exchanged for a baseline relation
871 0 : switch( eVertOrient )
872 : {
873 : case VertOrientation::LINE_TOP:
874 0 : eVertOrient = VertOrientation::BOTTOM;
875 0 : break;
876 : case VertOrientation::LINE_CENTER:
877 0 : eVertOrient = VertOrientation::CENTER;
878 0 : break;
879 : case VertOrientation::LINE_BOTTOM:
880 0 : eVertOrient = VertOrientation::TOP;
881 0 : break;
882 : }
883 : }
884 0 : else if( IsXMLToken( sVerticalRel, XML_CHAR ) )
885 : {
886 0 : switch( eVertOrient )
887 : {
888 : case VertOrientation::LINE_TOP:
889 0 : eVertOrient = VertOrientation::CHAR_TOP;
890 0 : break;
891 : case VertOrientation::LINE_CENTER:
892 0 : eVertOrient = VertOrientation::CHAR_CENTER;
893 0 : break;
894 : case VertOrientation::LINE_BOTTOM:
895 0 : eVertOrient = VertOrientation::CHAR_BOTTOM;
896 0 : break;
897 : }
898 : }
899 : }
900 0 : rListLevel.SetImageVertOrient( eVertOrient );
901 0 : }
902 :
903 0 : SvxXMLListLevelStyleAttrContext_Impl::~SvxXMLListLevelStyleAttrContext_Impl()
904 : {
905 0 : }
906 :
907 0 : SvXMLImportContext* SvxXMLListLevelStyleAttrContext_Impl::CreateChildContext(
908 : sal_uInt16 nPrefix, const OUString& rLocalName,
909 : const Reference< xml::sax::XAttributeList > & xAttrList )
910 : {
911 0 : SvXMLImportContext *pContext = 0;
912 0 : if ( XML_NAMESPACE_STYLE == nPrefix &&
913 0 : IsXMLToken( rLocalName, XML_LIST_LEVEL_LABEL_ALIGNMENT ) )
914 : {
915 0 : pContext = new SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( GetImport(),
916 : nPrefix,
917 : rLocalName,
918 : xAttrList,
919 0 : rListLevel );
920 : }
921 0 : if( !pContext )
922 : {
923 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
924 : }
925 :
926 0 : return pContext;
927 : }
928 :
929 : enum SvxXMLStyleAttributesLabelAlignmentAttrTokens
930 : {
931 : XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY,
932 : XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION,
933 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT,
934 : XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT,
935 :
936 : XML_TOK_STYLE_ATTRIBUTES_LABEL_ALIGNMENT_ATTR_END=XML_TOK_UNKNOWN
937 : };
938 0 : static const SvXMLTokenMapEntry* lcl_getStyleAlignmentAttributesAttrTokenMap()
939 : {
940 : static const SvXMLTokenMapEntry aStyleAlignmentAttributesAttrTokenMap[] =
941 : {
942 : { XML_NAMESPACE_TEXT, XML_LABEL_FOLLOWED_BY,
943 : XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY },
944 : { XML_NAMESPACE_TEXT, XML_LIST_TAB_STOP_POSITION,
945 : XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION },
946 : { XML_NAMESPACE_FO, XML_TEXT_INDENT,
947 : XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT },
948 : { XML_NAMESPACE_FO, XML_MARGIN_LEFT,
949 : XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT },
950 :
951 : XML_TOKEN_MAP_END
952 : };
953 0 : return aStyleAlignmentAttributesAttrTokenMap;
954 : }
955 0 : SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl::SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl(
956 : SvXMLImport& rImport, sal_uInt16 nPrfx,
957 : const OUString& rLName,
958 : const Reference< xml::sax::XAttributeList > & xAttrList,
959 : SvxXMLListLevelStyleContext_Impl& rLLevel ) :
960 : SvXMLImportContext( rImport, nPrfx, rLName ),
961 0 : rListLevel( rLLevel )
962 : {
963 0 : SvXMLTokenMap aTokenMap( lcl_getStyleAlignmentAttributesAttrTokenMap() );
964 0 : SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter();
965 :
966 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
967 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
968 : {
969 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
970 0 : OUString aLocalName;
971 : sal_uInt16 nPrefix =
972 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
973 0 : &aLocalName );
974 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
975 :
976 : sal_Int32 nVal;
977 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
978 : {
979 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY:
980 : {
981 0 : sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB;
982 0 : if( IsXMLToken( rValue, XML_SPACE ) )
983 0 : eLabelFollowedBy = LabelFollow::SPACE;
984 0 : else if( IsXMLToken( rValue, XML_NOTHING ) )
985 0 : eLabelFollowedBy = LabelFollow::NOTHING;
986 0 : rListLevel.SetLabelFollowedBy( eLabelFollowedBy );
987 : }
988 0 : break;
989 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION:
990 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, 0, SHRT_MAX))
991 0 : rListLevel.SetListtabStopPosition( nVal );
992 0 : break;
993 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT:
994 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, SHRT_MIN, SHRT_MAX))
995 0 : rListLevel.SetFirstLineIndent( nVal );
996 0 : break;
997 : case XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT:
998 0 : if (rUnitConv.convertMeasureToCore(nVal, rValue, SHRT_MIN, SHRT_MAX))
999 0 : rListLevel.SetIndentAt( nVal );
1000 0 : break;
1001 : }
1002 0 : }
1003 0 : }
1004 :
1005 0 : SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl::~SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl()
1006 : {
1007 0 : }
1008 :
1009 0 : class SvxXMLListStyle_Impl : public std::vector<SvxXMLListLevelStyleContext_Impl *> {};
1010 :
1011 0 : void SvxXMLListStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
1012 : const OUString& rLocalName,
1013 : const OUString& rValue )
1014 : {
1015 0 : if( XML_NAMESPACE_TEXT == nPrefixKey &&
1016 0 : IsXMLToken( rLocalName, XML_CONSECUTIVE_NUMBERING ) )
1017 : {
1018 0 : bConsecutive = IsXMLToken( rValue, XML_TRUE );
1019 : }
1020 : else
1021 : {
1022 0 : SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
1023 : }
1024 0 : }
1025 :
1026 0 : SvxXMLListStyleContext::SvxXMLListStyleContext( SvXMLImport& rImport,
1027 : sal_uInt16 nPrfx,
1028 : const OUString& rLName,
1029 : const Reference< xml::sax::XAttributeList > & xAttrList,
1030 : bool bOutl )
1031 : : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, bOutl ? XML_STYLE_FAMILY_TEXT_OUTLINE : XML_STYLE_FAMILY_TEXT_LIST )
1032 : , sIsPhysical( "IsPhysical" )
1033 : , sNumberingRules( "NumberingRules" )
1034 : , sName( "Name" )
1035 : , sIsContinuousNumbering( "IsContinuousNumbering" )
1036 : , pLevelStyles( 0 )
1037 : , nLevels( 0 )
1038 : , bConsecutive( false )
1039 0 : , bOutline( bOutl )
1040 : {
1041 0 : }
1042 :
1043 0 : SvxXMLListStyleContext::~SvxXMLListStyleContext()
1044 : {
1045 0 : if( pLevelStyles )
1046 : {
1047 0 : while( !pLevelStyles->empty() )
1048 : {
1049 0 : SvxXMLListLevelStyleContext_Impl *pStyle = pLevelStyles->back();
1050 0 : pLevelStyles->pop_back();
1051 0 : pStyle->ReleaseRef();
1052 : }
1053 : }
1054 :
1055 0 : delete pLevelStyles;
1056 0 : }
1057 :
1058 0 : TYPEINIT1( SvxXMLListStyleContext, SvXMLStyleContext );
1059 :
1060 0 : SvXMLImportContext *SvxXMLListStyleContext::CreateChildContext(
1061 : sal_uInt16 nPrefix,
1062 : const OUString& rLocalName,
1063 : const Reference< xml::sax::XAttributeList > & xAttrList )
1064 : {
1065 0 : SvXMLImportContext *pContext = 0;
1066 :
1067 0 : if( XML_NAMESPACE_TEXT == nPrefix &&
1068 : ( bOutline
1069 0 : ? IsXMLToken( rLocalName, XML_OUTLINE_LEVEL_STYLE )
1070 0 : : ( IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_NUMBER ) ||
1071 0 : IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_BULLET ) ||
1072 0 : IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_IMAGE ) ) ) )
1073 : {
1074 : SvxXMLListLevelStyleContext_Impl *pLevelStyle =
1075 0 : new SvxXMLListLevelStyleContext_Impl( GetImport(), nPrefix,
1076 0 : rLocalName, xAttrList );
1077 0 : if( !pLevelStyles )
1078 0 : pLevelStyles = new SvxXMLListStyle_Impl;
1079 0 : pLevelStyles->push_back( pLevelStyle );
1080 0 : pLevelStyle->AddRef();
1081 :
1082 0 : pContext = pLevelStyle;
1083 : }
1084 : else
1085 : {
1086 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1087 : }
1088 :
1089 0 : return pContext;
1090 : }
1091 :
1092 0 : void SvxXMLListStyleContext::FillUnoNumRule(
1093 : const Reference< container::XIndexReplace > & rNumRule,
1094 : const SvI18NMap *pI18NMap ) const
1095 : {
1096 : try
1097 : {
1098 0 : if( pLevelStyles && rNumRule.is() )
1099 : {
1100 0 : sal_uInt16 nCount = pLevelStyles->size();
1101 0 : sal_Int32 l_nLevels = rNumRule->getCount();
1102 0 : for( sal_uInt16 i=0; i < nCount; i++ )
1103 : {
1104 : SvxXMLListLevelStyleContext_Impl *pLevelStyle =
1105 0 : (*pLevelStyles)[i];
1106 0 : sal_Int32 nLevel = pLevelStyle->GetLevel();
1107 0 : if( nLevel >= 0 && nLevel < l_nLevels )
1108 : {
1109 : Sequence<beans::PropertyValue> aProps =
1110 0 : pLevelStyle->GetProperties( pI18NMap );
1111 0 : Any aAny;
1112 0 : aAny <<= aProps;
1113 0 : rNumRule->replaceByIndex( nLevel, aAny );
1114 : }
1115 : }
1116 : }
1117 :
1118 0 : Reference < XPropertySet > xPropSet( rNumRule, UNO_QUERY );
1119 0 : Reference< XPropertySetInfo > xPropSetInfo;
1120 0 : if (xPropSet.is())
1121 0 : xPropSetInfo = xPropSet->getPropertySetInfo();
1122 0 : if( xPropSetInfo.is() &&
1123 0 : xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) )
1124 : {
1125 0 : Any aAny;
1126 0 : sal_Bool bTmp = bConsecutive;
1127 0 : aAny.setValue( &bTmp, ::getBooleanCppuType() );
1128 0 : xPropSet->setPropertyValue( sIsContinuousNumbering, aAny );
1129 0 : }
1130 : }
1131 0 : catch (const Exception&)
1132 : {
1133 : OSL_FAIL( "SvxXMLListStyleContext::FillUnoNumRule - Exception caught" );
1134 : }
1135 0 : }
1136 :
1137 0 : void SvxXMLListStyleContext::CreateAndInsertLate( bool bOverwrite )
1138 : {
1139 0 : if( bOutline )
1140 : {
1141 0 : if( bOverwrite )
1142 : {
1143 : const Reference< XIndexReplace >& rNumRule =
1144 0 : GetImport().GetTextImport()->GetChapterNumbering();
1145 : // We don't set xNumberingRules here, to avoid using them
1146 : // as numbering rules.
1147 0 : if( rNumRule.is() )
1148 0 : FillUnoNumRule( rNumRule, 0 );
1149 : }
1150 : }
1151 : else
1152 : {
1153 0 : Reference < XStyle > xStyle;
1154 0 : const OUString& rName = GetDisplayName();
1155 0 : if( rName.isEmpty() )
1156 : {
1157 0 : SetValid( false );
1158 0 : return;
1159 : }
1160 :
1161 : const Reference < XNameContainer >& rNumStyles =
1162 0 : GetImport().GetTextImport()->GetNumberingStyles();
1163 0 : if( !rNumStyles.is() )
1164 : {
1165 0 : SetValid( false );
1166 0 : return;
1167 : }
1168 :
1169 0 : sal_Bool bNew = sal_False;
1170 0 : if( rNumStyles->hasByName( rName ) )
1171 : {
1172 0 : Any aAny = rNumStyles->getByName( rName );
1173 0 : aAny >>= xStyle;
1174 : }
1175 : else
1176 : {
1177 0 : Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(),
1178 0 : UNO_QUERY );
1179 : DBG_ASSERT( xFactory.is(), "no factory" );
1180 0 : if( !xFactory.is() )
1181 0 : return;
1182 :
1183 0 : Reference < XInterface > xIfc = xFactory->createInstance("com.sun.star.style.NumberingStyle");
1184 0 : if( !xIfc.is() )
1185 0 : return;
1186 0 : Reference < XStyle > xTmp( xIfc, UNO_QUERY );
1187 0 : xStyle = xTmp;
1188 0 : if( !xStyle.is() )
1189 0 : return;
1190 :
1191 0 : Any aAny;
1192 0 : aAny <<= xStyle;
1193 0 : rNumStyles->insertByName( rName, aAny );
1194 0 : bNew = sal_True;
1195 : }
1196 :
1197 0 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
1198 : Reference< XPropertySetInfo > xPropSetInfo =
1199 0 : xPropSet->getPropertySetInfo();
1200 0 : if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) )
1201 : {
1202 0 : Any aAny = xPropSet->getPropertyValue( sIsPhysical );
1203 0 : bNew = !*(sal_Bool *)aAny.getValue();
1204 : }
1205 :
1206 0 : if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
1207 0 : xPropSet->setPropertyValue( "Hidden", uno::makeAny( IsHidden( ) ) );
1208 :
1209 0 : if( rName != GetName() )
1210 0 : GetImport().AddStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
1211 0 : GetName(), rName );
1212 :
1213 0 : Any aAny = xPropSet->getPropertyValue( sNumberingRules );
1214 0 : aAny >>= xNumRules;
1215 0 : nLevels = xNumRules->getCount();
1216 0 : if( bOverwrite || bNew )
1217 : {
1218 0 : FillUnoNumRule( xNumRules, 0 );
1219 0 : aAny <<= xNumRules;
1220 0 : xPropSet->setPropertyValue( sNumberingRules, aAny );
1221 : }
1222 : else
1223 : {
1224 0 : SetValid( false );
1225 : }
1226 :
1227 0 : SetNew( bNew );
1228 : }
1229 : }
1230 :
1231 0 : void SvxXMLListStyleContext::CreateAndInsertAuto() const
1232 : {
1233 : DBG_ASSERT( !bOutline, "Outlines cannot be inserted here" );
1234 : DBG_ASSERT( !xNumRules.is(), "Numbering Rule is existing already" );
1235 :
1236 0 : const OUString& rName = GetName();
1237 0 : if( bOutline || xNumRules.is() || rName.isEmpty() )
1238 : {
1239 0 : ((SvxXMLListStyleContext *)this)->SetValid( false );
1240 0 : return;
1241 : }
1242 :
1243 0 : ((SvxXMLListStyleContext *)this)->xNumRules = CreateNumRule(
1244 0 : GetImport().GetModel() );
1245 0 : ((SvxXMLListStyleContext *)this)->nLevels = xNumRules->getCount();
1246 :
1247 0 : FillUnoNumRule( xNumRules, 0 );
1248 : }
1249 :
1250 0 : Reference < XIndexReplace > SvxXMLListStyleContext::CreateNumRule(
1251 : const Reference < XModel > & rModel )
1252 : {
1253 0 : Reference<XIndexReplace> xNumRule;
1254 :
1255 0 : Reference< XMultiServiceFactory > xFactory( rModel, UNO_QUERY );
1256 : DBG_ASSERT( xFactory.is(), "no factory" );
1257 0 : if( !xFactory.is() )
1258 0 : return xNumRule;
1259 :
1260 0 : Reference < XInterface > xIfc = xFactory->createInstance("com.sun.star.text.NumberingRules");
1261 0 : if( !xIfc.is() )
1262 0 : return xNumRule;
1263 :
1264 0 : xNumRule = Reference<XIndexReplace>( xIfc, UNO_QUERY );
1265 : DBG_ASSERT( xNumRule.is(), "go no numbering rule" );
1266 :
1267 0 : return xNumRule;
1268 : }
1269 :
1270 0 : void SvxXMLListStyleContext::SetDefaultStyle(
1271 : const Reference < XIndexReplace > & rNumRule,
1272 : sal_Int16 nLevel,
1273 : bool bOrdered )
1274 : {
1275 0 : Sequence<beans::PropertyValue> aPropSeq( bOrdered ? 1 : 4 );
1276 0 : beans::PropertyValue *pProps = aPropSeq.getArray();
1277 :
1278 0 : pProps->Name = "NumberingType";
1279 0 : (pProps++)->Value <<= (sal_Int16)(bOrdered ? NumberingType::ARABIC
1280 0 : : NumberingType::CHAR_SPECIAL );
1281 0 : if( !bOrdered )
1282 : {
1283 : // TODO: Bullet-Font
1284 0 : awt::FontDescriptor aFDesc;
1285 : aFDesc.Name =
1286 : #ifdef _WIN32
1287 : "StarBats"
1288 : #else
1289 : "starbats"
1290 : #endif
1291 0 : ;
1292 0 : aFDesc.Family = FAMILY_DONTKNOW ;
1293 0 : aFDesc.Pitch = PITCH_DONTKNOW ;
1294 0 : aFDesc.CharSet = RTL_TEXTENCODING_SYMBOL ;
1295 0 : aFDesc.Weight = WEIGHT_DONTKNOW;
1296 0 : pProps->Name = "BulletFont";
1297 0 : (pProps++)->Value <<= aFDesc;
1298 :
1299 0 : OUStringBuffer sTmp(1);
1300 0 : sTmp.append( (sal_Unicode)(0xF000 + 149) );
1301 0 : pProps->Name = "BulletChar";
1302 0 : (pProps++)->Value <<= sTmp.makeStringAndClear();
1303 0 : pProps->Name = "CharStyleName";
1304 0 : (pProps++)->Value <<= OUString( "Numbering Symbols" );
1305 : }
1306 :
1307 0 : Any aAny;
1308 0 : aAny <<= aPropSeq;
1309 0 : rNumRule->replaceByIndex( nLevel, aAny );
1310 0 : }
1311 :
1312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|