LibreOffice Module sc (master)  1
op.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 <rtl/math.hxx>
21 #include <rtl/character.hxx>
22 
23 #include <string.h>
24 
25 #include <scitems.hxx>
26 #include <patattr.hxx>
27 #include <docpool.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/udlnitem.hxx>
30 #include <editeng/wghtitem.hxx>
31 #include <editeng/justifyitem.hxx>
32 #include <unotools/configmgr.hxx>
33 
34 #include <formulacell.hxx>
35 #include <document.hxx>
36 #include <postit.hxx>
37 
38 #include <op.h>
39 #include <optab.h>
40 #include <tool.h>
41 #include "lotfilter.hxx"
42 #include <lotform.hxx>
43 #include <lotrange.hxx>
44 #include <ftools.hxx>
45 
46 #include <vector>
47 #include <map>
48 #include <memory>
49 
50 static sal_uInt16 nDefWidth = sal_uInt16( TWIPS_PER_CHAR * 10 );
51 
52 void NI(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
53 {
54  r.SeekRel( n );
55 }
56 
57 void OP_BOF(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 /*n*/)
58 {
59  r.SeekRel( 2 ); // skip version number
60 }
61 
62 void OP_EOF(LotusContext& rContext, SvStream& /*r*/, sal_uInt16 /*n*/)
63 {
64  rContext.bEOF = true;
65 }
66 
67 void OP_Integer(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
68 {
69  sal_uInt8 nFormat(0);
70  sal_uInt16 nTmpCol(0), nTmpRow(0);
71  sal_Int16 nValue(0);
72  r.ReadUChar(nFormat).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow).ReadInt16(nValue);
73  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
74  SCROW nRow(static_cast<SCROW>(nTmpRow));
75 
76  ScAddress aAddr(nCol, nRow, 0);
77  if (rContext.rDoc.ValidAddress(aAddr))
78  {
79  rContext.rDoc.EnsureTable(0);
80  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
81  rContext.rDoc.SetValue(aAddr, static_cast<double>(nValue));
82 
83  // 0 digits in fractional part!
84  SetFormat(rContext, nCol, nRow, 0, nFormat, 0);
85  }
86 }
87 
88 void OP_Number(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
89 {
90  sal_uInt8 nFormat(0);
91  sal_uInt16 nTmpCol(0), nTmpRow(0);
92  double fValue(0.0);
93  r.ReadUChar( nFormat ).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow).ReadDouble(fValue);
94  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
95  SCROW nRow(static_cast<SCROW>(nTmpRow));
96 
97  ScAddress aAddr(nCol, nRow, 0);
98  if (rContext.rDoc.ValidAddress(aAddr))
99  {
100  fValue = ::rtl::math::round( fValue, 15 );
101  rContext.rDoc.EnsureTable(0);
102  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
103  rContext.rDoc.SetValue(aAddr, fValue);
104 
105  SetFormat(rContext, nCol, nRow, 0, nFormat, nFractionalFloat);
106  }
107 }
108 
109 void OP_Label(LotusContext& rContext, SvStream& r, sal_uInt16 n)
110 {
111  sal_uInt8 nFormat(0);
112  sal_uInt16 nTmpCol(0), nTmpRow(0);
113  r.ReadUChar(nFormat).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow);
114  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
115  SCROW nRow(static_cast<SCROW>(nTmpRow));
116 
117  n -= std::min<sal_uInt16>(n, 5);
118 
119  std::vector<char> aText(n + 1);
120  n = r.ReadBytes(aText.data(), n);
121  aText[n] = 0;
122 
123  if (rContext.rDoc.ValidColRow(nCol, nRow))
124  {
125  nFormat &= 0x80; // don't change Bit 7
126  nFormat |= 0x75; // protected does not matter, special-text is set
127 
128  PutFormString(rContext, nCol, nRow, 0, aText.data());
129 
130  SetFormat(rContext, nCol, nRow, 0, nFormat, nFractionalStd);
131  }
132 }
133 
134 void OP_Formula(LotusContext &rContext, SvStream& r, sal_uInt16 /*n*/)
135 {
136  sal_uInt8 nFormat(0);
137  sal_uInt16 nTmpCol(0), nTmpRow(0);
138  r.ReadUChar(nFormat).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow);
139  r.SeekRel(8); // skip result
140  sal_uInt16 nFormulaSize(0);
141  r.ReadUInt16(nFormulaSize);
142 
143  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
144  SCROW nRow(static_cast<SCROW>(nTmpRow));
145 
146  std::unique_ptr<ScTokenArray> pResult;
147  sal_Int32 nBytesLeft = nFormulaSize;
148  ScAddress aAddress(nCol, nRow, 0);
149 
150  svl::SharedStringPool& rSPool = rContext.rDoc.GetSharedStringPool();
151  LotusToSc aConv(rContext, r, rSPool, rContext.eCharset, false);
152  aConv.Reset( aAddress );
153  aConv.Convert( pResult, nBytesLeft );
154  if (!aConv.good())
155  return;
156 
157  if (rContext.rDoc.ValidColRow(nCol, nRow))
158  {
159  ScFormulaCell* pCell = new ScFormulaCell(rContext.rDoc, aAddress, std::move(pResult));
160  pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
161  rContext.rDoc.EnsureTable(0);
162  rContext.rDoc.SetFormulaCell(ScAddress(nCol, nRow, 0), pCell);
163 
164  // nFormat = Default -> number of digits in fractional part like Float
165  SetFormat(rContext, nCol, nRow, 0, nFormat, nFractionalFloat);
166  }
167 }
168 
169 void OP_ColumnWidth(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
170 {
171  sal_uInt16 nTmpCol(0);
172  sal_uInt8 nWidthSpaces(0);
173  r.ReadUInt16(nTmpCol).ReadUChar(nWidthSpaces);
174  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
175 
176  if (!rContext.rDoc.ValidCol(nCol))
177  return;
178 
179  nCol = rContext.rDoc.SanitizeCol(nCol);
180 
181  sal_uInt16 nBreite;
182  if( nWidthSpaces )
183  // assuming 10cpi character set
184  nBreite = static_cast<sal_uInt16>( TWIPS_PER_CHAR * nWidthSpaces );
185  else
186  {
187  rContext.rDoc.SetColHidden(nCol, nCol, 0, true);
188  nBreite = nDefWidth;
189  }
190 
191  rContext.rDoc.SetColWidth(nCol, 0, nBreite);
192 }
193 
194 void OP_NamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
195 {
196  // POST: don't save for invalid coordinates
197  sal_uInt16 nColSt, nRowSt, nColEnd, nRowEnd;
198 
199  char cBuffer[ 16+1 ];
200  r.ReadBytes(cBuffer, 16);
201  cBuffer[ 16 ] = 0;
202 
203  r.ReadUInt16( nColSt ).ReadUInt16( nRowSt ).ReadUInt16( nColEnd ).ReadUInt16( nRowEnd );
204 
205  if (!r.good())
206  return;
207 
208  if (!rContext.rDoc.ValidColRow(static_cast<SCCOL>(nColSt), nRowSt) || !rContext.rDoc.ValidColRow(static_cast<SCCOL>(nColEnd), nRowEnd))
209  return;
210 
211  std::unique_ptr<LotusRange> pRange;
212 
213  if( nColSt == nColEnd && nRowSt == nRowEnd )
214  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
215  else
216  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
217  static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
218 
219  char cBuf[sizeof(cBuffer)+1];
220  if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
221  { // first char in name is a number -> prepend 'A'
222  cBuf[0] = 'A';
223  strcpy( cBuf + 1, cBuffer ); // #100211# - checked
224  }
225  else
226  strcpy( cBuf, cBuffer ); // #100211# - checked
227 
228  OUString aTmp( cBuf, strlen(cBuf), rContext.eCharset );
229 
230  aTmp = ScfTools::ConvertToScDefinedName( aTmp );
231 
232  rContext.maRangeNames.Append( &rContext.rDoc, std::move(pRange) );
233 }
234 
235 void OP_SymphNamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
236 {
237  // POST:don't save for invalid coordinates
238  sal_uInt16 nColSt, nRowSt, nColEnd, nRowEnd;
240 
241  char cBuffer[ 16+1 ];
242  r.ReadBytes(cBuffer, 16);
243  cBuffer[ 16 ] = 0;
244 
245  r.ReadUInt16( nColSt ).ReadUInt16( nRowSt ).ReadUInt16( nColEnd ).ReadUInt16( nRowEnd ).ReadUChar( nType );
246 
247  if (!r.good())
248  return;
249 
250  if (!rContext.rDoc.ValidColRow(static_cast<SCCOL>(nColSt), nRowSt) || !rContext.rDoc.ValidColRow(static_cast<SCCOL>(nColEnd), nRowEnd))
251  return;
252 
253  std::unique_ptr<LotusRange> pRange;
254 
255  if( nType )
256  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
257  else
258  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
259  static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
260 
261  char cBuf[sizeof(cBuffer)+1];
262  if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
263  { // first char in name is a number -> prepend 'A'
264  cBuf[0] = 'A';
265  strcpy( cBuf + 1, cBuffer ); // #100211# - checked
266  }
267  else
268  strcpy( cBuf, cBuffer ); // #100211# - checked
269 
270  OUString aTmp( cBuf, strlen(cBuf), rContext.eCharset );
271  aTmp = ScfTools::ConvertToScDefinedName( aTmp );
272 
273  rContext.maRangeNames.Append( &rContext.rDoc, std::move(pRange) );
274 }
275 
276 void OP_Footer(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
277 {
278  r.SeekRel( n );
279 }
280 
281 void OP_Header(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
282 {
283  r.SeekRel( n );
284 }
285 
286 void OP_Margins(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
287 {
288  r.SeekRel( n );
289 }
290 
291 void OP_HiddenCols(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
292 {
293  SCCOL nCount = 0;
294  for (sal_uInt16 nByte = 0; nByte < 32; ++nByte) // 32 Bytes with ...
295  {
296  sal_uInt8 nCurrent(0);
297  r.ReadUChar(nCurrent);
298  for (sal_uInt16 nBit = 0; nBit < 8; ++nBit) // ...each 8 Bits = 256 Bits
299  {
300  if( nCurrent & 0x01 ) // is lowest Bit set?
301  {
302  // -> Hidden Col
303  rContext.rDoc.SetColHidden(nCount, nCount, 0, true);
304  }
305 
306  nCount++;
307  nCurrent = nCurrent / 2; // the next please...
308  }
309  }
310 }
311 
312 void OP_Window1(LotusContext& rContext, SvStream& r, sal_uInt16 n)
313 {
314  r.SeekRel( 4 ); // skip Cursor Pos
315 
316  sal_uInt8 nDefaultFormat; // -> op.cpp, standard cell format
317  r.ReadUChar(nDefaultFormat);
318 
319  r.SeekRel( 1 ); // skip 'unused'
320 
321  r.ReadUInt16( nDefWidth );
322  if (!r.good())
323  return;
324 
325  r.SeekRel( n - 8 ); // skip the rest
326 
327  nDefWidth = static_cast<sal_uInt16>( TWIPS_PER_CHAR * nDefWidth );
328 
329  const bool bFuzzing = utl::ConfigManager::IsFuzzing();
330 
331  // instead of default, set all Cols in SC by hand
332  for (SCCOL nCol = 0 ; nCol <= rContext.rDoc.MaxCol() ; nCol++)
333  {
334  rContext.rDoc.SetColWidth( nCol, 0, nDefWidth );
335  if (bFuzzing)
336  break;
337  }
338 }
339 
340 void OP_Blank(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
341 {
342  sal_uInt8 nFormat(0);
343  sal_uInt16 nTmpCol(0), nTmpRow(0);
344  r.ReadUChar( nFormat ).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow);
345  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
346  SCROW nRow(static_cast<SCROW>(nTmpRow));
347 
348  SetFormat(rContext, nCol, nRow, 0, nFormat, nFractionalFloat);
349 }
350 
351 void OP_BOF123(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 /*n*/)
352 {
353  r.SeekRel( 26 );
354 }
355 
356 void OP_EOF123(LotusContext& rContext, SvStream& /*r*/, sal_uInt16 /*n*/)
357 {
358  rContext.bEOF = true;
359 }
360 
361 void OP_Label123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
362 {
363  sal_uInt8 nTmpTab(0), nTmpCol(0);
364  sal_uInt16 nTmpRow(0);
365  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
366  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
367  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
368  SCROW nRow(static_cast<SCROW>(nTmpRow));
369 
370  n -= std::min<sal_uInt16>(n, 4);
371 
372  std::unique_ptr<char[]> pText(new char[n + 1]);
373  r.ReadBytes(pText.get(), n);
374  pText[ n ] = 0;
375 
376  PutFormString(rContext, nCol, nRow, nTab, pText.get());
377 }
378 
379 void OP_Number123(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
380 {
381  sal_uInt16 nTmpRow(0);
382  sal_uInt8 nTmpCol(0), nTmpTab(0);
383  sal_uInt32 nValue(0);
384  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol).ReadUInt32(nValue);
385  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
386  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
387  SCROW nRow(static_cast<SCROW>(nTmpRow));
388 
389  ScAddress aAddr(nCol, nRow, nTab);
390  if (rContext.rDoc.ValidAddress(aAddr) && nTab <= rContext.rDoc.GetMaxTableNumber())
391  {
392  double fValue = Snum32ToDouble( nValue );
393  rContext.rDoc.EnsureTable(nTab);
394  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
395  rContext.rDoc.SetValue(aAddr, fValue);
396  }
397 }
398 
399 void OP_Formula123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
400 {
401  sal_uInt16 nTmpRow(0);
402  sal_uInt8 nTmpCol(0), nTmpTab(0);
403  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
404  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
405  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
406  SCROW nRow(static_cast<SCROW>(nTmpRow));
407  r.SeekRel( 8 ); // skip Result
408 
409  std::unique_ptr<ScTokenArray> pResult;
410  sal_Int32 nBytesLeft = (n > 12) ? n - 12 : 0;
411  ScAddress aAddress(nCol, nRow, nTab);
412 
413  svl::SharedStringPool& rSPool = rContext.rDoc.GetSharedStringPool();
414  LotusToSc aConv(rContext, r, rSPool, rContext.eCharset, true);
415  aConv.Reset( aAddress );
416  aConv.Convert( pResult, nBytesLeft );
417  if (!aConv.good())
418  return;
419 
420  if (rContext.rDoc.ValidAddress(aAddress) && nTab <= rContext.rDoc.GetMaxTableNumber())
421  {
422  ScFormulaCell* pCell = new ScFormulaCell(rContext.rDoc, aAddress, std::move(pResult));
423  pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
424  rContext.rDoc.EnsureTable(nTab);
425  rContext.rDoc.SetFormulaCell(aAddress, pCell);
426  }
427 }
428 
429 void OP_IEEENumber123(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
430 {
431  sal_uInt16 nTmpRow(0);
432  sal_uInt8 nTmpCol(0), nTmpTab(0);
433  double dValue(0.0);
434  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol).ReadDouble(dValue);
435  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
436  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
437  SCROW nRow(static_cast<SCROW>(nTmpRow));
438 
439  ScAddress aAddr(nCol, nRow, nTab);
440  if (rContext.rDoc.ValidAddress(aAddr) && nTab <= rContext.rDoc.GetMaxTableNumber())
441  {
442  rContext.rDoc.EnsureTable(nTab);
443  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
444  rContext.rDoc.SetValue(aAddr, dValue);
445  }
446 }
447 
448 void OP_Note123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
449 {
450  sal_uInt16 nTmpRow(0);
451  sal_uInt8 nTmpTab(0), nTmpCol(0);
452  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
453  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
454  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
455  SCROW nRow(static_cast<SCROW>(nTmpRow));
456 
457  n -= std::min<sal_uInt16>(n, 4);
458 
459  std::unique_ptr<char[]> pText(new char[n + 1]);
460  r.ReadBytes(pText.get(), n);
461  pText[ n ] = 0;
462 
463  OUString aNoteText(pText.get(), strlen(pText.get()), rContext.eCharset);
464  pText.reset();
465 
466  ScAddress aPos(nCol, nRow, nTab);
467  ScNoteUtil::CreateNoteFromString( rContext.rDoc, aPos, aNoteText, false, false );
468 }
469 
470 void OP_HorAlign123(LotusContext& /*rContext*/, sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet)
471 {
472 // pre: Pattern is stored in the last 3 bites of the 21st byte
473 // post: Appropriate Horizontal Alignment is set in rPattern according to the bit pattern.
474 //
475 // LEFT:001, RIGHT:010, CENTER:011, JUSTIFY:110,
476 // LEFT-Text/RIGHT-NUMBER:100, DEFAULT:000
477 
478  nAlignPattern = ( nAlignPattern & 0x07);
479 
480  switch (nAlignPattern)
481  {
482  case 1:
483  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Left, ATTR_HOR_JUSTIFY ) );
484  break;
485  case 2:
486  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Right, ATTR_HOR_JUSTIFY ) );
487  break;
488  case 3:
489  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Center, ATTR_HOR_JUSTIFY) );
490  break;
491  case 4:
492  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY ) );
493  break;
494  case 6:
495  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Block, ATTR_HOR_JUSTIFY ) );
496  break;
497  default:
498  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY ) );
499  break;
500  }
501 }
502 
503 void OP_VerAlign123(LotusContext& /*rContext*/, sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet)
504 {
505 // pre: Pattern is stored in the last 3 bites of the 22nd byte
506 // post: Appropriate Vertical Alignment is set in rPattern according to the bit pattern.
507 //
508 // TOP:001, MIDDLE:010, DOWN:100, DEFAULT:000
509 
510  nAlignPattern = ( nAlignPattern & 0x07);
511 
512  switch (nAlignPattern)
513  {
514  case 0:
515  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY) );
516  break;
517  case 1:
518  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Top, ATTR_VER_JUSTIFY) );
519  break;
520  case 2:
521  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Center, ATTR_VER_JUSTIFY) );
522  break;
523  case 4:
524  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Bottom, ATTR_VER_JUSTIFY) );
525  break;
526  default:
527  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY) );
528  break;
529  }
530 }
531 
532 void OP_CreatePattern123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
533 {
534  sal_uInt16 nCode;
535 
536  ScPatternAttr aPattern(rContext.rDoc.GetPool());
537  SfxItemSet& rItemSet = aPattern.GetItemSet();
538 
539  r.ReadUInt16( nCode );
540  n -= std::min<sal_uInt16>(n, 2);
541 
542  if ( nCode == 0x0fd2 )
543  {
544  sal_uInt16 nPatternId;
545  r.ReadUInt16( nPatternId );
546 
547  sal_uInt8 Hor_Align, Ver_Align, temp;
548  bool bIsBold,bIsUnderLine,bIsItalics;
549 
550  r.SeekRel(12);
551 
552  // Read 17th Byte
553  r.ReadUChar( temp );
554 
555  bIsBold = (temp & 0x01);
556  bIsItalics = (temp & 0x02);
557  bIsUnderLine = (temp & 0x04);
558 
559  if ( bIsBold )
560  rItemSet.Put( SvxWeightItem(WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
561  if ( bIsItalics )
563  if ( bIsUnderLine )
565 
566  r.SeekRel(3);
567 
568  // Read 21st Byte
569  r.ReadUChar( Hor_Align );
570  OP_HorAlign123(rContext, Hor_Align, rItemSet );
571 
572  r.ReadUChar( Ver_Align );
573  OP_VerAlign123(rContext, Ver_Align, rItemSet );
574 
575  rContext.aLotusPatternPool.emplace( nPatternId, aPattern );
576  n -= std::min<sal_uInt16>(n, 20);
577  }
578  r.SeekRel(n);
579 }
580 
581 void OP_SheetName123(LotusContext& rContext, SvStream& rStream, sal_uInt16 nLength)
582 {
583  if (nLength <= 4)
584  {
585  rStream.SeekRel(nLength);
586  return;
587  }
588 
589  // B0 36 [sheet number (2 bytes?)] [sheet name (null terminated char array)]
590  rStream.SeekRel(2); // ignore the first 2 bytes (B0 36).
591  sal_uInt16 nSheetNum(0);
592  rStream.ReadUInt16(nSheetNum);
593 
594  ::std::vector<char> sSheetName;
595  sSheetName.reserve(nLength-4);
596  for (sal_uInt16 i = 4; i < nLength; ++i)
597  {
598  char c;
599  rStream.ReadChar( c );
600  sSheetName.push_back(c);
601  }
602 
603  if (!ValidTab(nSheetNum))
604  return;
605  // coverity[tainted_data : FALSE] - ValidTab has sanitized nSheetNum
606  rContext.rDoc.MakeTable(nSheetNum);
607  if (!sSheetName.empty())
608  {
609  OUString aName(sSheetName.data(), strlen(sSheetName.data()), rContext.eCharset);
610  rContext.rDoc.RenameTab(nSheetNum, aName);
611  }
612 }
613 
615 {
616  sal_uInt16 nOpcode, nLength;
617  sal_uInt16 nCol = 0, nColCount = 0, nRow = 0, nRowCount = 0, nTab = 0, nData, nTabCount = 0, nLevel = 0;
618 
619  do
620  {
621  rStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
622  switch ( nOpcode )
623  {
624  case ROW_FORMAT_MARKER:
625  nLevel++;
626  break;
627  case COL_FORMAT_MARKER:
628  nLevel--;
629  if( nLevel == 1 )
630  {
631  nTab = nTab + nTabCount;
632  nCol = 0; nColCount = 0;
633  nRow = 0; nRowCount = 0;
634  }
635  break;
636  case LOTUS_FORMAT_INDEX:
637  if( nLength >= 2 )
638  {
639  rStream.ReadUInt16( nData );
640  rStream.SeekRel( nLength - 2 );
641  if( nLevel == 1 )
642  nTabCount = SanitizeTab(nData);
643  else if( nLevel == 2 )
644  {
645  nCol = nCol + nColCount;
646  nColCount = nData;
647  if ( nCol > 0xff ) // 256 is the max col size supported by 123
648  nCol = 0;
649  }
650  else if( nLevel == 3 )
651  {
652  nRow = nRow + nRowCount;
653  nRowCount = nData;
654  if ( nRow > 0x1fff ) // 8192 is the max row size supported by 123
655  nRow = 0;
656  }
657  }
658  else
659  rStream.SeekRel( nLength );
660  break;
661  case LOTUS_FORMAT_INFO:
662  if( nLength >= 2 )
663  {
664  rStream.ReadUInt16( nData );
665  rStream.SeekRel( nLength - 2 );
666  std::map<sal_uInt16, ScPatternAttr>::iterator loc = rContext.aLotusPatternPool.find( nData );
667  // #126338# apparently, files with invalid index occur in the wild -> don't crash then
668  if ( loc != rContext.aLotusPatternPool.end() )
669  for( int i = 0; i < nTabCount; i++)
670  {
671  rContext.rDoc.ApplyPatternAreaTab( nCol, nRow, nCol + nColCount - 1, nRow + nRowCount - 1, static_cast< SCTAB >( nTab + i ), loc->second );
672  }
673  }
674  else
675  rStream.SeekRel( nLength );
676  break;
677  default:
678  rStream.SeekRel( nLength );
679  break;
680  }
681  }
682  while( nLevel && rStream.good() );
683 
684  rContext.aLotusPatternPool.clear();
685 }
686 
687 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl_TextEncoding eCharset
Definition: lotfilter.hxx:43
void OP_SymphNamedRange(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:235
SvStream & ReadInt16(sal_Int16 &rInt16)
SCCOL SanitizeCol(SCCOL nCol) const
Definition: document.hxx:880
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:566
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
void OP_Note123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:448
#define COL_FORMAT_MARKER
Definition: optab.h:46
#define ROW_FORMAT_MARKER
Definition: optab.h:44
void OP_Label123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:361
static OUString ConvertToScDefinedName(const OUString &rName)
Converts a string to a valid Calc defined name or database range name.
Definition: ftools.cxx:148
SC_DLLPUBLIC void SetColHidden(SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bHidden)
Definition: document.cxx:4498
void OP_CreatePattern123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:532
void OP_Header(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:281
void OP_ColumnWidth(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:169
SC_DLLPUBLIC void SetValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rVal)
Definition: document.cxx:3489
void PutFormString(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString)
Definition: tool.cxx:38
void OP_Footer(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:276
void OP_VerAlign123(LotusContext &, sal_uInt8 nAlignPattern, SfxItemSet &rPatternItemSet)
Definition: op.cxx:503
#define TWIPS_PER_CHAR
Definition: global.hxx:91
void NI(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:52
sal_uInt64 SeekRel(sal_Int64 nPos)
void OP_EOF123(LotusContext &rContext, SvStream &, sal_uInt16)
Definition: op.cxx:356
ScDocument & rDoc
Definition: lotfilter.hxx:44
void Reset(const ScAddress &rEingPos)
Definition: lotform.cxx:363
LotusRangeList maRangeNames
Definition: lotfilter.hxx:51
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6087
void OP_BOF123(LotusContext &, SvStream &r, sal_uInt16)
Definition: op.cxx:351
WEIGHT_BOLD
void OP_Blank(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:340
void Append(const ScDocument *pDoc, std::unique_ptr< LotusRange > pLR)
Definition: tool.cxx:401
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:853
void OP_Margins(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:286
SC_DLLPUBLIC void SetColWidth(SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth)
Definition: document.cxx:4114
static bool IsFuzzing()
int nCount
#define LOTUS_FORMAT_INFO
Definition: optab.h:42
double Snum32ToDouble(sal_uInt32 nValue)
Definition: tool.cxx:129
SCTAB GetMaxTableNumber() const
Definition: document.hxx:804
sal_uInt16 nCode
static sal_uInt16 nDefWidth
Definition: op.cxx:50
void OP_HiddenCols(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:291
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:88
void OP_ApplyPatternArea123(LotusContext &rContext, SvStream &rStream)
Definition: op.cxx:614
void OP_HorAlign123(LotusContext &, sal_uInt8 nAlignPattern, SfxItemSet &rPatternItemSet)
Definition: op.cxx:470
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
#define LOTUS_FORMAT_INDEX
Definition: optab.h:40
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
int i
const sal_uInt8 nFractionalFloat
Definition: tool.h:31
void OP_Label(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:109
sal_Int16 SCCOL
Definition: types.hxx:21
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:874
constexpr TypedWhichId< SvxVerJustifyItem > ATTR_VER_JUSTIFY(132)
LINESTYLE_SINGLE
SC_DLLPUBLIC void ApplyPatternAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScPatternAttr &rAttr)
Definition: document.cxx:4817
SvStream & ReadUChar(unsigned char &rChar)
void OP_SheetName123(LotusContext &rContext, SvStream &rStream, sal_uInt16 nLength)
Definition: op.cxx:581
SvStream & ReadDouble(double &rDouble)
bool ValidAddress(const ScAddress &rAddress) const
Definition: document.hxx:879
void OP_Window1(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:312
SC_DLLPUBLIC void EnsureTable(SCTAB nTab)
Definition: documen2.cxx:540
void OP_Formula123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:399
std::size_t ReadBytes(void *pData, std::size_t nSize)
virtual void Convert(std::unique_ptr< ScTokenArray > &rpErg, sal_Int32 &nRest) override
Definition: lotform.cxx:391
bool ValidColRow(SCCOL nCol, SCROW nRow) const
Definition: document.hxx:876
const sal_uInt8 nFractionalStd
Definition: tool.h:30
void OP_Number(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:88
SCTAB SanitizeTab(SCTAB nTab)
Definition: address.hxx:138
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void OP_Integer(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:67
sal_Int32 SCROW
Definition: types.hxx:17
void OP_Number123(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:379
SvStream & ReadChar(char &rChar)
SC_DLLPUBLIC ScFormulaCell * SetFormulaCell(const ScAddress &rPos, ScFormulaCell *pCell)
Set formula cell, and transfer its ownership to the document.
Definition: documen2.cxx:1086
ITALIC_NORMAL
unsigned char sal_uInt8
OUString aName
void OP_EOF(LotusContext &rContext, SvStream &, sal_uInt16)
Definition: op.cxx:62
void OP_Formula(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:134
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
bool good() const
Definition: formel.hxx:125
bool good() const
void OP_BOF(LotusContext &, SvStream &r, sal_uInt16)
Definition: op.cxx:57
void OP_NamedRange(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:194
void OP_IEEENumber123(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:429
static ScPostIt * CreateNoteFromString(ScDocument &rDoc, const ScAddress &rPos, const OUString &rNoteText, bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId=0)
Creates a cell note based on the passed string and inserts it into the document.
Definition: postit.cxx:1275
sal_Int32 nLength
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
Definition: document.cxx:168
void AddRecalcMode(ScRecalcMode)
std::map< sal_uInt16, ScPatternAttr > aLotusPatternPool
Definition: lotfilter.hxx:45
bool ValidTab(SCTAB nTab)
Definition: address.hxx:104
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 nValue