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