Update ooo320-m1
[ooovba.git] / goodies / source / filter.vcl / idxf / dxfgrprd.cxx
blob8eb7051b0f79eff9e6324cb4417c563d3b72b707
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfgrprd.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
34 #include <string.h>
35 #include <stdlib.h>
36 #include <tools/stream.hxx>
37 #include "dxfgrprd.hxx"
39 // ----------------------------------------------------------------------------
41 // we use an own ReadLine function, because Stream::ReadLine stops if
42 // a 0-sign occurs; this functions converts 0-signs to blanks and reads
43 // a complete line until a cr/lf is found
45 BOOL DXFReadLine( SvStream& rIStm, ByteString& rStr )
47 char buf[256 + 1];
48 BOOL bEnd = FALSE;
49 ULONG nOldFilePos = rIStm.Tell();
50 char c = 0;
52 rStr.Erase();
54 while( !bEnd && !rIStm.GetError() ) // !!! nicht auf EOF testen,
55 // !!! weil wir blockweise
56 // !!! lesen
58 USHORT nLen = (USHORT)rIStm.Read( buf, sizeof(buf)-1 );
59 if( !nLen )
61 if( rStr.Len() == 0 )
62 return FALSE;
63 else
64 break;
67 for( USHORT n = 0; n < nLen ; n++ )
69 c = buf[n];
70 if( c != '\n' && c != '\r' )
72 if( !c )
73 c = ' ';
74 rStr += c;
76 else
78 bEnd = TRUE;
79 break;
84 if( !bEnd && !rIStm.GetError() && rStr.Len() )
85 bEnd = TRUE;
87 nOldFilePos += rStr.Len();
88 if( rIStm.Tell() > nOldFilePos )
89 nOldFilePos++;
90 rIStm.Seek( nOldFilePos ); // seeken wg. obigem BlockRead!
92 if( bEnd && (c=='\r' || c=='\n')) // Sonderbehandlung DOS-Dateien
94 char cTemp;
95 rIStm.Read((char*)&cTemp , sizeof(cTemp) );
96 if( cTemp == c || (cTemp != '\n' && cTemp != '\r') )
97 rIStm.Seek( nOldFilePos );
100 return bEnd;
103 // ------------------
105 DXFGroupReader::DXFGroupReader(SvStream & rIStream, USHORT nminpercent, USHORT nmaxpercent ) :
106 rIS(rIStream)
108 USHORT i;
110 nIBuffPos=0;
111 nIBuffSize=0;
112 bStatus=TRUE;
113 nLastG=0;
114 nGCount=0;
116 nMinPercent=(ULONG)nminpercent;
117 nMaxPercent=(ULONG)nmaxpercent;
118 nLastPercent=nMinPercent;
120 rIS.Seek(STREAM_SEEK_TO_END);
121 nFileSize=rIS.Tell();
122 rIS.Seek(0);
124 for (i=0; i<10; i++) S0_9[i][0]=0;
125 S100[ 0 ] = S102[ 0 ] = 0;
126 for (i=0; i<50; i++) F10_59[i]=0.0;
127 for (i=0; i<20; i++) I60_79[i]=0;
128 for (i=0; i<10; i++) I90_99[i]=0;
129 for (i=0; i< 8; i++) F140_147[i]=0.0;
130 for (i=0; i< 6; i++) I170_175[i]=0;
131 for (i=0; i<30; i++) F210_239[i]=0.0;
132 for (i=0; i<11; i++) S999_1009[i][0]=0;
133 for (i=0; i<50; i++) F1010_1059[i]=0.0;
134 for (i=0; i<20; i++) I1060_1079[i]=0;
139 USHORT DXFGroupReader::Read()
141 sal_uInt16 nG = 0;
142 if ( bStatus )
144 nGCount++;
145 nG = (sal_uInt16)ReadI();
146 if ( bStatus )
148 char aTmp[ DXF_MAX_STRING_LEN + 1 ];
150 if (nG< 10) ReadS(S0_9[nG]);
151 else if (nG< 60) F10_59[nG-10]=ReadF();
152 else if (nG< 80) I60_79[nG-60]=ReadI();
153 else if (nG< 90) ReadS( aTmp );
154 else if (nG< 99) I90_99[nG-90]=ReadI();
155 else if (nG==100) ReadS(S100);
156 else if (nG==102) ReadS(S102);
157 else if (nG==105) ReadS( aTmp );
158 else if (nG< 140) ReadS( aTmp );
159 else if (nG< 148) F140_147[nG-140]=ReadF();
160 else if (nG< 170) ReadS( aTmp );
161 else if (nG< 176) I170_175[nG-175]=ReadI();
162 else if (nG< 180) ReadI();
163 else if (nG< 210) ReadS( aTmp );
164 else if (nG< 240) F210_239[nG-210]=ReadF();
165 else if (nG<=369) ReadS( aTmp );
166 else if (nG< 999) ReadS( aTmp );
167 else if (nG<1010) ReadS(S999_1009[nG-999]);
168 else if (nG<1060) F1010_1059[nG-1010]=ReadF();
169 else if (nG<1080) I1060_1079[nG-1060]=ReadI();
170 else bStatus = sal_False;
173 if ( bStatus )
174 nLastG = nG;
175 else
177 nG = 0;
178 SetS( 0, "EOF" );
179 if ( nGCount != 0xffffffff )
181 // InfoBox(NULL,String("Fehler ab Gruppe Nr ")+String(nGCount)).Execute();
182 nGCount=0xffffffff;
185 nLastG = nG;
186 return nG;
190 long DXFGroupReader::GetI(USHORT nG)
192 sal_Int32 nRetValue = 0;
193 if ( ( nG >= 60 ) && ( nG <= 79 ) )
194 nRetValue = I60_79[ nG - 60 ];
195 else if ( ( nG >= 90 ) && ( nG <= 99 ) )
196 nRetValue = I90_99[ nG - 90 ];
197 else if ( ( nG >= 170 ) && ( nG <= 175 ) )
198 nRetValue = I170_175[ nG - 170 ];
199 else if ( ( nG >= 1060 ) && ( nG <= 1079 ) )
200 nRetValue = I1060_1079[ nG - 1060 ];
201 return nRetValue;
204 double DXFGroupReader::GetF(USHORT nG)
206 nG-=10;
207 if (nG<50) return F10_59[nG];
208 else {
209 nG-=130;
210 if (nG<8) return F140_147[nG];
211 else {
212 nG-=70;
213 if (nG<30) return F210_239[nG];
214 else {
215 nG-=800;
216 if (nG<50) return F1010_1059[nG];
217 else return 0;
223 const char * DXFGroupReader::GetS(USHORT nG)
225 if (nG<10) return S0_9[nG];
226 else if ( nG == 100 )
227 return S100;
228 else if ( nG == 102 )
229 return S102;
230 else
232 nG-=999;
233 if (nG<11) return S999_1009[nG];
234 else return NULL;
238 void DXFGroupReader::SetF(USHORT nG, double fF)
240 nG-=10;
241 if (nG<50) F10_59[nG]=fF;
242 else {
243 nG-=130;
244 if (nG<8) F140_147[nG]=fF;
245 else {
246 nG-=70;
247 if (nG<30) F210_239[nG]=fF;
248 else {
249 nG-=800;
250 if (nG<50) F1010_1059[nG]=fF;
257 void DXFGroupReader::SetS(USHORT nG, const char * sS)
259 char* pPtr = NULL;
260 if ( nG < 10 )
261 pPtr = S0_9[ nG ];
262 else if ( nG == 100 )
263 pPtr = S100;
264 else if ( nG == 102 )
265 pPtr = S102;
266 else
268 nG -= 999;
269 if ( nG < 11 )
270 pPtr = S999_1009[ nG ];
272 if ( pPtr )
273 strncpy( pPtr, sS, DXF_MAX_STRING_LEN + 1 );
277 void DXFGroupReader::ReadLine(char * ptgt)
279 ByteString aStr;
280 ULONG nLen;
282 DXFReadLine( rIS, aStr );
284 nLen = aStr.Len();
285 if ( nLen > DXF_MAX_STRING_LEN )
286 nLen = DXF_MAX_STRING_LEN;
288 memcpy( ptgt, aStr.GetBuffer(), nLen );
289 ptgt[ nLen ] = 0x00;
291 if ( pCallback )
293 const ULONG nPercent= nMinPercent + (nMaxPercent-nMinPercent)*rIS.Tell() / nFileSize;
295 if ( nPercent >= nLastPercent + 4 )
297 nLastPercent=nPercent;
298 if (((*pCallback)(pCallerData,(USHORT)nPercent))==TRUE)
299 bStatus=FALSE;
306 long DXFGroupReader::ReadI()
308 char sl[DXF_MAX_STRING_LEN+1],*p;
309 long res,nv;
311 ReadLine(sl);
313 p=sl;
315 while(*p==0x20) p++;
317 if ((*p<'0' || *p>'9') && *p!='-') {
318 bStatus=FALSE;
319 return 0;
322 if (*p=='-') {
323 nv=-1;
324 p++;
326 else nv=1;
328 res=0;
329 do {
330 res=res*10+(long)(*p-'0');
331 p++;
332 } while (*p>='0' && *p<='9');
334 while (*p==0x20) p++;
335 if (*p!=0) {
336 bStatus=FALSE;
337 return 0;
340 return res*nv;
344 double DXFGroupReader::ReadF()
346 char sl[DXF_MAX_STRING_LEN+1],*p;
348 ReadLine(sl);
349 p=sl;
350 while(*p==0x20) p++;
351 if ((*p<'0' || *p>'9') && *p!='.' && *p!='-') {
352 bStatus=FALSE;
353 return 0.0;
355 return atof(p);
359 void DXFGroupReader::ReadS(char * ptgt)
361 ReadLine(ptgt);