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