/src/libreoffice/xmloff/source/style/xmlnumi.cxx
Line | Count | Source |
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/frame/XModel.hpp> |
24 | | #include <com/sun/star/graphic/XGraphic.hpp> |
25 | | #include <com/sun/star/awt/FontDescriptor.hpp> |
26 | | #include <com/sun/star/text/HoriOrientation.hpp> |
27 | | #include <com/sun/star/text/VertOrientation.hpp> |
28 | | #include <com/sun/star/text/PositionAndSpaceMode.hpp> |
29 | | #include <com/sun/star/text/LabelFollow.hpp> |
30 | | #include <com/sun/star/container/XNameContainer.hpp> |
31 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
32 | | #include <com/sun/star/style/XStyle.hpp> |
33 | | #include <com/sun/star/io/XOutputStream.hpp> |
34 | | #include <com/sun/star/awt/XBitmap.hpp> |
35 | | #include <com/sun/star/style/NumberingType.hpp> |
36 | | #include <com/sun/star/container/XIndexReplace.hpp> |
37 | | |
38 | | #include <o3tl/any.hxx> |
39 | | #include <o3tl/temporary.hxx> |
40 | | #include <sal/log.hxx> |
41 | | #include <comphelper/diagnose_ex.hxx> |
42 | | #include <comphelper/sequence.hxx> |
43 | | #include <comphelper/propertyvalue.hxx> |
44 | | |
45 | | #include <tools/fontenum.hxx> |
46 | | #include <tools/color.hxx> |
47 | | |
48 | | #include <sax/tools/converter.hxx> |
49 | | |
50 | | #include <vcl/vclenum.hxx> |
51 | | |
52 | | #include <xmloff/xmlnamespace.hxx> |
53 | | #include <xmloff/xmlimp.hxx> |
54 | | #include <xmloff/XMLBase64ImportContext.hxx> |
55 | | #include <xmloff/xmltoken.hxx> |
56 | | |
57 | | #include <xmloff/xmluconv.hxx> |
58 | | #include "fonthdl.hxx" |
59 | | #include <xmloff/XMLFontStylesContext.hxx> |
60 | | #include <xmloff/families.hxx> |
61 | | #include <xmloff/maptype.hxx> |
62 | | |
63 | | #include <xmloff/xmlnumi.hxx> |
64 | | #include <optional> |
65 | | |
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::beans; |
71 | | using namespace ::com::sun::star::container; |
72 | | using namespace ::com::sun::star::lang; |
73 | | using namespace ::com::sun::star::frame; |
74 | | using namespace ::xmloff::token; |
75 | | using namespace ::com::sun::star::io; |
76 | | |
77 | | class SvxXMLListLevelStyleContext_Impl; |
78 | | |
79 | | namespace { |
80 | | |
81 | | class SvxXMLListLevelStyleAttrContext_Impl : public SvXMLImportContext |
82 | | { |
83 | | SvxXMLListLevelStyleContext_Impl& rListLevel; |
84 | | |
85 | | public: |
86 | | |
87 | | SvxXMLListLevelStyleAttrContext_Impl( |
88 | | SvXMLImport& rImport, sal_Int32 nElement, |
89 | | const Reference< xml::sax::XFastAttributeList >& xAttrList, |
90 | | SvxXMLListLevelStyleContext_Impl& rLLevel ); |
91 | | |
92 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
93 | | sal_Int32 nElement, |
94 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
95 | | }; |
96 | | |
97 | | class SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl : public SvXMLImportContext |
98 | | { |
99 | | public: |
100 | | |
101 | | SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( |
102 | | SvXMLImport& rImport, sal_Int32 nElement, |
103 | | const Reference< xml::sax::XFastAttributeList >& xAttrList, |
104 | | SvxXMLListLevelStyleContext_Impl& rLLevel ); |
105 | | }; |
106 | | |
107 | | } |
108 | | |
109 | | class SvxXMLListLevelStyleContext_Impl : public SvXMLImportContext |
110 | | { |
111 | | friend SvxXMLListLevelStyleAttrContext_Impl; |
112 | | |
113 | | OUString sPrefix; |
114 | | OUString sSuffix; |
115 | | std::optional<OUString> sListFormat; // It is optional to distinguish empty format string |
116 | | // from not existing format string in old docs |
117 | | OUString sTextStyleName; |
118 | | OUString sNumFormat; |
119 | | OUString sNumLetterSync; |
120 | | OUString sBulletFontName; |
121 | | OUString sBulletFontStyleName; |
122 | | OUString sImageURL; |
123 | | |
124 | | Reference < XOutputStream > xBase64Stream; |
125 | | |
126 | | sal_Int32 nLevel; |
127 | | sal_Int32 nSpaceBefore; |
128 | | sal_Int32 nMinLabelWidth; |
129 | | sal_Int32 nMinLabelDist; |
130 | | sal_Int32 nImageWidth; |
131 | | sal_Int32 nImageHeight; |
132 | | sal_Int16 nNumStartValue; |
133 | | sal_Int16 nNumDisplayLevels; |
134 | | |
135 | | sal_Int16 eAdjust; |
136 | | sal_Int16 eBulletFontFamily; |
137 | | sal_Int16 eBulletFontPitch; |
138 | | rtl_TextEncoding eBulletFontEncoding; |
139 | | sal_Int16 eImageVertOrient; |
140 | | |
141 | | sal_UCS4 cBullet; |
142 | | |
143 | | sal_Int16 nRelSize; |
144 | | Color m_nColor; |
145 | | |
146 | | sal_Int16 ePosAndSpaceMode; |
147 | | sal_Int16 eLabelFollowedBy; |
148 | | sal_Int32 nListtabStopPosition; |
149 | | sal_Int32 nFirstLineIndent; |
150 | | sal_Int32 nIndentAt; |
151 | | |
152 | | bool bBullet : 1; |
153 | | bool bImage : 1; |
154 | | bool bNum : 1; |
155 | | bool bHasColor : 1; |
156 | | |
157 | | bool m_bIsLegal = false; |
158 | | |
159 | 9.05k | void SetRelSize( sal_Int16 nRel ) { nRelSize = nRel; } |
160 | | void SetColor( Color nColor ) |
161 | 11.4k | { m_nColor = nColor; bHasColor = true; } |
162 | 10.1k | void SetSpaceBefore( sal_Int32 nSet ) { nSpaceBefore = nSet; } |
163 | 8.68k | void SetMinLabelWidth( sal_Int32 nSet ) { nMinLabelWidth = nSet; } |
164 | 1.17k | void SetMinLabelDist( sal_Int32 nSet ) { nMinLabelDist = nSet; } |
165 | 949 | void SetAdjust( sal_Int16 eSet ) { eAdjust = eSet; } |
166 | | |
167 | 8.72k | void SetBulletFontName( const OUString& rSet ) { sBulletFontName = rSet; } |
168 | | void SetBulletFontStyleName( const OUString& rSet ) |
169 | 16 | { sBulletFontStyleName = rSet; } |
170 | 19 | void SetBulletFontFamily( sal_Int16 eSet ) { eBulletFontFamily = eSet; } |
171 | 19 | void SetBulletFontPitch( sal_Int16 eSet ) { eBulletFontPitch = eSet; } |
172 | | void SetBulletFontEncoding( rtl_TextEncoding eSet ) |
173 | 1.13k | { eBulletFontEncoding = eSet; } |
174 | | |
175 | 0 | void SetImageWidth( sal_Int32 nSet ) { nImageWidth = nSet; } |
176 | 0 | void SetImageHeight( sal_Int32 nSet ) { nImageHeight = nSet; } |
177 | | void SetImageVertOrient( sal_Int16 eSet ) |
178 | 40.8k | { eImageVertOrient = eSet; } |
179 | | |
180 | | public: |
181 | | |
182 | | SvxXMLListLevelStyleContext_Impl( |
183 | | SvXMLImport& rImport, sal_Int32 nElement, |
184 | | const Reference< xml::sax::XFastAttributeList > & xAttrList ); |
185 | | |
186 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
187 | | sal_Int32 nElement, |
188 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
189 | | |
190 | 14.3k | sal_Int32 GetLevel() const { return nLevel; } |
191 | | Sequence<beans::PropertyValue> GetProperties(); |
192 | | |
193 | | void SetPosAndSpaceMode( sal_Int16 eValue ) |
194 | 13.7k | { |
195 | 13.7k | ePosAndSpaceMode = eValue; |
196 | 13.7k | } |
197 | | void SetLabelFollowedBy( sal_Int16 eValue ) |
198 | 13.6k | { |
199 | 13.6k | eLabelFollowedBy = eValue; |
200 | 13.6k | } |
201 | | void SetListtabStopPosition( sal_Int32 nValue ) |
202 | 13.2k | { |
203 | 13.2k | nListtabStopPosition = nValue; |
204 | 13.2k | } |
205 | | void SetFirstLineIndent( sal_Int32 nValue ) |
206 | 11.9k | { |
207 | 11.9k | nFirstLineIndent = nValue; |
208 | 11.9k | } |
209 | | void SetIndentAt( sal_Int32 nValue ) |
210 | 11.9k | { |
211 | 11.9k | nIndentAt = nValue; |
212 | 11.9k | } |
213 | | }; |
214 | | |
215 | | constexpr OUStringLiteral gsStarBats( u"StarBats" ); |
216 | | constexpr OUStringLiteral gsStarMath( u"StarMath" ); |
217 | | |
218 | | SvxXMLListLevelStyleContext_Impl::SvxXMLListLevelStyleContext_Impl( |
219 | | SvXMLImport& rImport, sal_Int32 nElement, |
220 | | const Reference< xml::sax::XFastAttributeList > & xAttrList ) |
221 | | |
222 | 28.4k | : SvXMLImportContext( rImport ) |
223 | 28.4k | , sNumFormat( u"1"_ustr ) |
224 | 28.4k | , nLevel( -1 ) |
225 | 28.4k | , nSpaceBefore( 0 ) |
226 | 28.4k | , nMinLabelWidth( 0 ) |
227 | 28.4k | , nMinLabelDist( 0 ) |
228 | 28.4k | , nImageWidth( 0 ) |
229 | 28.4k | , nImageHeight( 0 ) |
230 | 28.4k | , nNumStartValue( 1 ) |
231 | 28.4k | , nNumDisplayLevels( 1 ) |
232 | 28.4k | , eAdjust( HoriOrientation::LEFT ) |
233 | 28.4k | , eBulletFontFamily( FAMILY_DONTKNOW ) |
234 | 28.4k | , eBulletFontPitch( PITCH_DONTKNOW ) |
235 | 28.4k | , eBulletFontEncoding( RTL_TEXTENCODING_DONTKNOW ) |
236 | 28.4k | , eImageVertOrient(0) |
237 | 28.4k | , cBullet( 0 ) |
238 | 28.4k | , nRelSize(0) |
239 | 28.4k | , m_nColor(0) |
240 | 28.4k | , ePosAndSpaceMode( PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION ) |
241 | 28.4k | , eLabelFollowedBy( LabelFollow::LISTTAB ) |
242 | 28.4k | , nListtabStopPosition( 0 ) |
243 | 28.4k | , nFirstLineIndent( 0 ) |
244 | 28.4k | , nIndentAt( 0 ) |
245 | 28.4k | , bBullet( false ) |
246 | 28.4k | , bImage( false ) |
247 | 28.4k | , bNum( false ) |
248 | 28.4k | , bHasColor( false ) |
249 | 28.4k | { |
250 | 28.4k | switch (nElement & TOKEN_MASK) |
251 | 28.4k | { |
252 | 9.89k | case XML_LIST_LEVEL_STYLE_NUMBER: |
253 | 16.5k | case XML_OUTLINE_LEVEL_STYLE: |
254 | 16.5k | bNum = true; |
255 | 16.5k | break; |
256 | 11.9k | case XML_LIST_LEVEL_STYLE_BULLET: |
257 | 11.9k | bBullet = true; |
258 | 11.9k | break; |
259 | 0 | case XML_LIST_LEVEL_STYLE_IMAGE: |
260 | 0 | bImage = true; |
261 | 0 | break; |
262 | 28.4k | } |
263 | | |
264 | 28.4k | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
265 | 71.5k | { |
266 | 71.5k | switch( aIter.getToken() ) |
267 | 71.5k | { |
268 | 28.0k | case XML_ELEMENT(TEXT, XML_LEVEL): |
269 | 28.0k | nLevel = aIter.toInt32(); |
270 | 28.0k | if( nLevel >= 1 ) |
271 | 27.9k | nLevel--; |
272 | 113 | else |
273 | 113 | nLevel = 0; |
274 | 28.0k | break; |
275 | 7.16k | case XML_ELEMENT(TEXT, XML_STYLE_NAME): |
276 | 7.16k | sTextStyleName = aIter.toString(); |
277 | 7.16k | break; |
278 | 11.7k | case XML_ELEMENT(TEXT, XML_BULLET_CHAR): |
279 | 11.7k | if (!aIter.isEmpty()) |
280 | 11.7k | { |
281 | 11.7k | cBullet = aIter.toString().iterateCodePoints(&o3tl::temporary(sal_Int32(0))); |
282 | 11.7k | } |
283 | 11.7k | break; |
284 | 0 | case XML_ELEMENT(XLINK, XML_HREF): |
285 | 0 | if( bImage ) |
286 | 0 | sImageURL = aIter.toString(); |
287 | 0 | break; |
288 | 0 | case XML_ELEMENT(XLINK, XML_TYPE): |
289 | 0 | case XML_ELEMENT(XLINK, XML_SHOW): |
290 | 0 | case XML_ELEMENT(XLINK, XML_ACTUATE): |
291 | | // This properties will be ignored |
292 | 0 | break; |
293 | 15.5k | case XML_ELEMENT(STYLE, XML_NUM_FORMAT): |
294 | 15.5k | if( bNum ) |
295 | 15.5k | sNumFormat = aIter.toString(); |
296 | 15.5k | break; |
297 | 0 | case XML_ELEMENT(STYLE, XML_NUM_PREFIX): |
298 | 0 | sPrefix = aIter.toString(); |
299 | 0 | break; |
300 | 7.68k | case XML_ELEMENT(STYLE, XML_NUM_SUFFIX): |
301 | 7.68k | sSuffix = aIter.toString(); |
302 | 7.68k | break; |
303 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LIST_FORMAT): |
304 | 0 | case XML_ELEMENT(LO_EXT, XML_NUM_LIST_FORMAT): |
305 | 0 | sListFormat = std::make_optional(aIter.toString()); |
306 | 0 | break; |
307 | 0 | case XML_ELEMENT(LO_EXT, XML_IS_LEGAL): |
308 | 0 | m_bIsLegal = aIter.toBoolean(); |
309 | 0 | break; |
310 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): |
311 | 0 | if( bNum ) |
312 | 0 | sNumLetterSync = aIter.toString(); |
313 | 0 | break; |
314 | 3 | case XML_ELEMENT(TEXT, XML_START_VALUE): |
315 | 3 | if( bNum ) |
316 | 3 | { |
317 | 3 | sal_Int32 nTmp = aIter.toInt32(); |
318 | 3 | nNumStartValue = |
319 | 3 | (nTmp < 0) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX |
320 | 3 | : static_cast<sal_Int16>(nTmp) ); |
321 | 3 | } |
322 | 3 | break; |
323 | 1.27k | case XML_ELEMENT(TEXT, XML_DISPLAY_LEVELS): |
324 | 1.27k | if( bNum ) |
325 | 1.27k | { |
326 | 1.27k | sal_Int32 nTmp = aIter.toInt32(); |
327 | 1.27k | nNumDisplayLevels = |
328 | 1.27k | (nTmp < 1) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX |
329 | 1.24k | : static_cast<sal_Int16>(nTmp) ); |
330 | 1.27k | } |
331 | 1.27k | break; |
332 | 105 | default: |
333 | 105 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
334 | 71.5k | } |
335 | 71.5k | } |
336 | 28.4k | } |
337 | | |
338 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLListLevelStyleContext_Impl::createFastChildContext( |
339 | | sal_Int32 nElement, |
340 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
341 | 41.5k | { |
342 | 41.5k | if( nElement == XML_ELEMENT(STYLE, XML_LIST_LEVEL_PROPERTIES) || |
343 | 14.5k | nElement == XML_ELEMENT(STYLE, XML_TEXT_PROPERTIES) ) |
344 | 40.8k | { |
345 | 40.8k | return new SvxXMLListLevelStyleAttrContext_Impl( GetImport(), |
346 | 40.8k | nElement, |
347 | 40.8k | xAttrList, |
348 | 40.8k | *this ); |
349 | 40.8k | } |
350 | 633 | else if( nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA) ) |
351 | 0 | { |
352 | 0 | if( bImage && sImageURL.isEmpty() && !xBase64Stream.is() ) |
353 | 0 | { |
354 | 0 | xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); |
355 | 0 | if( xBase64Stream.is() ) |
356 | 0 | return new XMLBase64ImportContext( GetImport(), xBase64Stream ); |
357 | 0 | } |
358 | 0 | } |
359 | 633 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
360 | 633 | return nullptr; |
361 | 633 | } |
362 | | |
363 | | Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties() |
364 | 14.1k | { |
365 | 14.1k | if (!bBullet && !bImage && !bNum) |
366 | 0 | { |
367 | 0 | return Sequence<beans::PropertyValue>(); |
368 | 0 | } |
369 | | |
370 | 14.1k | sal_Int16 eType = NumberingType::NUMBER_NONE; |
371 | 14.1k | std::vector<beans::PropertyValue> aProperties; |
372 | | |
373 | 14.1k | if( bBullet ) |
374 | 7.13k | { |
375 | 7.13k | eType = NumberingType::CHAR_SPECIAL; |
376 | 7.13k | } |
377 | 14.1k | if( bImage ) |
378 | 0 | { |
379 | 0 | eType = NumberingType::BITMAP; |
380 | 0 | } |
381 | 14.1k | if( bNum ) |
382 | 7.02k | { |
383 | 7.02k | eType = NumberingType::ARABIC; |
384 | 7.02k | GetImport().GetMM100UnitConverter().convertNumFormat( |
385 | 7.02k | eType, sNumFormat, sNumLetterSync, true ); |
386 | 7.02k | } |
387 | | |
388 | 14.1k | if (bBullet && !sSuffix.isEmpty()) |
389 | 0 | { |
390 | 0 | sal_uInt16 const nVersion(GetImport().getGeneratorVersion()); |
391 | 0 | sal_Int32 nUPD; |
392 | 0 | sal_Int32 nBuildId; |
393 | 0 | if (GetImport().getBuildIds(nUPD, nBuildId) |
394 | 0 | && ( (SvXMLImport::OOo_1x == nVersion) |
395 | 0 | || (SvXMLImport::OOo_2x == nVersion) |
396 | 0 | || (310 == nUPD) || (320 == nUPD) || (330 == nUPD) |
397 | 0 | || ((300 == nUPD) && (nBuildId <= 9573)))) |
398 | 0 | { |
399 | | // #i93908# OOo < 3.4 wrote a bogus suffix for bullet chars |
400 | 0 | sSuffix.clear(); // clear it |
401 | 0 | } |
402 | 0 | } |
403 | | |
404 | 14.1k | if (!sListFormat.has_value()) |
405 | 14.1k | { |
406 | | // This is older document: it has no list format, but can probably contain prefix and/or suffix |
407 | | // Generate list format string, based on this |
408 | 14.1k | sListFormat = std::make_optional(sPrefix); |
409 | | |
410 | 29.3k | for (int i = 1; i <= nNumDisplayLevels; i++) |
411 | 15.2k | { |
412 | 15.2k | *sListFormat += "%"; |
413 | 15.2k | *sListFormat += OUString::number(nLevel - nNumDisplayLevels + i + 1); |
414 | 15.2k | *sListFormat += "%"; |
415 | 15.2k | if (i != nNumDisplayLevels) |
416 | 1.08k | *sListFormat += "."; // Default separator for older ODT |
417 | 15.2k | } |
418 | | |
419 | 14.1k | *sListFormat += sSuffix; |
420 | 14.1k | } |
421 | | |
422 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"NumberingType"_ustr, eType)); |
423 | | |
424 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"Prefix"_ustr, sPrefix)); |
425 | | |
426 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"Suffix"_ustr, sSuffix)); |
427 | | |
428 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"Adjust"_ustr, eAdjust)); |
429 | | |
430 | 14.1k | sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth; |
431 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"LeftMargin"_ustr, nLeftMargin)); |
432 | | |
433 | 14.1k | sal_Int32 nFirstLineOffset = -nMinLabelWidth; |
434 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"FirstLineOffset"_ustr, nFirstLineOffset)); |
435 | | |
436 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"SymbolTextDistance"_ustr, static_cast<sal_Int16>(nMinLabelDist))); |
437 | | |
438 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"PositionAndSpaceMode"_ustr, ePosAndSpaceMode)); |
439 | | |
440 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"LabelFollowedBy"_ustr, eLabelFollowedBy)); |
441 | | |
442 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"ListtabStopPosition"_ustr, nListtabStopPosition)); |
443 | | |
444 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"FirstLineIndent"_ustr, nFirstLineIndent)); |
445 | | |
446 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"IndentAt"_ustr, nIndentAt)); |
447 | | |
448 | 14.1k | OUString sDisplayTextStyleName = GetImport().GetStyleDisplayName(XmlStyleFamily::TEXT_TEXT, sTextStyleName); |
449 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"CharStyleName"_ustr, sDisplayTextStyleName)); |
450 | | |
451 | 14.1k | if( bBullet ) |
452 | 7.13k | { |
453 | 7.13k | awt::FontDescriptor aFDesc; |
454 | 7.13k | aFDesc.Name = sBulletFontName; |
455 | 7.13k | if( !sBulletFontName.isEmpty() ) |
456 | 5.67k | { |
457 | 5.67k | aFDesc.StyleName = sBulletFontStyleName; |
458 | 5.67k | aFDesc.Family = eBulletFontFamily; |
459 | 5.67k | aFDesc.Pitch = eBulletFontPitch; |
460 | 5.67k | aFDesc.CharSet = eBulletFontEncoding; |
461 | 5.67k | aFDesc.Weight = WEIGHT_DONTKNOW; |
462 | 5.67k | bool bStarSymbol = false; |
463 | 5.67k | if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarBats ) ) |
464 | 0 | { |
465 | 0 | cBullet = GetImport().ConvStarBatsCharToStarSymbol( cBullet ); |
466 | 0 | bStarSymbol = true; |
467 | 0 | } |
468 | 5.67k | else if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarMath ) ) |
469 | 0 | { |
470 | 0 | cBullet = GetImport().ConvStarMathCharToStarSymbol( cBullet ); |
471 | 0 | bStarSymbol = true; |
472 | 0 | } |
473 | 5.67k | if( bStarSymbol ) |
474 | 0 | aFDesc.Name = "StarSymbol" ; |
475 | 5.67k | } |
476 | | |
477 | | // Must append 'cBullet' even if it is zero |
478 | | // if 'bBullet' is true and 'cBullet' is zero - BulletChar property must be 0. |
479 | 7.13k | aProperties.push_back(comphelper::makePropertyValue(u"BulletChar"_ustr, OUString(&cBullet, 1))); |
480 | 7.13k | aProperties.push_back(comphelper::makePropertyValue(u"BulletFont"_ustr, aFDesc)); |
481 | 7.13k | } |
482 | | |
483 | 14.1k | if( bImage ) |
484 | 0 | { |
485 | 0 | uno::Reference<graphic::XGraphic> xGraphic; |
486 | 0 | if (!sImageURL.isEmpty()) |
487 | 0 | { |
488 | 0 | xGraphic = GetImport().loadGraphicByURL(sImageURL); |
489 | 0 | } |
490 | 0 | else if( xBase64Stream.is() ) |
491 | 0 | { |
492 | 0 | xGraphic = GetImport().loadGraphicFromBase64(xBase64Stream); |
493 | 0 | } |
494 | |
|
495 | 0 | uno::Reference<awt::XBitmap> xBitmap; |
496 | 0 | if (xGraphic.is()) |
497 | 0 | xBitmap.set(xGraphic, uno::UNO_QUERY); |
498 | |
|
499 | 0 | if (xBitmap.is()) |
500 | 0 | { |
501 | 0 | aProperties.push_back(comphelper::makePropertyValue(u"GraphicBitmap"_ustr, xBitmap)); |
502 | 0 | } |
503 | |
|
504 | 0 | awt::Size aSize(nImageWidth, nImageHeight); |
505 | 0 | aProperties.push_back(comphelper::makePropertyValue(u"GraphicSize"_ustr, aSize)); |
506 | 0 | aProperties.push_back(comphelper::makePropertyValue(u"VertOrient"_ustr, eImageVertOrient)); |
507 | 0 | } |
508 | | |
509 | 14.1k | if( bNum ) |
510 | 6.98k | { |
511 | 6.98k | aProperties.push_back(comphelper::makePropertyValue(u"StartWith"_ustr, nNumStartValue)); |
512 | 6.98k | aProperties.push_back(comphelper::makePropertyValue(u"ParentNumbering"_ustr, nNumDisplayLevels)); |
513 | 6.98k | } |
514 | | |
515 | 14.1k | if( ( bNum || bBullet ) && nRelSize ) |
516 | 4.85k | { |
517 | 4.85k | aProperties.push_back(comphelper::makePropertyValue(u"BulletRelSize"_ustr, nRelSize)); |
518 | 4.85k | } |
519 | | |
520 | 14.1k | if( !bImage && bHasColor ) |
521 | 6.08k | { |
522 | 6.08k | aProperties.push_back(comphelper::makePropertyValue(u"BulletColor"_ustr, m_nColor)); |
523 | 6.08k | } |
524 | | |
525 | 14.1k | aProperties.push_back(comphelper::makePropertyValue(u"ListFormat"_ustr, *sListFormat)); |
526 | | |
527 | 14.1k | if (m_bIsLegal) |
528 | 0 | aProperties.push_back(comphelper::makePropertyValue(u"IsLegal"_ustr, true)); |
529 | | |
530 | 14.1k | return comphelper::containerToSequence(aProperties); |
531 | 14.1k | } |
532 | | |
533 | | SvxXMLListLevelStyleAttrContext_Impl::SvxXMLListLevelStyleAttrContext_Impl( |
534 | | SvXMLImport& rImport, sal_Int32 /*nElement*/, |
535 | | const Reference< xml::sax::XFastAttributeList > & xAttrList, |
536 | | SvxXMLListLevelStyleContext_Impl& rLLevel ) : |
537 | 40.8k | SvXMLImportContext( rImport ), |
538 | 40.8k | rListLevel( rLLevel ) |
539 | 40.8k | { |
540 | 40.8k | SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter(); |
541 | | |
542 | 40.8k | OUString sFontName, sFontFamily, sFontStyleName, sFontFamilyGeneric, |
543 | 40.8k | sFontPitch, sFontCharset; |
544 | 40.8k | OUString sVerticalPos, sVerticalRel; |
545 | | |
546 | 40.8k | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
547 | 65.8k | { |
548 | 65.8k | sal_Int32 nVal; |
549 | 65.8k | switch( aIter.getToken() ) |
550 | 65.8k | { |
551 | 10.2k | case XML_ELEMENT(TEXT, XML_SPACE_BEFORE): |
552 | 10.2k | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView(), SHRT_MIN, SHRT_MAX)) |
553 | 10.1k | rListLevel.SetSpaceBefore( nVal ); |
554 | 10.2k | break; |
555 | 8.72k | case XML_ELEMENT(TEXT, XML_MIN_LABEL_WIDTH): |
556 | 8.72k | if (rUnitConv.convertMeasureToCore( nVal, aIter.toView(), 0, SHRT_MAX )) |
557 | 8.68k | rListLevel.SetMinLabelWidth( nVal ); |
558 | 8.72k | break; |
559 | 1.17k | case XML_ELEMENT(TEXT, XML_MIN_LABEL_DISTANCE): |
560 | 1.17k | if (rUnitConv.convertMeasureToCore( nVal, aIter.toView(), 0, USHRT_MAX )) |
561 | 1.17k | rListLevel.SetMinLabelDist( nVal ); |
562 | 1.17k | break; |
563 | 0 | case XML_ELEMENT(FO, XML_TEXT_ALIGN): |
564 | 949 | case XML_ELEMENT(FO_COMPAT, XML_TEXT_ALIGN): |
565 | 949 | if( !aIter.isEmpty() ) |
566 | 949 | { |
567 | 949 | sal_Int16 eAdjust = HoriOrientation::LEFT; |
568 | 949 | if( IsXMLToken( aIter, XML_CENTER ) ) |
569 | 0 | eAdjust = HoriOrientation::CENTER; |
570 | 949 | else if( IsXMLToken( aIter, XML_END ) ) |
571 | 947 | eAdjust = HoriOrientation::RIGHT; |
572 | 949 | rListLevel.SetAdjust( eAdjust ); |
573 | 949 | } |
574 | 949 | break; |
575 | 28 | case XML_ELEMENT(STYLE, XML_FONT_NAME): |
576 | 28 | sFontName = aIter.toString(); |
577 | 28 | break; |
578 | 0 | case XML_ELEMENT(FO, XML_FONT_FAMILY): |
579 | 8.70k | case XML_ELEMENT(FO_COMPAT, XML_FONT_FAMILY): |
580 | 8.70k | sFontFamily = aIter.toString(); |
581 | 8.70k | break; |
582 | 4 | case XML_ELEMENT(STYLE, XML_FONT_FAMILY_GENERIC): |
583 | 4 | sFontFamilyGeneric = aIter.toString(); |
584 | 4 | break; |
585 | 0 | case XML_ELEMENT(STYLE, XML_FONT_STYLE_NAME): |
586 | 0 | sFontStyleName = aIter.toString(); |
587 | 0 | break; |
588 | 5 | case XML_ELEMENT(STYLE, XML_FONT_PITCH): |
589 | 5 | sFontPitch = aIter.toString(); |
590 | 5 | break; |
591 | 1.29k | case XML_ELEMENT(STYLE, XML_FONT_CHARSET): |
592 | 1.29k | sFontCharset = aIter.toString(); |
593 | 1.29k | break; |
594 | 2 | case XML_ELEMENT(STYLE, XML_VERTICAL_POS): |
595 | 2 | sVerticalPos = aIter.toString(); |
596 | 2 | break; |
597 | 2 | case XML_ELEMENT(STYLE, XML_VERTICAL_REL): |
598 | 2 | sVerticalRel = aIter.toString(); |
599 | 2 | break; |
600 | 0 | case XML_ELEMENT(FO, XML_WIDTH): |
601 | 0 | case XML_ELEMENT(FO_COMPAT, XML_WIDTH): |
602 | 0 | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView())) |
603 | 0 | rListLevel.SetImageWidth( nVal ); |
604 | 0 | break; |
605 | 0 | case XML_ELEMENT(FO, XML_HEIGHT): |
606 | 0 | case XML_ELEMENT(FO_COMPAT, XML_HEIGHT): |
607 | 0 | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView())) |
608 | 0 | rListLevel.SetImageHeight( nVal ); |
609 | 0 | break; |
610 | 0 | case XML_ELEMENT(FO, XML_COLOR): |
611 | 2.29k | case XML_ELEMENT(FO_COMPAT, XML_COLOR): |
612 | 2.29k | { |
613 | 2.29k | Color nColor; |
614 | 2.29k | if (::sax::Converter::convertColor( nColor, aIter.toView() )) |
615 | 2.27k | rListLevel.SetColor( nColor ); |
616 | 2.29k | } |
617 | 2.29k | break; |
618 | 9.31k | case XML_ELEMENT(STYLE, XML_USE_WINDOW_FONT_COLOR): |
619 | 9.31k | { |
620 | 9.31k | if( IsXMLToken( aIter, XML_TRUE ) ) |
621 | 9.20k | rListLevel.SetColor(COL_AUTO); |
622 | 9.31k | } |
623 | 9.31k | break; |
624 | 0 | case XML_ELEMENT(FO, XML_FONT_SIZE): |
625 | 9.09k | case XML_ELEMENT(FO_COMPAT, XML_FONT_SIZE): |
626 | 9.09k | if (::sax::Converter::convertPercent( nVal, aIter.toView() )) |
627 | 9.05k | rListLevel.SetRelSize( static_cast<sal_Int16>(nVal) ); |
628 | 9.09k | break; |
629 | 13.7k | case XML_ELEMENT(TEXT, XML_LIST_LEVEL_POSITION_AND_SPACE_MODE): |
630 | 13.7k | { |
631 | 13.7k | sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION; |
632 | 13.7k | if( IsXMLToken( aIter, XML_LABEL_ALIGNMENT ) ) |
633 | 13.5k | ePosAndSpaceMode = PositionAndSpaceMode::LABEL_ALIGNMENT; |
634 | 13.7k | rListLevel.SetPosAndSpaceMode( ePosAndSpaceMode ); |
635 | 13.7k | } |
636 | 13.7k | break; |
637 | 299 | default: |
638 | 299 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
639 | 65.8k | } |
640 | 65.8k | } |
641 | | |
642 | 40.8k | if( !sFontName.isEmpty() ) |
643 | 28 | { |
644 | 28 | const XMLFontStylesContext *pFontDecls = |
645 | 28 | GetImport().GetFontDecls(); |
646 | 28 | if( pFontDecls ) |
647 | 27 | { |
648 | 27 | ::std::vector < XMLPropertyState > aProps; |
649 | 27 | if( pFontDecls->FillProperties( sFontName, aProps, 0, 1, 2, 3, 4 ) ) |
650 | 16 | { |
651 | 16 | OUString sTmp; |
652 | 16 | sal_Int16 nTmp = 0; |
653 | 16 | for( const auto& rProp : aProps ) |
654 | 80 | { |
655 | 80 | switch( rProp.mnIndex ) |
656 | 80 | { |
657 | 16 | case 0: |
658 | 16 | rProp.maValue >>= sTmp; |
659 | 16 | rListLevel.SetBulletFontName( sTmp); |
660 | 16 | break; |
661 | 16 | case 1: |
662 | 16 | rProp.maValue >>= sTmp; |
663 | 16 | rListLevel.SetBulletFontStyleName( sTmp ); |
664 | 16 | break; |
665 | 16 | case 2: |
666 | 16 | rProp.maValue >>= nTmp; |
667 | 16 | rListLevel.SetBulletFontFamily( nTmp ); |
668 | 16 | break; |
669 | 16 | case 3: |
670 | 16 | rProp.maValue >>= nTmp; |
671 | 16 | rListLevel.SetBulletFontPitch( nTmp ); |
672 | 16 | break; |
673 | 16 | case 4: |
674 | 16 | rProp.maValue >>= nTmp; |
675 | 16 | rListLevel.SetBulletFontEncoding( nTmp ); |
676 | 16 | break; |
677 | 80 | } |
678 | 80 | } |
679 | 16 | } |
680 | 27 | } |
681 | 28 | } |
682 | 40.8k | if( !sFontFamily.isEmpty() ) |
683 | 8.70k | { |
684 | 8.70k | Any aAny; |
685 | | |
686 | 8.70k | XMLFontFamilyNamePropHdl aFamilyNameHdl; |
687 | 8.70k | if( aFamilyNameHdl.importXML( sFontFamily, aAny, rUnitConv ) ) |
688 | 8.70k | { |
689 | 8.70k | OUString sTmp; |
690 | 8.70k | aAny >>= sTmp; |
691 | 8.70k | rListLevel.SetBulletFontName( sTmp); |
692 | 8.70k | } |
693 | | |
694 | 8.70k | XMLFontFamilyPropHdl aFamilyHdl; |
695 | 8.70k | if( !sFontFamilyGeneric.isEmpty() && |
696 | 3 | aFamilyHdl.importXML( sFontFamilyGeneric, aAny, rUnitConv ) ) |
697 | 3 | { |
698 | 3 | sal_Int16 nTmp = 0; |
699 | 3 | aAny >>= nTmp; |
700 | 3 | rListLevel.SetBulletFontFamily( nTmp ); |
701 | 3 | } |
702 | | |
703 | 8.70k | if( !sFontStyleName.isEmpty() ) |
704 | 0 | rListLevel.SetBulletFontStyleName( sFontStyleName ); |
705 | | |
706 | 8.70k | XMLFontPitchPropHdl aPitchHdl; |
707 | 8.70k | if( !sFontPitch.isEmpty() && |
708 | 3 | aPitchHdl.importXML( sFontPitch, aAny, rUnitConv ) ) |
709 | 3 | { |
710 | 3 | sal_Int16 nTmp = 0; |
711 | 3 | aAny >>= nTmp; |
712 | 3 | rListLevel.SetBulletFontPitch( nTmp ); |
713 | 3 | } |
714 | | |
715 | 8.70k | XMLFontEncodingPropHdl aEncHdl; |
716 | 8.70k | if( !sFontCharset.isEmpty() && |
717 | 1.12k | aEncHdl.importXML( sFontCharset, aAny, rUnitConv ) ) |
718 | 1.12k | { |
719 | 1.12k | sal_Int16 nTmp = 0; |
720 | 1.12k | aAny >>= nTmp; |
721 | 1.12k | rListLevel.SetBulletFontEncoding( nTmp ); |
722 | 1.12k | } |
723 | 8.70k | } |
724 | | |
725 | 40.8k | sal_Int16 eVertOrient = VertOrientation::LINE_CENTER; |
726 | 40.8k | if( !sVerticalPos.isEmpty() ) |
727 | 2 | { |
728 | 2 | if( IsXMLToken( sVerticalPos, XML_TOP ) ) |
729 | 1 | eVertOrient = VertOrientation::LINE_TOP; |
730 | 1 | else if( IsXMLToken( sVerticalPos, XML_BOTTOM ) ) |
731 | 0 | eVertOrient = VertOrientation::LINE_BOTTOM; |
732 | 2 | } |
733 | 40.8k | if( !sVerticalRel.isEmpty() ) |
734 | 2 | { |
735 | 2 | if( IsXMLToken( sVerticalRel, XML_BASELINE ) ) |
736 | 0 | { |
737 | | // TOP and BOTTOM are exchanged for a baseline relation |
738 | 0 | switch( eVertOrient ) |
739 | 0 | { |
740 | 0 | case VertOrientation::LINE_TOP: |
741 | 0 | eVertOrient = VertOrientation::BOTTOM; |
742 | 0 | break; |
743 | 0 | case VertOrientation::LINE_CENTER: |
744 | 0 | eVertOrient = VertOrientation::CENTER; |
745 | 0 | break; |
746 | 0 | case VertOrientation::LINE_BOTTOM: |
747 | 0 | eVertOrient = VertOrientation::TOP; |
748 | 0 | break; |
749 | 0 | } |
750 | 0 | } |
751 | 2 | else if( IsXMLToken( sVerticalRel, XML_CHAR ) ) |
752 | 0 | { |
753 | 0 | switch( eVertOrient ) |
754 | 0 | { |
755 | 0 | case VertOrientation::LINE_TOP: |
756 | 0 | eVertOrient = VertOrientation::CHAR_TOP; |
757 | 0 | break; |
758 | 0 | case VertOrientation::LINE_CENTER: |
759 | 0 | eVertOrient = VertOrientation::CHAR_CENTER; |
760 | 0 | break; |
761 | 0 | case VertOrientation::LINE_BOTTOM: |
762 | 0 | eVertOrient = VertOrientation::CHAR_BOTTOM; |
763 | 0 | break; |
764 | 0 | } |
765 | 0 | } |
766 | 2 | } |
767 | 40.8k | rListLevel.SetImageVertOrient( eVertOrient ); |
768 | 40.8k | } |
769 | | |
770 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLListLevelStyleAttrContext_Impl::createFastChildContext( |
771 | | sal_Int32 nElement, |
772 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
773 | 13.7k | { |
774 | 13.7k | if ( nElement == XML_ELEMENT(STYLE, XML_LIST_LEVEL_LABEL_ALIGNMENT) ) |
775 | 13.6k | { |
776 | 13.6k | return new SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( GetImport(), |
777 | 13.6k | nElement, |
778 | 13.6k | xAttrList, |
779 | 13.6k | rListLevel ); |
780 | 13.6k | } |
781 | 123 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
782 | 123 | return nullptr; |
783 | 123 | } |
784 | | |
785 | | |
786 | | SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl::SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( |
787 | | SvXMLImport& rImport, sal_Int32 /*nElement*/, |
788 | | const Reference< xml::sax::XFastAttributeList > & xAttrList, |
789 | | SvxXMLListLevelStyleContext_Impl& rLLevel ) : |
790 | 13.6k | SvXMLImportContext( rImport ) |
791 | 13.6k | { |
792 | 13.6k | SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter(); |
793 | | |
794 | 13.6k | sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB; |
795 | 13.6k | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
796 | 50.9k | { |
797 | 50.9k | sal_Int32 nVal; |
798 | 50.9k | switch( aIter.getToken() ) |
799 | 50.9k | { |
800 | 13.5k | case XML_ELEMENT(TEXT, XML_LABEL_FOLLOWED_BY): |
801 | 13.5k | case XML_ELEMENT(LO_EXT, XML_LABEL_FOLLOWED_BY): |
802 | 13.5k | { |
803 | 13.5k | if( eLabelFollowedBy == LabelFollow::NEWLINE) |
804 | | //NewLine from LO_EXT has precedence over other values of the Non LO_EXT namespace |
805 | 0 | break; |
806 | 13.5k | if( IsXMLToken( aIter, XML_SPACE ) ) |
807 | 0 | eLabelFollowedBy = LabelFollow::SPACE; |
808 | 13.5k | else if( IsXMLToken( aIter, XML_NOTHING ) ) |
809 | 0 | eLabelFollowedBy = LabelFollow::NOTHING; |
810 | 13.5k | else if( IsXMLToken( aIter, XML_NEWLINE ) ) |
811 | 1 | eLabelFollowedBy = LabelFollow::NEWLINE; |
812 | 13.5k | } |
813 | 0 | break; |
814 | 13.3k | case XML_ELEMENT(TEXT, XML_LIST_TAB_STOP_POSITION): |
815 | 13.3k | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView(), 0, SHRT_MAX)) |
816 | 13.2k | rLLevel.SetListtabStopPosition( nVal ); |
817 | 13.3k | break; |
818 | 0 | case XML_ELEMENT(FO, XML_TEXT_INDENT): |
819 | 11.9k | case XML_ELEMENT(FO_COMPAT, XML_TEXT_INDENT): |
820 | 11.9k | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView(), SHRT_MIN, SHRT_MAX)) |
821 | 11.9k | rLLevel.SetFirstLineIndent( nVal ); |
822 | 11.9k | break; |
823 | 0 | case XML_ELEMENT(FO, XML_MARGIN_LEFT): |
824 | 12.0k | case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT): |
825 | 12.0k | if (rUnitConv.convertMeasureToCore(nVal, aIter.toView(), SHRT_MIN, SHRT_MAX)) |
826 | 11.9k | rLLevel.SetIndentAt( nVal ); |
827 | 12.0k | break; |
828 | 107 | default: |
829 | 107 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
830 | 50.9k | } |
831 | 50.9k | } |
832 | 13.6k | rLLevel.SetLabelFollowedBy( eLabelFollowedBy ); |
833 | 13.6k | } |
834 | | |
835 | | void SvxXMLListStyleContext::SetAttribute( sal_Int32 nElement, |
836 | | const OUString& rValue ) |
837 | 3.92k | { |
838 | 3.92k | if( nElement == XML_ELEMENT(TEXT, XML_CONSECUTIVE_NUMBERING) ) |
839 | 0 | { |
840 | 0 | m_bConsecutive = IsXMLToken( rValue, XML_TRUE ); |
841 | 0 | } |
842 | 3.92k | else |
843 | 3.92k | { |
844 | 3.92k | SvXMLStyleContext::SetAttribute( nElement, rValue ); |
845 | 3.92k | } |
846 | 3.92k | } |
847 | | |
848 | | constexpr OUString sIsPhysical( u"IsPhysical"_ustr ); |
849 | | constexpr OUString sNumberingRules( u"NumberingRules"_ustr ); |
850 | | constexpr OUString sIsContinuousNumbering( u"IsContinuousNumbering"_ustr ); |
851 | | |
852 | | SvxXMLListStyleContext::SvxXMLListStyleContext( SvXMLImport& rImport, |
853 | | bool bOutl ) |
854 | 3.60k | : SvXMLStyleContext( rImport, bOutl ? XmlStyleFamily::TEXT_OUTLINE : XmlStyleFamily::TEXT_LIST ) |
855 | 3.60k | , m_bConsecutive( false ) |
856 | 3.60k | , m_bOutline( bOutl ) |
857 | 3.60k | { |
858 | 3.60k | } |
859 | | |
860 | 3.60k | SvxXMLListStyleContext::~SvxXMLListStyleContext() {} |
861 | | |
862 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLListStyleContext::createFastChildContext( |
863 | | sal_Int32 nElement, |
864 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
865 | 29.5k | { |
866 | 29.5k | if( m_bOutline |
867 | 29.5k | ? nElement == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL_STYLE) |
868 | 29.5k | : ( nElement == XML_ELEMENT(TEXT, XML_LIST_LEVEL_STYLE_NUMBER) || |
869 | 12.3k | nElement == XML_ELEMENT(TEXT, XML_LIST_LEVEL_STYLE_BULLET) || |
870 | 447 | nElement == XML_ELEMENT(TEXT, XML_LIST_LEVEL_STYLE_IMAGE ) ) ) |
871 | 28.4k | { |
872 | 28.4k | rtl::Reference<SvxXMLListLevelStyleContext_Impl> xLevelStyle{ |
873 | 28.4k | new SvxXMLListLevelStyleContext_Impl( GetImport(), nElement, xAttrList )}; |
874 | 28.4k | if( !m_pLevelStyles ) |
875 | 3.58k | m_pLevelStyles = std::make_unique<SvxXMLListStyle_Impl>(); |
876 | 28.4k | m_pLevelStyles->push_back( xLevelStyle ); |
877 | | |
878 | 28.4k | return xLevelStyle; |
879 | 28.4k | } |
880 | 1.02k | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
881 | 1.02k | return nullptr; |
882 | 1.02k | } |
883 | | |
884 | | void SvxXMLListStyleContext::FillUnoNumRule( |
885 | | const Reference<container::XIndexReplace> & rNumRule) const |
886 | 1.63k | { |
887 | 1.63k | try |
888 | 1.63k | { |
889 | 1.63k | if( m_pLevelStyles && rNumRule.is() ) |
890 | 1.63k | { |
891 | 1.63k | sal_Int32 l_nLevels = rNumRule->getCount(); |
892 | 1.63k | for (const auto& pLevelStyle : *m_pLevelStyles) |
893 | 14.3k | { |
894 | 14.3k | sal_Int32 nLevel = pLevelStyle->GetLevel(); |
895 | 14.3k | if( nLevel >= 0 && nLevel < l_nLevels ) |
896 | 14.1k | { |
897 | 14.1k | Sequence<beans::PropertyValue> aProps = |
898 | 14.1k | pLevelStyle->GetProperties(); |
899 | 14.1k | rNumRule->replaceByIndex( nLevel, Any(aProps) ); |
900 | 14.1k | } |
901 | 14.3k | } |
902 | 1.63k | } |
903 | | |
904 | 1.63k | Reference < XPropertySet > xPropSet( rNumRule, UNO_QUERY ); |
905 | 1.63k | Reference< XPropertySetInfo > xPropSetInfo; |
906 | 1.63k | if (xPropSet.is()) |
907 | 959 | xPropSetInfo = xPropSet->getPropertySetInfo(); |
908 | 1.63k | if( xPropSetInfo.is() && |
909 | 959 | xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) ) |
910 | 959 | { |
911 | 959 | xPropSet->setPropertyValue( sIsContinuousNumbering, Any(m_bConsecutive) ); |
912 | 959 | } |
913 | 1.63k | } |
914 | 1.63k | catch (const Exception&) |
915 | 1.63k | { |
916 | 34 | TOOLS_WARN_EXCEPTION("xmloff.style", "" ); |
917 | 34 | } |
918 | 1.63k | } |
919 | | |
920 | | void SvxXMLListStyleContext::CreateAndInsertLate( bool bOverwrite ) |
921 | 1.12k | { |
922 | 1.12k | if( m_bOutline ) |
923 | 639 | { |
924 | 639 | if( bOverwrite ) |
925 | 639 | { |
926 | 639 | const Reference< XIndexReplace >& rNumRule = |
927 | 639 | GetImport().GetTextImport()->GetChapterNumbering(); |
928 | | // We don't set xNumberingRules here, to avoid using them |
929 | | // as numbering rules. |
930 | 639 | if( rNumRule.is() ) |
931 | 589 | FillUnoNumRule(rNumRule); |
932 | 639 | } |
933 | 639 | } |
934 | 483 | else |
935 | 483 | { |
936 | 483 | Reference < XStyle > xStyle; |
937 | 483 | const OUString& rName = GetDisplayName(); |
938 | 483 | if( rName.isEmpty() ) |
939 | 67 | { |
940 | 67 | SetValid( false ); |
941 | 67 | return; |
942 | 67 | } |
943 | | |
944 | 416 | const Reference < XNameContainer >& rNumStyles = |
945 | 416 | GetImport().GetTextImport()->GetNumberingStyles(); |
946 | 416 | if( !rNumStyles.is() ) |
947 | 12 | { |
948 | 12 | SetValid( false ); |
949 | 12 | return; |
950 | 12 | } |
951 | | |
952 | 404 | bool bNew = false; |
953 | 404 | if( rNumStyles->hasByName( rName ) ) |
954 | 117 | { |
955 | 117 | Any aAny = rNumStyles->getByName( rName ); |
956 | 117 | aAny >>= xStyle; |
957 | 117 | } |
958 | 287 | else |
959 | 287 | { |
960 | 287 | Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), |
961 | 287 | UNO_QUERY ); |
962 | 287 | SAL_WARN_IF( !xFactory.is(), "xmloff", "no factory" ); |
963 | 287 | if( !xFactory.is() ) |
964 | 0 | return; |
965 | | |
966 | 287 | Reference < XInterface > xIfc = xFactory->createInstance(u"com.sun.star.style.NumberingStyle"_ustr); |
967 | 287 | if( !xIfc.is() ) |
968 | 0 | return; |
969 | 287 | xStyle.set(xIfc, UNO_QUERY); |
970 | 287 | if( !xStyle.is() ) |
971 | 0 | return; |
972 | | |
973 | 287 | rNumStyles->insertByName( rName, Any(xStyle) ); |
974 | 287 | bNew = true; |
975 | 287 | } |
976 | | |
977 | 404 | Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); |
978 | 404 | Reference< XPropertySetInfo > xPropSetInfo = |
979 | 404 | xPropSet->getPropertySetInfo(); |
980 | 404 | if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) ) |
981 | 117 | { |
982 | 117 | Any aAny = xPropSet->getPropertyValue( sIsPhysical ); |
983 | 117 | bNew = !*o3tl::doAccess<bool>(aAny); |
984 | 117 | } |
985 | | |
986 | 404 | if ( xPropSetInfo->hasPropertyByName( u"Hidden"_ustr ) ) |
987 | 404 | xPropSet->setPropertyValue( u"Hidden"_ustr, uno::Any( IsHidden( ) ) ); |
988 | | |
989 | 404 | if( rName != GetName() ) |
990 | 398 | GetImport().AddStyleDisplayName( XmlStyleFamily::TEXT_LIST, |
991 | 398 | GetName(), rName ); |
992 | | |
993 | 404 | Any aAny = xPropSet->getPropertyValue( sNumberingRules ); |
994 | 404 | aAny >>= m_xNumRules; |
995 | 404 | if( bOverwrite || bNew ) |
996 | 404 | { |
997 | 404 | FillUnoNumRule(m_xNumRules); |
998 | 404 | xPropSet->setPropertyValue( sNumberingRules, Any(m_xNumRules) ); |
999 | 404 | } |
1000 | 0 | else |
1001 | 0 | { |
1002 | 0 | SetValid( false ); |
1003 | 0 | } |
1004 | | |
1005 | 404 | SetNew( bNew ); |
1006 | 404 | } |
1007 | 1.12k | } |
1008 | | |
1009 | | void SvxXMLListStyleContext::CreateAndInsertAuto() const |
1010 | 0 | { |
1011 | 0 | SAL_WARN_IF( m_bOutline, "xmloff", "Outlines cannot be inserted here" ); |
1012 | 0 | SAL_WARN_IF( m_xNumRules.is(), "xmloff", "Numbering Rule is existing already" ); |
1013 | | |
1014 | 0 | const OUString& rName = GetName(); |
1015 | 0 | if( m_bOutline || m_xNumRules.is() || rName.isEmpty() ) |
1016 | 0 | { |
1017 | 0 | const_cast<SvxXMLListStyleContext *>(this)->SetValid( false ); |
1018 | 0 | return; |
1019 | 0 | } |
1020 | | |
1021 | 0 | const_cast<SvxXMLListStyleContext *>(this)->m_xNumRules = CreateNumRule( |
1022 | 0 | GetImport().GetModel() ); |
1023 | |
|
1024 | 0 | FillUnoNumRule(m_xNumRules); |
1025 | 0 | } |
1026 | | |
1027 | | Reference < XIndexReplace > SvxXMLListStyleContext::CreateNumRule( |
1028 | | const Reference < XModel > & rModel ) |
1029 | 102k | { |
1030 | 102k | Reference<XIndexReplace> xNumRule; |
1031 | | |
1032 | 102k | Reference< XMultiServiceFactory > xFactory( rModel, UNO_QUERY ); |
1033 | 102k | SAL_WARN_IF( !xFactory.is(), "xmloff", "no factory" ); |
1034 | 102k | if( !xFactory.is() ) |
1035 | 0 | return xNumRule; |
1036 | | |
1037 | 102k | Reference < XInterface > xIfc = xFactory->createInstance(u"com.sun.star.text.NumberingRules"_ustr); |
1038 | 102k | if( !xIfc.is() ) |
1039 | 0 | return xNumRule; |
1040 | | |
1041 | 102k | xNumRule.set( xIfc, UNO_QUERY ); |
1042 | 102k | SAL_WARN_IF( !xNumRule.is(), "xmloff", "go no numbering rule" ); |
1043 | | |
1044 | 102k | return xNumRule; |
1045 | 102k | } |
1046 | | |
1047 | | void SvxXMLListStyleContext::SetDefaultStyle( |
1048 | | const Reference < XIndexReplace > & rNumRule, |
1049 | | sal_Int16 nLevel, |
1050 | | bool bOrdered ) |
1051 | 101k | { |
1052 | 101k | Sequence<beans::PropertyValue> aPropSeq( bOrdered ? 1 : 4 ); |
1053 | 101k | beans::PropertyValue *pProps = aPropSeq.getArray(); |
1054 | | |
1055 | 101k | pProps->Name = "NumberingType"; |
1056 | 101k | (pProps++)->Value <<= static_cast<sal_Int16>(bOrdered ? NumberingType::ARABIC |
1057 | 101k | : NumberingType::CHAR_SPECIAL ); |
1058 | 101k | if( !bOrdered ) |
1059 | 101k | { |
1060 | | // TODO: Bullet-Font |
1061 | 101k | awt::FontDescriptor aFDesc; |
1062 | 101k | aFDesc.Name = |
1063 | | #ifdef _WIN32 |
1064 | | "StarBats" |
1065 | | #else |
1066 | 101k | "starbats" |
1067 | 101k | #endif |
1068 | 101k | ; |
1069 | 101k | aFDesc.Family = FAMILY_DONTKNOW ; |
1070 | 101k | aFDesc.Pitch = PITCH_DONTKNOW ; |
1071 | 101k | aFDesc.CharSet = RTL_TEXTENCODING_SYMBOL ; |
1072 | 101k | aFDesc.Weight = WEIGHT_DONTKNOW; |
1073 | 101k | pProps->Name = "BulletFont"; |
1074 | 101k | (pProps++)->Value <<= aFDesc; |
1075 | | |
1076 | 101k | pProps->Name = "BulletChar"; |
1077 | 101k | (pProps++)->Value <<= OUString(sal_Unicode(0xF000 + 149)); |
1078 | 101k | pProps->Name = "CharStyleName"; |
1079 | 101k | (pProps++)->Value <<= u"Numbering Symbols"_ustr; |
1080 | 101k | } |
1081 | | |
1082 | 101k | rNumRule->replaceByIndex( nLevel, Any(aPropSeq) ); |
1083 | 101k | } |
1084 | | |
1085 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |