fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / lotus / filter.cxx
blobf0ad80ebadb0b676997202dccd951561b7556945
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 // Discover WKS, WK1 und WK3; s.a op.cpp
22 #include <string.h>
23 #include <map>
25 #include "filter.hxx"
26 #include "document.hxx"
27 #include "compiler.hxx"
28 #include "scerrors.hxx"
30 #include "root.hxx"
31 #include "lotrange.hxx"
32 #include "optab.h"
33 #include "scmem.h"
34 #include "decl.h"
35 #include "tool.h"
36 #include "fprogressbar.hxx"
37 #include "lotfilter.hxx"
39 static FltError
40 generate_Opcodes(LotusContext &rContext, SvStream& aStream,
41 ScfStreamProgressBar& aPrgrsBar)
43 OPCODE_FKT *pOps;
44 int nOps;
46 switch (rContext.eTyp)
48 case eWK_1:
49 case eWK_2:
50 pOps = rContext.pOpFkt;
51 nOps = FKT_LIMIT;
52 break;
53 case eWK123:
54 pOps = rContext.pOpFkt123;
55 nOps = FKT_LIMIT123;
56 break;
57 case eWK3: return eERR_NI;
58 case eWK_Error: return eERR_FORMAT;
59 default: return eERR_UNKN_WK;
62 // #i76299# seems that SvStream::IsEof() does not work correctly
63 aStream.Seek( STREAM_SEEK_TO_END );
64 sal_Size nStrmSize = aStream.Tell();
65 aStream.Seek( STREAM_SEEK_TO_BEGIN );
66 while( !rContext.bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
68 sal_uInt16 nOpcode, nLength;
70 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
71 aPrgrsBar.Progress();
72 if( nOpcode == LOTUS_EOF )
73 rContext.bEOF = true;
74 else if( nOpcode == LOTUS_FILEPASSWD )
75 return eERR_FILEPASSWD;
76 else if( nOpcode < nOps )
77 pOps[ nOpcode ] (rContext, aStream, nLength);
78 else if (rContext.eTyp == eWK123 && nOpcode == LOTUS_PATTERN)
80 // This is really ugly - needs re-factoring ...
81 aStream.SeekRel(nLength);
82 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
83 if ( nOpcode == 0x29a)
85 aStream.SeekRel(nLength);
86 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
87 if ( nOpcode == 0x804 )
89 aStream.SeekRel(nLength);
90 OP_ApplyPatternArea123(rContext, aStream);
92 else
93 aStream.SeekRel(nLength);
95 else
96 aStream.SeekRel(nLength);
98 else
99 aStream.SeekRel( nLength );
102 MemDelete(rContext);
104 rContext.pDoc->CalcAfterLoad();
106 return eERR_OK;
109 WKTYP ScanVersion(LotusContext &rContext, SvStream& aStream)
111 // PREC: pWKDatei: pointer to open file
112 // POST: return: type of file
113 sal_uInt16 nOpcode(0), nVersNr(0), nRecLen(0);
115 // first byte has to be 0 because of BOF!
116 aStream.ReadUInt16( nOpcode );
117 if (nOpcode != rContext.nBOF)
118 return eWK_UNKNOWN;
120 aStream.ReadUInt16( nRecLen ).ReadUInt16( nVersNr );
122 if( aStream.IsEof() )
123 return eWK_Error;
125 switch( nVersNr )
127 case 0x0404:
128 if( nRecLen == 2 )
129 return eWK_1;
130 else
131 return eWK_UNKNOWN;
133 case 0x0406:
134 if( nRecLen == 2 )
135 return eWK_2;
136 else
137 return eWK_UNKNOWN;
139 case 0x1000:
140 aStream.ReadUInt16( nVersNr );
141 if( aStream.IsEof() ) return eWK_Error;
142 if( nVersNr == 0x0004 && nRecLen == 26 )
143 { // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
144 sal_Char aDummy[22];
145 aStream.Read( aDummy, 22 );
146 return aStream.IsEof() ? eWK_Error : eWK3;
148 break;
149 case 0x1003:
150 if( nRecLen == 0x1a )
151 return eWK123;
152 else
153 return eWK_UNKNOWN;
154 case 0x1005:
155 if( nRecLen == 0x1a )
156 return eWK123;
157 else
158 return eWK_UNKNOWN;
161 return eWK_UNKNOWN;
164 FltError ScImportLotus123old(LotusContext& rContext, SvStream& aStream, ScDocument* pDocument, rtl_TextEncoding eSrc )
166 aStream.Seek( 0UL );
168 // make document pointer global
169 rContext.pDoc = pDocument;
170 rContext.bEOF = false;
171 rContext.eCharVon = eSrc;
173 // allocate memory
174 if( !MemNew(rContext) )
175 return eERR_NOMEM;
177 // initialize page format (only Tab 0!)
178 // initialize page format; meaning: get defaults from SC TODO:
179 //scGetPageFormat( 0, &aPage );
181 // start progressbar
182 ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
184 // detect file type
185 rContext.eTyp = ScanVersion(rContext, aStream);
186 rContext.aLotusPatternPool.clear();
188 return generate_Opcodes(rContext, aStream, aPrgrsBar);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */