LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/lotus - op.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 134 303 44.2 %
Date: 2012-12-27 Functions: 10 28 35.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <tools/solar.h>
      21             : #include <rtl/math.hxx>
      22             : 
      23             : #include <stdio.h>
      24             : #include <string.h>
      25             : #include <math.h>
      26             : #include <ctype.h>
      27             : #include <stdlib.h>
      28             : 
      29             : #include "scitems.hxx"
      30             : #include "patattr.hxx"
      31             : #include "docpool.hxx"
      32             : #include <svx/algitem.hxx>
      33             : #include <editeng/postitem.hxx>
      34             : #include <editeng/udlnitem.hxx>
      35             : #include <editeng/wghtitem.hxx>
      36             : #include <editeng/justifyitem.hxx>
      37             : 
      38             : #include "cell.hxx"
      39             : #include "rangenam.hxx"
      40             : #include "document.hxx"
      41             : #include "postit.hxx"
      42             : 
      43             : #include "op.h"
      44             : #include "optab.h"
      45             : #include "tool.h"
      46             : #include "decl.h"
      47             : #include "lotform.hxx"
      48             : #include "lotrange.hxx"
      49             : 
      50             : #include "root.hxx"
      51             : 
      52             : #include "ftools.hxx"
      53             : 
      54             : #include <vector>
      55             : #include <map>
      56             : 
      57             : extern WKTYP eTyp;           // -> filter.cxx, aktueller Dateityp
      58             : extern sal_Bool bEOF;           // -> filter.cxx, zeigt Dateiende an
      59             : extern sal_uInt8 nDefaultFormat; // -> tool.cxx, Default-Zellenformat
      60             : extern ScDocument* pDoc;           // -> filter.cxx, Aufhaenger zum Dokumentzugriff
      61             : extern CharSet eCharVon;       // -> filter.cxx, character set specified
      62             : 
      63             : static sal_uInt16 nDefWidth = ( sal_uInt16 ) ( TWIPS_PER_CHAR * 10 );
      64             : 
      65             : extern std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
      66             : 
      67           8 : void NI( SvStream& r, sal_uInt16 n )
      68             : {
      69           8 :     r.SeekRel( n );
      70           8 : }
      71             : 
      72             : 
      73           0 : void OP_BOF( SvStream& r, sal_uInt16 /*n*/ )
      74             : {
      75           0 :     r.SeekRel( 2 );        // Versionsnummer ueberlesen
      76           0 : }
      77             : 
      78             : 
      79           0 : void OP_EOF( SvStream& /*r*/, sal_uInt16 /*n*/ )
      80             : {
      81           0 :     bEOF = sal_True;
      82           0 : }
      83             : 
      84             : 
      85           0 : void OP_Integer( SvStream& r, sal_uInt16 /*n*/ )
      86             : {
      87             :     sal_uInt8           nFormat;
      88             :     sal_uInt16          nCol, nRow;
      89           0 :     SCTAB           nTab = 0;
      90             :     sal_Int16           nValue;
      91             : 
      92           0 :     r >> nFormat >> nCol >> nRow >> nValue;
      93             : 
      94           0 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
      95             :     {
      96           0 :         ScValueCell*  pZelle = new ScValueCell( ( double ) nValue );
      97           0 :         pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, true );
      98             : 
      99             :         // 0 Stellen nach'm Komma!
     100           0 :         SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, 0 );
     101             :     }
     102           0 : }
     103             : 
     104             : 
     105           0 : void OP_Number( SvStream& r, sal_uInt16 /*n*/ )
     106             : {
     107             :     sal_uInt8           nFormat;
     108             :     sal_uInt16          nCol, nRow;
     109           0 :     SCTAB           nTab = 0;
     110             :     double          fValue;
     111             : 
     112           0 :     r >> nFormat >> nCol >> nRow >> fValue;
     113             : 
     114           0 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
     115             :     {
     116           0 :         fValue = ::rtl::math::round( fValue, 15 );
     117           0 :         ScValueCell*  pZelle = new ScValueCell( fValue );
     118           0 :         pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, true );
     119             : 
     120           0 :         SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
     121             :     }
     122           0 : }
     123             : 
     124             : 
     125           0 : void OP_Label( SvStream& r, sal_uInt16 n )
     126             : {
     127             :     sal_uInt8           nFormat;
     128             :     sal_uInt16          nCol, nRow;
     129           0 :     SCTAB           nTab = 0;
     130             : 
     131           0 :     r >> nFormat >> nCol >> nRow;
     132             : 
     133           0 :     n -= (n > 5) ? 5 : n;
     134             : 
     135           0 :     sal_Char* pText = new sal_Char[n + 1];
     136           0 :     r.Read( pText, n );
     137           0 :     pText[n] = 0;
     138             : 
     139           0 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
     140             :     {
     141           0 :         nFormat &= 0x80;    // Bit 7 belassen
     142           0 :         nFormat |= 0x75;    // protected egal, special-text gesetzt
     143             : 
     144           0 :         PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText );
     145             : 
     146           0 :         SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezStd );
     147             :     }
     148             : 
     149           0 :     delete [] pText;
     150           0 : }
     151             : 
     152           0 : void OP_Formula( SvStream& r, sal_uInt16 /*n*/ )
     153             : {
     154             :     sal_uInt8               nFormat;
     155             :     sal_uInt16              nCol, nRow, nFormulaSize;
     156           0 :     SCTAB                   nTab = 0;
     157             : 
     158           0 :     r >> nFormat >> nCol >> nRow;
     159           0 :     r.SeekRel( 8 );    // Ergebnis ueberspringen
     160           0 :     r >> nFormulaSize;
     161             : 
     162             :     const ScTokenArray* pErg;
     163           0 :     sal_Int32               nBytesLeft = nFormulaSize;
     164           0 :     ScAddress           aAddress( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab );
     165             : 
     166           0 :     LotusToSc           aConv( r, pLotusRoot->eCharsetQ, false );
     167           0 :     aConv.Reset( aAddress );
     168           0 :     aConv.Convert( pErg, nBytesLeft );
     169             : 
     170           0 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
     171             :     {
     172           0 :         ScFormulaCell*    pZelle = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
     173             : 
     174           0 :         pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
     175             : 
     176           0 :         pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, true );
     177             : 
     178             :         // nFormat = Standard -> Nachkommastellen wie Float
     179           0 :         SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
     180           0 :     }
     181           0 : }
     182             : 
     183             : 
     184           0 : void OP_ColumnWidth( SvStream& r, sal_uInt16 /*n*/ )
     185             : {
     186             :     sal_uInt16              nCol, nBreite;
     187             :     sal_uInt8               nWidthSpaces;
     188           0 :     SCTAB                   nTab = 0;
     189             : 
     190           0 :     r >> nCol >> nWidthSpaces;
     191             : 
     192           0 :     if (ValidCol( static_cast<SCCOL>(nCol)))
     193             :     {
     194           0 :         if( nWidthSpaces )
     195             :             // Annahme: 10cpi-Zeichensatz
     196           0 :             nBreite = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nWidthSpaces );
     197             :         else
     198             :         {
     199           0 :             pDoc->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), 0, true);
     200           0 :             nBreite = nDefWidth;
     201             :         }
     202             : 
     203           0 :         pDoc->SetColWidth( static_cast<SCCOL> (nCol), nTab, nBreite );
     204             :     }
     205           0 : }
     206             : 
     207             : 
     208           0 : void OP_NamedRange( SvStream& r, sal_uInt16 /*n*/ )
     209             :     {
     210             :     // POST:    waren Koordinaten ungueltig, wird nicht gespeichert
     211             :     sal_uInt16              nColSt, nRowSt, nColEnd, nRowEnd;
     212             : 
     213             :     sal_Char cPuffer[ 16+1 ];
     214           0 :     r.Read( cPuffer, 16 );
     215           0 :     cPuffer[ 16 ] = 0;
     216             : 
     217           0 :     r >> nColSt >> nRowSt >> nColEnd >> nRowEnd;
     218             : 
     219           0 :     if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
     220             :     {
     221             :         LotusRange*      pRange;
     222             : 
     223           0 :         if( nColSt == nColEnd && nRowSt == nRowEnd )
     224           0 :             pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
     225             :         else
     226             :             pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
     227           0 :                     static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
     228             : 
     229             :         sal_Char cBuf[sizeof(cPuffer)+1];
     230           0 :         if( isdigit( *cPuffer ) )
     231             :         {  // erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
     232           0 :             cBuf[0] = 'A';
     233           0 :             strcpy( cBuf + 1, cPuffer );       // #100211# - checked
     234             :         }
     235             :         else
     236           0 :             strcpy( cBuf, cPuffer );           // #100211# - checked
     237             : 
     238           0 :         String        aTmp( cBuf, pLotusRoot->eCharsetQ );
     239             : 
     240           0 :         ScfTools::ConvertToScDefinedName( aTmp );
     241             : 
     242           0 :         pLotusRoot->pRangeNames->Append( pRange, aTmp );
     243             :     }
     244           0 : }
     245             : 
     246             : 
     247           0 : void OP_SymphNamedRange( SvStream& r, sal_uInt16 /*n*/ )
     248             : {
     249             :     // POST:    waren Koordinaten ungueltig, wird nicht gespeichert
     250             :     sal_uInt16              nColSt, nRowSt, nColEnd, nRowEnd;
     251             :     sal_uInt8               nType;
     252             : 
     253             :     sal_Char cPuffer[ 16+1 ];
     254           0 :     r.Read( cPuffer, 16 );
     255           0 :     cPuffer[ 16 ] = 0;
     256             : 
     257           0 :     r >> nColSt >> nRowSt >> nColEnd >> nRowEnd >> nType;
     258             : 
     259           0 :     if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
     260             :     {
     261             :         LotusRange*      pRange;
     262             : 
     263           0 :         if( nType )
     264           0 :             pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
     265             :         else
     266             :             pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
     267           0 :                     static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
     268             : 
     269             :         sal_Char cBuf[sizeof(cPuffer)+1];
     270           0 :         if( isdigit( *cPuffer ) )
     271             :         {  // erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
     272           0 :             cBuf[0] = 'A';
     273           0 :             strcpy( cBuf + 1, cPuffer );       // #100211# - checked
     274             :         }
     275             :         else
     276           0 :             strcpy( cBuf, cPuffer );           // #100211# - checked
     277             : 
     278           0 :         String    aTmp( cBuf, pLotusRoot->eCharsetQ );
     279           0 :         ScfTools::ConvertToScDefinedName( aTmp );
     280             : 
     281           0 :         pLotusRoot->pRangeNames->Append( pRange, aTmp );
     282             :     }
     283           0 : }
     284             : 
     285             : 
     286           0 : void OP_Footer( SvStream& r, sal_uInt16 n )
     287             : {
     288           0 :     r.SeekRel( n );
     289           0 : }
     290             : 
     291             : 
     292           0 : void OP_Header( SvStream& r, sal_uInt16 n )
     293             : {
     294           0 :     r.SeekRel( n );
     295           0 : }
     296             : 
     297             : 
     298           0 : void OP_Margins( SvStream& r, sal_uInt16 n )
     299             : {
     300           0 :     r.SeekRel( n );
     301           0 : }
     302             : 
     303             : 
     304           0 : void OP_HiddenCols( SvStream& r, sal_uInt16 /*n*/ )
     305             : {
     306             :     sal_uInt16      nByte, nBit;
     307             :     SCCOL       nCount;
     308             :     sal_uInt8       nAkt;
     309           0 :     nCount = 0;
     310             : 
     311           0 :     for( nByte = 0 ; nByte < 32 ; nByte++ ) // 32 Bytes mit ...
     312             :     {
     313           0 :         r >> nAkt;
     314           0 :         for( nBit = 0 ; nBit < 8 ; nBit++ ) // ...jeweils 8 Bits = 256 Bits
     315             :         {
     316           0 :             if( nAkt & 0x01 )   // unterstes Bit gesetzt?
     317             :                 // -> Hidden Col
     318           0 :                 pDoc->SetColHidden(nCount, nCount, 0, true);
     319             : 
     320           0 :             nCount++;
     321           0 :             nAkt = nAkt / 2;    // der Naechste bitte...
     322             :         }
     323             :     }
     324           0 : }
     325             : 
     326             : 
     327           0 : void OP_Window1( SvStream& r, sal_uInt16 n )
     328             : {
     329           0 :     r.SeekRel( 4 );    // Cursor Pos ueberspringen
     330             : 
     331           0 :     r >> nDefaultFormat;
     332             : 
     333           0 :     r.SeekRel( 1 );    // 'unused' ueberspringen
     334             : 
     335           0 :     r >> nDefWidth;
     336             : 
     337           0 :     r.SeekRel( n - 8 );  // und den Rest ueberspringen
     338             : 
     339           0 :     nDefWidth = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nDefWidth );
     340             : 
     341             :     // statt Defaulteinstellung in SC alle Cols zu Fuss setzen
     342           0 :     for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ )
     343           0 :         pDoc->SetColWidth( nCol, 0, nDefWidth );
     344           0 : }
     345             : 
     346             : 
     347           0 : void OP_Blank( SvStream& r, sal_uInt16 /*n*/ )
     348             : {
     349             :     sal_uInt16      nCol, nRow;
     350             :     sal_uInt8       nFormat;
     351           0 :     r >> nFormat >> nCol >> nRow;
     352             : 
     353           0 :     SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), 0, nFormat, nDezFloat );
     354           0 : }
     355             : 
     356           1 : void OP_BOF123( SvStream& r, sal_uInt16 /*n*/ )
     357             : {
     358           1 :     r.SeekRel( 26 );
     359           1 : }
     360             : 
     361             : 
     362           0 : void OP_EOF123( SvStream& /*r*/, sal_uInt16 /*n*/ )
     363             : {
     364           0 :     bEOF = sal_True;
     365           0 : }
     366             : 
     367           2 : void OP_Label123( SvStream& r, sal_uInt16 n )
     368             : {
     369             :     sal_uInt8      nTab, nCol;
     370             :     sal_uInt16    nRow;
     371           2 :     r >> nRow >> nTab >> nCol;
     372           2 :     n -= (n > 4) ? 4 : n;
     373             : 
     374           2 :     sal_Char* pText = new sal_Char[n + 1];
     375           2 :     r.Read( pText, n );
     376           2 :     pText[ n ] = 0;
     377             : 
     378           2 :     PutFormString( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pText );
     379             : 
     380           2 :     delete []pText;
     381           2 : }
     382             : 
     383           2 : void OP_Number123( SvStream& r, sal_uInt16 /*n*/ )
     384             : {
     385             :     sal_uInt8    nCol,nTab;
     386             :     sal_uInt16  nRow;
     387             :     sal_uInt32   nValue;
     388             : 
     389           2 :     r >> nRow >> nTab >> nCol >> nValue;
     390             : 
     391           2 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab <= pDoc->GetMaxTableNumber())
     392             :     {
     393           2 :         double fValue = Snum32ToDouble( nValue );
     394             : 
     395           2 :         ScValueCell *pCell = new ScValueCell( fValue );
     396           2 :         pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, true );
     397             :     }
     398           2 : }
     399             : 
     400           4 : void OP_Formula123( SvStream& r, sal_uInt16 n )
     401             : {
     402             :     sal_uInt8 nCol,nTab;
     403             :     sal_uInt16 nRow;
     404             : 
     405           4 :     r >> nRow >> nTab >> nCol;
     406           4 :     r.SeekRel( 8 );    // Result- jump over
     407             : 
     408             :     const ScTokenArray* pErg;
     409           4 :     sal_Int32 nBytesLeft = (n > 12) ? n - 12 : 0;
     410           4 :     ScAddress aAddress( nCol, nRow, nTab );
     411             : 
     412           4 :     LotusToSc aConv( r, pLotusRoot->eCharsetQ, sal_True );
     413           4 :     aConv.Reset( aAddress );
     414           4 :     aConv.Convert( pErg, nBytesLeft );
     415             : 
     416           4 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab <= pDoc->GetMaxTableNumber())
     417             :     {
     418           4 :         ScFormulaCell* pCell = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
     419             : 
     420           4 :         pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
     421             : 
     422           4 :         pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, true );
     423           4 :     }
     424           4 : }
     425             : 
     426           0 : void OP_IEEENumber123( SvStream& r, sal_uInt16 /*n*/ )
     427             : {
     428             :     sal_uInt8 nCol,nTab;
     429             :     sal_uInt16 nRow;
     430             :     double dValue;
     431             : 
     432           0 :     r >> nRow >> nTab >> nCol >> dValue;
     433             : 
     434           0 :     if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab <= pDoc->GetMaxTableNumber())
     435             :     {
     436           0 :         ScValueCell *pCell = new ScValueCell(dValue);
     437           0 :         pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, true );
     438             :     }
     439           0 : }
     440             : 
     441           1 : void OP_Note123( SvStream& r, sal_uInt16 n)
     442             : {
     443             :     sal_uInt8 nTab, nCol;
     444             :     sal_uInt16 nRow;
     445           1 :     r >> nRow >> nTab >> nCol;
     446           1 :     n -= (n > 4) ? 4 : n;
     447             : 
     448           1 :     sal_Char* pText = new sal_Char[n + 1];
     449           1 :     r.Read( pText, n );
     450           1 :     pText[ n ] = 0;
     451             : 
     452           1 :     String aNoteText(pText,pLotusRoot->eCharsetQ);
     453           1 :     delete [] pText;
     454             : 
     455           1 :     ScAddress aPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab) );
     456           1 :     ScNoteUtil::CreateNoteFromString( *pDoc, aPos, aNoteText, false, false );
     457           1 : }
     458             : 
     459           9 : void OP_HorAlign123( sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet )
     460             : {
     461             : //      pre:  Pattern is stored in the last 3 bites of the 21st byte
     462             : //      post: Appropriate Horizontal Alignement is set in rPattern according to the bit pattern.
     463             : //
     464             : //      LEFT:001, RIGHT:010, CENTER:011, JUSTIFY:110,
     465             : //      LEFT-Text/RIGHT-NUMBER:100, DEFAULT:000
     466             : 
     467           9 :     nAlignPattern = ( nAlignPattern & 0x07);
     468             : 
     469           9 :     switch (nAlignPattern)
     470             :     {
     471             :         case 1:
     472           0 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY ) );
     473           0 :             break;
     474             :           case 2:
     475           1 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY ) );
     476           1 :             break;
     477             :         case 3:
     478           0 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY) );
     479           0 :             break;
     480             :         case 4:
     481           4 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ) );
     482           4 :             break;
     483             :         case 6:
     484           0 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_BLOCK, ATTR_HOR_JUSTIFY ) );
     485           0 :             break;
     486             :         default:
     487           4 :             rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ) );
     488           4 :             break;
     489             :       }
     490           9 : }
     491             : 
     492           9 : void OP_VerAlign123( sal_uInt8 nAlignPattern,SfxItemSet& rPatternItemSet  )
     493             : {
     494             : //      pre:  Pattern is stored in the last 3 bites of the 22nd byte
     495             : //      post: Appropriate Verticle Alignement is set in rPattern according to the bit pattern.
     496             : //
     497             : //      TOP:001, MIDDLE:010, DOWN:100, DEFAULT:000
     498             : 
     499           9 :     nAlignPattern = ( nAlignPattern & 0x07);
     500             : 
     501           9 :     switch (nAlignPattern)
     502             :     {
     503             :         case 0:
     504           3 :             rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY) );
     505           3 :             break;
     506             :         case 1:
     507           3 :             rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_TOP, ATTR_VER_JUSTIFY) );
     508           3 :             break;
     509             :         case 2:
     510           2 :             rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY) );
     511           2 :             break;
     512             :         case 4:
     513           1 :             rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_BOTTOM, ATTR_VER_JUSTIFY) );
     514           1 :             break;
     515             :         default:
     516           0 :             rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY) );
     517           0 :             break;
     518             :     }
     519           9 : }
     520             : 
     521          34 : void OP_CreatePattern123( SvStream& r, sal_uInt16 n)
     522             : {
     523             :     sal_uInt16 nCode,nPatternId;
     524             : 
     525          34 :     ScPatternAttr aPattern(pDoc->GetPool());
     526          34 :     SfxItemSet& rItemSet = aPattern.GetItemSet();
     527             : 
     528          34 :     r >> nCode;
     529          34 :     n -= (n > 2) ? 2 : n;
     530             : 
     531          34 :     if ( nCode == 0x0fd2 )
     532             :     {
     533           9 :         r >> nPatternId;
     534             : 
     535             :         sal_uInt8 Hor_Align, Ver_Align, temp;
     536             :         sal_Bool bIsBold,bIsUnderLine,bIsItalics;
     537             : 
     538           9 :         r.SeekRel(12);
     539             : 
     540             :         // Read 17th Byte
     541           9 :         r >> temp;
     542             : 
     543           9 :         bIsBold = (temp & 0x01);
     544           9 :         bIsItalics = (temp & 0x02);
     545           9 :         bIsUnderLine = (temp & 0x04);
     546             : 
     547           9 :         if ( bIsBold )
     548           0 :             rItemSet.Put( SvxWeightItem(WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
     549           9 :         if ( bIsItalics )
     550           0 :             rItemSet.Put( SvxPostureItem(ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
     551           9 :         if ( bIsUnderLine )
     552           0 :             rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
     553             : 
     554           9 :         r.SeekRel(3);
     555             : 
     556             :         // Read 21st Byte
     557           9 :         r >> Hor_Align;
     558           9 :         OP_HorAlign123( Hor_Align, rItemSet );
     559             : 
     560           9 :         r >> Ver_Align;
     561           9 :         OP_VerAlign123( Ver_Align, rItemSet );
     562             : 
     563           9 :         aLotusPatternPool.insert( std::map<sal_uInt16, ScPatternAttr>::value_type( nPatternId, aPattern ) );
     564           9 :         n -= (n > 20) ? 20 : n;
     565             :     }
     566          34 :     r.SeekRel(n);
     567          34 : }
     568             : 
     569           0 : void OP_SheetName123( SvStream& rStream, sal_uInt16 nLength )
     570             : {
     571           0 :     if (nLength <= 4)
     572             :     {
     573           0 :         rStream.SeekRel(nLength);
     574           0 :         return;
     575             :     }
     576             : 
     577             :     // B0 36 [sheet number (2 bytes?)] [sheet name (null terminated char array)]
     578             : 
     579             :     sal_uInt16 nDummy;
     580           0 :     rStream >> nDummy; // ignore the first 2 bytes (B0 36).
     581           0 :     rStream >> nDummy;
     582           0 :     SCTAB nSheetNum = static_cast<SCTAB>(nDummy);
     583           0 :     pDoc->MakeTable(nSheetNum);
     584             : 
     585           0 :     ::std::vector<sal_Char> sSheetName;
     586           0 :     sSheetName.reserve(nLength-4);
     587           0 :     for (sal_uInt16 i = 4; i < nLength; ++i)
     588             :     {
     589             :         sal_Char c;
     590           0 :         rStream >> c;
     591           0 :         sSheetName.push_back(c);
     592             :     }
     593             : 
     594           0 :     if (!sSheetName.empty())
     595             :     {
     596           0 :         String aName(&sSheetName[0], eCharVon);
     597           0 :         pDoc->RenameTab(nSheetNum, aName);
     598           0 :     }
     599             : }
     600             : 
     601           1 : void OP_ApplyPatternArea123( SvStream& rStream )
     602             : {
     603             :     sal_uInt16 nOpcode, nLength;
     604           1 :     sal_uInt16 nCol = 0, nColCount = 0, nRow = 0, nRowCount = 0, nTab = 0, nData, nTabCount = 0, nLevel = 0;
     605             : 
     606          65 :     do
     607             :     {
     608          33 :         rStream >> nOpcode >> nLength;
     609          33 :         switch ( nOpcode )
     610             :         {
     611             :             case ROW_FORMAT_MARKER:
     612           6 :                 nLevel++;
     613           6 :                 break;
     614             :             case COL_FORMAT_MARKER:
     615           6 :                 nLevel--;
     616           6 :                 if( nLevel == 1 )
     617             :                 {
     618           2 :                     nTab = nTab + nTabCount;
     619           2 :                     nCol = 0; nColCount = 0;
     620           2 :                     nRow = 0; nRowCount = 0;
     621             :                 }
     622           6 :                 break;
     623             :             case LOTUS_FORMAT_INDEX:
     624          15 :                 if( nLength >= 2 )
     625             :                 {
     626          15 :                     rStream >> nData;
     627          15 :                     rStream.SeekRel( nLength - 2 );
     628          15 :                     if( nLevel == 1 )
     629           2 :                         nTabCount = nData;
     630          13 :                     else if( nLevel == 2 )
     631             :                     {
     632           5 :                         nCol = nCol + nColCount;
     633           5 :                         nColCount = nData;
     634           5 :                         if ( nCol > 0xff ) // 256 is the max col size supported by 123
     635           0 :                             nCol = 0;
     636             :                     }
     637           8 :                     else if( nLevel == 3 )
     638             :                     {
     639           8 :                         nRow = nRow + nRowCount;
     640           8 :                         nRowCount = nData;
     641           8 :                         if ( nRow > 0x1fff ) // 8192 is the max row size supported by 123
     642           2 :                             nRow = 0;
     643             :                     }
     644             :                 }
     645             :                 else
     646           0 :                     rStream.SeekRel( nLength );
     647          15 :                 break;
     648             :             case LOTUS_FORMAT_INFO:
     649           3 :                 if( nLength >= 2 )
     650             :                 {
     651           3 :                     rStream >> nData;
     652           3 :                     rStream.SeekRel( nLength - 2 );
     653           3 :                     std::map<sal_uInt16, ScPatternAttr>::iterator loc = aLotusPatternPool.find( nData );
     654             :                     // #126338# apparently, files with invalid index occur in the wild -> don't crash then
     655           3 :                     if ( loc != aLotusPatternPool.end() )
     656           6 :                         for( int i = 0; i < nTabCount; i++)
     657             :                         {
     658           3 :                             pDoc->ApplyPatternAreaTab( nCol, nRow, nCol +  nColCount - 1, nRow + nRowCount - 1, static_cast< SCTAB >( nTab + i ), loc->second );
     659             :                         }
     660             :                 }
     661             :                 else
     662           0 :                     rStream.SeekRel( nLength );
     663           3 :                 break;
     664             :             default:
     665           3 :                 rStream.SeekRel( nLength );
     666           3 :                 break;
     667             :         }
     668             :     }
     669          32 :     while( nLevel && !rStream.IsEof() );
     670             : 
     671           1 :     aLotusPatternPool.clear();
     672           1 : }
     673             : 
     674             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10