summaryrefslogtreecommitdiff
path: root/filter/source/graphicfilter/idxf/dxfgrprd.cxx
blob: f09b17e80635bfc79a0d8302ea08c3410a5f0721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_filter.hxx"

#include <string.h>
#include <stdlib.h>
#include <tools/stream.hxx>
#include "dxfgrprd.hxx"

// ----------------------------------------------------------------------------

// we use an own ReadLine function, because Stream::ReadLine stops if
// a 0-sign occurs; this functions converts 0-signs to blanks and reads
// a complete line until a cr/lf is found

BOOL DXFReadLine( SvStream& rIStm, ByteString& rStr )
{
    char  buf[256 + 1];
    BOOL  bEnd = FALSE;
    ULONG nOldFilePos = rIStm.Tell();
    char  c = 0;

    rStr.Erase();

    while( !bEnd && !rIStm.GetError() )   // !!! nicht auf EOF testen,
                                          // !!! weil wir blockweise
                                          // !!! lesen
    {
        USHORT nLen = (USHORT)rIStm.Read( buf, sizeof(buf)-1 );
        if( !nLen )
        {
            if( rStr.Len() == 0 )
                return FALSE;
            else
                break;
        }

        for( USHORT n = 0; n < nLen ; n++ )
        {
            c = buf[n];
            if( c != '\n' && c != '\r' )
            {
                if( !c )
                    c = ' ';
                rStr += c;
            }
            else
            {
                bEnd = TRUE;
                break;
            }
        }
    }

    if( !bEnd && !rIStm.GetError() && rStr.Len() )
        bEnd = TRUE;

    nOldFilePos += rStr.Len();
    if( rIStm.Tell() > nOldFilePos )
        nOldFilePos++;
    rIStm.Seek( nOldFilePos );  // seeken wg. obigem BlockRead!

    if( bEnd && (c=='\r' || c=='\n'))  // Sonderbehandlung DOS-Dateien
    {
        char cTemp;
        rIStm.Read((char*)&cTemp , sizeof(cTemp) );
        if( cTemp == c || (cTemp != '\n' && cTemp != '\r') )
            rIStm.Seek( nOldFilePos );
    }

    return bEnd;
}

// ------------------

DXFGroupReader::DXFGroupReader(SvStream & rIStream, USHORT nminpercent, USHORT nmaxpercent ) :
    rIS(rIStream)
{
    USHORT i;

    nIBuffPos=0;
    nIBuffSize=0;
    bStatus=TRUE;
    nLastG=0;
    nGCount=0;

    nMinPercent=(ULONG)nminpercent;
    nMaxPercent=(ULONG)nmaxpercent;
    nLastPercent=nMinPercent;

    rIS.Seek(STREAM_SEEK_TO_END);
    nFileSize=rIS.Tell();
    rIS.Seek(0);

    for (i=0; i<10; i++) S0_9[i][0]=0;
    S100[ 0 ] = S102[ 0 ] = 0;
    for (i=0; i<50; i++) F10_59[i]=0.0;
    for (i=0; i<20; i++) I60_79[i]=0;
    for (i=0; i<10; i++) I90_99[i]=0;
    for (i=0; i< 8; i++) F140_147[i]=0.0;
    for (i=0; i< 6; i++) I170_175[i]=0;
    for (i=0; i<30; i++) F210_239[i]=0.0;
    for (i=0; i<11; i++) S999_1009[i][0]=0;
    for (i=0; i<50; i++) F1010_1059[i]=0.0;
    for (i=0; i<20; i++) I1060_1079[i]=0;

}


USHORT DXFGroupReader::Read()
{
    sal_uInt16 nG = 0;
    if ( bStatus )
    {
        nGCount++;
        nG = (sal_uInt16)ReadI();
        if ( bStatus )
        {
            char aTmp[ DXF_MAX_STRING_LEN + 1 ];

            if      (nG<  10) ReadS(S0_9[nG]);
            else if (nG<  60) F10_59[nG-10]=ReadF();
            else if (nG<  80) I60_79[nG-60]=ReadI();
            else if (nG<  90) ReadS( aTmp );
            else if (nG<  99) I90_99[nG-90]=ReadI();
            else if (nG==100) ReadS(S100);
            else if (nG==102) ReadS(S102);
            else if (nG==105) ReadS( aTmp );
            else if (nG< 140) ReadS( aTmp );
            else if (nG< 148) F140_147[nG-140]=ReadF();
            else if (nG< 170) ReadS( aTmp );
            else if (nG< 176) I170_175[nG-175]=ReadI();
            else if (nG< 180) ReadI();
            else if (nG< 210) ReadS( aTmp );
            else if (nG< 240) F210_239[nG-210]=ReadF();
            else if (nG<=369) ReadS( aTmp );
            else if (nG< 999) ReadS( aTmp );
            else if (nG<1010) ReadS(S999_1009[nG-999]);
            else if (nG<1060) F1010_1059[nG-1010]=ReadF();
            else if (nG<1080) I1060_1079[nG-1060]=ReadI();
            else bStatus = sal_False;
        }
    }
    if ( bStatus )
        nLastG = nG;
    else
    {
        nG = 0;
        SetS( 0, "EOF" );
        if ( nGCount != 0xffffffff )
        {
            // InfoBox(NULL,String("Fehler ab Gruppe Nr ")+String(nGCount)).Execute();
            nGCount=0xffffffff;
        }
    }
    nLastG = nG;
    return nG;
}


long DXFGroupReader::GetI(USHORT nG)
{
    sal_Int32 nRetValue = 0;
    if ( ( nG >= 60 ) && ( nG <= 79 ) )
        nRetValue = I60_79[ nG - 60 ];
    else if ( ( nG >= 90 ) && ( nG <= 99 ) )
        nRetValue = I90_99[ nG - 90 ];
    else if ( ( nG >= 170 ) && ( nG <= 175 ) )
        nRetValue = I170_175[ nG - 170 ];
    else if ( ( nG >= 1060 ) && ( nG <= 1079 ) )
        nRetValue = I1060_1079[ nG - 1060 ];
    return nRetValue;
}

double DXFGroupReader::GetF(USHORT nG)
{
    nG-=10;
    if (nG<50) return F10_59[nG];
    else {
        nG-=130;
        if (nG<8) return F140_147[nG];
        else {
            nG-=70;
            if (nG<30) return F210_239[nG];
            else {
                nG-=800;
                if (nG<50) return F1010_1059[nG];
                else return 0;
            }
        }
    }
}

const char * DXFGroupReader::GetS(USHORT nG)
{
    if (nG<10) return S0_9[nG];
    else if ( nG == 100 )
        return S100;
    else if ( nG == 102 )
        return S102;
    else
    {
        nG-=999;
        if (nG<11) return S999_1009[nG];
        else return NULL;
    }
}

void DXFGroupReader::SetF(USHORT nG, double fF)
{
    nG-=10;
    if (nG<50) F10_59[nG]=fF;
    else {
        nG-=130;
        if (nG<8) F140_147[nG]=fF;
        else {
            nG-=70;
            if (nG<30) F210_239[nG]=fF;
            else {
                nG-=800;
                if (nG<50) F1010_1059[nG]=fF;
            }
        }
    }
}


void DXFGroupReader::SetS(USHORT nG, const char * sS)
{
    char* pPtr = NULL;
    if ( nG < 10 )
        pPtr = S0_9[ nG ];
    else if ( nG == 100 )
        pPtr = S100;
    else if ( nG == 102 )
        pPtr = S102;
    else
    {
        nG -= 999;
        if ( nG < 11 )
            pPtr = S999_1009[ nG ];
    }
    if ( pPtr )
        strncpy( pPtr, sS, DXF_MAX_STRING_LEN + 1 );
}


void DXFGroupReader::ReadLine(char * ptgt)
{
    ByteString  aStr;
    ULONG       nLen;

    DXFReadLine( rIS, aStr );

    nLen = aStr.Len();
    if ( nLen > DXF_MAX_STRING_LEN )
        nLen = DXF_MAX_STRING_LEN;

    memcpy( ptgt, aStr.GetBuffer(), nLen );
    ptgt[ nLen ] = 0x00;
/*
    if ( pCallback )
    {
        const ULONG nPercent= nMinPercent + (nMaxPercent-nMinPercent)*rIS.Tell() / nFileSize;

        if ( nPercent >= nLastPercent + 4 )
        {
            nLastPercent=nPercent;
            if (((*pCallback)(pCallerData,(USHORT)nPercent))==TRUE)
                bStatus=FALSE;
        }
    }
*/
}


long DXFGroupReader::ReadI()
{
    char sl[DXF_MAX_STRING_LEN+1],*p;
    long res,nv;

    ReadLine(sl);

    p=sl;

    while(*p==0x20) p++;

    if ((*p<'0' || *p>'9') && *p!='-') {
        bStatus=FALSE;
        return 0;
    }

    if (*p=='-') {
        nv=-1;
        p++;
    }
    else nv=1;

    res=0;
    do {
        res=res*10+(long)(*p-'0');
        p++;
    } while (*p>='0' && *p<='9');

    while (*p==0x20) p++;
    if (*p!=0) {
        bStatus=FALSE;
        return 0;
    }

    return res*nv;
}


double DXFGroupReader::ReadF()
{
    char sl[DXF_MAX_STRING_LEN+1],*p;

    ReadLine(sl);
    p=sl;
    while(*p==0x20) p++;
    if ((*p<'0' || *p>'9') && *p!='.' && *p!='-') {
        bStatus=FALSE;
        return 0.0;
    }
    return atof(p);
}


void DXFGroupReader::ReadS(char * ptgt)
{
    ReadLine(ptgt);
}