Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <string.h>
21 : #include <osl/endian.h>
22 : #include <tools/stream.hxx>
23 : #include <tools/fract.hxx>
24 : #include <vcl/gdimtf.hxx>
25 : #include <tools/color.hxx>
26 : #include <vcl/virdev.hxx>
27 : #include "sgffilt.hxx"
28 : #include "sgfbram.hxx"
29 : #include <boost/scoped_array.hpp>
30 :
31 4 : SgfHeader::SgfHeader()
32 : {
33 4 : memset( this, 0, sizeof( SgfHeader ) );
34 4 : }
35 :
36 4 : SvStream& ReadSgfHeader(SvStream& rIStream, SgfHeader& rHead)
37 : {
38 4 : rIStream.Read(&rHead.Magic, SgfHeaderSize);
39 : #if defined OSL_BIGENDIAN
40 : rHead.Magic =OSL_SWAPWORD(rHead.Magic );
41 : rHead.Version=OSL_SWAPWORD(rHead.Version);
42 : rHead.Typ =OSL_SWAPWORD(rHead.Typ );
43 : rHead.Xsize =OSL_SWAPWORD(rHead.Xsize );
44 : rHead.Ysize =OSL_SWAPWORD(rHead.Ysize );
45 : rHead.Xoffs =OSL_SWAPWORD(rHead.Xoffs );
46 : rHead.Yoffs =OSL_SWAPWORD(rHead.Yoffs );
47 : rHead.Planes =OSL_SWAPWORD(rHead.Planes );
48 : rHead.SwGrCol=OSL_SWAPWORD(rHead.SwGrCol);
49 : rHead.OfsLo =OSL_SWAPWORD(rHead.OfsLo );
50 : rHead.OfsHi =OSL_SWAPWORD(rHead.OfsHi );
51 : #endif
52 4 : return rIStream;
53 : }
54 :
55 4 : bool SgfHeader::ChkMagic()
56 4 : { return Magic=='J'*256+'J'; }
57 :
58 2 : sal_uInt32 SgfHeader::GetOffset()
59 2 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
60 :
61 2 : SgfEntry::SgfEntry()
62 : {
63 2 : memset( this, 0, sizeof( SgfEntry ) );
64 2 : }
65 :
66 4 : SvStream& ReadSgfEntry(SvStream& rIStream, SgfEntry& rEntr)
67 : {
68 4 : rIStream.Read(&rEntr.Typ, SgfEntrySize);
69 : #if defined OSL_BIGENDIAN
70 : rEntr.Typ =OSL_SWAPWORD(rEntr.Typ );
71 : rEntr.iFrei=OSL_SWAPWORD(rEntr.iFrei);
72 : rEntr.lFreiLo=OSL_SWAPWORD (rEntr.lFreiLo);
73 : rEntr.lFreiHi=OSL_SWAPWORD (rEntr.lFreiHi);
74 : rEntr.OfsLo=OSL_SWAPWORD(rEntr.OfsLo);
75 : rEntr.OfsHi=OSL_SWAPWORD(rEntr.OfsHi);
76 : #endif
77 4 : return rIStream;
78 : }
79 :
80 4 : sal_uInt32 SgfEntry::GetOffset()
81 4 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
82 :
83 0 : SvStream& ReadSgfVector(SvStream& rIStream, SgfVector& rVect)
84 : {
85 0 : rIStream.Read(&rVect, sizeof(rVect));
86 : #if defined OSL_BIGENDIAN
87 : rVect.Flag =OSL_SWAPWORD(rVect.Flag );
88 : rVect.x =OSL_SWAPWORD(rVect.x );
89 : rVect.y =OSL_SWAPWORD(rVect.y );
90 : rVect.OfsLo=OSL_SWAPDWORD (rVect.OfsLo);
91 : rVect.OfsHi=OSL_SWAPDWORD (rVect.OfsHi);
92 : #endif
93 0 : return rIStream;
94 : }
95 :
96 0 : SvStream& WriteBmpFileHeader(SvStream& rOStream, BmpFileHeader& rHead)
97 : {
98 : #if defined OSL_BIGENDIAN
99 : rHead.Typ =OSL_SWAPWORD(rHead.Typ );
100 : rHead.SizeLo =OSL_SWAPWORD(rHead.SizeLo );
101 : rHead.SizeHi =OSL_SWAPWORD(rHead.SizeHi );
102 : rHead.Reserve1=OSL_SWAPWORD(rHead.Reserve1);
103 : rHead.Reserve2=OSL_SWAPWORD(rHead.Reserve2);
104 : rHead.OfsLo =OSL_SWAPWORD(rHead.OfsLo );
105 : rHead.OfsHi =OSL_SWAPWORD(rHead.OfsHi );
106 : #endif
107 0 : rOStream.Write(&rHead, sizeof(rHead));
108 : #if defined OSL_BIGENDIAN
109 : rHead.Typ =OSL_SWAPWORD(rHead.Typ );
110 : rHead.SizeLo =OSL_SWAPWORD(rHead.SizeLo );
111 : rHead.SizeHi =OSL_SWAPWORD(rHead.SizeHi );
112 : rHead.Reserve1=OSL_SWAPWORD(rHead.Reserve1);
113 : rHead.Reserve2=OSL_SWAPWORD(rHead.Reserve2);
114 : rHead.OfsLo =OSL_SWAPWORD(rHead.OfsLo );
115 : rHead.OfsHi =OSL_SWAPWORD(rHead.OfsHi );
116 : #endif
117 0 : return rOStream;
118 : }
119 :
120 0 : void BmpFileHeader::SetSize(sal_uInt32 Size)
121 : {
122 0 : SizeLo=sal_uInt16(Size & 0x0000FFFF);
123 0 : SizeHi=sal_uInt16((Size & 0xFFFF0000)>>16);
124 0 : }
125 :
126 0 : void BmpFileHeader::SetOfs(sal_uInt32 Ofs)
127 : {
128 0 : OfsLo=sal_uInt16(Ofs & 0x0000FFFF);
129 0 : OfsHi=sal_uInt16((Ofs & 0xFFFF0000)>>16);
130 0 : }
131 :
132 0 : sal_uInt32 BmpFileHeader::GetOfs()
133 : {
134 0 : return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi);
135 : }
136 :
137 0 : SvStream& WriteBmpInfoHeader(SvStream& rOStream, BmpInfoHeader& rInfo)
138 : {
139 : #if defined OSL_BIGENDIAN
140 : rInfo.Size =OSL_SWAPDWORD (rInfo.Size );
141 : rInfo.Width =OSL_SWAPDWORD (rInfo.Width );
142 : rInfo.Hight =OSL_SWAPDWORD (rInfo.Hight );
143 : rInfo.Planes =OSL_SWAPWORD(rInfo.Planes );
144 : rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
145 : rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
146 : rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
147 : rInfo.xDpmm =OSL_SWAPDWORD (rInfo.xDpmm );
148 : rInfo.yDpmm =OSL_SWAPDWORD (rInfo.yDpmm );
149 : rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
150 : rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
151 : #endif
152 0 : rOStream.Write(&rInfo, sizeof(rInfo));
153 : #if defined OSL_BIGENDIAN
154 : rInfo.Size =OSL_SWAPDWORD (rInfo.Size );
155 : rInfo.Width =OSL_SWAPDWORD (rInfo.Width );
156 : rInfo.Hight =OSL_SWAPDWORD (rInfo.Hight );
157 : rInfo.Planes =OSL_SWAPWORD(rInfo.Planes );
158 : rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
159 : rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
160 : rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
161 : rInfo.xDpmm =OSL_SWAPDWORD (rInfo.xDpmm );
162 : rInfo.yDpmm =OSL_SWAPDWORD (rInfo.yDpmm );
163 : rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
164 : rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
165 : #endif
166 0 : return rOStream;
167 : }
168 :
169 0 : SvStream& WriteRGBQuad(SvStream& rOStream, const RGBQuad& rQuad)
170 : {
171 0 : rOStream.Write(&rQuad, sizeof(rQuad));
172 0 : return rOStream;
173 : }
174 :
175 : class PcxExpand
176 : {
177 : private:
178 : sal_uInt16 Count;
179 : sal_uInt8 Data;
180 : public:
181 0 : PcxExpand()
182 : : Count(0)
183 0 : , Data(0)
184 0 : {}
185 : sal_uInt8 GetByte(SvStream& rInp);
186 : };
187 :
188 0 : sal_uInt8 PcxExpand::GetByte(SvStream& rInp)
189 : {
190 0 : if (Count>0) {
191 0 : Count--;
192 : } else {
193 0 : rInp.Read(&Data, 1);
194 0 : if ((Data & 0xC0) == 0xC0) {
195 0 : Count=(Data & 0x3F) -1;
196 0 : rInp.Read(&Data, 1);
197 : }
198 : }
199 0 : return Data;
200 : }
201 :
202 0 : bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
203 : {
204 : BmpFileHeader aBmpHead;
205 : BmpInfoHeader aBmpInfo;
206 0 : sal_uInt16 nWdtInp=(rHead.Xsize+7)/8; // width of input bitmap in bytes
207 : sal_uInt16 nWdtOut; // width of output bitmap in bytes
208 : sal_uInt16 nColors; // color count (1, 16, 256)
209 : sal_uInt16 nColBits; // number of bits per pixel (2, 4, 8)
210 : sal_uInt16 i,j,k; // column/row/plane counter
211 : sal_uInt16 a,b; // helper variables
212 0 : sal_uInt8 pl1 = 0; // masks for the planes
213 0 : boost::scoped_array<sal_uInt8> pBuf; // buffer for a pixel row
214 0 : PcxExpand aPcx;
215 : sal_uLong nOfs;
216 : sal_uInt8 cRGB[4];
217 :
218 0 : if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8;
219 0 : nColors=1<<nColBits;
220 0 : nWdtOut=((rHead.Xsize*nColBits+31)/32)*4;
221 0 : aBmpHead.Typ='B'+'M'*256;
222 0 : aBmpHead.SetOfs(sizeof(aBmpHead)+sizeof(aBmpInfo)+nColors*4);
223 0 : aBmpHead.SetSize(aBmpHead.GetOfs()+nWdtOut*rHead.Ysize);
224 0 : aBmpHead.Reserve1=0;
225 0 : aBmpHead.Reserve2=0;
226 0 : aBmpInfo.Size=sizeof(aBmpInfo);
227 0 : aBmpInfo.Width=rHead.Xsize;
228 0 : aBmpInfo.Hight=rHead.Ysize;
229 0 : aBmpInfo.Planes=1;
230 0 : aBmpInfo.PixBits=nColBits;
231 0 : aBmpInfo.Compress=0;
232 0 : aBmpInfo.ImgSize=0;
233 0 : aBmpInfo.xDpmm=0;
234 0 : aBmpInfo.yDpmm=0;
235 0 : aBmpInfo.ColUsed=0;
236 0 : aBmpInfo.ColMust=0;
237 0 : pBuf.reset(new sal_uInt8[nWdtOut]);
238 0 : if (!pBuf) return false; // error: no more memory available
239 0 : WriteBmpFileHeader( rOut, aBmpHead );
240 0 : WriteBmpInfoHeader( rOut, aBmpInfo );
241 0 : memset(pBuf.get(),0,nWdtOut); // fill buffer with zeroes
242 :
243 0 : if (nColors==2)
244 : {
245 :
246 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
247 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
248 0 : nOfs=rOut.Tell();
249 0 : for (j=0;j<rHead.Ysize;j++)
250 0 : rOut.Write(pBuf.get(), nWdtOut); // fill file with zeroes
251 0 : for (j=0;j<rHead.Ysize;j++) {
252 0 : for(i=0;i<nWdtInp;i++) {
253 0 : pBuf[i]=aPcx.GetByte(rInp);
254 : }
255 0 : for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
256 0 : rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
257 0 : rOut.Write(pBuf.get(), nWdtOut);
258 : }
259 0 : } else if (nColors==16) {
260 0 : sal_uInt8 pl2= 0; // planes' masks
261 :
262 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
263 0 : WriteRGBQuad( rOut, RGBQuad(0x24,0x24,0x24) ); // gray 80%
264 0 : WriteRGBQuad( rOut, RGBQuad(0x49,0x49,0x49) ); // gray 60%
265 0 : WriteRGBQuad( rOut, RGBQuad(0x92,0x92,0x92) ); // gray 40%
266 0 : WriteRGBQuad( rOut, RGBQuad(0x6D,0x6D,0x6D) ); // gray 30%
267 0 : WriteRGBQuad( rOut, RGBQuad(0xB6,0xB6,0xB6) ); // gray 20%
268 0 : WriteRGBQuad( rOut, RGBQuad(0xDA,0xDA,0xDA) ); // gray 10%
269 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
270 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
271 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0x00,0x00) ); // red
272 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0xFF) ); // blue
273 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0x00,0xFF) ); // magenta
274 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0xFF,0x00) ); // green
275 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0x00) ); // yellow
276 0 : WriteRGBQuad( rOut, RGBQuad(0x00,0xFF,0xFF) ); // cyan
277 0 : WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
278 :
279 0 : nOfs=rOut.Tell();
280 0 : for (j=0;j<rHead.Ysize;j++)
281 0 : rOut.Write(pBuf.get(), nWdtOut); // fill file with zeroes
282 0 : for (j=0;j<rHead.Ysize;j++) {
283 0 : memset(pBuf.get(),0,nWdtOut);
284 0 : for(k=0;k<4;k++) {
285 0 : if (k==0) {
286 0 : pl1=0x10; pl2=0x01;
287 : } else {
288 0 : pl1<<=1; pl2<<=1;
289 : }
290 0 : for(i=0;i<nWdtInp;i++) {
291 0 : a=i*4;
292 0 : b=aPcx.GetByte(rInp);
293 0 : if (b & 0x80) pBuf[a ]|=pl1;
294 0 : if (b & 0x40) pBuf[a ]|=pl2;
295 0 : if (b & 0x20) pBuf[a+1]|=pl1;
296 0 : if (b & 0x10) pBuf[a+1]|=pl2;
297 0 : if (b & 0x08) pBuf[a+2]|=pl1;
298 0 : if (b & 0x04) pBuf[a+2]|=pl2;
299 0 : if (b & 0x02) pBuf[a+3]|=pl1;
300 0 : if (b & 0x01) pBuf[a+3]|=pl2;
301 : }
302 : }
303 0 : for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
304 0 : rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
305 0 : rOut.Write(pBuf.get(), nWdtOut);
306 : }
307 0 : } else if (nColors==256) {
308 0 : cRGB[3]=0; // fourth palette entry for BMP
309 0 : for (i=0;i<256;i++) { // copy palette
310 0 : rInp.Read(cRGB, 3);
311 0 : pl1=cRGB[0]; // switch red and blue
312 0 : cRGB[0]=cRGB[2];
313 0 : cRGB[2]=pl1;
314 0 : rOut.Write(cRGB, 4);
315 : }
316 :
317 0 : nOfs=rOut.Tell();
318 0 : for (j=0;j<rHead.Ysize;j++)
319 0 : rOut.Write(pBuf.get(), nWdtOut); // fill file with zeroes
320 0 : for (j=0;j<rHead.Ysize;j++) {
321 0 : for(i=0;i<rHead.Xsize;i++)
322 0 : pBuf[i]=aPcx.GetByte(rInp);
323 0 : for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
324 0 : rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
325 0 : rOut.Write(pBuf.get(), nWdtOut);
326 : }
327 : }
328 0 : return true;
329 : }
330 :
331 0 : bool SgfBMapFilter(SvStream& rInp, SvStream& rOut)
332 : {
333 : sal_uLong nFileStart; // offset of SgfHeaders. Usually 0.
334 0 : SgfHeader aHead;
335 0 : SgfEntry aEntr;
336 : sal_uLong nNext;
337 0 : bool bRdFlag=false; // read graphics entry?
338 0 : bool bRet=false; // return value
339 :
340 0 : nFileStart=rInp.Tell();
341 0 : ReadSgfHeader( rInp, aHead );
342 0 : if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 ||
343 0 : aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) {
344 0 : nNext=aHead.GetOffset();
345 0 : while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) {
346 0 : rInp.Seek(nFileStart+nNext);
347 0 : ReadSgfEntry( rInp, aEntr );
348 0 : nNext=aEntr.GetOffset();
349 0 : if (aEntr.Typ==aHead.Typ) {
350 0 : bRdFlag=true;
351 0 : switch(aEntr.Typ) {
352 : case SgfBitImag0:
353 : case SgfBitImag1:
354 : case SgfBitImag2:
355 0 : case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break;
356 : }
357 : }
358 : } // while(nNext)
359 : }
360 0 : if (rInp.GetError()) bRet=false;
361 0 : return bRet;
362 : }
363 :
364 : // for StarDraw embedded SGF vector
365 : long SgfVectXofs=0;
366 : long SgfVectYofs=0;
367 : long SgfVectXmul=0;
368 : long SgfVectYmul=0;
369 : long SgfVectXdiv=0;
370 : long SgfVectYdiv=0;
371 : bool SgfVectScal=false;
372 :
373 0 : Color Hpgl2SvFarbe( sal_uInt8 nFarb )
374 : {
375 0 : sal_uLong nColor = COL_BLACK;
376 :
377 0 : switch (nFarb & 0x07) {
378 0 : case 0: nColor=COL_WHITE; break;
379 0 : case 1: nColor=COL_YELLOW; break;
380 0 : case 2: nColor=COL_LIGHTMAGENTA; break;
381 0 : case 3: nColor=COL_LIGHTRED; break;
382 0 : case 4: nColor=COL_LIGHTCYAN; break;
383 0 : case 5: nColor=COL_LIGHTGREEN; break;
384 0 : case 6: nColor=COL_LIGHTBLUE; break;
385 0 : case 7: nColor=COL_BLACK; break;
386 : }
387 0 : Color aColor( nColor );
388 0 : return aColor;
389 : }
390 :
391 0 : bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf)
392 : {
393 0 : ScopedVclPtrInstance< VirtualDevice > aOutDev;
394 : SgfVector aVect;
395 : sal_uInt8 nFarb;
396 0 : sal_uInt8 nFrb0=7;
397 : sal_uInt8 nLTyp;
398 : sal_uInt8 nOTyp;
399 0 : bool bEoDt=false;
400 0 : Point aP0(0,0);
401 0 : Point aP1(0,0);
402 0 : sal_uInt16 RecNr=0;
403 :
404 0 : rMtf.Record(aOutDev.get());
405 0 : aOutDev->SetLineColor(Color(COL_BLACK));
406 0 : aOutDev->SetFillColor(Color(COL_BLACK));
407 :
408 0 : while (!bEoDt && !rInp.GetError()) {
409 0 : ReadSgfVector( rInp, aVect ); RecNr++;
410 0 : nFarb=(sal_uInt8) (aVect.Flag & 0x000F);
411 0 : nLTyp=(sal_uInt8)((aVect.Flag & 0x00F0) >>4);
412 0 : nOTyp=(sal_uInt8)((aVect.Flag & 0x0F00) >>8);
413 0 : bEoDt=(aVect.Flag & 0x4000) !=0;
414 0 : bool bPDwn=(aVect.Flag & 0x8000) !=0;
415 :
416 0 : long x=aVect.x-rHead.Xoffs;
417 0 : long y=rHead.Ysize-(aVect.y-rHead.Yoffs);
418 0 : if (SgfVectScal) {
419 0 : if (SgfVectXdiv==0) SgfVectXdiv=rHead.Xsize;
420 0 : if (SgfVectYdiv==0) SgfVectYdiv=rHead.Ysize;
421 0 : if (SgfVectXdiv==0) SgfVectXdiv=1;
422 0 : if (SgfVectYdiv==0) SgfVectYdiv=1;
423 0 : x=SgfVectXofs+ x *SgfVectXmul /SgfVectXdiv;
424 0 : y=SgfVectYofs+ y *SgfVectXmul /SgfVectYdiv;
425 : }
426 0 : aP1=Point(x,y);
427 0 : if (!bEoDt && !rInp.GetError()) {
428 0 : if (bPDwn && nLTyp<=6) {
429 0 : switch(nOTyp) {
430 0 : case 1: if (nFarb!=nFrb0) {
431 0 : switch(rHead.SwGrCol) {
432 0 : case SgfVectFarb: aOutDev->SetLineColor(Hpgl2SvFarbe(nFarb)); break;
433 0 : case SgfVectGray: break;
434 0 : case SgfVectWdth: break;
435 : }
436 : }
437 0 : aOutDev->DrawLine(aP0,aP1); break; // line
438 0 : case 2: break; // circle
439 0 : case 3: break; // text
440 0 : case 5: aOutDev->DrawRect(Rectangle(aP0,aP1)); break; // rectangle (solid)
441 : }
442 : }
443 0 : aP0=aP1;
444 0 : nFrb0=nFarb;
445 : }
446 : }
447 0 : rMtf.Stop();
448 0 : rMtf.WindStart();
449 : MapMode aMap( MAP_10TH_MM, Point(),
450 0 : Fraction( 1, 4 ), Fraction( 1, 4 ) );
451 0 : rMtf.SetPrefMapMode( aMap );
452 0 : rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) );
453 0 : return true;
454 : }
455 :
456 0 : bool SgfVectFilter(SvStream& rInp, GDIMetaFile& rMtf)
457 : {
458 : sal_uLong nFileStart; // offset of SgfHeaders. Usually 0.
459 0 : SgfHeader aHead;
460 0 : SgfEntry aEntr;
461 : sal_uLong nNext;
462 0 : bool bRet=false; // return value
463 :
464 0 : nFileStart=rInp.Tell();
465 0 : ReadSgfHeader( rInp, aHead );
466 0 : if (aHead.ChkMagic() && aHead.Typ==SGF_SIMPVECT) {
467 0 : nNext=aHead.GetOffset();
468 0 : while (nNext && !rInp.GetError()) {
469 0 : rInp.Seek(nFileStart+nNext);
470 0 : ReadSgfEntry( rInp, aEntr );
471 0 : nNext=aEntr.GetOffset();
472 0 : if (aEntr.Typ==aHead.Typ) {
473 0 : bRet=SgfFilterVect(rInp,aHead,aEntr,rMtf);
474 : }
475 : } // while(nNext)
476 : }
477 0 : return bRet;
478 : }
479 :
480 : /*************************************************************************
481 : |*
482 : |* CheckSgfTyp()
483 : |*
484 : |* Description determine which kind of SGF/SGV it is
485 : |*
486 : *************************************************************************/
487 2 : sal_uInt8 CheckSgfTyp(SvStream& rInp, sal_uInt16& nVersion)
488 : {
489 : #if OSL_DEBUG_LEVEL > 1 // check record size, new Compiler had different alignment!
490 : if (sizeof(SgfHeader)!=SgfHeaderSize ||
491 : sizeof(SgfEntry) !=SgfEntrySize ||
492 : sizeof(SgfVector)!=SgfVectorSize ||
493 : sizeof(BmpFileHeader)!=BmpFileHeaderSize ||
494 : sizeof(BmpInfoHeader)!=BmpInfoHeaderSize ||
495 : sizeof(RGBQuad )!=RGBQuadSize ) return SGF_DONTKNOW;
496 : #endif
497 :
498 : sal_uLong nPos;
499 2 : SgfHeader aHead;
500 2 : nVersion=0;
501 2 : nPos=rInp.Tell();
502 2 : ReadSgfHeader( rInp, aHead );
503 2 : rInp.Seek(nPos);
504 2 : if (aHead.ChkMagic()) {
505 2 : nVersion=aHead.Version;
506 2 : switch(aHead.Typ) {
507 : case SgfBitImag0:
508 : case SgfBitImag1:
509 : case SgfBitImag2:
510 0 : case SgfBitImgMo: return SGF_BITIMAGE;
511 0 : case SgfSimpVect: return SGF_SIMPVECT;
512 0 : case SgfPostScrp: return SGF_POSTSCRP;
513 2 : case SgfStarDraw: return SGF_STARDRAW;
514 0 : default : return SGF_DONTKNOW;
515 : }
516 : } else {
517 0 : return SGF_DONTKNOW;
518 : }
519 : }
520 :
521 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|