1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfgrprd.cxx,v $
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"
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
)
49 ULONG nOldFilePos
= rIStm
.Tell();
54 while( !bEnd
&& !rIStm
.GetError() ) // !!! nicht auf EOF testen,
55 // !!! weil wir blockweise
58 USHORT nLen
= (USHORT
)rIStm
.Read( buf
, sizeof(buf
)-1 );
67 for( USHORT n
= 0; n
< nLen
; n
++ )
70 if( c
!= '\n' && c
!= '\r' )
84 if( !bEnd
&& !rIStm
.GetError() && rStr
.Len() )
87 nOldFilePos
+= rStr
.Len();
88 if( rIStm
.Tell() > nOldFilePos
)
90 rIStm
.Seek( nOldFilePos
); // seeken wg. obigem BlockRead!
92 if( bEnd
&& (c
=='\r' || c
=='\n')) // Sonderbehandlung DOS-Dateien
95 rIStm
.Read((char*)&cTemp
, sizeof(cTemp
) );
96 if( cTemp
== c
|| (cTemp
!= '\n' && cTemp
!= '\r') )
97 rIStm
.Seek( nOldFilePos
);
103 // ------------------
105 DXFGroupReader::DXFGroupReader(SvStream
& rIStream
, USHORT nminpercent
, USHORT nmaxpercent
) :
116 nMinPercent
=(ULONG
)nminpercent
;
117 nMaxPercent
=(ULONG
)nmaxpercent
;
118 nLastPercent
=nMinPercent
;
120 rIS
.Seek(STREAM_SEEK_TO_END
);
121 nFileSize
=rIS
.Tell();
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()
145 nG
= (sal_uInt16
)ReadI();
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
;
179 if ( nGCount
!= 0xffffffff )
181 // InfoBox(NULL,String("Fehler ab Gruppe Nr ")+String(nGCount)).Execute();
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 ];
204 double DXFGroupReader::GetF(USHORT nG
)
207 if (nG
<50) return F10_59
[nG
];
210 if (nG
<8) return F140_147
[nG
];
213 if (nG
<30) return F210_239
[nG
];
216 if (nG
<50) return F1010_1059
[nG
];
223 const char * DXFGroupReader::GetS(USHORT nG
)
225 if (nG
<10) return S0_9
[nG
];
226 else if ( nG
== 100 )
228 else if ( nG
== 102 )
233 if (nG
<11) return S999_1009
[nG
];
238 void DXFGroupReader::SetF(USHORT nG
, double fF
)
241 if (nG
<50) F10_59
[nG
]=fF
;
244 if (nG
<8) F140_147
[nG
]=fF
;
247 if (nG
<30) F210_239
[nG
]=fF
;
250 if (nG
<50) F1010_1059
[nG
]=fF
;
257 void DXFGroupReader::SetS(USHORT nG
, const char * sS
)
262 else if ( nG
== 100 )
264 else if ( nG
== 102 )
270 pPtr
= S999_1009
[ nG
];
273 strncpy( pPtr
, sS
, DXF_MAX_STRING_LEN
+ 1 );
277 void DXFGroupReader::ReadLine(char * ptgt
)
282 DXFReadLine( rIS
, aStr
);
285 if ( nLen
> DXF_MAX_STRING_LEN
)
286 nLen
= DXF_MAX_STRING_LEN
;
288 memcpy( ptgt
, aStr
.GetBuffer(), nLen
);
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)
306 long DXFGroupReader::ReadI()
308 char sl
[DXF_MAX_STRING_LEN
+1],*p
;
317 if ((*p
<'0' || *p
>'9') && *p
!='-') {
330 res
=res
*10+(long)(*p
-'0');
332 } while (*p
>='0' && *p
<='9');
334 while (*p
==0x20) p
++;
344 double DXFGroupReader::ReadF()
346 char sl
[DXF_MAX_STRING_LEN
+1],*p
;
351 if ((*p
<'0' || *p
>'9') && *p
!='.' && *p
!='-') {
359 void DXFGroupReader::ReadS(char * ptgt
)