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::unique_ptr<char[]> pText(new char[n + 1]);
120  r.ReadBytes(pText.get(), n);
121  pText[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, pText.get());
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 (!(rContext.rDoc.ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && rContext.rDoc.ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd)))
206  return;
207 
208  std::unique_ptr<LotusRange> pRange;
209 
210  if( nColSt == nColEnd && nRowSt == nRowEnd )
211  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
212  else
213  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
214  static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
215 
216  char cBuf[sizeof(cBuffer)+1];
217  if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
218  { // first char in name is a number -> prepend 'A'
219  cBuf[0] = 'A';
220  strcpy( cBuf + 1, cBuffer ); // #100211# - checked
221  }
222  else
223  strcpy( cBuf, cBuffer ); // #100211# - checked
224 
225  OUString aTmp( cBuf, strlen(cBuf), rContext.eCharset );
226 
227  aTmp = ScfTools::ConvertToScDefinedName( aTmp );
228 
229  rContext.maRangeNames.Append( &rContext.rDoc, std::move(pRange) );
230 }
231 
232 void OP_SymphNamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
233 {
234  // POST:don't save for invalid coordinates
235  sal_uInt16 nColSt, nRowSt, nColEnd, nRowEnd;
237 
238  char cBuffer[ 16+1 ];
239  r.ReadBytes(cBuffer, 16);
240  cBuffer[ 16 ] = 0;
241 
242  r.ReadUInt16( nColSt ).ReadUInt16( nRowSt ).ReadUInt16( nColEnd ).ReadUInt16( nRowEnd ).ReadUChar( nType );
243 
244  if (!(rContext.rDoc.ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && rContext.rDoc.ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd)))
245  return;
246 
247  std::unique_ptr<LotusRange> pRange;
248 
249  if( nType )
250  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
251  else
252  pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
253  static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
254 
255  char cBuf[sizeof(cBuffer)+1];
256  if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
257  { // first char in name is a number -> prepend 'A'
258  cBuf[0] = 'A';
259  strcpy( cBuf + 1, cBuffer ); // #100211# - checked
260  }
261  else
262  strcpy( cBuf, cBuffer ); // #100211# - checked
263 
264  OUString aTmp( cBuf, strlen(cBuf), rContext.eCharset );
265  aTmp = ScfTools::ConvertToScDefinedName( aTmp );
266 
267  rContext.maRangeNames.Append( &rContext.rDoc, std::move(pRange) );
268 }
269 
270 void OP_Footer(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
271 {
272  r.SeekRel( n );
273 }
274 
275 void OP_Header(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
276 {
277  r.SeekRel( n );
278 }
279 
280 void OP_Margins(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 n)
281 {
282  r.SeekRel( n );
283 }
284 
285 void OP_HiddenCols(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
286 {
287  sal_uInt16 nByte, nBit;
288  SCCOL nCount;
289  sal_uInt8 nCurrent;
290  nCount = 0;
291 
292  for( nByte = 0 ; nByte < 32 ; nByte++ ) // 32 Bytes with ...
293  {
294  r.ReadUChar( nCurrent );
295  for( nBit = 0 ; nBit < 8 ; nBit++ ) // ...each 8 Bits = 256 Bits
296  {
297  if( nCurrent & 0x01 ) // is lowest Bit set?
298  {
299  // -> Hidden Col
300  rContext.rDoc.SetColHidden(nCount, nCount, 0, true);
301  }
302 
303  nCount++;
304  nCurrent = nCurrent / 2; // the next please...
305  }
306  }
307 }
308 
309 void OP_Window1(LotusContext& rContext, SvStream& r, sal_uInt16 n)
310 {
311  r.SeekRel( 4 ); // skip Cursor Pos
312 
313  sal_uInt8 nDefaultFormat; // -> op.cpp, standard cell format
314  r.ReadUChar(nDefaultFormat);
315 
316  r.SeekRel( 1 ); // skip 'unused'
317 
318  r.ReadUInt16( nDefWidth );
319  if (!r.good())
320  return;
321 
322  r.SeekRel( n - 8 ); // skip the rest
323 
324  nDefWidth = static_cast<sal_uInt16>( TWIPS_PER_CHAR * nDefWidth );
325 
326  const bool bFuzzing = utl::ConfigManager::IsFuzzing();
327 
328  // instead of default, set all Cols in SC by hand
329  for (SCCOL nCol = 0 ; nCol <= rContext.rDoc.MaxCol() ; nCol++)
330  {
331  rContext.rDoc.SetColWidth( nCol, 0, nDefWidth );
332  if (bFuzzing)
333  break;
334  }
335 }
336 
337 void OP_Blank(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
338 {
339  sal_uInt8 nFormat(0);
340  sal_uInt16 nTmpCol(0), nTmpRow(0);
341  r.ReadUChar( nFormat ).ReadUInt16(nTmpCol).ReadUInt16(nTmpRow);
342  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
343  SCROW nRow(static_cast<SCROW>(nTmpRow));
344 
345  SetFormat(rContext, nCol, nRow, 0, nFormat, nFractionalFloat);
346 }
347 
348 void OP_BOF123(LotusContext& /*rContext*/, SvStream& r, sal_uInt16 /*n*/)
349 {
350  r.SeekRel( 26 );
351 }
352 
353 void OP_EOF123(LotusContext& rContext, SvStream& /*r*/, sal_uInt16 /*n*/)
354 {
355  rContext.bEOF = true;
356 }
357 
358 void OP_Label123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
359 {
360  sal_uInt8 nTmpTab(0), nTmpCol(0);
361  sal_uInt16 nTmpRow(0);
362  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
363  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
364  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
365  SCROW nRow(static_cast<SCROW>(nTmpRow));
366 
367  n -= std::min<sal_uInt16>(n, 4);
368 
369  std::unique_ptr<char[]> pText(new char[n + 1]);
370  r.ReadBytes(pText.get(), n);
371  pText[ n ] = 0;
372 
373  PutFormString(rContext, nCol, nRow, nTab, pText.get());
374 }
375 
376 void OP_Number123(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
377 {
378  sal_uInt16 nTmpRow(0);
379  sal_uInt8 nTmpCol(0), nTmpTab(0);
380  sal_uInt32 nValue(0);
381  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol).ReadUInt32(nValue);
382  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
383  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
384  SCROW nRow(static_cast<SCROW>(nTmpRow));
385 
386  ScAddress aAddr(nCol, nRow, nTab);
387  if (rContext.rDoc.ValidAddress(aAddr) && nTab <= rContext.rDoc.GetMaxTableNumber())
388  {
389  double fValue = Snum32ToDouble( nValue );
390  rContext.rDoc.EnsureTable(nTab);
391  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
392  rContext.rDoc.SetValue(aAddr, fValue);
393  }
394 }
395 
396 void OP_Formula123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
397 {
398  sal_uInt16 nTmpRow(0);
399  sal_uInt8 nTmpCol(0), nTmpTab(0);
400  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
401  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
402  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
403  SCROW nRow(static_cast<SCROW>(nTmpRow));
404  r.SeekRel( 8 ); // skip Result
405 
406  std::unique_ptr<ScTokenArray> pResult;
407  sal_Int32 nBytesLeft = (n > 12) ? n - 12 : 0;
408  ScAddress aAddress(nCol, nRow, nTab);
409 
410  svl::SharedStringPool& rSPool = rContext.rDoc.GetSharedStringPool();
411  LotusToSc aConv(rContext, r, rSPool, rContext.eCharset, true);
412  aConv.Reset( aAddress );
413  aConv.Convert( pResult, nBytesLeft );
414  if (!aConv.good())
415  return;
416 
417  if (rContext.rDoc.ValidAddress(aAddress) && nTab <= rContext.rDoc.GetMaxTableNumber())
418  {
419  ScFormulaCell* pCell = new ScFormulaCell(rContext.rDoc, aAddress, std::move(pResult));
420  pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
421  rContext.rDoc.EnsureTable(nTab);
422  rContext.rDoc.SetFormulaCell(aAddress, pCell);
423  }
424 }
425 
426 void OP_IEEENumber123(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
427 {
428  sal_uInt16 nTmpRow(0);
429  sal_uInt8 nTmpCol(0), nTmpTab(0);
430  double dValue(0.0);
431  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol).ReadDouble(dValue);
432  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
433  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
434  SCROW nRow(static_cast<SCROW>(nTmpRow));
435 
436  ScAddress aAddr(nCol, nRow, nTab);
437  if (rContext.rDoc.ValidAddress(aAddr) && nTab <= rContext.rDoc.GetMaxTableNumber())
438  {
439  rContext.rDoc.EnsureTable(nTab);
440  // coverity[tainted_data : FALSE] - ValidAddress has sanitized aAddr
441  rContext.rDoc.SetValue(aAddr, dValue);
442  }
443 }
444 
445 void OP_Note123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
446 {
447  sal_uInt16 nTmpRow(0);
448  sal_uInt8 nTmpTab(0), nTmpCol(0);
449  r.ReadUInt16(nTmpRow).ReadUChar(nTmpTab).ReadUChar(nTmpCol);
450  SCTAB nTab(static_cast<SCTAB>(nTmpTab));
451  SCCOL nCol(static_cast<SCCOL>(nTmpCol));
452  SCROW nRow(static_cast<SCROW>(nTmpRow));
453 
454  n -= std::min<sal_uInt16>(n, 4);
455 
456  std::unique_ptr<char[]> pText(new char[n + 1]);
457  r.ReadBytes(pText.get(), n);
458  pText[ n ] = 0;
459 
460  OUString aNoteText(pText.get(), strlen(pText.get()), rContext.eCharset);
461  pText.reset();
462 
463  ScAddress aPos(nCol, nRow, nTab);
464  ScNoteUtil::CreateNoteFromString( rContext.rDoc, aPos, aNoteText, false, false );
465 }
466 
467 void OP_HorAlign123(LotusContext& /*rContext*/, sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet)
468 {
469 // pre: Pattern is stored in the last 3 bites of the 21st byte
470 // post: Appropriate Horizontal Alignment is set in rPattern according to the bit pattern.
471 //
472 // LEFT:001, RIGHT:010, CENTER:011, JUSTIFY:110,
473 // LEFT-Text/RIGHT-NUMBER:100, DEFAULT:000
474 
475  nAlignPattern = ( nAlignPattern & 0x07);
476 
477  switch (nAlignPattern)
478  {
479  case 1:
480  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Left, ATTR_HOR_JUSTIFY ) );
481  break;
482  case 2:
483  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Right, ATTR_HOR_JUSTIFY ) );
484  break;
485  case 3:
486  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Center, ATTR_HOR_JUSTIFY) );
487  break;
488  case 4:
489  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY ) );
490  break;
491  case 6:
492  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Block, ATTR_HOR_JUSTIFY ) );
493  break;
494  default:
495  rPatternItemSet.Put( SvxHorJustifyItem( SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY ) );
496  break;
497  }
498 }
499 
500 void OP_VerAlign123(LotusContext& /*rContext*/, sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet)
501 {
502 // pre: Pattern is stored in the last 3 bites of the 22nd byte
503 // post: Appropriate Vertical Alignment is set in rPattern according to the bit pattern.
504 //
505 // TOP:001, MIDDLE:010, DOWN:100, DEFAULT:000
506 
507  nAlignPattern = ( nAlignPattern & 0x07);
508 
509  switch (nAlignPattern)
510  {
511  case 0:
512  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY) );
513  break;
514  case 1:
515  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Top, ATTR_VER_JUSTIFY) );
516  break;
517  case 2:
518  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Center, ATTR_VER_JUSTIFY) );
519  break;
520  case 4:
521  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Bottom, ATTR_VER_JUSTIFY) );
522  break;
523  default:
524  rPatternItemSet.Put( SvxVerJustifyItem(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY) );
525  break;
526  }
527 }
528 
529 void OP_CreatePattern123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
530 {
531  sal_uInt16 nCode;
532 
533  ScPatternAttr aPattern(rContext.rDoc.GetPool());
534  SfxItemSet& rItemSet = aPattern.GetItemSet();
535 
536  r.ReadUInt16( nCode );
537  n -= std::min<sal_uInt16>(n, 2);
538 
539  if ( nCode == 0x0fd2 )
540  {
541  sal_uInt16 nPatternId;
542  r.ReadUInt16( nPatternId );
543 
544  sal_uInt8 Hor_Align, Ver_Align, temp;
545  bool bIsBold,bIsUnderLine,bIsItalics;
546 
547  r.SeekRel(12);
548 
549  // Read 17th Byte
550  r.ReadUChar( temp );
551 
552  bIsBold = (temp & 0x01);
553  bIsItalics = (temp & 0x02);
554  bIsUnderLine = (temp & 0x04);
555 
556  if ( bIsBold )
557  rItemSet.Put( SvxWeightItem(WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
558  if ( bIsItalics )
560  if ( bIsUnderLine )
562 
563  r.SeekRel(3);
564 
565  // Read 21st Byte
566  r.ReadUChar( Hor_Align );
567  OP_HorAlign123(rContext, Hor_Align, rItemSet );
568 
569  r.ReadUChar( Ver_Align );
570  OP_VerAlign123(rContext, Ver_Align, rItemSet );
571 
572  rContext.aLotusPatternPool.emplace( nPatternId, aPattern );
573  n -= std::min<sal_uInt16>(n, 20);
574  }
575  r.SeekRel(n);
576 }
577 
578 void OP_SheetName123(LotusContext& rContext, SvStream& rStream, sal_uInt16 nLength)
579 {
580  if (nLength <= 4)
581  {
582  rStream.SeekRel(nLength);
583  return;
584  }
585 
586  // B0 36 [sheet number (2 bytes?)] [sheet name (null terminated char array)]
587  rStream.SeekRel(2); // ignore the first 2 bytes (B0 36).
588  sal_uInt16 nSheetNum(0);
589  rStream.ReadUInt16(nSheetNum);
590 
591  ::std::vector<char> sSheetName;
592  sSheetName.reserve(nLength-4);
593  for (sal_uInt16 i = 4; i < nLength; ++i)
594  {
595  char c;
596  rStream.ReadChar( c );
597  sSheetName.push_back(c);
598  }
599 
600  if (!ValidTab(nSheetNum))
601  return;
602  // coverity[tainted_data : FALSE] - ValidTab has sanitized nSheetNum
603  rContext.rDoc.MakeTable(nSheetNum);
604  if (!sSheetName.empty())
605  {
606  OUString aName(sSheetName.data(), strlen(sSheetName.data()), rContext.eCharset);
607  rContext.rDoc.RenameTab(nSheetNum, aName);
608  }
609 }
610 
612 {
613  sal_uInt16 nOpcode, nLength;
614  sal_uInt16 nCol = 0, nColCount = 0, nRow = 0, nRowCount = 0, nTab = 0, nData, nTabCount = 0, nLevel = 0;
615 
616  do
617  {
618  rStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
619  switch ( nOpcode )
620  {
621  case ROW_FORMAT_MARKER:
622  nLevel++;
623  break;
624  case COL_FORMAT_MARKER:
625  nLevel--;
626  if( nLevel == 1 )
627  {
628  nTab = nTab + nTabCount;
629  nCol = 0; nColCount = 0;
630  nRow = 0; nRowCount = 0;
631  }
632  break;
633  case LOTUS_FORMAT_INDEX:
634  if( nLength >= 2 )
635  {
636  rStream.ReadUInt16( nData );
637  rStream.SeekRel( nLength - 2 );
638  if( nLevel == 1 )
639  nTabCount = SanitizeTab(nData);
640  else if( nLevel == 2 )
641  {
642  nCol = nCol + nColCount;
643  nColCount = nData;
644  if ( nCol > 0xff ) // 256 is the max col size supported by 123
645  nCol = 0;
646  }
647  else if( nLevel == 3 )
648  {
649  nRow = nRow + nRowCount;
650  nRowCount = nData;
651  if ( nRow > 0x1fff ) // 8192 is the max row size supported by 123
652  nRow = 0;
653  }
654  }
655  else
656  rStream.SeekRel( nLength );
657  break;
658  case LOTUS_FORMAT_INFO:
659  if( nLength >= 2 )
660  {
661  rStream.ReadUInt16( nData );
662  rStream.SeekRel( nLength - 2 );
663  std::map<sal_uInt16, ScPatternAttr>::iterator loc = rContext.aLotusPatternPool.find( nData );
664  // #126338# apparently, files with invalid index occur in the wild -> don't crash then
665  if ( loc != rContext.aLotusPatternPool.end() )
666  for( int i = 0; i < nTabCount; i++)
667  {
668  rContext.rDoc.ApplyPatternAreaTab( nCol, nRow, nCol + nColCount - 1, nRow + nRowCount - 1, static_cast< SCTAB >( nTab + i ), loc->second );
669  }
670  }
671  else
672  rStream.SeekRel( nLength );
673  break;
674  default:
675  rStream.SeekRel( nLength );
676  break;
677  }
678  }
679  while( nLevel && rStream.good() );
680 
681  rContext.aLotusPatternPool.clear();
682 }
683 
684 /* 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:232
SvStream & ReadInt16(sal_Int16 &rInt16)
SCCOL SanitizeCol(SCCOL nCol) const
Definition: document.hxx:879
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:565
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
void OP_Note123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:445
#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:358
static OUString ConvertToScDefinedName(const OUString &rName)
Converts a string to a valid Calc defined name or database range name.
Definition: ftools.cxx:144
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:529
void OP_Header(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:275
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:37
void OP_Footer(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:270
void OP_VerAlign123(LotusContext &, sal_uInt8 nAlignPattern, SfxItemSet &rPatternItemSet)
Definition: op.cxx:500
#define TWIPS_PER_CHAR
Definition: global.hxx:90
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:353
ScDocument & rDoc
Definition: lotfilter.hxx:44
void Reset(const ScAddress &rEingPos)
Definition: lotform.cxx:357
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:348
WEIGHT_BOLD
void OP_Blank(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:337
void Append(const ScDocument *pDoc, std::unique_ptr< LotusRange > pLR)
Definition: tool.cxx:400
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:852
void OP_Margins(LotusContext &, SvStream &r, sal_uInt16 n)
Definition: op.cxx:280
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:128
SCTAB GetMaxTableNumber() const
Definition: document.hxx:803
sal_uInt16 nCode
static sal_uInt16 nDefWidth
Definition: op.cxx:50
void OP_HiddenCols(LotusContext &rContext, SvStream &r, sal_uInt16)
Definition: op.cxx:285
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:87
void OP_ApplyPatternArea123(LotusContext &rContext, SvStream &rStream)
Definition: op.cxx:611
void OP_HorAlign123(LotusContext &, sal_uInt8 nAlignPattern, SfxItemSet &rPatternItemSet)
Definition: op.cxx:467
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:870
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:873
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:578
SvStream & ReadDouble(double &rDouble)
bool ValidAddress(const ScAddress &rAddress) const
Definition: document.hxx:878
void OP_Window1(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:309
SC_DLLPUBLIC void EnsureTable(SCTAB nTab)
Definition: documen2.cxx:539
void OP_Formula123(LotusContext &rContext, SvStream &r, sal_uInt16 n)
Definition: op.cxx:396
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:385
bool ValidColRow(SCCOL nCol, SCROW nRow) const
Definition: document.hxx:875
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:376
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:1083
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:400
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:426
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:167
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