xref: /trunk/main/svtools/source/filter/sgfbram.cxx (revision c82f2877)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <string.h>
28 #include <osl/endian.h>
29 #include <tools/stream.hxx>
30 #include <vcl/gdimtf.hxx>
31 #include <tools/color.hxx>
32 #include <vcl/virdev.hxx>
33 #include "sgffilt.hxx"
34 #include "sgfbram.hxx"
35 
36 /*************************************************************************
37 |*
38 |*    operator>>( SvStream&, SgfHeader& )
39 |*
40 |*    Beschreibung
41 |*    Ersterstellung    JOE 23.06.93
42 |*    Letzte Aenderung  JOE 23.06.93
43 |*
44 *************************************************************************/
operator >>(SvStream & rIStream,SgfHeader & rHead)45 SvStream& operator>>(SvStream& rIStream, SgfHeader& rHead)
46 {
47 	rIStream.Read((char*)&rHead.Magic,SgfHeaderSize);
48 #if defined OSL_BIGENDIAN
49 	rHead.Magic  =SWAPSHORT(rHead.Magic  );
50 	rHead.Version=SWAPSHORT(rHead.Version);
51 	rHead.Typ    =SWAPSHORT(rHead.Typ    );
52 	rHead.Xsize  =SWAPSHORT(rHead.Xsize  );
53 	rHead.Ysize  =SWAPSHORT(rHead.Ysize  );
54 	rHead.Xoffs  =SWAPSHORT(rHead.Xoffs  );
55 	rHead.Yoffs  =SWAPSHORT(rHead.Yoffs  );
56 	rHead.Planes =SWAPSHORT(rHead.Planes );
57 	rHead.SwGrCol=SWAPSHORT(rHead.SwGrCol);
58 	rHead.OfsLo  =SWAPSHORT(rHead.OfsLo  );
59 	rHead.OfsHi  =SWAPSHORT(rHead.OfsHi  );
60 #endif
61 	return rIStream;
62 }
63 
64 
65 /*************************************************************************
66 |*
67 |*    SgfHeader::ChkMagic()
68 |*
69 |*    Beschreibung
70 |*    Ersterstellung    JOE 23.06.93
71 |*    Letzte Aenderung  JOE 23.06.93
72 |*
73 *************************************************************************/
ChkMagic()74 sal_Bool SgfHeader::ChkMagic()
75 { return Magic=='J'*256+'J'; }
76 
GetOffset()77 sal_uInt32 SgfHeader::GetOffset()
78 { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
79 
80 
81 /*************************************************************************
82 |*
83 |*    operator>>( SvStream&, SgfEntry& )
84 |*
85 |*    Beschreibung
86 |*    Ersterstellung    JOE 23.06.93
87 |*    Letzte Aenderung  JOE 23.06.93
88 |*
89 *************************************************************************/
operator >>(SvStream & rIStream,SgfEntry & rEntr)90 SvStream& operator>>(SvStream& rIStream, SgfEntry& rEntr)
91 {
92 	rIStream.Read((char*)&rEntr.Typ,SgfEntrySize);
93 #if defined OSL_BIGENDIAN
94 	rEntr.Typ  =SWAPSHORT(rEntr.Typ  );
95 	rEntr.iFrei=SWAPSHORT(rEntr.iFrei);
96 	rEntr.lFreiLo=SWAPSHORT (rEntr.lFreiLo);
97 	rEntr.lFreiHi=SWAPSHORT (rEntr.lFreiHi);
98 	rEntr.OfsLo=SWAPSHORT(rEntr.OfsLo);
99 	rEntr.OfsHi=SWAPSHORT(rEntr.OfsHi);
100 #endif
101 	return rIStream;
102 }
103 
GetOffset()104 sal_uInt32 SgfEntry::GetOffset()
105 { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
106 
107 
108 /*************************************************************************
109 |*
110 |*    operator>>( SvStream&, SgfVector& )
111 |*
112 |*    Beschreibung
113 |*    Ersterstellung    JOE 23.06.93
114 |*    Letzte Aenderung  JOE 23.06.93
115 |*
116 *************************************************************************/
operator >>(SvStream & rIStream,SgfVector & rVect)117 SvStream& operator>>(SvStream& rIStream, SgfVector& rVect)
118 {
119 	rIStream.Read((char*)&rVect,sizeof(rVect));
120 #if defined OSL_BIGENDIAN
121 	rVect.Flag =SWAPSHORT(rVect.Flag );
122 	rVect.x    =SWAPSHORT(rVect.x    );
123 	rVect.y    =SWAPSHORT(rVect.y    );
124 	rVect.OfsLo=SWAPLONG (rVect.OfsLo);
125 	rVect.OfsHi=SWAPLONG (rVect.OfsHi);
126 #endif
127 	return rIStream;
128 }
129 
130 
131 /*************************************************************************
132 |*
133 |*    operator<<( SvStream&, BmpFileHeader& )
134 |*
135 |*    Beschreibung
136 |*    Ersterstellung    JOE 23.06.93
137 |*    Letzte Aenderung  JOE 23.06.93
138 |*
139 *************************************************************************/
operator <<(SvStream & rOStream,BmpFileHeader & rHead)140 SvStream& operator<<(SvStream& rOStream, BmpFileHeader& rHead)
141 {
142 #if defined OSL_BIGENDIAN
143 	rHead.Typ     =SWAPSHORT(rHead.Typ     );
144 	rHead.SizeLo  =SWAPSHORT(rHead.SizeLo  );
145 	rHead.SizeHi  =SWAPSHORT(rHead.SizeHi  );
146 	rHead.Reserve1=SWAPSHORT(rHead.Reserve1);
147 	rHead.Reserve2=SWAPSHORT(rHead.Reserve2);
148 	rHead.OfsLo   =SWAPSHORT(rHead.OfsLo   );
149 	rHead.OfsHi   =SWAPSHORT(rHead.OfsHi   );
150 #endif
151 	rOStream.Write((char*)&rHead,sizeof(rHead));
152 #if defined OSL_BIGENDIAN
153 	rHead.Typ     =SWAPSHORT(rHead.Typ     );
154 	rHead.SizeLo  =SWAPSHORT(rHead.SizeLo  );
155 	rHead.SizeHi  =SWAPSHORT(rHead.SizeHi  );
156 	rHead.Reserve1=SWAPSHORT(rHead.Reserve1);
157 	rHead.Reserve2=SWAPSHORT(rHead.Reserve2);
158 	rHead.OfsLo   =SWAPSHORT(rHead.OfsLo   );
159 	rHead.OfsHi   =SWAPSHORT(rHead.OfsHi   );
160 #endif
161 	return rOStream;
162 }
163 
SetSize(sal_uInt32 Size)164 void BmpFileHeader::SetSize(sal_uInt32 Size)
165 {
166 	SizeLo=sal_uInt16(Size & 0x0000FFFF);
167 	SizeHi=sal_uInt16((Size & 0xFFFF0000)>>16);
168 }
169 
SetOfs(sal_uInt32 Ofs)170 void BmpFileHeader::SetOfs(sal_uInt32 Ofs)
171 {
172 	OfsLo=sal_uInt16(Ofs & 0x0000FFFF);
173 	OfsHi=sal_uInt16((Ofs & 0xFFFF0000)>>16);
174 }
175 
GetOfs()176 sal_uInt32 BmpFileHeader::GetOfs()
177 {
178 	return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi);
179 }
180 
181 /*************************************************************************
182 |*
183 |*    operator<<( SvStream&, BmpInfoHeader& )
184 |*
185 |*    Beschreibung
186 |*    Ersterstellung    JOE 23.06.93
187 |*    Letzte Aenderung  JOE 23.06.93
188 |*
189 *************************************************************************/
operator <<(SvStream & rOStream,BmpInfoHeader & rInfo)190 SvStream& operator<<(SvStream& rOStream, BmpInfoHeader& rInfo)
191 {
192 #if defined OSL_BIGENDIAN
193 	rInfo.Size    =SWAPLONG (rInfo.Size    );
194 	rInfo.Width   =SWAPLONG (rInfo.Width   );
195 	rInfo.Hight   =SWAPLONG (rInfo.Hight   );
196 	rInfo.Planes  =SWAPSHORT(rInfo.Planes  );
197 	rInfo.PixBits =SWAPSHORT(rInfo.PixBits );
198 	rInfo.Compress=SWAPLONG (rInfo.Compress);
199 	rInfo.ImgSize =SWAPLONG (rInfo.ImgSize );
200 	rInfo.xDpmm   =SWAPLONG (rInfo.xDpmm   );
201 	rInfo.yDpmm   =SWAPLONG (rInfo.yDpmm   );
202 	rInfo.ColUsed =SWAPLONG (rInfo.ColUsed );
203 	rInfo.ColMust =SWAPLONG (rInfo.ColMust );
204 #endif
205 	rOStream.Write((char*)&rInfo,sizeof(rInfo));
206 #if defined OSL_BIGENDIAN
207 	rInfo.Size    =SWAPLONG (rInfo.Size    );
208 	rInfo.Width   =SWAPLONG (rInfo.Width   );
209 	rInfo.Hight   =SWAPLONG (rInfo.Hight   );
210 	rInfo.Planes  =SWAPSHORT(rInfo.Planes  );
211 	rInfo.PixBits =SWAPSHORT(rInfo.PixBits );
212 	rInfo.Compress=SWAPLONG (rInfo.Compress);
213 	rInfo.ImgSize =SWAPLONG (rInfo.ImgSize );
214 	rInfo.xDpmm   =SWAPLONG (rInfo.xDpmm   );
215 	rInfo.yDpmm   =SWAPLONG (rInfo.yDpmm   );
216 	rInfo.ColUsed =SWAPLONG (rInfo.ColUsed );
217 	rInfo.ColMust =SWAPLONG (rInfo.ColMust );
218 #endif
219 	return rOStream;
220 }
221 
222 
223 /*************************************************************************
224 |*
225 |*    operator<<( SvStream&, RGBQuad& )
226 |*
227 |*    Beschreibung
228 |*    Ersterstellung    JOE 23.06.93
229 |*    Letzte Aenderung  JOE 23.06.93
230 |*
231 *************************************************************************/
operator <<(SvStream & rOStream,const RGBQuad & rQuad)232 SvStream& operator<<(SvStream& rOStream, const RGBQuad& rQuad)
233 {
234 	rOStream.Write((char*)&rQuad,sizeof(rQuad));
235 	return rOStream;
236 }
237 
238 
239 ////////////////////////////////////////////////////////////////////////////////////////////////////
240 // PcxExpand ///////////////////////////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////////////////////////////////////////
242 
243 class PcxExpand
244 {
245 private:
246 	sal_uInt16 Count;
247 	sal_uInt8   Data;
248 public:
PcxExpand()249 				  PcxExpand() { Count=0; }
250 	sal_uInt8 GetByte(SvStream& rInp);
251 };
252 
GetByte(SvStream & rInp)253 sal_uInt8 PcxExpand::GetByte(SvStream& rInp)
254 {
255 	if (Count>0) {
256 		Count--;
257 	} else {
258 		rInp.Read((char*)&Data,1);
259 		if ((Data & 0xC0) == 0xC0) {
260 			Count=(Data & 0x3F) -1;
261 			rInp.Read((char*)&Data,1);
262 		}
263 	}
264 	return Data;
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////////////////////////
268 // SgfBMapFilter ///////////////////////////////////////////////////////////////////////////////////
269 ////////////////////////////////////////////////////////////////////////////////////////////////////
270 
271 
272 /*************************************************************************
273 |*
274 |*    SgfFilterBmp()
275 |*
276 |*    Beschreibung
277 |*    Ersterstellung    JOE 23.06.93
278 |*    Letzte Aenderung  JOE 23.06.93
279 |*
280 *************************************************************************/
SgfFilterBMap(SvStream & rInp,SvStream & rOut,SgfHeader & rHead,SgfEntry &)281 sal_Bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
282 {
283 	BmpFileHeader  aBmpHead;
284 	BmpInfoHeader  aBmpInfo;
285 	sal_uInt16 nWdtInp=(rHead.Xsize+7)/8;  // Breite der Input-Bitmap in Bytes
286 	sal_uInt16         nWdtOut;            // Breite der Output-Bitmap in Bytes
287 	sal_uInt16         nColors;            // Anzahl der Farben     (1,16,256)
288 	sal_uInt16         nColBits;           // Anzahl der Bits/Pixel (2, 4,  8)
289     sal_uInt16         i,j,k;              // Spaltenzaehler, Zeilenzaehler, Planezaehler
290 	sal_uInt16         a,b;                // Hilfsvariable
291     sal_uInt8           pl1 = 0,pl2= 0;     // Masken fuer die Planes
292     sal_uInt8*          pBuf=NULL;          // Buffer fuer eine Pixelzeile
293 	PcxExpand      aPcx;
294 	sal_uLong          nOfs;
295 	sal_uInt8           cRGB[4];
296 
297 	if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8;
298 	nColors=1<<nColBits;
299 	nWdtOut=((rHead.Xsize*nColBits+31)/32)*4;
300 	aBmpHead.Typ='B'+'M'*256;
301 	aBmpHead.SetOfs(sizeof(aBmpHead)+sizeof(aBmpInfo)+nColors*4);
302 	aBmpHead.SetSize(aBmpHead.GetOfs()+nWdtOut*rHead.Ysize);
303 	aBmpHead.Reserve1=0;
304 	aBmpHead.Reserve2=0;
305 	aBmpInfo.Size=sizeof(aBmpInfo);
306 	aBmpInfo.Width=rHead.Xsize;
307 	aBmpInfo.Hight=rHead.Ysize;
308 	aBmpInfo.Planes=1;
309 	aBmpInfo.PixBits=nColBits;
310 	aBmpInfo.Compress=0;
311 	aBmpInfo.ImgSize=0;
312 	aBmpInfo.xDpmm=0;
313 	aBmpInfo.yDpmm=0;
314 	aBmpInfo.ColUsed=0;
315 	aBmpInfo.ColMust=0;
316 	pBuf=new sal_uInt8[nWdtOut];
317 	if (!pBuf) return sal_False;       // Fehler: kein Speichel da
318 	rOut<<aBmpHead<<aBmpInfo;
319     memset(pBuf,0,nWdtOut);        // Buffer mit Nullen fuellen
320 
321 	if (nColors==2)
322 	{
323 
324 		rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
325 		rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
326 		nOfs=rOut.Tell();
327 		for (j=0;j<rHead.Ysize;j++)
328             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
329 		for (j=0;j<rHead.Ysize;j++) {
330 			for(i=0;i<nWdtInp;i++) {
331 				pBuf[i]=aPcx.GetByte(rInp);
332 			}
333 			for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0;     // noch bis zu 3 Bytes
334             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
335 			rOut.Write((char*)pBuf,nWdtOut);
336 		}
337 	} else if (nColors==16) {
338 		rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
339 		rOut<<RGBQuad(0x24,0x24,0x24); // Grau 80%
340 		rOut<<RGBQuad(0x49,0x49,0x49); // Grau 60%
341 		rOut<<RGBQuad(0x92,0x92,0x92); // Grau 40%
342 		rOut<<RGBQuad(0x6D,0x6D,0x6D); // Grau 30%
343 		rOut<<RGBQuad(0xB6,0xB6,0xB6); // Grau 20%
344 		rOut<<RGBQuad(0xDA,0xDA,0xDA); // Grau 10%
345 		rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
346 		rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
347 		rOut<<RGBQuad(0xFF,0x00,0x00); // Rot
348 		rOut<<RGBQuad(0x00,0x00,0xFF); // Blau
349 		rOut<<RGBQuad(0xFF,0x00,0xFF); // Magenta
350 		rOut<<RGBQuad(0x00,0xFF,0x00); // Gruen
351 		rOut<<RGBQuad(0xFF,0xFF,0x00); // Gelb
352 		rOut<<RGBQuad(0x00,0xFF,0xFF); // Cyan
353 		rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
354 
355 		nOfs=rOut.Tell();
356 		for (j=0;j<rHead.Ysize;j++)
357             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
358 		for (j=0;j<rHead.Ysize;j++) {
359 			memset(pBuf,0,nWdtOut);
360 			for(k=0;k<4;k++) {
361 				if (k==0) {
362 					pl1=0x10; pl2=0x01;
363 				} else {
364 					pl1<<=1; pl2<<=1;
365 				}
366 				for(i=0;i<nWdtInp;i++) {
367 					a=i*4;
368 					b=aPcx.GetByte(rInp);
369 					if (b & 0x80) pBuf[a  ]|=pl1;
370 					if (b & 0x40) pBuf[a  ]|=pl2;
371 					if (b & 0x20) pBuf[a+1]|=pl1;
372 					if (b & 0x10) pBuf[a+1]|=pl2;
373 					if (b & 0x08) pBuf[a+2]|=pl1;
374 					if (b & 0x04) pBuf[a+2]|=pl2;
375 					if (b & 0x02) pBuf[a+3]|=pl1;
376 					if (b & 0x01) pBuf[a+3]|=pl2;
377 				}
378 			}
379 			for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0;            // noch bis zu 3 Bytes
380             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
381 			rOut.Write((char*)pBuf,nWdtOut);
382 		}
383 	} else if (nColors==256) {
384         cRGB[3]=0;                      // der 4. Paletteneintrag fuer BMP
385 		for (i=0;i<256;i++) {           // Palette kopieren
386 			rInp.Read((char*)cRGB,3);
387 			pl1=cRGB[0];                // Rot mit Blau tauschen
388 			cRGB[0]=cRGB[2];
389 			cRGB[2]=pl1;
390 			rOut.Write((char*)cRGB,4);
391 		}
392 
393 		nOfs=rOut.Tell();
394 		for (j=0;j<rHead.Ysize;j++)
395             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
396 		for (j=0;j<rHead.Ysize;j++) {
397 			for(i=0;i<rHead.Xsize;i++)
398 				pBuf[i]=aPcx.GetByte(rInp);
399 			for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0;          // noch bis zu 3 Bytes
400             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
401 			rOut.Write((char*)pBuf,nWdtOut);
402 		}
403 	}
404 	delete[] pBuf;
405 	return sal_True;
406 }
407 
408 
409 /*************************************************************************
410 |*
411 |*    SgfBMapFilter()
412 |*
413 |*    Beschreibung
414 |*    Ersterstellung    JOE 23.06.93
415 |*    Letzte Aenderung  JOE 23.06.93
416 |*
417 *************************************************************************/
SgfBMapFilter(SvStream & rInp,SvStream & rOut)418 sal_Bool SgfBMapFilter(SvStream& rInp, SvStream& rOut)
419 {
420 	sal_uLong     nFileStart;            // Offset des SgfHeaders. Im allgemeinen 0.
421 	SgfHeader aHead;
422 	SgfEntry  aEntr;
423 	sal_uLong     nNext;
424 	sal_Bool      bRdFlag=sal_False;         // Grafikentry gelesen ?
425 	sal_Bool      bRet=sal_False;            // Returncode
426 
427 	nFileStart=rInp.Tell();
428 	rInp>>aHead;
429 	if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 ||
430 							 aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) {
431 		nNext=aHead.GetOffset();
432 		while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) {
433 			rInp.Seek(nFileStart+nNext);
434 			rInp>>aEntr;
435 			nNext=aEntr.GetOffset();
436 			if (aEntr.Typ==aHead.Typ) {
437 				bRdFlag=sal_True;
438 				switch(aEntr.Typ) {
439 					case SgfBitImag0:
440 					case SgfBitImag1:
441 					case SgfBitImag2:
442 					case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break;
443 				}
444 			}
445 		} // while(nNext)
446 	}
447 	if (rInp.GetError()) bRet=sal_False;
448 	return(bRet);
449 }
450 
451 
452 ////////////////////////////////////////////////////////////////////////////////////////////////////
453 // SgfVectFilter ///////////////////////////////////////////////////////////////////////////////////
454 ////////////////////////////////////////////////////////////////////////////////////////////////////
455 
456 // Fuer StarDraw Embedded SGF-Vector
457 long SgfVectXofs=0;
458 long SgfVectYofs=0;
459 long SgfVectXmul=0;
460 long SgfVectYmul=0;
461 long SgfVectXdiv=0;
462 long SgfVectYdiv=0;
463 sal_Bool SgfVectScal=sal_False;
464 
465 ////////////////////////////////////////////////////////////
466 // Hpgl2SvFarbe ////////////////////////////////////////////
467 ////////////////////////////////////////////////////////////
468 
Hpgl2SvFarbe(sal_uInt8 nFarb)469 Color Hpgl2SvFarbe( sal_uInt8 nFarb )
470 {
471 	sal_uLong nColor = COL_BLACK;
472 
473 	switch (nFarb & 0x07) {
474 		case 0:  nColor=COL_WHITE;        break;
475 		case 1:  nColor=COL_YELLOW;       break;
476 		case 2:  nColor=COL_LIGHTMAGENTA; break;
477 		case 3:  nColor=COL_LIGHTRED;     break;
478 		case 4:  nColor=COL_LIGHTCYAN;    break;
479 		case 5:  nColor=COL_LIGHTGREEN;   break;
480 		case 6:  nColor=COL_LIGHTBLUE;    break;
481 		case 7:  nColor=COL_BLACK;        break;
482 	}
483 	Color aColor( nColor );
484 	return aColor;
485 }
486 
487 /*************************************************************************
488 |*
489 |*    SgfFilterVect()
490 |*
491 |*    Beschreibung
492 |*    Ersterstellung    JOE 23.06.93
493 |*    Letzte Aenderung  JOE 23.06.93
494 |*
495 *************************************************************************/
SgfFilterVect(SvStream & rInp,SgfHeader & rHead,SgfEntry &,GDIMetaFile & rMtf)496 sal_Bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf)
497 {
498 	VirtualDevice aOutDev;
499 	SgfVector aVect;
500 	sal_uInt8      nFarb;
501 	sal_uInt8      nFrb0=7;
502 	sal_uInt8      nLTyp;
503 	sal_uInt8      nOTyp;
504 	sal_Bool      bEoDt=sal_False;
505 	sal_Bool      bPDwn=sal_False;
506 	Point     aP0(0,0);
507 	Point     aP1(0,0);
508 	String    Msg;
509 	sal_uInt16    RecNr=0;
510 
511 	rMtf.Record(&aOutDev);
512 	aOutDev.SetLineColor(Color(COL_BLACK));
513 	aOutDev.SetFillColor(Color(COL_BLACK));
514 
515 	while (!bEoDt && !rInp.GetError()) {
516 		rInp>>aVect; RecNr++;
517 		nFarb=(sal_uInt8) (aVect.Flag & 0x000F);
518 		nLTyp=(sal_uInt8)((aVect.Flag & 0x00F0) >>4);
519 		nOTyp=(sal_uInt8)((aVect.Flag & 0x0F00) >>8);
520 		bEoDt=(aVect.Flag & 0x4000) !=0;
521 		bPDwn=(aVect.Flag & 0x8000) !=0;
522 
523 		long x=aVect.x-rHead.Xoffs;
524 		long y=rHead.Ysize-(aVect.y-rHead.Yoffs);
525 		if (SgfVectScal) {
526 			if (SgfVectXdiv==0) SgfVectXdiv=rHead.Xsize;
527 			if (SgfVectYdiv==0) SgfVectYdiv=rHead.Ysize;
528 			if (SgfVectXdiv==0) SgfVectXdiv=1;
529 			if (SgfVectYdiv==0) SgfVectYdiv=1;
530 			x=SgfVectXofs+ x *SgfVectXmul /SgfVectXdiv;
531 			y=SgfVectYofs+ y *SgfVectXmul /SgfVectYdiv;
532 		}
533 		aP1=Point(x,y);
534 		if (!bEoDt && !rInp.GetError()) {
535 			if (bPDwn && nLTyp<=6) {
536 				switch(nOTyp) {
537 					case 1: if (nFarb!=nFrb0) {
538 								switch(rHead.SwGrCol) {
539 									case SgfVectFarb: aOutDev.SetLineColor(Hpgl2SvFarbe(nFarb)); break;
540 									case SgfVectGray:                          break;
541 									case SgfVectWdth:                          break;
542 								}
543 							}
544 							aOutDev.DrawLine(aP0,aP1);            break; // Linie
545 					case 2:                                       break; // Kreis
546 					case 3:                                       break; // Text
547 					case 5: aOutDev.DrawRect(Rectangle(aP0,aP1)); break; // Rechteck (solid)
548 				}
549 			}
550 			aP0=aP1;
551 			nFrb0=nFarb;
552 		}
553 	}
554 	rMtf.Stop();
555 	rMtf.WindStart();
556 	MapMode aMap( MAP_10TH_MM, Point(),
557 				  Fraction( 1, 4 ), Fraction( 1, 4 ) );
558 	rMtf.SetPrefMapMode( aMap );
559 	rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) );
560 	return sal_True;
561 }
562 
563 
564 /*************************************************************************
565 |*
566 |*    SgfVectFilter()
567 |*
568 |*    Beschreibung
569 |*    Ersterstellung    JOE 23.06.93
570 |*    Letzte Aenderung  JOE 23.06.93
571 |*
572 *************************************************************************/
SgfVectFilter(SvStream & rInp,GDIMetaFile & rMtf)573 sal_Bool SgfVectFilter(SvStream& rInp, GDIMetaFile& rMtf)
574 {
575 	sal_uLong     nFileStart;            // Offset des SgfHeaders. Im allgemeinen 0.
576 	SgfHeader aHead;
577 	SgfEntry  aEntr;
578 	sal_uLong     nNext;
579 	sal_Bool      bRdFlag=sal_False;         // Grafikentry gelesen ?
580 	sal_Bool      bRet=sal_False;            // Returncode
581 
582 	nFileStart=rInp.Tell();
583 	rInp>>aHead;
584 	if (aHead.ChkMagic() && aHead.Typ==SGF_SIMPVECT) {
585 		nNext=aHead.GetOffset();
586 		while (nNext && !bRdFlag && !rInp.GetError()) {
587 			rInp.Seek(nFileStart+nNext);
588 			rInp>>aEntr;
589 			nNext=aEntr.GetOffset();
590 			if (aEntr.Typ==aHead.Typ) {
591 				bRet=SgfFilterVect(rInp,aHead,aEntr,rMtf);
592 			}
593 		} // while(nNext)
594 		if (bRdFlag) {
595 			if (!rInp.GetError()) bRet=sal_True;  // Scheinbar Ok
596 		}
597 	}
598 	return(bRet);
599 }
600 
601 
602 /*************************************************************************
603 |*
604 |*    SgfFilterPScr()
605 |*
606 |*    Beschreibung
607 |*    Ersterstellung    JOE 23.06.93
608 |*    Letzte Aenderung  JOE 23.06.93
609 |*
610 *************************************************************************/
SgfFilterPScr(SvStream &,SgfHeader &,SgfEntry &)611 sal_Bool SgfFilterPScr(SvStream&, SgfHeader&, SgfEntry&)
612 {
613 	return sal_False;  // PostSrcipt wird noch nicht unterstuetzt !
614 }
615 
616 
617 /*************************************************************************
618 |*
619 |*    CheckSgfTyp()
620 |*
621 |*    Beschreibung      Feststellen, um was fuer ein SGF/SGV es sich handelt.
622 |*    Ersterstellung    JOE 23.06.93
623 |*    Letzte Aenderung  JOE 23.06.93
624 |*
625 *************************************************************************/
CheckSgfTyp(SvStream & rInp,sal_uInt16 & nVersion)626 sal_uInt8 CheckSgfTyp(SvStream& rInp, sal_uInt16& nVersion)
627 {
628 #if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Allignment!
629 	if (sizeof(SgfHeader)!=SgfHeaderSize ||
630 		sizeof(SgfEntry) !=SgfEntrySize  ||
631 		sizeof(SgfVector)!=SgfVectorSize ||
632 		sizeof(BmpFileHeader)!=BmpFileHeaderSize ||
633 		sizeof(BmpInfoHeader)!=BmpInfoHeaderSize ||
634 		sizeof(RGBQuad  )!=RGBQuadSize   )  return SGF_DONTKNOW;
635 #endif
636 
637 	sal_uLong     nPos;
638 	SgfHeader aHead;
639 	nVersion=0;
640 	nPos=rInp.Tell();
641 	rInp>>aHead;
642 	rInp.Seek(nPos);
643 	if (aHead.ChkMagic()) {
644 		nVersion=aHead.Version;
645 		switch(aHead.Typ) {
646 			case SgfBitImag0:
647 			case SgfBitImag1:
648 			case SgfBitImag2:
649 			case SgfBitImgMo: return SGF_BITIMAGE;
650 			case SgfSimpVect: return SGF_SIMPVECT;
651 			case SgfPostScrp: return SGF_POSTSCRP;
652 			case SgfStarDraw: return SGF_STARDRAW;
653 			default         : return SGF_DONTKNOW;
654 		}
655 	} else {
656 		return SGF_DONTKNOW;
657 	}
658 }
659