LibreOffice Module sw (master) 1
xmlimpit.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 "xmlimpit.hxx"
21
22#include <sal/log.hxx>
24#include <utility>
25#include <xmloff/xmluconv.hxx>
26#include <svl/itempool.hxx>
27#include <svl/poolitem.hxx>
28#include <svl/itemset.hxx>
30#include <editeng/xmlcnitm.hxx>
31#include <editeng/memberids.h>
32#include <osl/diagnose.h>
33
34#include <hintids.hxx>
35#include <unomid.h>
36#include <svx/unomid.hxx>
37#include <editeng/lrspitem.hxx>
38#include <editeng/ulspitem.hxx>
39#include <editeng/shaditem.hxx>
40#include <editeng/boxitem.hxx>
42#include <editeng/keepitem.hxx>
43#include <editeng/brushitem.hxx>
44#include <editeng/frmdir.hxx>
45#include <fmtpdsc.hxx>
46#include <fmtornt.hxx>
47#include <fmtfsize.hxx>
48
49#include <xmloff/prhdlfac.hxx>
50#include <xmloff/xmltypes.hxx>
51#include <xmloff/xmlprhdl.hxx>
52#include <xmloff/xmlimp.hxx>
54#include "xmlithlp.hxx"
55#include <com/sun/star/uno/Any.hxx>
56
57using ::editeng::SvxBorderLine;
58using namespace ::com::sun::star;
59using namespace ::xmloff::token;
60using uno::Any;
61
63
65 SvXMLItemMapEntriesRef aMapEntries ) :
66 mrMapEntries(std::move( aMapEntries ))
67{
68}
69
71{
72}
73
74void
76{
77 mrMapEntries = std::move(rMapEntries);
78}
79
80// fills the given itemset with the attributes in the given list
82 uno::Reference< xml::sax::XFastAttributeList > const & xAttrList,
83 const SvXMLUnitConverter& rUnitConverter,
84 const SvXMLNamespaceMap& rNamespaceMap )
85{
86 std::unique_ptr<SvXMLAttrContainerItem> pUnknownItem;
87 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
88 {
89 if( IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_XMLNS) )
90 continue;
91
92 sal_Int32 nToken = aIter.getToken();
93 const OUString sValue = aIter.toString();
94
95 // find a map entry for this attribute
96 sal_Int32 nLookupToken = nToken;
97 // compatibility namespaces need to be transformed into current namespace before looking up
99 nLookupToken = XML_ELEMENT(FO, (nLookupToken & TOKEN_MASK));
100 SvXMLItemMapEntry const * pEntry = mrMapEntries->getByName( nLookupToken );
101
102 if( pEntry )
103 {
104 // we have a valid map entry here, so lets use it...
105 if( 0 == (pEntry->nMemberId & (MID_SW_FLAG_NO_ITEM_IMPORT|
107 {
108 // first get item from itemset
109 const SfxPoolItem* pItem = nullptr;
110 SfxItemState eState = rSet.GetItemState( pEntry->nWhichId, true,
111 &pItem );
112
113 // if it's not set, try the pool
114 if (SfxItemState::SET != eState && SfxItemPool::IsWhich(pEntry->nWhichId))
115 pItem = &rSet.GetPool()->GetDefaultItem(pEntry->nWhichId);
116
117 // do we have an item?
118 if(eState >= SfxItemState::DEFAULT && pItem)
119 {
120 std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
121 bool bPut = false;
122
123 if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
124 {
125 bPut = PutXMLValue( *pNewItem, sValue,
126 o3tl::narrowing<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ),
127 rUnitConverter );
128
129 }
130 else
131 {
132 bPut = handleSpecialItem( *pEntry, *pNewItem, rSet,
133 sValue, rUnitConverter );
134 }
135
136 if( bPut )
137 rSet.Put( std::move(pNewItem) );
138 }
139 else
140 {
141 OSL_FAIL( "Could not get a needed item for xml import!" );
142 }
143 }
144 else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
145 {
146 handleNoItem( *pEntry, rSet, sValue, rUnitConverter,
147 rNamespaceMap );
148 }
149 }
150 else
151 {
152 if( !pUnknownItem )
153 {
154 const SfxPoolItem* pItem = nullptr;
155 if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true,
156 &pItem ) )
157 {
158 pUnknownItem.reset( static_cast<SvXMLAttrContainerItem*>( pItem->Clone() ) );
159 }
160 else
161 {
162 pUnknownItem.reset( new SvXMLAttrContainerItem( nUnknownWhich ) );
163 }
164 }
165 if( pUnknownItem )
166 {
168 pUnknownItem->AddAttr( SvXMLImport::getNameFromToken( nToken ), sValue );
169 else
170 {
171 const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &rNamespaceMap);
172 OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
173 if ( !rAttrNamespacePrefix.isEmpty() )
174 sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
175 OUString aLocalName, aPrefix, aNamespace;
176 rNamespaceMap.GetKeyByAttrName( sAttrName, &aPrefix, &aLocalName,
177 &aNamespace );
178 if ( !rAttrNamespacePrefix.isEmpty() )
179 pUnknownItem->AddAttr( rAttrNamespacePrefix, aNamespace, aLocalName,
180 sValue );
181 else
182 pUnknownItem->AddAttr( aLocalName, sValue );
183 }
184 }
185 }
186 }
187
188 importXMLUnknownAttributes(rSet, xAttrList, rUnitConverter, pUnknownItem);
189
190 if( pUnknownItem )
191 {
192 rSet.Put( *pUnknownItem );
193 }
194
195 finished(rSet, rUnitConverter);
196}
197
199 uno::Reference< xml::sax::XFastAttributeList > const & xAttrList,
200 const SvXMLUnitConverter& rUnitConverter,
201 std::unique_ptr<SvXMLAttrContainerItem>& pUnknownItem)
202{
203 const css::uno::Sequence< css::xml::Attribute > unknownAttributes = xAttrList->getUnknownAttributes();
204 for (const auto & rAttribute : unknownAttributes)
205 {
206 if( !pUnknownItem )
207 {
208 const SfxPoolItem* pItem = nullptr;
209 if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true,
210 &pItem ) )
211 {
212 pUnknownItem.reset( static_cast<SvXMLAttrContainerItem*>( pItem->Clone() ) );
213 }
214 else
215 {
216 pUnknownItem.reset( new SvXMLAttrContainerItem( nUnknownWhich ) );
217 }
218 }
219 if( pUnknownItem )
220 {
221 if( rAttribute.NamespaceURL.isEmpty() )
222 pUnknownItem->AddAttr( rAttribute.Name, rAttribute.Value );
223 else
224 {
225 OUString sPrefix;
226 OUString sName = rAttribute.Name;
227 int i = sName.indexOf(':');
228 if (i != -1)
229 {
230 sPrefix = sName.copy(0, i-1);
231 sName = sName.copy(i+1);
232 }
233 // the sax parser doesn't reject these, strangely
234 if (sName.indexOf(':') == -1)
235 pUnknownItem->AddAttr( sPrefix, rAttribute.NamespaceURL, sName,
236 rAttribute.Value );
237 else
238 SAL_WARN("sw", "ignoring dodgy attribute: " + rAttribute.Name);
239 }
240 }
241 }
242
243 if( pUnknownItem )
244 {
245 rSet.Put( *pUnknownItem );
246 }
247
248 finished(rSet, rUnitConverter);
249}
250
253bool
255 SfxPoolItem& /*rItem*/,
256 SfxItemSet& /*rSet*/,
257 const OUString& /*rValue*/,
258 const SvXMLUnitConverter& /*rUnitConverter*/ )
259{
260 OSL_FAIL( "unsupported special item in xml import" );
261 return false;
262}
263
267 SfxItemSet& /*rSet*/,
268 const OUString& /*rValue*/,
269 const SvXMLUnitConverter& /*rUnitConverter*/,
270 const SvXMLNamespaceMap& /*rNamespaceMap*/ )
271{
272 OSL_FAIL( "unsupported no item in xml import" );
273 return false;
274}
275
276void
278{
279 // nothing to do here
280}
281
282namespace {
283
284struct BoxHolder
285{
286 std::unique_ptr<SvxBorderLine> pTop;
287 std::unique_ptr<SvxBorderLine> pBottom;
288 std::unique_ptr<SvxBorderLine> pLeft;
289 std::unique_ptr<SvxBorderLine> pRight;
290
291 BoxHolder(BoxHolder const&) = delete;
292 BoxHolder& operator=(BoxHolder const&) = delete;
293
294 explicit BoxHolder(SvxBoxItem const & rBox)
295 {
296 if (rBox.GetTop())
297 pTop.reset(new SvxBorderLine( *rBox.GetTop() ));
298 if (rBox.GetBottom())
299 pBottom.reset(new SvxBorderLine( *rBox.GetBottom() ));
300 if (rBox.GetLeft())
301 pLeft.reset(new SvxBorderLine( *rBox.GetLeft() ));
302 if (rBox.GetRight())
303 pRight.reset(new SvxBorderLine( *rBox.GetRight() ));
304 }
305};
306
307}
308
309// put an XML-string value into an item
311 SfxPoolItem& rItem,
312 const OUString& rValue,
313 sal_uInt16 nMemberId,
314 const SvXMLUnitConverter& rUnitConverter )
315{
316 bool bOk = false;
317
318 switch (rItem.Which())
319 {
322 case RES_MARGIN_RIGHT:
323 assert(false); // is only called for frame formats?
324 break;
325
326 case RES_LR_SPACE:
327 {
328 SvxLRSpaceItem& rLRSpace = dynamic_cast<SvxLRSpaceItem&>(rItem);
329
330 switch( nMemberId )
331 {
332 case MID_L_MARGIN:
333 case MID_R_MARGIN:
334 {
335 sal_Int32 nProp = 100;
336 sal_Int32 nAbs = 0;
337
338 if( rValue.indexOf( '%' ) != -1 )
339 bOk = ::sax::Converter::convertPercent(nProp, rValue);
340 else
341 bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue);
342
343 if( bOk )
344 {
345 switch( nMemberId )
346 {
347 case MID_L_MARGIN:
348 rLRSpace.SetTextLeft( nAbs, o3tl::narrowing<sal_uInt16>(nProp) );
349 break;
350 case MID_R_MARGIN:
351 rLRSpace.SetRight( nAbs, o3tl::narrowing<sal_uInt16>(nProp) );
352 break;
353 }
354 }
355 }
356 break;
357
359 {
360 assert(false); // it looks like this can't be called? (frame formats only, aTableItemMap)
361 sal_Int32 nProp = 100;
362 sal_Int32 nAbs = 0;
363
364 if( rValue.indexOf( '%' ) != -1 )
365 bOk = ::sax::Converter::convertPercent(nProp, rValue);
366 else
367 bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue,
368 -0x7fff, 0x7fff );
369
370 rLRSpace.SetTextFirstLineOffset( static_cast<short>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) );
371 }
372 break;
373
374 case MID_FIRST_AUTO:
375 {
376 assert(false); // it looks like this can't be called? (frame formats only, aTableItemMap)
377 bool bAutoFirst(false);
378 bOk = ::sax::Converter::convertBool( bAutoFirst, rValue );
379 if( bOk )
380 rLRSpace.SetAutoFirst( bAutoFirst );
381 }
382 break;
383
384 default:
385 OSL_FAIL( "unknown member id!");
386 }
387 }
388 break;
389
390 case RES_UL_SPACE:
391 {
392 SvxULSpaceItem& rULSpace = dynamic_cast<SvxULSpaceItem&>(rItem);
393
394 sal_Int32 nProp = 100;
395 sal_Int32 nAbs = 0;
396
397 if( rValue.indexOf( '%' ) != -1 )
398 bOk = ::sax::Converter::convertPercent( nProp, rValue );
399 else
400 bOk = rUnitConverter.convertMeasureToCore( nAbs, rValue );
401
402 switch( nMemberId )
403 {
404 case MID_UP_MARGIN:
405 rULSpace.SetUpper( o3tl::narrowing<sal_uInt16>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) );
406 break;
407 case MID_LO_MARGIN:
408 rULSpace.SetLower( o3tl::narrowing<sal_uInt16>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) );
409 break;
410 default:
411 OSL_FAIL("unknown MemberId");
412 }
413 }
414 break;
415
416 case RES_SHADOW:
417 {
418 SvxShadowItem& rShadow = dynamic_cast<SvxShadowItem&>(rItem);
419
420 bool bColorFound = false;
421 bool bOffsetFound = false;
422
423 SvXMLTokenEnumerator aTokenEnum( rValue );
424
425 Color aColor( 128,128, 128 );
426 rShadow.SetLocation( SvxShadowLocation::BottomRight );
427
428 std::u16string_view aToken;
429 while( aTokenEnum.getNextToken( aToken ) )
430 {
431 if( IsXMLToken( aToken, XML_NONE ) )
432 {
433 rShadow.SetLocation( SvxShadowLocation::NONE );
434 bOk = true;
435 }
436 else if( !bColorFound && aToken.substr(0,1) == u"#" )
437 {
438 bOk = ::sax::Converter::convertColor( aColor, aToken );
439 if( !bOk )
440 return false;
441
442 bColorFound = true;
443 }
444 else if( !bOffsetFound )
445 {
446 sal_Int32 nX = 0, nY = 0;
447
448 bOk = rUnitConverter.convertMeasureToCore( nX, aToken );
449 if( bOk && aTokenEnum.getNextToken( aToken ) )
450 bOk = rUnitConverter.convertMeasureToCore( nY, aToken );
451
452 if( bOk )
453 {
454 if( nX < 0 )
455 {
456 if( nY < 0 )
457 {
458 rShadow.SetLocation( SvxShadowLocation::TopLeft );
459 }
460 else
461 {
462 rShadow.SetLocation( SvxShadowLocation::BottomLeft );
463 }
464 }
465 else
466 {
467 if( nY < 0 )
468 {
469 rShadow.SetLocation( SvxShadowLocation::TopRight );
470 }
471 else
472 {
473 rShadow.SetLocation( SvxShadowLocation::BottomRight );
474 }
475 }
476
477 if( nX < 0 ) nX *= -1;
478 if( nY < 0 ) nY *= -1;
479
480 rShadow.SetWidth( static_cast< sal_uInt16 >( (nX + nY) >> 1 ) );
481 }
482 }
483 }
484
485 if( bOk && ( bColorFound || bOffsetFound ) )
486 {
487 rShadow.SetColor(aColor);
488 }
489 else
490 bOk = false;
491 }
492 break;
493
494 case RES_BOX:
495 {
496 SvxBoxItem& rBox = dynamic_cast<SvxBoxItem&>(rItem);
497
498 // copy SvxBorderLines
499 BoxHolder aBoxes(rBox);
500
501 sal_Int32 nTemp;
502
503 switch( nMemberId )
504 {
510 if (!rUnitConverter.convertMeasureToCore( nTemp, rValue,
511 0, 0xffff ))
512 {
513 return false;
514 }
515
516 if( nMemberId == LEFT_BORDER_PADDING ||
517 nMemberId == ALL_BORDER_PADDING )
518 rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::LEFT );
519 if( nMemberId == RIGHT_BORDER_PADDING ||
520 nMemberId == ALL_BORDER_PADDING )
521 rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::RIGHT );
522 if( nMemberId == TOP_BORDER_PADDING ||
523 nMemberId == ALL_BORDER_PADDING )
524 rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::TOP );
525 if( nMemberId == BOTTOM_BORDER_PADDING ||
526 nMemberId == ALL_BORDER_PADDING )
527 rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::BOTTOM);
528 break;
529
530 case ALL_BORDER:
531 case LEFT_BORDER:
532 case RIGHT_BORDER:
533 case TOP_BORDER:
534 case BOTTOM_BORDER:
535 {
536 bool bHasStyle = false;
537 bool bHasWidth = false;
538 bool bHasColor = false;
539
540 sal_uInt16 nStyle = USHRT_MAX;
541 sal_uInt16 nWidth = 0;
542 sal_uInt16 nNamedWidth = USHRT_MAX;
543
544 Color aColor( COL_BLACK );
545
546 if( !sw_frmitems_parseXMLBorder( rValue, rUnitConverter,
547 bHasStyle, nStyle,
548 bHasWidth, nWidth, nNamedWidth,
549 bHasColor, aColor ) )
550 return false;
551
552 if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
553 sw_frmitems_setXMLBorder( aBoxes.pTop,
554 bHasStyle, nStyle,
555 bHasWidth, nWidth, nNamedWidth,
556 bHasColor, aColor );
557
558 if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
559 sw_frmitems_setXMLBorder( aBoxes.pBottom,
560 bHasStyle, nStyle,
561 bHasWidth, nWidth, nNamedWidth,
562 bHasColor, aColor );
563
564 if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
565 sw_frmitems_setXMLBorder( aBoxes.pLeft,
566 bHasStyle, nStyle,
567 bHasWidth, nWidth, nNamedWidth,
568 bHasColor, aColor );
569
570 if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
571 sw_frmitems_setXMLBorder( aBoxes.pRight,
572 bHasStyle, nStyle,
573 bHasWidth, nWidth, nNamedWidth,
574 bHasColor, aColor );
575 }
576 break;
582 {
583 SvXMLTokenEnumerator aTokenEnum( rValue );
584
585 sal_Int32 nInWidth, nDistance, nOutWidth;
586
587 std::u16string_view aToken;
588 if( !aTokenEnum.getNextToken( aToken ) )
589 return false;
590
591 if (!rUnitConverter.convertMeasureToCore(nInWidth, aToken))
592 return false;
593
594 if( !aTokenEnum.getNextToken( aToken ) )
595 return false;
596
597 if (!rUnitConverter.convertMeasureToCore(nDistance, aToken))
598 return false;
599
600 if( !aTokenEnum.getNextToken( aToken ) )
601 return false;
602
603 if (!rUnitConverter.convertMeasureToCore(nOutWidth, aToken))
604 return false;
605
606 // #i61946: accept line style even it's not part of our "normal" set of line styles
607 sal_uInt16 nWidth = 0;
608
609 if( TOP_BORDER_LINE_WIDTH == nMemberId ||
610 ALL_BORDER_LINE_WIDTH == nMemberId )
611 sw_frmitems_setXMLBorder( aBoxes.pTop, nWidth,
612 static_cast< sal_uInt16 >( nOutWidth ),
613 static_cast< sal_uInt16 >( nInWidth ),
614 static_cast< sal_uInt16 >( nDistance ) );
615
616 if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
617 ALL_BORDER_LINE_WIDTH == nMemberId )
618 sw_frmitems_setXMLBorder( aBoxes.pBottom, nWidth,
619 static_cast< sal_uInt16 >( nOutWidth ),
620 static_cast< sal_uInt16 >( nInWidth ),
621 static_cast< sal_uInt16 >( nDistance ) );
622
623 if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
624 ALL_BORDER_LINE_WIDTH == nMemberId )
625 sw_frmitems_setXMLBorder( aBoxes.pLeft, nWidth,
626 static_cast< sal_uInt16 >( nOutWidth ),
627 static_cast< sal_uInt16 >( nInWidth ),
628 static_cast< sal_uInt16 >( nDistance ) );
629
630 if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
631 ALL_BORDER_LINE_WIDTH == nMemberId )
632 sw_frmitems_setXMLBorder( aBoxes.pRight, nWidth,
633 static_cast< sal_uInt16 >( nOutWidth ),
634 static_cast< sal_uInt16 >( nInWidth ),
635 static_cast< sal_uInt16 >( nDistance ) );
636 }
637 break;
638 }
639
640 rBox.SetLine( aBoxes.pTop.get(), SvxBoxItemLine::TOP );
641 rBox.SetLine( aBoxes.pBottom.get(), SvxBoxItemLine::BOTTOM );
642 rBox.SetLine( aBoxes.pLeft.get(), SvxBoxItemLine::LEFT );
643 rBox.SetLine( aBoxes.pRight.get(), SvxBoxItemLine::RIGHT );
644
645 bOk = true;
646 }
647 break;
648
649 case RES_BREAK:
650 {
651 SvxFormatBreakItem& rFormatBreak = dynamic_cast<SvxFormatBreakItem&>(rItem);
652 sal_uInt16 eEnum{};
653
654 if( !SvXMLUnitConverter::convertEnum( eEnum, rValue, psXML_BreakType ) )
655 return false;
656
657 if( eEnum == 0 )
658 {
659 rFormatBreak.SetValue( SvxBreak::NONE );
660 bOk = true;
661 }
662 else
663 {
664 switch( nMemberId )
665 {
666 case MID_BREAK_BEFORE:
667 rFormatBreak.SetValue( eEnum == 1 ?
668 SvxBreak::ColumnBefore :
669 SvxBreak::PageBefore );
670 break;
671 case MID_BREAK_AFTER:
672 rFormatBreak.SetValue( eEnum == 1 ?
673 SvxBreak::ColumnAfter :
674 SvxBreak::PageAfter );
675 break;
676 }
677 bOk = true;
678 }
679 }
680 break;
681
682 case RES_KEEP:
683 {
684 SvxFormatKeepItem& rFormatKeep = dynamic_cast<SvxFormatKeepItem&>(rItem);
685
686 if( IsXMLToken( rValue, XML_ALWAYS ) ||
687 IsXMLToken( rValue, XML_TRUE ) )
688 {
689 rFormatKeep.SetValue( true );
690 bOk = true;
691 }
692 else if( IsXMLToken( rValue, XML_AUTO ) ||
693 IsXMLToken( rValue, XML_FALSE ) )
694 {
695 rFormatKeep.SetValue( false );
696 bOk = true;
697 }
698 }
699 break;
700
701 case RES_BACKGROUND:
702 {
703 SvxBrushItem& rBrush = dynamic_cast<SvxBrushItem&>(rItem);
704
705 Color aTempColor;
706 switch( nMemberId )
707 {
708 case MID_BACK_COLOR:
709 if( IsXMLToken( rValue, XML_TRANSPARENT ) )
710 {
711 rBrush.GetColor().SetAlpha(0);
712 bOk = true;
713 }
714 else if (::sax::Converter::convertColor(aTempColor, rValue))
715 {
716 aTempColor.SetAlpha(255);
717 rBrush.SetColor( aTempColor );
718 bOk = true;
719 }
720 break;
721
723 {
724 SvxGraphicPosition eGraphicPos = rBrush.GetGraphicPos();
728 {
729 if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
730 GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
731 rBrush.SetGraphicPos( nPos );
732 bOk = true;
733 }
734 }
735 break;
736
738 {
741 SvXMLTokenEnumerator aTokenEnum( rValue );
742 std::u16string_view aToken;
743 bool bHori = false, bVert = false;
744 bOk = true;
745 while( bOk && aTokenEnum.getNextToken( aToken ) )
746 {
747 if( bHori && bVert )
748 {
749 bOk = false;
750 }
751 else if( std::u16string_view::npos != aToken.find( '%' ) )
752 {
753 sal_Int32 nPrc = 50;
754 if (::sax::Converter::convertPercent(nPrc, aToken))
755 {
756 if( !bHori )
757 {
758 ePos = nPrc < 25 ? GPOS_LT :
759 (nPrc < 75 ? GPOS_MM : GPOS_RB);
760 bHori = true;
761 }
762 else
763 {
764 eTmp = nPrc < 25 ? GPOS_LT:
765 (nPrc < 75 ? GPOS_LM : GPOS_LB);
767 bVert = true;
768 }
769 }
770 else
771 {
772 // wrong percentage
773 bOk = false;
774 }
775 }
776 else if( IsXMLToken( aToken, XML_CENTER ) )
777 {
778 if( bHori )
780 else if ( bVert )
782 else
783 ePos = GPOS_MM;
784 }
785 else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
787 {
788 if( bVert )
790 ePos, nTmp );
791 else if( !bHori )
792 ePos = nTmp;
793 else
794 bOk = false;
795 bHori = true;
796 }
797 else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
799 {
800 if( bHori )
802 ePos, nTmp );
803 else if( !bVert )
804 ePos = nTmp;
805 else
806 bOk = false;
807 bVert = true;
808 }
809 else
810 {
811 bOk = false;
812 }
813 }
814
815 if( GPOS_NONE == ePos ) bOk = false;
816 if( bOk )
817 rBrush.SetGraphicPos( ePos );
818 }
819 break;
820
822 rBrush.SetGraphicFilter( rValue );
823 bOk = true;
824 break;
825 }
826 }
827 break;
828
829 case RES_PAGEDESC:
830 {
831 SwFormatPageDesc& rPageDesc = dynamic_cast<SwFormatPageDesc&>(rItem);
832
833 if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
834 {
835 sal_Int32 nVal;
837 nVal, rValue, 0, USHRT_MAX);
838 // i#114163 tdf#77111: OOo < 3.3 had a bug where it wrote
839 // "auto" as "0" for tables - now that we support a real offset
840 // 0, this fake "0" MUST NOT be imported as offset 0!
841 if( bOk && nVal > 0 )
842 rPageDesc.SetNumOffset( o3tl::narrowing<sal_uInt16>(nVal) );
843 }
844 }
845 break;
846
847 case RES_LAYOUT_SPLIT:
848 case RES_ROW_SPLIT:
849 {
850 SfxBoolItem& rSplit = dynamic_cast<SfxBoolItem&>(rItem);
851
852 if( IsXMLToken( rValue, XML_AUTO ) ||
853 IsXMLToken( rValue, XML_TRUE ) )
854 {
855 rSplit.SetValue( true );
856 bOk = true;
857 }
858 else if( IsXMLToken( rValue, XML_ALWAYS ) ||
859 IsXMLToken( rValue, XML_FALSE ) )
860 {
861 rSplit.SetValue( false );
862 bOk = true;
863 }
864 }
865 break;
866
867 case RES_PRINT:
868 {
869 SfxBoolItem& rHasTextChangesOnly = dynamic_cast<SfxBoolItem&>(rItem);
870
871 if( IsXMLToken( rValue, XML_TRUE ) )
872 {
873 rHasTextChangesOnly.SetValue( true );
874 bOk = true;
875 }
876 else if( IsXMLToken( rValue, XML_FALSE ) )
877 {
878 rHasTextChangesOnly.SetValue( false );
879 bOk = true;
880 }
881 }
882 break;
883
884 case RES_HORI_ORIENT:
885 {
886 SwFormatHoriOrient& rHoriOrient = dynamic_cast<SwFormatHoriOrient&>(rItem);
887
888 sal_Int16 nValue;
891 if( bOk )
892 rHoriOrient.SetHoriOrient( nValue );
893 }
894 break;
895
896 case RES_VERT_ORIENT:
897 {
898 SwFormatVertOrient& rVertOrient = dynamic_cast<SwFormatVertOrient&>(rItem);
899
900 sal_Int16 nValue;
903 if( bOk )
904 rVertOrient.SetVertOrient( nValue );
905 //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
906 else if(rValue.isEmpty())
907 {
909 bOk = true;
910 }
911 }
912 break;
913
914 case RES_FRM_SIZE:
915 {
916 SwFormatFrameSize& rFrameSize = dynamic_cast<SwFormatFrameSize&>(rItem);
917
918 bool bSetHeight = false;
919 bool bSetWidth = false;
920 bool bSetSizeType = false;
922 sal_Int32 nMin = MINLAY;
923
924 switch( nMemberId )
925 {
927 {
928 sal_Int32 nValue;
930 if( bOk )
931 {
932 if( nValue < 1 )
933 nValue = 1;
934 else if( nValue > 100 )
935 nValue = 100;
936
937 rFrameSize.SetWidthPercent( static_cast<sal_Int8>(nValue) );
938 }
939 }
940 break;
942 bSetWidth = true;
943 break;
945 eSizeType = SwFrameSize::Minimum;
946 bSetHeight = true;
947 nMin = 1;
948 bSetSizeType = true;
949 break;
951 eSizeType = SwFrameSize::Fixed;
952 bSetHeight = true;
953 nMin = 1;
954 bSetSizeType = true;
955 break;
957 eSizeType = SwFrameSize::Fixed;
958 bSetWidth = true;
959 bSetSizeType = true;
960 break;
962 {
963 sal_Int32 nPos = rValue.indexOf( '*' );
964 if( -1 != nPos )
965 {
966 sal_Int32 nValue = rValue.toInt32();
967 if( nValue < MINLAY )
968 nValue = MINLAY;
969 else if( nValue > SAL_MAX_UINT16 )
971
972 rFrameSize.SetWidth( o3tl::narrowing<sal_uInt16>(nValue) );
974 bOk = true;
975 }
976 }
977 break;
978 }
979
980 if( bSetHeight || bSetWidth )
981 {
982 sal_Int32 nValue;
983 bOk = rUnitConverter.convertMeasureToCore(nValue, rValue, nMin,
984 USHRT_MAX );
985 if( bOk )
986 {
987 if( bSetWidth )
988 rFrameSize.SetWidth( o3tl::narrowing<sal_uInt16>(nValue) );
989 if( bSetHeight )
990 rFrameSize.SetHeight( o3tl::narrowing<sal_uInt16>(nValue) );
991 if( bSetSizeType )
992 rFrameSize.SetHeightSizeType( eSizeType );
993 }
994 }
995 }
996 break;
997
998 case RES_FRAMEDIR:
999 {
1000 if (IsXMLToken(rValue, XML_BT_LR))
1001 {
1002 // Read bt-lr from the extension namespace, handle other values
1003 // below.
1004 Any aAny;
1005 aAny <<= static_cast<sal_uInt16>(SvxFrameDirection::Vertical_LR_BT);
1006 bOk = rItem.PutValue(aAny, 0);
1007 }
1008 else if (IsXMLToken(rValue, XML_TB_RL90))
1009 {
1010 // Read tb-rl90 from the extension namespace.
1011 Any aAny;
1012 aAny <<= static_cast<sal_uInt16>(SvxFrameDirection::Vertical_RL_TB90);
1013 bOk = rItem.PutValue(aAny, 0);
1014 }
1015 else
1016 {
1017 std::unique_ptr<XMLPropertyHandler> pWritingModeHandler =
1020 Any aAny;
1021 bOk = pWritingModeHandler->importXML( rValue, aAny,
1022 rUnitConverter );
1023 if( bOk )
1024 bOk = rItem.PutValue( aAny, 0 );
1025 }
1026 }
1027 break;
1028
1030 {
1031 SfxBoolItem& rBorders = dynamic_cast<SfxBoolItem&>(rItem);
1032
1033 if( IsXMLToken( rValue, XML_COLLAPSING ) )
1034 {
1035 rBorders.SetValue(true);
1036 bOk = true;
1037 }
1038 else if( IsXMLToken( rValue, XML_SEPARATING ) )
1039 {
1040 rBorders.SetValue(false);
1041 bOk = true;
1042 }
1043 else
1044 bOk = false;
1045 }
1046 break;
1047
1048 default:
1049 OSL_FAIL("Item not implemented!");
1050 break;
1051 }
1052
1053 return bOk;
1054}
1055
1056/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::chart::ChartAxisLabelPosition ePos
SvxGraphicPosition
GPOS_LT
GPOS_NONE
GPOS_MM
GPOS_TILED
GPOS_AREA
GPOS_LB
GPOS_LM
GPOS_RB
void SetAlpha(sal_uInt8 nAlpha)
void SetValue(bool const bTheValue)
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
static bool IsWhich(sal_uInt16 nId)
SfxItemPool * GetPool() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 Which() const
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
SvXMLImportItemMapper(SvXMLItemMapEntriesRef aMapEntries)
Definition: xmlimpit.cxx:64
virtual void setMapEntries(SvXMLItemMapEntriesRef rMapEntries)
Definition: xmlimpit.cxx:75
void importXMLUnknownAttributes(SfxItemSet &rSet, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, const SvXMLUnitConverter &rUnitConverter, std::unique_ptr< SvXMLAttrContainerItem > &pUnknownItem)
Definition: xmlimpit.cxx:198
SvXMLItemMapEntriesRef mrMapEntries
Definition: xmlimpit.hxx:34
static bool PutXMLValue(SfxPoolItem &rItem, const OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
This method is called for every item that should be set based upon an XML attribute value.
Definition: xmlimpit.cxx:310
virtual bool handleSpecialItem(const SvXMLItemMapEntry &rEntry, SfxPoolItem &rItem, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter)
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set
Definition: xmlimpit.cxx:254
virtual void finished(SfxItemSet &rSet, SvXMLUnitConverter const &rUnitConverter) const
This method is called when all attributes have benn processed.
Definition: xmlimpit.cxx:277
virtual ~SvXMLImportItemMapper()
Definition: xmlimpit.cxx:70
void importXML(SfxItemSet &rSet, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap)
fills the given itemset with the attributes in the given list
Definition: xmlimpit.cxx:81
virtual bool handleNoItem(const SvXMLItemMapEntry &rEntry, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap)
this method is called for every item that has the MID_SW_FLAG_NO_ITEM_IMPORT flag set
Definition: xmlimpit.cxx:266
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
bool getNextToken(std::u16string_view &rToken)
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
const editeng::SvxBorderLine * GetTop() const
const editeng::SvxBorderLine * GetRight() const
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
const editeng::SvxBorderLine * GetLeft() const
void SetDistance(sal_Int16 nNew, SvxBoxItemLine nLine)
const editeng::SvxBorderLine * GetBottom() const
void SetGraphicPos(SvxGraphicPosition eNew)
const Color & GetColor() const
void SetColor(const Color &rCol)
SvxGraphicPosition GetGraphicPos() const
void SetGraphicFilter(const OUString &rNew)
void SetRight(const tools::Long nR, const sal_uInt16 nProp=100)
void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp=100)
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
void SetAutoFirst(const bool bNew)
void SetLocation(SvxShadowLocation eNew)
void SetWidth(sal_uInt16 nNew)
void SetColor(const Color &rNew)
void SetHeight(tools::Long n)
void SetWidth(tools::Long n)
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
void SetWidthPercent(sal_uInt8 n)
Definition: fmtfsize.hxx:95
void SetHeightSizeType(SwFrameSize eSize)
Definition: fmtfsize.hxx:81
Defines the horizontal position of a fly frame.
Definition: fmtornt.hxx:73
void SetHoriOrient(sal_Int16 eNew)
Definition: fmtornt.hxx:96
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:36
void SetNumOffset(const ::std::optional< sal_uInt16 > &oNum)
Definition: fmtpdsc.hxx:65
Defines the vertical position of a fly frame.
Definition: fmtornt.hxx:37
void SetVertOrient(sal_Int16 eNew)
Definition: fmtornt.hxx:59
static std::unique_ptr< XMLPropertyHandler > CreatePropertyHandler(sal_Int32 nType)
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertBool(bool &rBool, std::u16string_view rString)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
float u
sal_Int16 nValue
SwFrameSize
Definition: fmtfsize.hxx:36
@ Fixed
Frame cannot be moved in Var-direction.
@ Variable
Frame is variable in Var-direction.
@ Minimum
Value in Var-direction gives minimum (can be exceeded but not be less).
OUString sName
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(126)
constexpr TypedWhichId< SvxFormatKeepItem > RES_KEEP(116)
constexpr TypedWhichId< SwFormatRowSplit > RES_ROW_SPLIT(128)
constexpr TypedWhichId< SvxFirstLineIndentItem > RES_MARGIN_FIRSTLINE(91)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(109)
constexpr TypedWhichId< SvxShadowItem > RES_SHADOW(113)
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(108)
constexpr TypedWhichId< SvXMLAttrContainerItem > RES_UNKNOWNATR_CONTAINER(RES_UNKNOWNATR_BEGIN)
constexpr TypedWhichId< SwFormatLayoutSplit > RES_LAYOUT_SPLIT(119)
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SfxBoolItem > RES_COLLAPSING_BORDERS(131)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(112)
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(100)
constexpr TypedWhichId< SvxRightMarginItem > RES_MARGIN_RIGHT(93)
constexpr TypedWhichId< SvxTextLeftMarginItem > RES_MARGIN_TEXTLEFT(92)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(97)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(98)
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(104)
sal_uInt16 nPos
OUString sPrefix
#define SAL_WARN(area, stream)
#define BOTTOM_BORDER
#define MID_BACK_COLOR
#define MID_LO_MARGIN
#define MID_FIRST_AUTO
#define MID_GRAPHIC_REPEAT
#define MID_GRAPHIC_POSITION
#define MID_BREAK_BEFORE
#define TOP_BORDER
#define RIGHT_BORDER
#define MID_R_MARGIN
#define MID_FIRST_LINE_INDENT
#define MID_L_MARGIN
#define MID_UP_MARGIN
#define LEFT_BORDER
#define MID_BREAK_AFTER
#define MID_GRAPHIC_FILTER
int i
const sal_uInt16 XML_NAMESPACE_NONE
const sal_uInt16 XML_NAMESPACE_XMLNS
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_ALWAYS
XML_AUTO
XML_TRUE
XML_NONE
XML_BT_LR
XML_COLLAPSING
XML_FALSE
XML_CENTER
XML_TRANSPARENT
XML_SEPARATING
XML_TB_RL90
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
SfxItemState
DefTokenId nToken
static SfxItemSet & rSet
sal_uInt16 nWhichId
Definition: xmlitmap.hxx:44
sal_uInt32 nMemberId
Definition: xmlitmap.hxx:49
#define MINLAY
Definition: swtypes.hxx:62
#define SAL_MAX_UINT16
signed char sal_Int8
#define MID_FRMSIZE_REL_COL_WIDTH
Definition: unomid.h:82
#define MID_FRMSIZE_MIN_HEIGHT
Definition: unomid.h:79
#define MID_FRMSIZE_FIX_HEIGHT
Definition: unomid.h:80
#define MID_FRMSIZE_REL_WIDTH
Definition: unomid.h:72
#define MID_FRMSIZE_WIDTH
Definition: unomid.h:74
#define MID_PAGEDESC_PAGENUMOFFSET
Definition: unomid.h:27
#define MID_FRMSIZE_COL_WIDTH
Definition: unomid.h:81
#define ALL_BORDER_PADDING
#define TOP_BORDER_LINE_WIDTH
#define BOTTOM_BORDER_PADDING
#define BOTTOM_BORDER_LINE_WIDTH
#define ALL_BORDER_LINE_WIDTH
#define LEFT_BORDER_PADDING
#define LEFT_BORDER_LINE_WIDTH
#define ALL_BORDER
#define RIGHT_BORDER_PADDING
#define RIGHT_BORDER_LINE_WIDTH
#define TOP_BORDER_PADDING
#define XML_ELEMENT(prefix, name)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_Int32 TOKEN_MASK
constexpr sal_uInt16 nUnknownWhich
Definition: xmlimpit.cxx:62
const struct SvXMLEnumMapEntry< sal_Int16 > aXMLTableVAlignMap[]
Definition: xmlithlp.cxx:318
const struct SvXMLEnumMapEntry< sal_Int16 > aXMLTableAlignMap[]
Definition: xmlithlp.cxx:307
const struct SvXMLEnumMapEntry< SvxGraphicPosition > psXML_BrushHoriPos[]
Definition: xmlithlp.cxx:223
void sw_frmitems_MergeXMLVertPos(SvxGraphicPosition &ePos, SvxGraphicPosition eVert)
Definition: xmlithlp.cxx:267
const struct SvXMLEnumMapEntry< SvxGraphicPosition > psXML_BrushVertPos[]
Definition: xmlithlp.cxx:230
bool sw_frmitems_parseXMLBorder(std::u16string_view rValue, const SvXMLUnitConverter &rUnitConverter, bool &rHasStyle, sal_uInt16 &rStyle, bool &rHasWidth, sal_uInt16 &rWidth, sal_uInt16 &rNamedWidth, bool &rHasColor, Color &rColor)
Define various helper variables and functions for xmlimpit.cxx and xmlexpit.cxx.
Definition: xmlithlp.cxx:77
const struct SvXMLEnumMapEntry< sal_uInt16 > psXML_BreakType[]
Definition: xmlithlp.cxx:297
bool sw_frmitems_setXMLBorder(std::unique_ptr< SvxBorderLine > &rpLine, bool bHasStyle, sal_uInt16 nStyle, bool bHasWidth, sal_uInt16 nWidth, sal_uInt16 nNamedWidth, bool bHasColor, const Color &rColor)
Definition: xmlithlp.cxx:138
const struct SvXMLEnumMapEntry< SvxGraphicPosition > psXML_BrushRepeat[]
Definition: xmlithlp.cxx:215
void sw_frmitems_MergeXMLHoriPos(SvxGraphicPosition &ePos, SvxGraphicPosition eHori)
Definition: xmlithlp.cxx:237
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:29
#define MID_SW_FLAG_SPECIAL_ITEM_IMPORT
Definition: xmlitmap.hxx:32
#define MID_SW_FLAG_NO_ITEM_IMPORT
Definition: xmlitmap.hxx:33
#define MID_SW_FLAG_ELEMENT_ITEM_IMPORT
Definition: xmlitmap.hxx:36
constexpr sal_uInt16 XML_NAMESPACE_FO_COMPAT
#define XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT