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  rNamespaceMap );
138  }
139 
140  if( bPut )
141  rSet.Put( *pNewItem );
142  }
143  else
144  {
145  OSL_FAIL( "Could not get a needed item for xml import!" );
146  }
147  }
148  else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
149  {
150  handleNoItem( *pEntry, rSet, rValue, rUnitConverter,
151  rNamespaceMap );
152  }
153  }
154  else if( USHRT_MAX != nUnknownWhich )
155  {
156  if( !pUnknownItem )
157  {
158  const SfxPoolItem* pItem = nullptr;
159  if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true,
160  &pItem ) )
161  {
162  pUnknownItem.reset( static_cast<SvXMLAttrContainerItem*>( pItem->Clone() ) );
163  }
164  else
165  {
166  pUnknownItem.reset( new SvXMLAttrContainerItem( nUnknownWhich ) );
167  }
168  }
169  if( pUnknownItem )
170  {
171  if( XML_NAMESPACE_NONE == nPrefix )
172  pUnknownItem->AddAttr( aLocalName, rValue );
173  else
174  pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName,
175  rValue );
176  }
177  }
178  }
179 
180  if( pUnknownItem )
181  {
182  rSet.Put( *pUnknownItem );
183  }
184 
185  finished(rSet, rUnitConverter);
186 }
187 
190 bool
192  SfxPoolItem& /*rItem*/,
193  SfxItemSet& /*rSet*/,
194  const OUString& /*rValue*/,
195  const SvXMLUnitConverter& /*rUnitConverter*/,
196  const SvXMLNamespaceMap& /*rNamespaceMap*/ )
197 {
198  OSL_FAIL( "unsupported special item in xml import" );
199  return false;
200 }
201 
205  SfxItemSet& /*rSet*/,
206  const OUString& /*rValue*/,
207  const SvXMLUnitConverter& /*rUnitConverter*/,
208  const SvXMLNamespaceMap& /*rNamespaceMap*/ )
209 {
210  OSL_FAIL( "unsupported no item in xml import" );
211  return false;
212 }
213 
214 void
216 {
217  // nothing to do here
218 }
219 
220 struct BoxHolder
221 {
222  std::unique_ptr<SvxBorderLine> pTop;
223  std::unique_ptr<SvxBorderLine> pBottom;
224  std::unique_ptr<SvxBorderLine> pLeft;
225  std::unique_ptr<SvxBorderLine> pRight;
226 
227  BoxHolder(BoxHolder const&) = delete;
228  BoxHolder& operator=(BoxHolder const&) = delete;
229 
230  explicit BoxHolder(SvxBoxItem const & rBox)
231  {
232  if (rBox.GetTop())
233  pTop.reset(new SvxBorderLine( *rBox.GetTop() ));
234  if (rBox.GetBottom())
235  pBottom.reset(new SvxBorderLine( *rBox.GetBottom() ));
236  if (rBox.GetLeft())
237  pLeft.reset(new SvxBorderLine( *rBox.GetLeft() ));
238  if (rBox.GetRight())
239  pRight.reset(new SvxBorderLine( *rBox.GetRight() ));
240  }
241 };
242 
243 // put an XML-string value into an item
245  SfxPoolItem& rItem,
246  const OUString& rValue,
247  sal_uInt16 nMemberId,
248  const SvXMLUnitConverter& rUnitConverter )
249 {
250  bool bOk = false;
251 
252  switch (rItem.Which())
253  {
254  case RES_LR_SPACE:
255  {
256  SvxLRSpaceItem& rLRSpace = dynamic_cast<SvxLRSpaceItem&>(rItem);
257 
258  switch( nMemberId )
259  {
260  case MID_L_MARGIN:
261  case MID_R_MARGIN:
262  {
263  sal_Int32 nProp = 100;
264  sal_Int32 nAbs = 0;
265 
266  if( rValue.indexOf( '%' ) != -1 )
267  bOk = ::sax::Converter::convertPercent(nProp, rValue);
268  else
269  bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue);
270 
271  if( bOk )
272  {
273  switch( nMemberId )
274  {
275  case MID_L_MARGIN:
276  rLRSpace.SetTextLeft( nAbs, static_cast<sal_uInt16>(nProp) );
277  break;
278  case MID_R_MARGIN:
279  rLRSpace.SetRight( nAbs, static_cast<sal_uInt16>(nProp) );
280  break;
281  }
282  }
283  }
284  break;
285 
287  {
288  sal_Int32 nProp = 100;
289  sal_Int32 nAbs = 0;
290 
291  if( rValue.indexOf( '%' ) != -1 )
292  bOk = ::sax::Converter::convertPercent(nProp, rValue);
293  else
294  bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue,
295  -0x7fff, 0x7fff );
296 
297  rLRSpace.SetTextFirstLineOfst( static_cast<short>(nAbs), static_cast<sal_uInt16>(nProp) );
298  }
299  break;
300 
301  case MID_FIRST_AUTO:
302  {
303  bool bAutoFirst(false);
304  bOk = ::sax::Converter::convertBool( bAutoFirst, rValue );
305  if( bOk )
306  rLRSpace.SetAutoFirst( bAutoFirst );
307  }
308  break;
309 
310  default:
311  OSL_FAIL( "unknown member id!");
312  }
313  }
314  break;
315 
316  case RES_UL_SPACE:
317  {
318  SvxULSpaceItem& rULSpace = dynamic_cast<SvxULSpaceItem&>(rItem);
319 
320  sal_Int32 nProp = 100;
321  sal_Int32 nAbs = 0;
322 
323  if( rValue.indexOf( '%' ) != -1 )
324  bOk = ::sax::Converter::convertPercent( nProp, rValue );
325  else
326  bOk = rUnitConverter.convertMeasureToCore( nAbs, rValue );
327 
328  switch( nMemberId )
329  {
330  case MID_UP_MARGIN:
331  rULSpace.SetUpper( static_cast<sal_uInt16>(nAbs), static_cast<sal_uInt16>(nProp) );
332  break;
333  case MID_LO_MARGIN:
334  rULSpace.SetLower( static_cast<sal_uInt16>(nAbs), static_cast<sal_uInt16>(nProp) );
335  break;
336  default:
337  OSL_FAIL("unknown MemberId");
338  }
339  }
340  break;
341 
342  case RES_SHADOW:
343  {
344  SvxShadowItem& rShadow = dynamic_cast<SvxShadowItem&>(rItem);
345 
346  bool bColorFound = false;
347  bool bOffsetFound = false;
348 
349  SvXMLTokenEnumerator aTokenEnum( rValue );
350 
351  Color aColor( 128,128, 128 );
352  rShadow.SetLocation( SvxShadowLocation::BottomRight );
353 
354  OUString aToken;
355  while( aTokenEnum.getNextToken( aToken ) )
356  {
357  if( IsXMLToken( aToken, XML_NONE ) )
358  {
359  rShadow.SetLocation( SvxShadowLocation::NONE );
360  bOk = true;
361  }
362  else if( !bColorFound && aToken.startsWith("#") )
363  {
364  bOk = ::sax::Converter::convertColor( aColor, aToken );
365  if( !bOk )
366  return false;
367 
368  bColorFound = true;
369  }
370  else if( !bOffsetFound )
371  {
372  sal_Int32 nX = 0, nY = 0;
373 
374  bOk = rUnitConverter.convertMeasureToCore( nX, aToken );
375  if( bOk && aTokenEnum.getNextToken( aToken ) )
376  bOk = rUnitConverter.convertMeasureToCore( nY, aToken );
377 
378  if( bOk )
379  {
380  if( nX < 0 )
381  {
382  if( nY < 0 )
383  {
384  rShadow.SetLocation( SvxShadowLocation::TopLeft );
385  }
386  else
387  {
388  rShadow.SetLocation( SvxShadowLocation::BottomLeft );
389  }
390  }
391  else
392  {
393  if( nY < 0 )
394  {
395  rShadow.SetLocation( SvxShadowLocation::TopRight );
396  }
397  else
398  {
399  rShadow.SetLocation( SvxShadowLocation::BottomRight );
400  }
401  }
402 
403  if( nX < 0 ) nX *= -1;
404  if( nY < 0 ) nY *= -1;
405 
406  rShadow.SetWidth( static_cast< sal_uInt16 >( (nX + nY) >> 1 ) );
407  }
408  }
409  }
410 
411  if( bOk && ( bColorFound || bOffsetFound ) )
412  {
413  rShadow.SetColor(aColor);
414  }
415  else
416  bOk = false;
417  }
418  break;
419 
420  case RES_BOX:
421  {
422  SvxBoxItem& rBox = dynamic_cast<SvxBoxItem&>(rItem);
423 
424  // copy SvxBorderLines
425  BoxHolder aBoxes(rBox);
426 
427  sal_Int32 nTemp;
428 
429  switch( nMemberId )
430  {
431  case ALL_BORDER_PADDING:
432  case LEFT_BORDER_PADDING:
434  case TOP_BORDER_PADDING:
436  if (!rUnitConverter.convertMeasureToCore( nTemp, rValue,
437  0, 0xffff ))
438  {
439  return false;
440  }
441 
442  if( nMemberId == LEFT_BORDER_PADDING ||
443  nMemberId == ALL_BORDER_PADDING )
444  rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::LEFT );
445  if( nMemberId == RIGHT_BORDER_PADDING ||
446  nMemberId == ALL_BORDER_PADDING )
447  rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::RIGHT );
448  if( nMemberId == TOP_BORDER_PADDING ||
449  nMemberId == ALL_BORDER_PADDING )
450  rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::TOP );
451  if( nMemberId == BOTTOM_BORDER_PADDING ||
452  nMemberId == ALL_BORDER_PADDING )
453  rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::BOTTOM);
454  break;
455 
456  case ALL_BORDER:
457  case LEFT_BORDER:
458  case RIGHT_BORDER:
459  case TOP_BORDER:
460  case BOTTOM_BORDER:
461  {
462  bool bHasStyle = false;
463  bool bHasWidth = false;
464  bool bHasColor = false;
465 
466  sal_uInt16 nStyle = USHRT_MAX;
467  sal_uInt16 nWidth = 0;
468  sal_uInt16 nNamedWidth = USHRT_MAX;
469 
470  Color aColor( COL_BLACK );
471 
472  if( !sw_frmitems_parseXMLBorder( rValue, rUnitConverter,
473  bHasStyle, nStyle,
474  bHasWidth, nWidth, nNamedWidth,
475  bHasColor, aColor ) )
476  return false;
477 
478  if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
480  bHasStyle, nStyle,
481  bHasWidth, nWidth, nNamedWidth,
482  bHasColor, aColor );
483 
484  if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
486  bHasStyle, nStyle,
487  bHasWidth, nWidth, nNamedWidth,
488  bHasColor, aColor );
489 
490  if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
492  bHasStyle, nStyle,
493  bHasWidth, nWidth, nNamedWidth,
494  bHasColor, aColor );
495 
496  if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
498  bHasStyle, nStyle,
499  bHasWidth, nWidth, nNamedWidth,
500  bHasColor, aColor );
501  }
502  break;
508  {
509  SvXMLTokenEnumerator aTokenEnum( rValue );
510 
511  sal_Int32 nInWidth, nDistance, nOutWidth;
512 
513  OUString aToken;
514  if( !aTokenEnum.getNextToken( aToken ) )
515  return false;
516 
517  if (!rUnitConverter.convertMeasureToCore(nInWidth, aToken))
518  return false;
519 
520  if( !aTokenEnum.getNextToken( aToken ) )
521  return false;
522 
523  if (!rUnitConverter.convertMeasureToCore(nDistance, aToken))
524  return false;
525 
526  if( !aTokenEnum.getNextToken( aToken ) )
527  return false;
528 
529  if (!rUnitConverter.convertMeasureToCore(nOutWidth, aToken))
530  return false;
531 
532  // #i61946: accept line style even it's not part of our "normal" set of line styles
533  sal_uInt16 nWidth = 0;
534 
535  if( TOP_BORDER_LINE_WIDTH == nMemberId ||
536  ALL_BORDER_LINE_WIDTH == nMemberId )
537  sw_frmitems_setXMLBorder( aBoxes.pTop, nWidth,
538  static_cast< sal_uInt16 >( nOutWidth ),
539  static_cast< sal_uInt16 >( nInWidth ),
540  static_cast< sal_uInt16 >( nDistance ) );
541 
542  if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
543  ALL_BORDER_LINE_WIDTH == nMemberId )
544  sw_frmitems_setXMLBorder( aBoxes.pBottom, nWidth,
545  static_cast< sal_uInt16 >( nOutWidth ),
546  static_cast< sal_uInt16 >( nInWidth ),
547  static_cast< sal_uInt16 >( nDistance ) );
548 
549  if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
550  ALL_BORDER_LINE_WIDTH == nMemberId )
551  sw_frmitems_setXMLBorder( aBoxes.pLeft, nWidth,
552  static_cast< sal_uInt16 >( nOutWidth ),
553  static_cast< sal_uInt16 >( nInWidth ),
554  static_cast< sal_uInt16 >( nDistance ) );
555 
556  if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
557  ALL_BORDER_LINE_WIDTH == nMemberId )
558  sw_frmitems_setXMLBorder( aBoxes.pRight, nWidth,
559  static_cast< sal_uInt16 >( nOutWidth ),
560  static_cast< sal_uInt16 >( nInWidth ),
561  static_cast< sal_uInt16 >( nDistance ) );
562  }
563  break;
564  }
565 
566  rBox.SetLine( aBoxes.pTop.get(), SvxBoxItemLine::TOP );
567  rBox.SetLine( aBoxes.pBottom.get(), SvxBoxItemLine::BOTTOM );
568  rBox.SetLine( aBoxes.pLeft.get(), SvxBoxItemLine::LEFT );
569  rBox.SetLine( aBoxes.pRight.get(), SvxBoxItemLine::RIGHT );
570 
571  bOk = true;
572  }
573  break;
574 
575  case RES_BREAK:
576  {
577  SvxFormatBreakItem& rFormatBreak = dynamic_cast<SvxFormatBreakItem&>(rItem);
578  sal_uInt16 eEnum{};
579 
580  if( !SvXMLUnitConverter::convertEnum( eEnum, rValue, psXML_BreakType ) )
581  return false;
582 
583  if( eEnum == 0 )
584  {
585  rFormatBreak.SetValue( SvxBreak::NONE );
586  bOk = true;
587  }
588  else
589  {
590  switch( nMemberId )
591  {
592  case MID_BREAK_BEFORE:
593  rFormatBreak.SetValue( eEnum == 1 ?
594  SvxBreak::ColumnBefore :
595  SvxBreak::PageBefore );
596  break;
597  case MID_BREAK_AFTER:
598  rFormatBreak.SetValue( eEnum == 1 ?
599  SvxBreak::ColumnAfter :
600  SvxBreak::PageAfter );
601  break;
602  }
603  bOk = true;
604  }
605  }
606  break;
607 
608  case RES_KEEP:
609  {
610  SvxFormatKeepItem& rFormatKeep = dynamic_cast<SvxFormatKeepItem&>(rItem);
611 
612  if( IsXMLToken( rValue, XML_ALWAYS ) ||
613  IsXMLToken( rValue, XML_TRUE ) )
614  {
615  rFormatKeep.SetValue( true );
616  bOk = true;
617  }
618  else if( IsXMLToken( rValue, XML_AUTO ) ||
619  IsXMLToken( rValue, XML_FALSE ) )
620  {
621  rFormatKeep.SetValue( false );
622  bOk = true;
623  }
624  }
625  break;
626 
627  case RES_BACKGROUND:
628  {
629  SvxBrushItem& rBrush = dynamic_cast<SvxBrushItem&>(rItem);
630 
631  sal_Int32 nTempColor(0);
632  switch( nMemberId )
633  {
634  case MID_BACK_COLOR:
635  if( IsXMLToken( rValue, XML_TRANSPARENT ) )
636  {
637  rBrush.GetColor().SetTransparency(0xff);
638  bOk = true;
639  }
640  else if (::sax::Converter::convertColor(nTempColor, rValue))
641  {
642  Color aTempColor(nTempColor);
643  aTempColor.SetTransparency(0);
644  rBrush.SetColor( aTempColor );
645  bOk = true;
646  }
647  break;
648 
649  case MID_GRAPHIC_REPEAT:
650  {
651  SvxGraphicPosition eGraphicPos = rBrush.GetGraphicPos();
653  if( SvXMLUnitConverter::convertEnum( nPos, rValue,
655  {
656  if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
657  GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
658  rBrush.SetGraphicPos( nPos );
659  bOk = true;
660  }
661  }
662  break;
663 
665  {
667  SvxGraphicPosition nTmp;
668  SvXMLTokenEnumerator aTokenEnum( rValue );
669  OUString aToken;
670  bool bHori = false, bVert = false;
671  bOk = true;
672  while( bOk && aTokenEnum.getNextToken( aToken ) )
673  {
674  if( bHori && bVert )
675  {
676  bOk = false;
677  }
678  else if( -1 != aToken.indexOf( '%' ) )
679  {
680  sal_Int32 nPrc = 50;
681  if (::sax::Converter::convertPercent(nPrc, aToken))
682  {
683  if( !bHori )
684  {
685  ePos = nPrc < 25 ? GPOS_LT :
686  (nPrc < 75 ? GPOS_MM : GPOS_RB);
687  bHori = true;
688  }
689  else
690  {
691  eTmp = nPrc < 25 ? GPOS_LT:
692  (nPrc < 75 ? GPOS_LM : GPOS_LB);
693  sw_frmitems_MergeXMLVertPos( ePos, eTmp );
694  bVert = true;
695  }
696  }
697  else
698  {
699  // wrong percentage
700  bOk = false;
701  }
702  }
703  else if( IsXMLToken( aToken, XML_CENTER ) )
704  {
705  if( bHori )
707  else if ( bVert )
709  else
710  ePos = GPOS_MM;
711  }
712  else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
714  {
715  if( bVert )
717  ePos, nTmp );
718  else if( !bHori )
719  ePos = nTmp;
720  else
721  bOk = false;
722  bHori = true;
723  }
724  else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
726  {
727  if( bHori )
729  ePos, nTmp );
730  else if( !bVert )
731  ePos = nTmp;
732  else
733  bOk = false;
734  bVert = true;
735  }
736  else
737  {
738  bOk = false;
739  }
740  }
741 
742  if( GPOS_NONE == ePos ) bOk = false;
743  if( bOk )
744  rBrush.SetGraphicPos( ePos );
745  }
746  break;
747 
748  case MID_GRAPHIC_FILTER:
749  rBrush.SetGraphicFilter( rValue );
750  bOk = true;
751  break;
752  }
753  }
754  break;
755 
756  case RES_PAGEDESC:
757  {
758  SwFormatPageDesc& rPageDesc = dynamic_cast<SwFormatPageDesc&>(rItem);
759 
760  if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
761  {
762  sal_Int32 nVal;
764  nVal, rValue, 0, USHRT_MAX);
765  // i#114163 tdf#77111: OOo < 3.3 had a bug where it wrote
766  // "auto" as "0" for tables - now that we support a real offset
767  // 0, this fake "0" MUST NOT be imported as offset 0!
768  if( bOk && nVal > 0 )
769  rPageDesc.SetNumOffset( static_cast<sal_uInt16>(nVal) );
770  }
771  }
772  break;
773 
774  case RES_LAYOUT_SPLIT:
775  case RES_ROW_SPLIT:
776  {
777  SfxBoolItem& rSplit = dynamic_cast<SfxBoolItem&>(rItem);
778 
779  if( IsXMLToken( rValue, XML_AUTO ) ||
780  IsXMLToken( rValue, XML_TRUE ) )
781  {
782  rSplit.SetValue( true );
783  bOk = true;
784  }
785  else if( IsXMLToken( rValue, XML_ALWAYS ) ||
786  IsXMLToken( rValue, XML_FALSE ) )
787  {
788  rSplit.SetValue( false );
789  bOk = true;
790  }
791  }
792  break;
793 
794  case RES_HORI_ORIENT:
795  {
796  SwFormatHoriOrient& rHoriOrient = dynamic_cast<SwFormatHoriOrient&>(rItem);
797 
798  sal_Int16 nValue;
799  bOk = SvXMLUnitConverter::convertEnum( nValue, rValue,
801  if( bOk )
802  rHoriOrient.SetHoriOrient( nValue );
803  }
804  break;
805 
806  case RES_VERT_ORIENT:
807  {
808  SwFormatVertOrient& rVertOrient = dynamic_cast<SwFormatVertOrient&>(rItem);
809 
810  sal_Int16 nValue;
811  bOk = SvXMLUnitConverter::convertEnum( nValue, rValue,
813  if( bOk )
814  rVertOrient.SetVertOrient( nValue );
815  //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
816  else if(rValue.isEmpty())
817  {
819  bOk = true;
820  }
821  }
822  break;
823 
824  case RES_FRM_SIZE:
825  {
826  SwFormatFrameSize& rFrameSize = dynamic_cast<SwFormatFrameSize&>(rItem);
827 
828  bool bSetHeight = false;
829  bool bSetWidth = false;
830  bool bSetSizeType = false;
831  SwFrameSize eSizeType = ATT_VAR_SIZE;
832  sal_Int32 nMin = MINLAY;
833 
834  switch( nMemberId )
835  {
837  {
838  sal_Int32 nValue;
839  bOk = ::sax::Converter::convertPercent( nValue, rValue );
840  if( bOk )
841  {
842  if( nValue < 1 )
843  nValue = 1;
844  else if( nValue > 100 )
845  nValue = 100;
846 
847  rFrameSize.SetWidthPercent( static_cast<sal_Int8>(nValue) );
848  }
849  }
850  break;
851  case MID_FRMSIZE_WIDTH:
852  bSetWidth = true;
853  break;
855  eSizeType = ATT_MIN_SIZE;
856  bSetHeight = true;
857  nMin = 1;
858  bSetSizeType = true;
859  break;
861  eSizeType = ATT_FIX_SIZE;
862  bSetHeight = true;
863  nMin = 1;
864  bSetSizeType = true;
865  break;
867  eSizeType = ATT_FIX_SIZE;
868  bSetWidth = true;
869  bSetSizeType = true;
870  break;
872  {
873  sal_Int32 nPos = rValue.indexOf( '*' );
874  if( -1 != nPos )
875  {
876  sal_Int32 nValue = rValue.toInt32();
877  if( nValue < MINLAY )
878  nValue = MINLAY;
879  else if( nValue > SAL_MAX_UINT16 )
880  nValue = SAL_MAX_UINT16;
881 
882  rFrameSize.SetWidth( static_cast<sal_uInt16>(nValue) );
883  rFrameSize.SetHeightSizeType( ATT_VAR_SIZE );
884  bOk = true;
885  }
886  }
887  break;
888  }
889 
890  sal_Int32 nValue;
891  if( bSetHeight || bSetWidth )
892  {
893  bOk = rUnitConverter.convertMeasureToCore(nValue, rValue, nMin,
894  USHRT_MAX );
895  if( bOk )
896  {
897  if( bSetWidth )
898  rFrameSize.SetWidth( static_cast<sal_uInt16>(nValue) );
899  if( bSetHeight )
900  rFrameSize.SetHeight( static_cast<sal_uInt16>(nValue) );
901  if( bSetSizeType )
902  rFrameSize.SetHeightSizeType( eSizeType );
903  }
904  }
905  }
906  break;
907 
908  case RES_FRAMEDIR:
909  {
910  if (IsXMLToken(rValue, XML_BT_LR))
911  {
912  // Read bt-lr from the extension namespace, handle other values
913  // below.
914  Any aAny;
915  aAny <<= static_cast<sal_uInt16>(SvxFrameDirection::Vertical_LR_BT);
916  bOk = rItem.PutValue(aAny, 0);
917  }
918  else
919  {
920  std::unique_ptr<XMLPropertyHandler> pWritingModeHandler =
923  Any aAny;
924  bOk = pWritingModeHandler->importXML( rValue, aAny,
925  rUnitConverter );
926  if( bOk )
927  bOk = rItem.PutValue( aAny, 0 );
928  }
929  }
930  break;
931 
933  {
934  SfxBoolItem& rBorders = dynamic_cast<SfxBoolItem&>(rItem);
935 
936  if( IsXMLToken( rValue, XML_COLLAPSING ) )
937  {
938  rBorders.SetValue(true);
939  bOk = true;
940  }
941  else if( IsXMLToken( rValue, XML_SEPARATING ) )
942  {
943  rBorders.SetValue(false);
944  bOk = true;
945  }
946  else
947  bOk = false;
948  }
949  break;
950 
951  default:
952  OSL_FAIL("Item not implemented!");
953  break;
954  }
955 
956  return bOk;
957 }
958 
959 /* 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:230
#define RES_FRM_SIZE
Definition: hintids.hxx:194
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:208
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:212
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:204
#define MID_FRMSIZE_REL_WIDTH
Definition: unomid.h:72
void SetColor(const Color &rNew)
#define RES_FRAMEDIR
Definition: hintids.hxx:225
#define LEFT_BORDER_PADDING
#define MINLAY
Definition: swtypes.hxx:66
std::unique_ptr< SvxBorderLine > pRight
Definition: xmlimpit.cxx:225
XML_ALWAYS
std::unique_ptr< SvxBorderLine > pBottom
Definition: xmlimpit.cxx:223
#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:224
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:267
#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
virtual bool handleSpecialItem(const SvXMLItemMapEntry &rEntry, SfxPoolItem &rItem, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap)
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set ...
Definition: xmlimpit.cxx:191
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:197
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:227
const struct SvXMLEnumMapEntry< sal_Int16 > aXMLTableAlignMap[]
Definition: xmlithlp.cxx:313
#define RES_BACKGROUND
Definition: hintids.hxx:210
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:222
SvXMLItemMapEntriesRef mrMapEntries
Definition: xmlimpit.hxx:37
#define RES_VERT_ORIENT
Definition: hintids.hxx:207
#define TOP_BORDER
int i
SvxGraphicPosition
XML_BT_LR
#define RES_LAYOUT_SPLIT
Definition: hintids.hxx:218
#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:215
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:244
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:196
#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)
static bool convertNumber(sal_Int32 &rValue, const OUString &rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
void SetWidthPercent(sal_uInt8 n)
Definition: fmtfsize.hxx:95
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:259
void SetLocation(SvxShadowLocation eNew)
const struct SvXMLEnumMapEntry< SvxGraphicPosition > psXML_BrushHoriPos[]
Definition: xmlithlp.cxx:229
#define RES_KEEP
Definition: hintids.hxx:215
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:211
#define RIGHT_BORDER
#define MID_FRMSIZE_COL_WIDTH
Definition: unomid.h:81
GPOS_RB
#define RES_COLLAPSING_BORDERS
Definition: hintids.hxx:229
GPOS_LB
void SetAutoFirst(const bool bNew)
#define RES_PAGEDESC
Definition: hintids.hxx:198
#define RES_BREAK
Definition: hintids.hxx:199
#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
XML_TRANSPARENT
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
#define MID_UP_MARGIN