LCOV - code coverage report
Current view: top level - vcl/source/filter - sgfbram.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 262 0.0 %
Date: 2014-04-14 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          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 <vcl/gdimtf.hxx>
      24             : #include <tools/color.hxx>
      25             : #include <vcl/virdev.hxx>
      26             : #include "sgffilt.hxx"
      27             : #include "sgfbram.hxx"
      28             : #include <boost/scoped_array.hpp>
      29             : 
      30           0 : SgfHeader::SgfHeader()
      31             : {
      32           0 :     memset( this, 0, sizeof( SgfHeader ) );
      33           0 : }
      34             : 
      35           0 : SvStream& ReadSgfHeader(SvStream& rIStream, SgfHeader& rHead)
      36             : {
      37           0 :     rIStream.Read((char*)&rHead.Magic,SgfHeaderSize);
      38             : #if defined OSL_BIGENDIAN
      39             :     rHead.Magic  =OSL_SWAPWORD(rHead.Magic  );
      40             :     rHead.Version=OSL_SWAPWORD(rHead.Version);
      41             :     rHead.Typ    =OSL_SWAPWORD(rHead.Typ    );
      42             :     rHead.Xsize  =OSL_SWAPWORD(rHead.Xsize  );
      43             :     rHead.Ysize  =OSL_SWAPWORD(rHead.Ysize  );
      44             :     rHead.Xoffs  =OSL_SWAPWORD(rHead.Xoffs  );
      45             :     rHead.Yoffs  =OSL_SWAPWORD(rHead.Yoffs  );
      46             :     rHead.Planes =OSL_SWAPWORD(rHead.Planes );
      47             :     rHead.SwGrCol=OSL_SWAPWORD(rHead.SwGrCol);
      48             :     rHead.OfsLo  =OSL_SWAPWORD(rHead.OfsLo  );
      49             :     rHead.OfsHi  =OSL_SWAPWORD(rHead.OfsHi  );
      50             : #endif
      51           0 :     return rIStream;
      52             : }
      53             : 
      54           0 : bool SgfHeader::ChkMagic()
      55           0 : { return Magic=='J'*256+'J'; }
      56             : 
      57           0 : sal_uInt32 SgfHeader::GetOffset()
      58           0 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
      59             : 
      60           0 : SgfEntry::SgfEntry()
      61             : {
      62           0 :     memset( this, 0, sizeof( SgfEntry ) );
      63           0 : }
      64             : 
      65           0 : SvStream& ReadSgfEntry(SvStream& rIStream, SgfEntry& rEntr)
      66             : {
      67           0 :     rIStream.Read((char*)&rEntr.Typ,SgfEntrySize);
      68             : #if defined OSL_BIGENDIAN
      69             :     rEntr.Typ  =OSL_SWAPWORD(rEntr.Typ  );
      70             :     rEntr.iFrei=OSL_SWAPWORD(rEntr.iFrei);
      71             :     rEntr.lFreiLo=OSL_SWAPWORD (rEntr.lFreiLo);
      72             :     rEntr.lFreiHi=OSL_SWAPWORD (rEntr.lFreiHi);
      73             :     rEntr.OfsLo=OSL_SWAPWORD(rEntr.OfsLo);
      74             :     rEntr.OfsHi=OSL_SWAPWORD(rEntr.OfsHi);
      75             : #endif
      76           0 :     return rIStream;
      77             : }
      78             : 
      79           0 : sal_uInt32 SgfEntry::GetOffset()
      80           0 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
      81             : 
      82           0 : SvStream& ReadSgfVector(SvStream& rIStream, SgfVector& rVect)
      83             : {
      84           0 :     rIStream.Read((char*)&rVect,sizeof(rVect));
      85             : #if defined OSL_BIGENDIAN
      86             :     rVect.Flag =OSL_SWAPWORD(rVect.Flag );
      87             :     rVect.x    =OSL_SWAPWORD(rVect.x    );
      88             :     rVect.y    =OSL_SWAPWORD(rVect.y    );
      89             :     rVect.OfsLo=OSL_SWAPDWORD (rVect.OfsLo);
      90             :     rVect.OfsHi=OSL_SWAPDWORD (rVect.OfsHi);
      91             : #endif
      92           0 :     return rIStream;
      93             : }
      94             : 
      95           0 : SvStream& WriteBmpFileHeader(SvStream& rOStream, BmpFileHeader& rHead)
      96             : {
      97             : #if defined OSL_BIGENDIAN
      98             :     rHead.Typ     =OSL_SWAPWORD(rHead.Typ     );
      99             :     rHead.SizeLo  =OSL_SWAPWORD(rHead.SizeLo  );
     100             :     rHead.SizeHi  =OSL_SWAPWORD(rHead.SizeHi  );
     101             :     rHead.Reserve1=OSL_SWAPWORD(rHead.Reserve1);
     102             :     rHead.Reserve2=OSL_SWAPWORD(rHead.Reserve2);
     103             :     rHead.OfsLo   =OSL_SWAPWORD(rHead.OfsLo   );
     104             :     rHead.OfsHi   =OSL_SWAPWORD(rHead.OfsHi   );
     105             : #endif
     106           0 :     rOStream.Write((char*)&rHead,sizeof(rHead));
     107             : #if defined OSL_BIGENDIAN
     108             :     rHead.Typ     =OSL_SWAPWORD(rHead.Typ     );
     109             :     rHead.SizeLo  =OSL_SWAPWORD(rHead.SizeLo  );
     110             :     rHead.SizeHi  =OSL_SWAPWORD(rHead.SizeHi  );
     111             :     rHead.Reserve1=OSL_SWAPWORD(rHead.Reserve1);
     112             :     rHead.Reserve2=OSL_SWAPWORD(rHead.Reserve2);
     113             :     rHead.OfsLo   =OSL_SWAPWORD(rHead.OfsLo   );
     114             :     rHead.OfsHi   =OSL_SWAPWORD(rHead.OfsHi   );
     115             : #endif
     116           0 :     return rOStream;
     117             : }
     118             : 
     119           0 : void BmpFileHeader::SetSize(sal_uInt32 Size)
     120             : {
     121           0 :     SizeLo=sal_uInt16(Size & 0x0000FFFF);
     122           0 :     SizeHi=sal_uInt16((Size & 0xFFFF0000)>>16);
     123           0 : }
     124             : 
     125           0 : void BmpFileHeader::SetOfs(sal_uInt32 Ofs)
     126             : {
     127           0 :     OfsLo=sal_uInt16(Ofs & 0x0000FFFF);
     128           0 :     OfsHi=sal_uInt16((Ofs & 0xFFFF0000)>>16);
     129           0 : }
     130             : 
     131           0 : sal_uInt32 BmpFileHeader::GetOfs()
     132             : {
     133           0 :     return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi);
     134             : }
     135             : 
     136           0 : SvStream& WriteBmpInfoHeader(SvStream& rOStream, BmpInfoHeader& rInfo)
     137             : {
     138             : #if defined OSL_BIGENDIAN
     139             :     rInfo.Size    =OSL_SWAPDWORD (rInfo.Size    );
     140             :     rInfo.Width   =OSL_SWAPDWORD (rInfo.Width   );
     141             :     rInfo.Hight   =OSL_SWAPDWORD (rInfo.Hight   );
     142             :     rInfo.Planes  =OSL_SWAPWORD(rInfo.Planes  );
     143             :     rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
     144             :     rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
     145             :     rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
     146             :     rInfo.xDpmm   =OSL_SWAPDWORD (rInfo.xDpmm   );
     147             :     rInfo.yDpmm   =OSL_SWAPDWORD (rInfo.yDpmm   );
     148             :     rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
     149             :     rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
     150             : #endif
     151           0 :     rOStream.Write((char*)&rInfo,sizeof(rInfo));
     152             : #if defined OSL_BIGENDIAN
     153             :     rInfo.Size    =OSL_SWAPDWORD (rInfo.Size    );
     154             :     rInfo.Width   =OSL_SWAPDWORD (rInfo.Width   );
     155             :     rInfo.Hight   =OSL_SWAPDWORD (rInfo.Hight   );
     156             :     rInfo.Planes  =OSL_SWAPWORD(rInfo.Planes  );
     157             :     rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
     158             :     rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
     159             :     rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
     160             :     rInfo.xDpmm   =OSL_SWAPDWORD (rInfo.xDpmm   );
     161             :     rInfo.yDpmm   =OSL_SWAPDWORD (rInfo.yDpmm   );
     162             :     rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
     163             :     rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
     164             : #endif
     165           0 :     return rOStream;
     166             : }
     167             : 
     168           0 : SvStream& WriteRGBQuad(SvStream& rOStream, const RGBQuad& rQuad)
     169             : {
     170           0 :     rOStream.Write((char*)&rQuad,sizeof(rQuad));
     171           0 :     return rOStream;
     172             : }
     173             : 
     174             : class PcxExpand
     175             : {
     176             : private:
     177             :     sal_uInt16 Count;
     178             :     sal_uInt8   Data;
     179             : public:
     180           0 :     PcxExpand()
     181             :         : Count(0)
     182           0 :         , Data(0)
     183           0 :     {}
     184             :     sal_uInt8 GetByte(SvStream& rInp);
     185             : };
     186             : 
     187           0 : sal_uInt8 PcxExpand::GetByte(SvStream& rInp)
     188             : {
     189           0 :     if (Count>0) {
     190           0 :         Count--;
     191             :     } else {
     192           0 :         rInp.Read((char*)&Data,1);
     193           0 :         if ((Data & 0xC0) == 0xC0) {
     194           0 :             Count=(Data & 0x3F) -1;
     195           0 :             rInp.Read((char*)&Data,1);
     196             :         }
     197             :     }
     198           0 :     return Data;
     199             : }
     200             : 
     201           0 : bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
     202             : {
     203             :     BmpFileHeader  aBmpHead;
     204             :     BmpInfoHeader  aBmpInfo;
     205           0 :     sal_uInt16 nWdtInp=(rHead.Xsize+7)/8;  // width of input bitmap in bytes
     206             :     sal_uInt16         nWdtOut;            // width of output bitmap in bytes
     207             :     sal_uInt16         nColors;            // color count (1, 16, 256)
     208             :     sal_uInt16         nColBits;           // number of bits per pixel (2, 4, 8)
     209             :     sal_uInt16         i,j,k;              // column/row/plane counter
     210             :     sal_uInt16         a,b;                // helper variables
     211           0 :     sal_uInt8           pl1 = 0;            // masks for the planes
     212           0 :     boost::scoped_array<sal_uInt8> pBuf;   // buffer for a pixel row
     213           0 :     PcxExpand      aPcx;
     214             :     sal_uLong          nOfs;
     215             :     sal_uInt8           cRGB[4];
     216             : 
     217           0 :     if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8;
     218           0 :     nColors=1<<nColBits;
     219           0 :     nWdtOut=((rHead.Xsize*nColBits+31)/32)*4;
     220           0 :     aBmpHead.Typ='B'+'M'*256;
     221           0 :     aBmpHead.SetOfs(sizeof(aBmpHead)+sizeof(aBmpInfo)+nColors*4);
     222           0 :     aBmpHead.SetSize(aBmpHead.GetOfs()+nWdtOut*rHead.Ysize);
     223           0 :     aBmpHead.Reserve1=0;
     224           0 :     aBmpHead.Reserve2=0;
     225           0 :     aBmpInfo.Size=sizeof(aBmpInfo);
     226           0 :     aBmpInfo.Width=rHead.Xsize;
     227           0 :     aBmpInfo.Hight=rHead.Ysize;
     228           0 :     aBmpInfo.Planes=1;
     229           0 :     aBmpInfo.PixBits=nColBits;
     230           0 :     aBmpInfo.Compress=0;
     231           0 :     aBmpInfo.ImgSize=0;
     232           0 :     aBmpInfo.xDpmm=0;
     233           0 :     aBmpInfo.yDpmm=0;
     234           0 :     aBmpInfo.ColUsed=0;
     235           0 :     aBmpInfo.ColMust=0;
     236           0 :     pBuf.reset(new sal_uInt8[nWdtOut]);
     237           0 :     if (!pBuf) return false;       // error: no more memory available
     238           0 :     WriteBmpFileHeader( rOut, aBmpHead );
     239           0 :     WriteBmpInfoHeader( rOut, aBmpInfo );
     240           0 :     memset(pBuf.get(),0,nWdtOut);        // fill buffer with zeroes
     241             : 
     242           0 :     if (nColors==2)
     243             :     {
     244             : 
     245           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
     246           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
     247           0 :         nOfs=rOut.Tell();
     248           0 :         for (j=0;j<rHead.Ysize;j++)
     249           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
     250           0 :         for (j=0;j<rHead.Ysize;j++) {
     251           0 :             for(i=0;i<nWdtInp;i++) {
     252           0 :                 pBuf[i]=aPcx.GetByte(rInp);
     253             :             }
     254           0 :             for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0;     // up to 3 bytes
     255           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
     256           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);
     257             :         }
     258           0 :     } else if (nColors==16) {
     259           0 :         sal_uInt8 pl2= 0;     // planes' masks
     260             : 
     261           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
     262           0 :         WriteRGBQuad( rOut, RGBQuad(0x24,0x24,0x24) ); // gray 80%
     263           0 :         WriteRGBQuad( rOut, RGBQuad(0x49,0x49,0x49) ); // gray 60%
     264           0 :         WriteRGBQuad( rOut, RGBQuad(0x92,0x92,0x92) ); // gray 40%
     265           0 :         WriteRGBQuad( rOut, RGBQuad(0x6D,0x6D,0x6D) ); // gray 30%
     266           0 :         WriteRGBQuad( rOut, RGBQuad(0xB6,0xB6,0xB6) ); // gray 20%
     267           0 :         WriteRGBQuad( rOut, RGBQuad(0xDA,0xDA,0xDA) ); // gray 10%
     268           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
     269           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0x00) ); // black
     270           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0x00,0x00) ); // red
     271           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0x00,0xFF) ); // blue
     272           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0x00,0xFF) ); // magenta
     273           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0xFF,0x00) ); // green
     274           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0x00) ); // yellow
     275           0 :         WriteRGBQuad( rOut, RGBQuad(0x00,0xFF,0xFF) ); // cyan
     276           0 :         WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
     277             : 
     278           0 :         nOfs=rOut.Tell();
     279           0 :         for (j=0;j<rHead.Ysize;j++)
     280           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
     281           0 :         for (j=0;j<rHead.Ysize;j++) {
     282           0 :             memset(pBuf.get(),0,nWdtOut);
     283           0 :             for(k=0;k<4;k++) {
     284           0 :                 if (k==0) {
     285           0 :                     pl1=0x10; pl2=0x01;
     286             :                 } else {
     287           0 :                     pl1<<=1; pl2<<=1;
     288             :                 }
     289           0 :                 for(i=0;i<nWdtInp;i++) {
     290           0 :                     a=i*4;
     291           0 :                     b=aPcx.GetByte(rInp);
     292           0 :                     if (b & 0x80) pBuf[a  ]|=pl1;
     293           0 :                     if (b & 0x40) pBuf[a  ]|=pl2;
     294           0 :                     if (b & 0x20) pBuf[a+1]|=pl1;
     295           0 :                     if (b & 0x10) pBuf[a+1]|=pl2;
     296           0 :                     if (b & 0x08) pBuf[a+2]|=pl1;
     297           0 :                     if (b & 0x04) pBuf[a+2]|=pl2;
     298           0 :                     if (b & 0x02) pBuf[a+3]|=pl1;
     299           0 :                     if (b & 0x01) pBuf[a+3]|=pl2;
     300             :                 }
     301             :             }
     302           0 :             for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0;            // up to 3 bytes
     303           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
     304           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);
     305             :         }
     306           0 :     } else if (nColors==256) {
     307           0 :         cRGB[3]=0;                      // fourth palette entry for BMP
     308           0 :         for (i=0;i<256;i++) {           // copy palette
     309           0 :             rInp.Read((char*)cRGB,3);
     310           0 :             pl1=cRGB[0];                // switch red and blue
     311           0 :             cRGB[0]=cRGB[2];
     312           0 :             cRGB[2]=pl1;
     313           0 :             rOut.Write((char*)cRGB,4);
     314             :         }
     315             : 
     316           0 :         nOfs=rOut.Tell();
     317           0 :         for (j=0;j<rHead.Ysize;j++)
     318           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
     319           0 :         for (j=0;j<rHead.Ysize;j++) {
     320           0 :             for(i=0;i<rHead.Xsize;i++)
     321           0 :                 pBuf[i]=aPcx.GetByte(rInp);
     322           0 :             for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0;          // up to 3 bytes
     323           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
     324           0 :             rOut.Write((char*)pBuf.get(),nWdtOut);
     325             :         }
     326             :     }
     327           0 :     return true;
     328             : }
     329             : 
     330           0 : bool SgfBMapFilter(SvStream& rInp, SvStream& rOut)
     331             : {
     332             :     sal_uLong     nFileStart;        // offset of SgfHeaders. Usually 0.
     333           0 :     SgfHeader aHead;
     334           0 :     SgfEntry  aEntr;
     335             :     sal_uLong     nNext;
     336           0 :     bool      bRdFlag=false;         // read graphics entry?
     337           0 :     bool      bRet=false;            // return value
     338             : 
     339           0 :     nFileStart=rInp.Tell();
     340           0 :     ReadSgfHeader( rInp, aHead );
     341           0 :     if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 ||
     342           0 :                              aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) {
     343           0 :         nNext=aHead.GetOffset();
     344           0 :         while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) {
     345           0 :             rInp.Seek(nFileStart+nNext);
     346           0 :             ReadSgfEntry( rInp, aEntr );
     347           0 :             nNext=aEntr.GetOffset();
     348           0 :             if (aEntr.Typ==aHead.Typ) {
     349           0 :                 bRdFlag=true;
     350           0 :                 switch(aEntr.Typ) {
     351             :                     case SgfBitImag0:
     352             :                     case SgfBitImag1:
     353             :                     case SgfBitImag2:
     354           0 :                     case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break;
     355             :                 }
     356             :             }
     357             :         } // while(nNext)
     358             :     }
     359           0 :     if (rInp.GetError()) bRet=false;
     360           0 :     return(bRet);
     361             : }
     362             : 
     363             : // for StarDraw embedded SGF vector
     364             : long SgfVectXofs=0;
     365             : long SgfVectYofs=0;
     366             : long SgfVectXmul=0;
     367             : long SgfVectYmul=0;
     368             : long SgfVectXdiv=0;
     369             : long SgfVectYdiv=0;
     370             : bool SgfVectScal=false;
     371             : 
     372           0 : Color Hpgl2SvFarbe( sal_uInt8 nFarb )
     373             : {
     374           0 :     sal_uLong nColor = COL_BLACK;
     375             : 
     376           0 :     switch (nFarb & 0x07) {
     377           0 :         case 0:  nColor=COL_WHITE;        break;
     378           0 :         case 1:  nColor=COL_YELLOW;       break;
     379           0 :         case 2:  nColor=COL_LIGHTMAGENTA; break;
     380           0 :         case 3:  nColor=COL_LIGHTRED;     break;
     381           0 :         case 4:  nColor=COL_LIGHTCYAN;    break;
     382           0 :         case 5:  nColor=COL_LIGHTGREEN;   break;
     383           0 :         case 6:  nColor=COL_LIGHTBLUE;    break;
     384           0 :         case 7:  nColor=COL_BLACK;        break;
     385             :     }
     386           0 :     Color aColor( nColor );
     387           0 :     return aColor;
     388             : }
     389             : 
     390           0 : bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf)
     391             : {
     392           0 :     VirtualDevice aOutDev;
     393             :     SgfVector aVect;
     394             :     sal_uInt8      nFarb;
     395           0 :     sal_uInt8      nFrb0=7;
     396             :     sal_uInt8      nLTyp;
     397             :     sal_uInt8      nOTyp;
     398           0 :     bool      bEoDt=false;
     399           0 :     bool      bPDwn=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);
     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 :         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           0 : 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           0 :     SgfHeader aHead;
     500           0 :     nVersion=0;
     501           0 :     nPos=rInp.Tell();
     502           0 :     ReadSgfHeader( rInp, aHead );
     503           0 :     rInp.Seek(nPos);
     504           0 :     if (aHead.ChkMagic()) {
     505           0 :         nVersion=aHead.Version;
     506           0 :         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           0 :             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: */

Generated by: LCOV version 1.10