LibreOffice Module sc (master)  1
eeimpars.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 <scitems.hxx>
21 #include <editeng/eeitem.hxx>
22 
23 #include <editeng/adjustitem.hxx>
24 #include <editeng/editobj.hxx>
26 #include <editeng/langitem.hxx>
27 #include <o3tl/unit_conversion.hxx>
28 #include <svx/svdograf.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svtools/htmlcfg.hxx>
31 #include <sfx2/sfxhtml.hxx>
32 #include <svl/numformat.hxx>
33 #include <svl/zforlist.hxx>
34 #include <vcl/virdev.hxx>
35 #include <vcl/svapp.hxx>
36 #include <unotools/charclass.hxx>
37 #include <unotools/configmgr.hxx>
38 #include <comphelper/string.hxx>
39 #include <osl/diagnose.h>
40 #include <officecfg/Office/Common.hxx>
41 
42 #include <eeimport.hxx>
43 #include <global.hxx>
44 #include <document.hxx>
45 #include <editutil.hxx>
46 #include <docpool.hxx>
47 #include <attrib.hxx>
48 #include <patattr.hxx>
49 #include <eeparser.hxx>
50 #include <drwlayer.hxx>
51 #include <rangenam.hxx>
52 #include <progress.hxx>
53 #include <stringutil.hxx>
54 #include <rowheightcontext.hxx>
55 #include <fuinsert.hxx>
56 
57 #include <globstr.hrc>
58 #include <scresid.hxx>
59 
60 #include <memory>
61 
62 ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
63  maRange( rRange ),
64  mpDoc( pDocP )
65 {
66  const ScPatternAttr* pPattern = mpDoc->GetPattern(
68  mpEngine.reset( new ScTabEditEngine(*pPattern, mpDoc->GetEditPool(), mpDoc, mpDoc->GetEditPool()) );
69  mpEngine->SetUpdateLayout( false );
70  mpEngine->EnableUndo( false );
71 }
72 
74 {
75  // Sequence important, or else we crash in some dtor!
76  // Is guaranteed as ScEEImport is base class
77 }
78 
79 ErrCode ScEEImport::Read( SvStream& rStream, const OUString& rBaseURL )
80 {
81  ErrCode nErr = mpParser->Read( rStream, rBaseURL );
82 
83  SCCOL nEndCol;
84  SCROW nEndRow;
85  mpParser->GetDimensions( nEndCol, nEndRow );
86  if ( nEndCol != 0 )
87  {
88  nEndCol += maRange.aStart.Col() - 1;
89  if ( nEndCol > mpDoc->MaxCol() )
90  nEndCol = mpDoc->MaxCol();
91  }
92  else
93  nEndCol = maRange.aStart.Col();
94  if ( nEndRow != 0 )
95  {
96  nEndRow += maRange.aStart.Row() - 1;
97  if ( nEndRow > mpDoc->MaxRow() )
98  nEndRow = mpDoc->MaxRow();
99  }
100  else
101  nEndRow = maRange.aStart.Row();
102  maRange.aEnd.Set( nEndCol, nEndRow, maRange.aStart.Tab() );
103 
104  return nErr;
105 }
106 
107 namespace
108 {
109  bool IsValidSel(const ScTabEditEngine& rEngine, const ESelection& rSel)
110  {
111  const auto nParaCount = rEngine.GetParagraphCount();
112  return rSel.nStartPara < nParaCount && rSel.nEndPara < nParaCount;
113  }
114 }
115 
116 void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
117 {
118  std::unique_ptr<ScProgress> pProgress( new ScProgress( mpDoc->GetDocumentShell(),
119  ScResId( STR_LOAD_DOC ), mpParser->ListSize(), true ) );
120  sal_uLong nProgress = 0;
121 
122  SCCOL nStartCol, nEndCol;
123  SCROW nStartRow, nEndRow;
124  SCTAB nTab;
125  SCROW nOverlapRowMax, nLastMergedRow;
126  SCCOL nMergeColAdd;
127  nStartCol = maRange.aStart.Col();
128  nStartRow = maRange.aStart.Row();
129  nTab = maRange.aStart.Tab();
130  nEndCol = maRange.aEnd.Col();
131  nEndRow = maRange.aEnd.Row();
132  nOverlapRowMax = 0;
133  nMergeColAdd = 0;
134  nLastMergedRow = SCROW_MAX;
135  bool bHasGraphics = false;
137  if (!pFormatter)
138  pFormatter = mpDoc->GetFormatTable();
139  bool bNumbersEnglishUS = false;
140  if (pFormatter->GetLanguage() == LANGUAGE_SYSTEM && !utl::ConfigManager::IsFuzzing())
141  {
142  // Automatic language option selected. Check for the global 'use US English' option.
143  bNumbersEnglishUS = officecfg::Office::Common::Filter::HTML::Import::NumbersEnglishUS::get();
144  }
145  ScDocumentPool* pDocPool = mpDoc->GetPool();
146  ScRangeName* pRangeNames = mpDoc->GetRangeName();
147  for ( size_t i = 0, n = mpParser->ListSize(); i < n; ++i )
148  {
149  pE = mpParser->ListEntry( i );
150  SCROW nRow = nStartRow + pE->nRow;
151  if ( nRow != nLastMergedRow )
152  nMergeColAdd = 0;
153  SCCOL nCol = nStartCol + pE->nCol + nMergeColAdd;
154  // Determine RowMerge
155  // Pure ColMerge and ColMerge of the first MergeRow already done during parsing
156  if (nRow <= nOverlapRowMax && mpDoc->ValidCol(nCol))
157  {
158  while ( nCol <= mpDoc->MaxCol() && mpDoc->HasAttrib( nCol, nRow, nTab,
159  nCol, nRow, nTab, HasAttrFlags::Overlapped ) )
160  {
161  nCol++;
162  nMergeColAdd++;
163  }
164  nLastMergedRow = nRow;
165  }
166  // Add for second run
167  pE->nCol = nCol;
168  pE->nRow = nRow;
169  if ( mpDoc->ValidCol(nCol) && mpDoc->ValidRow(nRow) )
170  {
171  SfxItemSet aSet = mpEngine->GetAttribs( pE->aSel );
172  // Remove default: we set left/right ourselves depending on Text or
173  // Number
174  // EditView.GetAttribs always returns complete Set filled with
175  // defaults
176  const SfxPoolItem& rItem = aSet.Get( EE_PARA_JUST );
177  if ( static_cast<const SvxAdjustItem&>(rItem).GetAdjust() == SvxAdjust::Left )
178  aSet.ClearItem( EE_PARA_JUST );
179 
180  // Test whether simple String without mixed attributes
181  bool bSimple = ( pE->aSel.nStartPara == pE->aSel.nEndPara );
182  for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && bSimple; nId++)
183  {
184  const SfxPoolItem* pItem = nullptr;
185  SfxItemState eState = aSet.GetItemState( nId, true, &pItem );
186  if (eState == SfxItemState::DONTCARE)
187  bSimple = false;
188  else if (eState == SfxItemState::SET)
189  {
190  if ( nId == EE_CHAR_ESCAPEMENT ) // Super-/Subscript always via EE
191  {
192  if ( static_cast<SvxEscapement>(static_cast<const SvxEscapementItem*>(pItem)->GetEnumValue())
193  != SvxEscapement::Off )
194  bSimple = false;
195  }
196  }
197  }
198  if ( bSimple )
199  { // Contains field commands?
200  SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, false );
201  if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
202  bSimple = false;
203  }
204 
205  // HTML
206  OUString aValStr, aNumStr;
207  double fVal = 0.0;
208  sal_uInt32 nNumForm = 0;
209  LanguageType eNumLang = LANGUAGE_NONE;
210  if ( pE->pNumStr )
211  { // SDNUM needs to be if SDVAL
212  aNumStr = *pE->pNumStr;
213  if ( pE->pValStr )
214  aValStr = *pE->pValStr;
216  nNumForm, eNumLang, aValStr, aNumStr, *pFormatter );
217  }
218 
219  // Set attributes
220  auto pAttr = std::make_unique<ScPatternAttr>( pDocPool );
221  pAttr->GetFromEditItemSet( &aSet );
222  SfxItemSet* pAttrItemSet = &pAttr->GetItemSet();
223  if (!aNumStr.isEmpty())
224  {
225  pAttrItemSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm ) );
226  pAttrItemSet->Put( SvxLanguageItem( eNumLang, ATTR_LANGUAGE_FORMAT ) );
227  }
228  const SfxItemSet& rESet = pE->aItemSet;
229  if ( rESet.Count() )
230  {
231  const SfxPoolItem* pItem;
232  if ( rESet.GetItemState( ATTR_BACKGROUND, false, &pItem) == SfxItemState::SET )
233  pAttrItemSet->Put( *pItem );
234  if ( rESet.GetItemState( ATTR_BORDER, false, &pItem) == SfxItemState::SET )
235  pAttrItemSet->Put( *pItem );
236  if ( rESet.GetItemState( ATTR_SHADOW, false, &pItem) == SfxItemState::SET )
237  pAttrItemSet->Put( *pItem );
238  // HTML
239  if ( rESet.GetItemState( ATTR_HOR_JUSTIFY, false, &pItem) == SfxItemState::SET )
240  pAttrItemSet->Put( *pItem );
241  if ( rESet.GetItemState( ATTR_VER_JUSTIFY, false, &pItem) == SfxItemState::SET )
242  pAttrItemSet->Put( *pItem );
243  if ( rESet.GetItemState( ATTR_LINEBREAK, false, &pItem) == SfxItemState::SET )
244  pAttrItemSet->Put( *pItem );
245  if ( rESet.GetItemState( ATTR_FONT_COLOR, false, &pItem) == SfxItemState::SET )
246  pAttrItemSet->Put( *pItem );
247  if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, false, &pItem) == SfxItemState::SET )
248  pAttrItemSet->Put( *pItem );
249  // HTML LATIN/CJK/CTL script type dependent
250  const SfxPoolItem* pFont;
251  if ( rESet.GetItemState( ATTR_FONT, false, &pFont) != SfxItemState::SET )
252  pFont = nullptr;
253  const SfxPoolItem* pHeight;
254  if ( rESet.GetItemState( ATTR_FONT_HEIGHT, false, &pHeight) != SfxItemState::SET )
255  pHeight = nullptr;
256  const SfxPoolItem* pWeight;
257  if ( rESet.GetItemState( ATTR_FONT_WEIGHT, false, &pWeight) != SfxItemState::SET )
258  pWeight = nullptr;
259  const SfxPoolItem* pPosture;
260  if ( rESet.GetItemState( ATTR_FONT_POSTURE, false, &pPosture) != SfxItemState::SET )
261  pPosture = nullptr;
262  // Number format
263  const SfxPoolItem* pNumFmt = nullptr;
264  if ( rESet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET )
265  pAttrItemSet->Put(*pNumFmt);
266  if ( pFont || pHeight || pWeight || pPosture )
267  {
268  OUString aStr( mpEngine->GetText( pE->aSel ) );
269  SvtScriptType nScriptType = mpDoc->GetStringScriptType( aStr );
270  const SvtScriptType nScripts[3] = { SvtScriptType::LATIN,
271  SvtScriptType::ASIAN, SvtScriptType::COMPLEX };
272  for (SvtScriptType nScript : nScripts)
273  {
274  if ( nScriptType & nScript )
275  {
276  if ( pFont )
277  {
278  pAttrItemSet->Put( pFont->CloneSetWhich(
280  }
281  if ( pHeight )
282  {
283  pAttrItemSet->Put( pHeight->CloneSetWhich(
285  }
286  if ( pWeight )
287  {
288  pAttrItemSet->Put( pWeight->CloneSetWhich(
290  }
291  if ( pPosture )
292  {
293  pAttrItemSet->Put( pPosture->CloneSetWhich(
295  }
296  }
297  }
298  }
299  }
300  if ( pE->nColOverlap > 1 || pE->nRowOverlap > 1 )
301  { // Merged cells, with SfxItemSet.Put() is faster than
302  // with ScDocument.DoMerge() afterwards
303  ScMergeAttr aMerge( pE->nColOverlap, pE->nRowOverlap );
304  pAttrItemSet->Put( aMerge );
305  SCROW nRO = 0;
306  if ( pE->nColOverlap > 1 )
307  mpDoc->ApplyFlagsTab( nCol+1, nRow,
308  nCol + pE->nColOverlap - 1, nRow, nTab,
309  ScMF::Hor );
310  if ( pE->nRowOverlap > 1 )
311  {
312  nRO = nRow + pE->nRowOverlap - 1;
313  mpDoc->ApplyFlagsTab( nCol, nRow+1,
314  nCol, nRO , nTab,
315  ScMF::Ver );
316  if ( nRO > nOverlapRowMax )
317  nOverlapRowMax = nRO;
318  }
319  if ( pE->nColOverlap > 1 && pE->nRowOverlap > 1 )
320  mpDoc->ApplyFlagsTab( nCol+1, nRow+1,
321  nCol + pE->nColOverlap - 1, nRO, nTab,
322  ScMF::Hor | ScMF::Ver );
323  }
324  const ScStyleSheet* pStyleSheet =
325  mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet();
326  pAttr->SetStyleSheet( const_cast<ScStyleSheet*>(pStyleSheet) );
327  auto rAttrItemSet2 = mpDoc->SetPattern( nCol, nRow, nTab, std::move(pAttr) )->GetItemSet();
328 
329  // Add data
330  if (bSimple)
331  {
332  ScSetStringParam aParam;
333  aParam.mpNumFormatter = pFormatter;
334  aParam.mbDetectNumberFormat = true;
336  aParam.mbHandleApostrophe = false;
337  aParam.mbCheckLinkFormula = true;
338 
339  if (!aValStr.isEmpty())
340  mpDoc->SetValue( nCol, nRow, nTab, fVal );
341  else if ( !pE->aSel.HasRange() )
342  {
343  // maybe ALT text of IMG or similar
344  mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
345  // If SelRange is completely empty, the succeeding text can be in the same paragraph!
346  }
347  else
348  {
349  OUString aStr;
350  if( pE->bEntirePara )
351  {
352  aStr = mpEngine->GetText( pE->aSel.nStartPara );
353  }
354  else
355  {
356  aStr = comphelper::string::strip(mpEngine->GetText(pE->aSel), ' ');
357  }
358 
359  bool bTextFormat = false;
360 
361  const SfxPoolItem* pNumFmt = nullptr;
362  if (rAttrItemSet2.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SfxItemState::SET)
363  {
364  sal_uInt32 nNumFmt = static_cast<const SfxUInt32Item*>(pNumFmt)->GetValue();
365  SvNumFormatType nType = pFormatter->GetType(nNumFmt);
366  if (nType == SvNumFormatType::TEXT)
367  // Format is set to Text.
368  bTextFormat = true;
369  }
370 
371  // TODO: RTF import should follow the language tag,
372  // currently this follows the HTML options for both, HTML
373  // and RTF.
374  if (bNumbersEnglishUS)
375  {
376  pFormatter->ChangeIntl( LANGUAGE_ENGLISH_US);
377  sal_uInt32 nIndex = pFormatter->GetStandardIndex( LANGUAGE_ENGLISH_US);
378  double fEnVal = 0.0;
379  if (pFormatter->IsNumberFormat( aStr, nIndex, fEnVal))
380  {
381  sal_uInt32 nNewIndex =
382  pFormatter->GetFormatForLanguageIfBuiltIn(
383  nIndex, LANGUAGE_SYSTEM);
384  OSL_ENSURE( nNewIndex != nIndex, "ScEEImport::WriteToDocument: NumbersEnglishUS not a built-in format?");
385  pFormatter->GetInputLineString( fEnVal, nNewIndex, aStr);
386  }
387  else
388  bTextFormat = true;
389  pFormatter->ChangeIntl( LANGUAGE_SYSTEM);
390  }
391 
392  // #105460#, #i4180# String cells can't contain tabs or linebreaks
393  // -> replace with spaces
394  aStr = aStr.replaceAll( "\t", " " );
395  aStr = aStr.replaceAll( "\n", " " );
396 
397  if (bTextFormat)
398  {
399  aParam.mbDetectNumberFormat = false;
401  }
402  else
403  aParam.mbDetectNumberFormat = bConvertDate;
404 
405  mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam);
406  }
407  }
408  else if (std::unique_ptr<EditTextObject> pTextObject = IsValidSel(*mpEngine, pE->aSel) ? mpEngine->CreateTextObject(pE->aSel) : nullptr)
409  {
410  // The cell will own the text object instance.
411  mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), std::move(pTextObject));
412  }
413  if ( !pE->maImageList.empty() )
414  bHasGraphics |= GraphicSize( nCol, nRow, pE );
415  if ( pE->pName )
416  { // Anchor Name => RangeName
417  if (!pRangeNames->findByUpperName(ScGlobal::getCharClass().uppercase(*pE->pName)))
418  {
419  ScRangeData* pData = new ScRangeData( *mpDoc, *pE->pName,
420  ScAddress( nCol, nRow, nTab ) );
421  pRangeNames->insert( pData );
422  }
423  }
424  }
425  pProgress->SetStateOnPercent( ++nProgress );
426  }
427  if ( bSizeColsRows )
428  {
429  // Column widths
430  ColWidthsMap& rColWidths = mpParser->GetColWidths();
431  if ( !rColWidths.empty() )
432  {
433  nProgress = 0;
434  pProgress->SetState( nProgress, nEndCol - nStartCol + 1 );
435  for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ )
436  {
437  sal_uInt16 nWidth = 0;
438  ColWidthsMap::const_iterator it = rColWidths.find( nCol );
439  if ( it != rColWidths.end() )
440  nWidth = it->second;
441  if ( nWidth )
442  mpDoc->SetColWidth( nCol, nTab, nWidth );
443  pProgress->SetState( ++nProgress );
444  }
445  }
446  pProgress.reset(); // SetOptimalHeight has its own ProgressBar
447  // Adjust line height, base is 100% zoom
448  Fraction aZoom( 1, 1 );
449  // Factor is printer to display ratio
450  double nPPTX = ScGlobal::nScreenPPTX * static_cast<double>(aZoom) / nOutputFactor;
451  double nPPTY = ScGlobal::nScreenPPTY * static_cast<double>(aZoom);
453  sc::RowHeightContext aCxt(mpDoc->MaxRow(), nPPTX, nPPTY, aZoom, aZoom, pVirtDev);
455  mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0, true);
456 
457  if ( !maRowHeights.empty() )
458  {
459  for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ )
460  {
461  RowHeightMap::const_iterator it = maRowHeights.find( nRow );
462  sal_uInt16 nHeight = it == maRowHeights.end() ? 0 : it->second;
463  if ( nHeight > mpDoc->GetRowHeight( nRow, nTab ) )
464  mpDoc->SetRowHeight( nRow, nTab, nHeight );
465  }
466  }
467  }
468  if ( !bHasGraphics )
469  return;
470 
471  // Insert graphics
472  for ( size_t i = 0, nListSize = mpParser->ListSize(); i < nListSize; ++i )
473  {
474  pE = mpParser->ListEntry( i );
475  if ( !pE->maImageList.empty() )
476  {
477  SCCOL nCol = pE->nCol;
478  SCROW nRow = pE->nRow;
479  if ( mpDoc->ValidCol(nCol) && mpDoc->ValidRow(nRow) )
480  InsertGraphic( nCol, nRow, nTab, pE );
481  }
482  }
483 }
484 
486 {
487  if ( pE->maImageList.empty() )
488  return false;
489  bool bHasGraphics = false;
491  tools::Long nWidth, nHeight;
492  nWidth = nHeight = 0;
493  char nDir = nHorizontal;
494  for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList)
495  {
496  ScHTMLImage* pI = pImage.get();
497  if ( pI->pGraphic )
498  bHasGraphics = true;
499  Size aSizePix = pI->aSize;
500  aSizePix.AdjustWidth(2 * pI->aSpace.X() );
501  aSizePix.AdjustHeight(2 * pI->aSpace.Y() );
502  Size aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MapUnit::MapTwip ) );
503  if ( nDir & nHorizontal )
504  nWidth += aLogicSize.Width();
505  else if ( nWidth < aLogicSize.Width() )
506  nWidth = aLogicSize.Width();
507  if ( nDir & nVertical )
508  nHeight += aLogicSize.Height();
509  else if ( nHeight < aLogicSize.Height() )
510  nHeight = aLogicSize.Height();
511  nDir = pI->nDir;
512  }
513  // Column widths
514  ColWidthsMap& rColWidths = mpParser->GetColWidths();
515  tools::Long nThisWidth = 0;
516  ColWidthsMap::const_iterator it = rColWidths.find( nCol );
517  if ( it != rColWidths.end() )
518  nThisWidth = it->second;
519  tools::Long nColWidths = nThisWidth;
520  SCCOL nColSpanCol = nCol + pE->nColOverlap;
521  for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
522  {
523  ColWidthsMap::const_iterator it2 = rColWidths.find( nC );
524  if ( it2 != rColWidths.end() )
525  nColWidths += it2->second;
526  }
527  if ( nWidth > nColWidths )
528  { // Only insert difference in first column
529  rColWidths[ nCol ] = nWidth - nColWidths + nThisWidth;
530  }
531  // Distribute line height difference between all affected lines
532  SCROW nRowSpan = pE->nRowOverlap;
533  nHeight /= nRowSpan;
534  if ( nHeight == 0 )
535  nHeight = 1; // For definite comparison
536  for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
537  {
538  RowHeightMap::const_iterator it2 = maRowHeights.find( nR );
539  tools::Long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
540  if ( nHeight > nRowHeight )
541  {
542  maRowHeights[ nR ] = nHeight;
543  }
544  }
545  return bHasGraphics;
546 }
547 
549  ScEEParseEntry* pE )
550 {
551  if ( pE->maImageList.empty() )
552  return ;
553  ScDrawLayer* pModel = mpDoc->GetDrawLayer();
554  if (!pModel)
555  {
556  mpDoc->InitDrawLayer();
557  pModel = mpDoc->GetDrawLayer();
558  }
559  SdrPage* pPage = pModel->GetPage( static_cast<sal_uInt16>(nTab) );
561 
562  Point aCellInsertPos(
565 
566  Point aInsertPos( aCellInsertPos );
567  Point aSpace;
568  Size aLogicSize;
569  char nDir = nHorizontal;
570  for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList)
571  {
572  ScHTMLImage* pI = pImage.get();
573  if ( nDir & nHorizontal )
574  { // Horizontal
575  aInsertPos.AdjustX(aLogicSize.Width() );
576  aInsertPos.AdjustX(aSpace.X() );
577  aInsertPos.setY( aCellInsertPos.Y() );
578  }
579  else
580  { // Vertical
581  aInsertPos.setX( aCellInsertPos.X() );
582  aInsertPos.AdjustY(aLogicSize.Height() );
583  aInsertPos.AdjustY(aSpace.Y() );
584  }
585  // Add offset of Spacing
586  aSpace = pDefaultDev->PixelToLogic( pI->aSpace, MapMode( MapUnit::Map100thMM ) );
587  aInsertPos += aSpace;
588 
589  Size aSizePix = pI->aSize;
590  aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MapUnit::Map100thMM ) );
591 
592  // Limit size
593  ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() );
594 
595  if ( pI->pGraphic )
596  {
597  tools::Rectangle aRect ( aInsertPos, aLogicSize );
598  SdrGrafObj* pObj = new SdrGrafObj(
599  *pModel,
600  *pI->pGraphic,
601  aRect);
602 
603  // calling SetGraphicLink here doesn't work
604  pObj->SetName( pI->aURL );
605 
606  pPage->InsertObject( pObj );
607 
608  // SetGraphicLink has to be used after inserting the object,
609  // otherwise an empty graphic is swapped in and the contact stuff crashes.
610  // See #i37444#.
611  pObj->SetGraphicLink( pI->aURL );
612 
613  pObj->SetLogicRect( aRect ); // Only after InsertObject!
614  }
615  nDir = pI->nDir;
616  }
617 }
618 
620  pEdit( pEditP ),
621  pPool( EditEngine::CreatePool() ),
622  pDocPool( new ScDocumentPool ),
623  nRtfLastToken(0),
624  nColCnt(0),
625  nRowCnt(0),
626  nColMax(0),
627  nRowMax(0)
628 {
629  // pPool is foisted on SvxRTFParser at RtfImportState::Start later on
630  pPool->SetSecondaryPool( pDocPool.get() );
631  pPool->FreezeIdRanges();
632  NewActEntry( nullptr );
633 }
634 
636 {
637  mxActEntry.reset();
638  maList.clear();
639 
640  // Don't delete Pool until the lists have been deleted
641  pPool->SetSecondaryPool( nullptr );
642  pDocPool.clear();
643  pPool.clear();
644 }
645 
647 { // New free-flying mxActEntry
648  mxActEntry = std::make_shared<ScEEParseEntry>(pPool.get());
649  mxActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0);
650  mxActEntry->aSel.nStartPos = 0;
651 }
652 
653 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setExtraHeight(sal_uInt16 nH)
bool GraphicSize(SCCOL nCol, SCROW nRow, ScEEParseEntry *)
Definition: eeimpars.cxx:485
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
std::vector< std::unique_ptr< ScHTMLImage > > maImageList
Definition: eeparser.hxx:63
constexpr double nPPTY
#define LANGUAGE_NONE
sal_Int32 nStartPara
sal_Int32 nIndex
ScDocument * mpDoc
Definition: eeimport.hxx:39
const char nHorizontal
Definition: eeparser.hxx:34
ScAddress aStart
Definition: address.hxx:499
Store parameters used in the ScDocument::SetString() method.
Definition: stringutil.hxx:34
constexpr TypedWhichId< SvxLanguageItem > ATTR_LANGUAGE_FORMAT(147)
bool mbHandleApostrophe
When true, treat input with a leading apostrophe as an escape character for a numeric value content...
Definition: stringutil.hxx:91
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
FormulaCommand pE
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
SfxItemSet aItemSet
Definition: eeparser.hxx:54
SCROW Row() const
Definition: address.hxx:261
#define LANGUAGE_ENGLISH_US
SvNumberFormatter * mpNumFormatter
Stores the pointer to the number formatter instance to be used during number format detection...
Definition: stringutil.hxx:70
std::unique_ptr< ContentProperties > pData
std::string GetValue
void SetName(const OUString &rStr, const bool bSetChanged=true)
void NewActEntry(const ScEEParseEntry *)
Definition: eeimpars.cxx:646
bool mbCheckLinkFormula
When true and the string results in a compiled formula, check the formula tokens for presence of func...
Definition: stringutil.hxx:100
OString strip(std::string_view rIn, char c)
ESelection aSel
Definition: eeparser.hxx:55
sal_uIntPtr sal_uLong
long Long
std::map< SCCOL, sal_uInt16 > ColWidthsMap
Definition: eeparser.hxx:95
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
SC_DLLPUBLIC bool ApplyFlagsTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, ScMF nFlags)
Definition: document.cxx:5038
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
sal_Int64 n
LanguageType GetLanguage() const
SvNumFormatType GetType(sal_uInt32 nFIndex) const
sal_Int16 nId
ScAddress aEnd
Definition: address.hxx:500
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
SC_DLLPUBLIC void SetValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rVal)
Definition: document.cxx:3489
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
std::unique_ptr< ScTabEditEngine > mpEngine
Definition: eeimport.hxx:41
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
const SCROW SCROW_MAX
Definition: address.hxx:55
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5205
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4192
TextFormatPolicy meSetTextNumFormat
Determine when to set the 'Text' number format to the cell where the input string is being set...
Definition: stringutil.hxx:83
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
static OutputDevice * GetDefaultDevice()
constexpr tools::Long Width() const
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
constexpr TypedWhichId< SvxShadowItem > ATTR_SHADOW(152)
SC_DLLPUBLIC void SetColWidth(SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth)
Definition: document.cxx:4114
sal_uInt32 GetStandardIndex(LanguageType eLnge=LANGUAGE_DONTKNOW)
bool bEntirePara
Definition: eeparser.hxx:73
static bool IsFuzzing()
static SC_DLLPUBLIC sal_uInt16 GetScriptedWhichID(SvtScriptType nScriptType, sal_uInt16 nWhich)
Map ATTR_((CJK|CTL)_)?FONT_...
Definition: global.cxx:867
ScEEImport(ScDocument *pDoc, const ScRange &rRange)
Definition: eeimpars.cxx:62
SCTAB Tab() const
Definition: address.hxx:270
SCROW nRowOverlap
Definition: eeparser.hxx:69
ScEEParser(EditEngine *)
Definition: eeimpars.cxx:619
std::unique_ptr< Graphic > pGraphic
Definition: eeparser.hxx:44
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4766
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
constexpr double nPPTX
std::optional< OUString > pValStr
Definition: eeparser.hxx:57
SC_DLLPUBLIC bool SetEditText(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
This method manages the lifecycle of the passed edit text object.
Definition: document.cxx:3425
bool ValidCol(SCCOL nCol, SCCOL nMaxCol)
Definition: address.hxx:92
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3394
virtual ~ScEEParser()
Definition: eeimpars.cxx:635
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:681
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:441
SC_DLLPUBLIC void SetPattern(const ScAddress &, const ScPatternAttr &rAttr)
Definition: document.cxx:5075
sal_Int32 nEndPara
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
Definition: documen9.cxx:98
SvtScriptType
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const char nVertical
Definition: eeparser.hxx:35
int i
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: address.hxx:405
#define LANGUAGE_SYSTEM
std::vector< std::shared_ptr< ScEEParseEntry > > maList
Definition: eeparser.hxx:105
sal_Int16 SCCOL
Definition: types.hxx:21
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:874
constexpr TypedWhichId< SvxVerJustifyItem > ATTR_VER_JUSTIFY(132)
static SC_DLLPUBLIC double nScreenPPTY
Vertical pixel per twips factor.
Definition: global.hxx:584
Set Text number format only when the input string is considered a special number but we only want to ...
Definition: stringutil.hxx:51
Size GetSize() const
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1016
void ScLimitSizeOnDrawPage(Size &rSize, Point &rPos, const Size &rPage)
Definition: fuins1.cxx:58
Point aSpace
Definition: eeparser.hxx:41
sal_uInt16 Count() const
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
const SdrPage * GetPage(sal_uInt16 nPgNum) const
std::unique_ptr< ScEEParser > mpParser
Definition: eeimport.hxx:43
RowHeightMap maRowHeights
Definition: eeimport.hxx:44
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
constexpr sal_uInt16 EE_CHAR_START(EE_PARA_END+1)
static double GetTableDataOptionsValNum(sal_uInt32 &nNumForm, LanguageType &eNumLang, const OUString &aValStr, const OUString &aNumStr, SvNumberFormatter &rFormatter)
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
void GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false)
SC_DLLPUBLIC void SetRowHeight(SCROW nRow, SCTAB nTab, sal_uInt16 nNewHeight)
Definition: document.cxx:4126
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
SvNumFormatType
virtual void SetLogicRect(const tools::Rectangle &rRect)
rtl::Reference< SfxItemPool > pPool
Definition: eeparser.hxx:103
constexpr sal_uInt16 EE_CHAR_END(EE_CHAR_START+32)
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
std::optional< OUString > pNumStr
Definition: eeparser.hxx:59
void SetGraphicLink(const OUString &rFileName)
SCCOL Col() const
Definition: address.hxx:266
sal_Int32 GetParagraphCount() const
SCCOL nColOverlap
Definition: eeparser.hxx:68
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
std::shared_ptr< ScEEParseEntry > mxActEntry
Definition: eeparser.hxx:106
SC_DLLPUBLIC bool SetOptimalHeight(sc::RowHeightContext &rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi)
Definition: document.cxx:4297
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
void InsertGraphic(SCCOL nCol, SCROW nRow, SCTAB nTab, ScEEParseEntry *)
Definition: eeimpars.cxx:548
bool ValidRow(SCROW nRow) const
Definition: document.hxx:875
bool HasRange() const
bool mbDetectNumberFormat
When true, we try to detect special number format (dates etc) from the input string, when false, we only try to detect a basic decimal number format.
Definition: stringutil.hxx:77
SfxItemState
void ChangeIntl(LanguageType eLnge)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr tools::Long Height() const
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
tools::Long AdjustWidth(tools::Long n)
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
static SC_DLLPUBLIC double nScreenPPTX
Horizontal pixel per twips factor.
Definition: global.hxx:582
virtual void WriteToDocument(bool bSizeColsRows=false, double nOutputFactor=1.0, SvNumberFormatter *pFormatter=nullptr, bool bConvertDate=true) override
Definition: eeimpars.cxx:116
Set Text number format if the input string can be parsed as a number or formula text.
Definition: stringutil.hxx:45
tools::Long AdjustHeight(tools::Long n)
ScRange maRange
Definition: eeimport.hxx:38
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:447
OUString aURL
Definition: eeparser.hxx:39
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
Size aSize
Definition: eeparser.hxx:40
virtual ~ScEEImport() override
Definition: eeimpars.cxx:73
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
static SC_DLLPUBLIC::tools::Long nLastRowHeightExtra
Definition: global.hxx:591
std::optional< OUString > pName
Definition: eeparser.hxx:61
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
OUString aAltText
Definition: eeparser.hxx:62
aStr
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:814
virtual ErrCode Read(SvStream &rStream, const OUString &rBaseURL) override
Definition: eeimpars.cxx:79
SC_DLLPUBLIC sal_uLong GetColOffset(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4255
B2DRange maRange
sal_Int16 SCTAB
Definition: types.hxx:22
rtl::Reference< SfxItemPool > pDocPool
Definition: eeparser.hxx:104
SC_DLLPUBLIC sal_uLong GetRowOffset(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4263