LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/filter - sgfbram.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 252 8.3 %
Date: 2012-12-27 Functions: 6 20 30.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             : 
      21             : #include <string.h>
      22             : #include <osl/endian.h>
      23             : #include <tools/stream.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             : 
      30           4 : SvStream& operator>>(SvStream& rIStream, SgfHeader& rHead)
      31             : {
      32           4 :     rIStream.Read((char*)&rHead.Magic,SgfHeaderSize);
      33             : #if defined OSL_BIGENDIAN
      34             :     rHead.Magic  =OSL_SWAPWORD(rHead.Magic  );
      35             :     rHead.Version=OSL_SWAPWORD(rHead.Version);
      36             :     rHead.Typ    =OSL_SWAPWORD(rHead.Typ    );
      37             :     rHead.Xsize  =OSL_SWAPWORD(rHead.Xsize  );
      38             :     rHead.Ysize  =OSL_SWAPWORD(rHead.Ysize  );
      39             :     rHead.Xoffs  =OSL_SWAPWORD(rHead.Xoffs  );
      40             :     rHead.Yoffs  =OSL_SWAPWORD(rHead.Yoffs  );
      41             :     rHead.Planes =OSL_SWAPWORD(rHead.Planes );
      42             :     rHead.SwGrCol=OSL_SWAPWORD(rHead.SwGrCol);
      43             :     rHead.OfsLo  =OSL_SWAPWORD(rHead.OfsLo  );
      44             :     rHead.OfsHi  =OSL_SWAPWORD(rHead.OfsHi  );
      45             : #endif
      46           4 :     return rIStream;
      47             : }
      48             : 
      49           4 : sal_Bool SgfHeader::ChkMagic()
      50           4 : { return Magic=='J'*256+'J'; }
      51             : 
      52           2 : sal_uInt32 SgfHeader::GetOffset()
      53           2 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
      54             : 
      55           4 : SvStream& operator>>(SvStream& rIStream, SgfEntry& rEntr)
      56             : {
      57           4 :     rIStream.Read((char*)&rEntr.Typ,SgfEntrySize);
      58             : #if defined OSL_BIGENDIAN
      59             :     rEntr.Typ  =OSL_SWAPWORD(rEntr.Typ  );
      60             :     rEntr.iFrei=OSL_SWAPWORD(rEntr.iFrei);
      61             :     rEntr.lFreiLo=OSL_SWAPWORD (rEntr.lFreiLo);
      62             :     rEntr.lFreiHi=OSL_SWAPWORD (rEntr.lFreiHi);
      63             :     rEntr.OfsLo=OSL_SWAPWORD(rEntr.OfsLo);
      64             :     rEntr.OfsHi=OSL_SWAPWORD(rEntr.OfsHi);
      65             : #endif
      66           4 :     return rIStream;
      67             : }
      68             : 
      69           4 : sal_uInt32 SgfEntry::GetOffset()
      70           4 : { return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi); }
      71             : 
      72           0 : SvStream& operator>>(SvStream& rIStream, SgfVector& rVect)
      73             : {
      74           0 :     rIStream.Read((char*)&rVect,sizeof(rVect));
      75             : #if defined OSL_BIGENDIAN
      76             :     rVect.Flag =OSL_SWAPWORD(rVect.Flag );
      77             :     rVect.x    =OSL_SWAPWORD(rVect.x    );
      78             :     rVect.y    =OSL_SWAPWORD(rVect.y    );
      79             :     rVect.OfsLo=OSL_SWAPDWORD (rVect.OfsLo);
      80             :     rVect.OfsHi=OSL_SWAPDWORD (rVect.OfsHi);
      81             : #endif
      82           0 :     return rIStream;
      83             : }
      84             : 
      85           0 : SvStream& operator<<(SvStream& rOStream, BmpFileHeader& rHead)
      86             : {
      87             : #if defined OSL_BIGENDIAN
      88             :     rHead.Typ     =OSL_SWAPWORD(rHead.Typ     );
      89             :     rHead.SizeLo  =OSL_SWAPWORD(rHead.SizeLo  );
      90             :     rHead.SizeHi  =OSL_SWAPWORD(rHead.SizeHi  );
      91             :     rHead.Reserve1=OSL_SWAPWORD(rHead.Reserve1);
      92             :     rHead.Reserve2=OSL_SWAPWORD(rHead.Reserve2);
      93             :     rHead.OfsLo   =OSL_SWAPWORD(rHead.OfsLo   );
      94             :     rHead.OfsHi   =OSL_SWAPWORD(rHead.OfsHi   );
      95             : #endif
      96           0 :     rOStream.Write((char*)&rHead,sizeof(rHead));
      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 :     return rOStream;
     107             : }
     108             : 
     109           0 : void BmpFileHeader::SetSize(sal_uInt32 Size)
     110             : {
     111           0 :     SizeLo=sal_uInt16(Size & 0x0000FFFF);
     112           0 :     SizeHi=sal_uInt16((Size & 0xFFFF0000)>>16);
     113           0 : }
     114             : 
     115           0 : void BmpFileHeader::SetOfs(sal_uInt32 Ofs)
     116             : {
     117           0 :     OfsLo=sal_uInt16(Ofs & 0x0000FFFF);
     118           0 :     OfsHi=sal_uInt16((Ofs & 0xFFFF0000)>>16);
     119           0 : }
     120             : 
     121           0 : sal_uInt32 BmpFileHeader::GetOfs()
     122             : {
     123           0 :     return sal_uInt32(OfsLo)+0x00010000*sal_uInt32(OfsHi);
     124             : }
     125             : 
     126           0 : SvStream& operator<<(SvStream& rOStream, BmpInfoHeader& rInfo)
     127             : {
     128             : #if defined OSL_BIGENDIAN
     129             :     rInfo.Size    =OSL_SWAPDWORD (rInfo.Size    );
     130             :     rInfo.Width   =OSL_SWAPDWORD (rInfo.Width   );
     131             :     rInfo.Hight   =OSL_SWAPDWORD (rInfo.Hight   );
     132             :     rInfo.Planes  =OSL_SWAPWORD(rInfo.Planes  );
     133             :     rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
     134             :     rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
     135             :     rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
     136             :     rInfo.xDpmm   =OSL_SWAPDWORD (rInfo.xDpmm   );
     137             :     rInfo.yDpmm   =OSL_SWAPDWORD (rInfo.yDpmm   );
     138             :     rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
     139             :     rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
     140             : #endif
     141           0 :     rOStream.Write((char*)&rInfo,sizeof(rInfo));
     142             : #if defined OSL_BIGENDIAN
     143             :     rInfo.Size    =OSL_SWAPDWORD (rInfo.Size    );
     144             :     rInfo.Width   =OSL_SWAPDWORD (rInfo.Width   );
     145             :     rInfo.Hight   =OSL_SWAPDWORD (rInfo.Hight   );
     146             :     rInfo.Planes  =OSL_SWAPWORD(rInfo.Planes  );
     147             :     rInfo.PixBits =OSL_SWAPWORD(rInfo.PixBits );
     148             :     rInfo.Compress=OSL_SWAPDWORD (rInfo.Compress);
     149             :     rInfo.ImgSize =OSL_SWAPDWORD (rInfo.ImgSize );
     150             :     rInfo.xDpmm   =OSL_SWAPDWORD (rInfo.xDpmm   );
     151             :     rInfo.yDpmm   =OSL_SWAPDWORD (rInfo.yDpmm   );
     152             :     rInfo.ColUsed =OSL_SWAPDWORD (rInfo.ColUsed );
     153             :     rInfo.ColMust =OSL_SWAPDWORD (rInfo.ColMust );
     154             : #endif
     155           0 :     return rOStream;
     156             : }
     157             : 
     158           0 : SvStream& operator<<(SvStream& rOStream, const RGBQuad& rQuad)
     159             : {
     160           0 :     rOStream.Write((char*)&rQuad,sizeof(rQuad));
     161           0 :     return rOStream;
     162             : }
     163             : 
     164             : 
     165             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     166             : // PcxExpand ///////////////////////////////////////////////////////////////////////////////////////
     167             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     168             : 
     169             : class PcxExpand
     170             : {
     171             : private:
     172             :     sal_uInt16 Count;
     173             :     sal_uInt8   Data;
     174             : public:
     175           0 :                   PcxExpand() { Count=0; }
     176             :     sal_uInt8 GetByte(SvStream& rInp);
     177             : };
     178             : 
     179           0 : sal_uInt8 PcxExpand::GetByte(SvStream& rInp)
     180             : {
     181           0 :     if (Count>0) {
     182           0 :         Count--;
     183             :     } else {
     184           0 :         rInp.Read((char*)&Data,1);
     185           0 :         if ((Data & 0xC0) == 0xC0) {
     186           0 :             Count=(Data & 0x3F) -1;
     187           0 :             rInp.Read((char*)&Data,1);
     188             :         }
     189             :     }
     190           0 :     return Data;
     191             : }
     192             : 
     193             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     194             : // SgfBMapFilter ///////////////////////////////////////////////////////////////////////////////////
     195             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     196             : 
     197           0 : sal_Bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
     198             : {
     199             :     BmpFileHeader  aBmpHead;
     200             :     BmpInfoHeader  aBmpInfo;
     201           0 :     sal_uInt16 nWdtInp=(rHead.Xsize+7)/8;  // Breite der Input-Bitmap in Bytes
     202             :     sal_uInt16         nWdtOut;            // Breite der Output-Bitmap in Bytes
     203             :     sal_uInt16         nColors;            // Anzahl der Farben     (1,16,256)
     204             :     sal_uInt16         nColBits;           // Anzahl der Bits/Pixel (2, 4,  8)
     205             :     sal_uInt16         i,j,k;              // Spaltenzaehler, Zeilenzaehler, Planezaehler
     206             :     sal_uInt16         a,b;                // Hilfsvariable
     207           0 :     sal_uInt8           pl1 = 0;            // Masken fuer die Planes
     208           0 :     sal_uInt8*          pBuf=NULL;          // Buffer fuer eine Pixelzeile
     209           0 :     PcxExpand      aPcx;
     210             :     sal_uLong          nOfs;
     211             :     sal_uInt8           cRGB[4];
     212             : 
     213           0 :     if (rHead.Planes<=1) nColBits=1; else nColBits=4; if (rHead.Typ==4) nColBits=8;
     214           0 :     nColors=1<<nColBits;
     215           0 :     nWdtOut=((rHead.Xsize*nColBits+31)/32)*4;
     216           0 :     aBmpHead.Typ='B'+'M'*256;
     217           0 :     aBmpHead.SetOfs(sizeof(aBmpHead)+sizeof(aBmpInfo)+nColors*4);
     218           0 :     aBmpHead.SetSize(aBmpHead.GetOfs()+nWdtOut*rHead.Ysize);
     219           0 :     aBmpHead.Reserve1=0;
     220           0 :     aBmpHead.Reserve2=0;
     221           0 :     aBmpInfo.Size=sizeof(aBmpInfo);
     222           0 :     aBmpInfo.Width=rHead.Xsize;
     223           0 :     aBmpInfo.Hight=rHead.Ysize;
     224           0 :     aBmpInfo.Planes=1;
     225           0 :     aBmpInfo.PixBits=nColBits;
     226           0 :     aBmpInfo.Compress=0;
     227           0 :     aBmpInfo.ImgSize=0;
     228           0 :     aBmpInfo.xDpmm=0;
     229           0 :     aBmpInfo.yDpmm=0;
     230           0 :     aBmpInfo.ColUsed=0;
     231           0 :     aBmpInfo.ColMust=0;
     232           0 :     pBuf=new sal_uInt8[nWdtOut];
     233           0 :     if (!pBuf) return sal_False;       // Fehler: kein Speichel da
     234           0 :     rOut<<aBmpHead<<aBmpInfo;
     235           0 :     memset(pBuf,0,nWdtOut);        // Buffer mit Nullen fuellen
     236             : 
     237           0 :     if (nColors==2)
     238             :     {
     239             : 
     240           0 :         rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
     241           0 :         rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
     242           0 :         nOfs=rOut.Tell();
     243           0 :         for (j=0;j<rHead.Ysize;j++)
     244           0 :             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
     245           0 :         for (j=0;j<rHead.Ysize;j++) {
     246           0 :             for(i=0;i<nWdtInp;i++) {
     247           0 :                 pBuf[i]=aPcx.GetByte(rInp);
     248             :             }
     249           0 :             for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0;     // noch bis zu 3 Bytes
     250           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
     251           0 :             rOut.Write((char*)pBuf,nWdtOut);
     252             :         }
     253           0 :     } else if (nColors==16) {
     254           0 :         sal_uInt8 pl2= 0;     // Masken fuer die Planes
     255             : 
     256           0 :         rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
     257           0 :         rOut<<RGBQuad(0x24,0x24,0x24); // Grau 80%
     258           0 :         rOut<<RGBQuad(0x49,0x49,0x49); // Grau 60%
     259           0 :         rOut<<RGBQuad(0x92,0x92,0x92); // Grau 40%
     260           0 :         rOut<<RGBQuad(0x6D,0x6D,0x6D); // Grau 30%
     261           0 :         rOut<<RGBQuad(0xB6,0xB6,0xB6); // Grau 20%
     262           0 :         rOut<<RGBQuad(0xDA,0xDA,0xDA); // Grau 10%
     263           0 :         rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
     264           0 :         rOut<<RGBQuad(0x00,0x00,0x00); // Schwarz
     265           0 :         rOut<<RGBQuad(0xFF,0x00,0x00); // Rot
     266           0 :         rOut<<RGBQuad(0x00,0x00,0xFF); // Blau
     267           0 :         rOut<<RGBQuad(0xFF,0x00,0xFF); // Magenta
     268           0 :         rOut<<RGBQuad(0x00,0xFF,0x00); // Gruen
     269           0 :         rOut<<RGBQuad(0xFF,0xFF,0x00); // Gelb
     270           0 :         rOut<<RGBQuad(0x00,0xFF,0xFF); // Cyan
     271           0 :         rOut<<RGBQuad(0xFF,0xFF,0xFF); // Weiss
     272             : 
     273           0 :         nOfs=rOut.Tell();
     274           0 :         for (j=0;j<rHead.Ysize;j++)
     275           0 :             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
     276           0 :         for (j=0;j<rHead.Ysize;j++) {
     277           0 :             memset(pBuf,0,nWdtOut);
     278           0 :             for(k=0;k<4;k++) {
     279           0 :                 if (k==0) {
     280           0 :                     pl1=0x10; pl2=0x01;
     281             :                 } else {
     282           0 :                     pl1<<=1; pl2<<=1;
     283             :                 }
     284           0 :                 for(i=0;i<nWdtInp;i++) {
     285           0 :                     a=i*4;
     286           0 :                     b=aPcx.GetByte(rInp);
     287           0 :                     if (b & 0x80) pBuf[a  ]|=pl1;
     288           0 :                     if (b & 0x40) pBuf[a  ]|=pl2;
     289           0 :                     if (b & 0x20) pBuf[a+1]|=pl1;
     290           0 :                     if (b & 0x10) pBuf[a+1]|=pl2;
     291           0 :                     if (b & 0x08) pBuf[a+2]|=pl1;
     292           0 :                     if (b & 0x04) pBuf[a+2]|=pl2;
     293           0 :                     if (b & 0x02) pBuf[a+3]|=pl1;
     294           0 :                     if (b & 0x01) pBuf[a+3]|=pl2;
     295             :                 }
     296             :             }
     297           0 :             for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0;            // noch bis zu 3 Bytes
     298           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
     299           0 :             rOut.Write((char*)pBuf,nWdtOut);
     300             :         }
     301           0 :     } else if (nColors==256) {
     302           0 :         cRGB[3]=0;                      // der 4. Paletteneintrag fuer BMP
     303           0 :         for (i=0;i<256;i++) {           // Palette kopieren
     304           0 :             rInp.Read((char*)cRGB,3);
     305           0 :             pl1=cRGB[0];                // Rot mit Blau tauschen
     306           0 :             cRGB[0]=cRGB[2];
     307           0 :             cRGB[2]=pl1;
     308           0 :             rOut.Write((char*)cRGB,4);
     309             :         }
     310             : 
     311           0 :         nOfs=rOut.Tell();
     312           0 :         for (j=0;j<rHead.Ysize;j++)
     313           0 :             rOut.Write((char*)pBuf,nWdtOut);  // Datei erstmal komplett mit Nullen fuellen
     314           0 :         for (j=0;j<rHead.Ysize;j++) {
     315           0 :             for(i=0;i<rHead.Xsize;i++)
     316           0 :                 pBuf[i]=aPcx.GetByte(rInp);
     317           0 :             for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0;          // noch bis zu 3 Bytes
     318           0 :             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // rueckwaerts schreiben!
     319           0 :             rOut.Write((char*)pBuf,nWdtOut);
     320             :         }
     321             :     }
     322           0 :     delete[] pBuf;
     323           0 :     return sal_True;
     324             : }
     325             : 
     326           0 : sal_Bool SgfBMapFilter(SvStream& rInp, SvStream& rOut)
     327             : {
     328             :     sal_uLong     nFileStart;            // Offset des SgfHeaders. Im allgemeinen 0.
     329             :     SgfHeader aHead;
     330             :     SgfEntry  aEntr;
     331             :     sal_uLong     nNext;
     332           0 :     sal_Bool      bRdFlag=sal_False;         // Grafikentry gelesen ?
     333           0 :     sal_Bool      bRet=sal_False;            // Returncode
     334             : 
     335           0 :     nFileStart=rInp.Tell();
     336           0 :     rInp>>aHead;
     337           0 :     if (aHead.ChkMagic() && (aHead.Typ==SgfBitImag0 || aHead.Typ==SgfBitImag1 ||
     338             :                              aHead.Typ==SgfBitImag2 || aHead.Typ==SgfBitImgMo)) {
     339           0 :         nNext=aHead.GetOffset();
     340           0 :         while (nNext && !bRdFlag && !rInp.GetError() && !rOut.GetError()) {
     341           0 :             rInp.Seek(nFileStart+nNext);
     342           0 :             rInp>>aEntr;
     343           0 :             nNext=aEntr.GetOffset();
     344           0 :             if (aEntr.Typ==aHead.Typ) {
     345           0 :                 bRdFlag=sal_True;
     346           0 :                 switch(aEntr.Typ) {
     347             :                     case SgfBitImag0:
     348             :                     case SgfBitImag1:
     349             :                     case SgfBitImag2:
     350           0 :                     case SgfBitImgMo: bRet=SgfFilterBMap(rInp,rOut,aHead,aEntr); break;
     351             :                 }
     352             :             }
     353             :         } // while(nNext)
     354             :     }
     355           0 :     if (rInp.GetError()) bRet=sal_False;
     356           0 :     return(bRet);
     357             : }
     358             : 
     359             : 
     360             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     361             : // SgfVectFilter ///////////////////////////////////////////////////////////////////////////////////
     362             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     363             : 
     364             : // Fuer 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             : sal_Bool SgfVectScal=sal_False;
     372             : 
     373             : ////////////////////////////////////////////////////////////
     374             : // Hpgl2SvFarbe ////////////////////////////////////////////
     375             : ////////////////////////////////////////////////////////////
     376             : 
     377           0 : Color Hpgl2SvFarbe( sal_uInt8 nFarb )
     378             : {
     379           0 :     sal_uLong nColor = COL_BLACK;
     380             : 
     381           0 :     switch (nFarb & 0x07) {
     382           0 :         case 0:  nColor=COL_WHITE;        break;
     383           0 :         case 1:  nColor=COL_YELLOW;       break;
     384           0 :         case 2:  nColor=COL_LIGHTMAGENTA; break;
     385           0 :         case 3:  nColor=COL_LIGHTRED;     break;
     386           0 :         case 4:  nColor=COL_LIGHTCYAN;    break;
     387           0 :         case 5:  nColor=COL_LIGHTGREEN;   break;
     388           0 :         case 6:  nColor=COL_LIGHTBLUE;    break;
     389           0 :         case 7:  nColor=COL_BLACK;        break;
     390             :     }
     391           0 :     Color aColor( nColor );
     392           0 :     return aColor;
     393             : }
     394             : 
     395           0 : sal_Bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf)
     396             : {
     397           0 :     VirtualDevice aOutDev;
     398             :     SgfVector aVect;
     399             :     sal_uInt8      nFarb;
     400           0 :     sal_uInt8      nFrb0=7;
     401             :     sal_uInt8      nLTyp;
     402             :     sal_uInt8      nOTyp;
     403           0 :     sal_Bool      bEoDt=sal_False;
     404           0 :     sal_Bool      bPDwn=sal_False;
     405           0 :     Point     aP0(0,0);
     406           0 :     Point     aP1(0,0);
     407           0 :     String    Msg;
     408           0 :     sal_uInt16    RecNr=0;
     409             : 
     410           0 :     rMtf.Record(&aOutDev);
     411           0 :     aOutDev.SetLineColor(Color(COL_BLACK));
     412           0 :     aOutDev.SetFillColor(Color(COL_BLACK));
     413             : 
     414           0 :     while (!bEoDt && !rInp.GetError()) {
     415           0 :         rInp>>aVect; RecNr++;
     416           0 :         nFarb=(sal_uInt8) (aVect.Flag & 0x000F);
     417           0 :         nLTyp=(sal_uInt8)((aVect.Flag & 0x00F0) >>4);
     418           0 :         nOTyp=(sal_uInt8)((aVect.Flag & 0x0F00) >>8);
     419           0 :         bEoDt=(aVect.Flag & 0x4000) !=0;
     420           0 :         bPDwn=(aVect.Flag & 0x8000) !=0;
     421             : 
     422           0 :         long x=aVect.x-rHead.Xoffs;
     423           0 :         long y=rHead.Ysize-(aVect.y-rHead.Yoffs);
     424           0 :         if (SgfVectScal) {
     425           0 :             if (SgfVectXdiv==0) SgfVectXdiv=rHead.Xsize;
     426           0 :             if (SgfVectYdiv==0) SgfVectYdiv=rHead.Ysize;
     427           0 :             if (SgfVectXdiv==0) SgfVectXdiv=1;
     428           0 :             if (SgfVectYdiv==0) SgfVectYdiv=1;
     429           0 :             x=SgfVectXofs+ x *SgfVectXmul /SgfVectXdiv;
     430           0 :             y=SgfVectYofs+ y *SgfVectXmul /SgfVectYdiv;
     431             :         }
     432           0 :         aP1=Point(x,y);
     433           0 :         if (!bEoDt && !rInp.GetError()) {
     434           0 :             if (bPDwn && nLTyp<=6) {
     435           0 :                 switch(nOTyp) {
     436           0 :                     case 1: if (nFarb!=nFrb0) {
     437           0 :                                 switch(rHead.SwGrCol) {
     438           0 :                                     case SgfVectFarb: aOutDev.SetLineColor(Hpgl2SvFarbe(nFarb)); break;
     439           0 :                                     case SgfVectGray:                          break;
     440           0 :                                     case SgfVectWdth:                          break;
     441             :                                 }
     442             :                             }
     443           0 :                             aOutDev.DrawLine(aP0,aP1);            break; // Linie
     444           0 :                     case 2:                                       break; // Kreis
     445           0 :                     case 3:                                       break; // Text
     446           0 :                     case 5: aOutDev.DrawRect(Rectangle(aP0,aP1)); break; // Rechteck (solid)
     447             :                 }
     448             :             }
     449           0 :             aP0=aP1;
     450           0 :             nFrb0=nFarb;
     451             :         }
     452             :     }
     453           0 :     rMtf.Stop();
     454           0 :     rMtf.WindStart();
     455             :     MapMode aMap( MAP_10TH_MM, Point(),
     456           0 :                   Fraction( 1, 4 ), Fraction( 1, 4 ) );
     457           0 :     rMtf.SetPrefMapMode( aMap );
     458           0 :     rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) );
     459           0 :     return sal_True;
     460             : }
     461             : 
     462             : 
     463           0 : sal_Bool SgfVectFilter(SvStream& rInp, GDIMetaFile& rMtf)
     464             : {
     465             :     sal_uLong     nFileStart;            // Offset des SgfHeaders. Im allgemeinen 0.
     466             :     SgfHeader aHead;
     467             :     SgfEntry  aEntr;
     468             :     sal_uLong     nNext;
     469           0 :     sal_Bool      bRdFlag=sal_False;         // Grafikentry gelesen ?
     470           0 :     sal_Bool      bRet=sal_False;            // Returncode
     471             : 
     472           0 :     nFileStart=rInp.Tell();
     473           0 :     rInp>>aHead;
     474           0 :     if (aHead.ChkMagic() && aHead.Typ==SGF_SIMPVECT) {
     475           0 :         nNext=aHead.GetOffset();
     476           0 :         while (nNext && !bRdFlag && !rInp.GetError()) {
     477           0 :             rInp.Seek(nFileStart+nNext);
     478           0 :             rInp>>aEntr;
     479           0 :             nNext=aEntr.GetOffset();
     480           0 :             if (aEntr.Typ==aHead.Typ) {
     481           0 :                 bRet=SgfFilterVect(rInp,aHead,aEntr,rMtf);
     482             :             }
     483             :         } // while(nNext)
     484           0 :         if (bRdFlag) {
     485           0 :             if (!rInp.GetError()) bRet=sal_True;  // Scheinbar Ok
     486             :         }
     487             :     }
     488           0 :     return(bRet);
     489             : }
     490             : 
     491             : /*************************************************************************
     492             : |*
     493             : |*    CheckSgfTyp()
     494             : |*
     495             : |*    Beschreibung      Feststellen, um was fuer ein SGF/SGV es sich handelt.
     496             : |*
     497             : *************************************************************************/
     498           2 : sal_uInt8 CheckSgfTyp(SvStream& rInp, sal_uInt16& nVersion)
     499             : {
     500             : #if OSL_DEBUG_LEVEL > 1 // Recordgroessen checken. Neuer Compiler hat vielleichte anderes Allignment!
     501             :     if (sizeof(SgfHeader)!=SgfHeaderSize ||
     502             :         sizeof(SgfEntry) !=SgfEntrySize  ||
     503             :         sizeof(SgfVector)!=SgfVectorSize ||
     504             :         sizeof(BmpFileHeader)!=BmpFileHeaderSize ||
     505             :         sizeof(BmpInfoHeader)!=BmpInfoHeaderSize ||
     506             :         sizeof(RGBQuad  )!=RGBQuadSize   )  return SGF_DONTKNOW;
     507             : #endif
     508             : 
     509             :     sal_uLong     nPos;
     510             :     SgfHeader aHead;
     511           2 :     nVersion=0;
     512           2 :     nPos=rInp.Tell();
     513           2 :     rInp>>aHead;
     514           2 :     rInp.Seek(nPos);
     515           2 :     if (aHead.ChkMagic()) {
     516           2 :         nVersion=aHead.Version;
     517           2 :         switch(aHead.Typ) {
     518             :             case SgfBitImag0:
     519             :             case SgfBitImag1:
     520             :             case SgfBitImag2:
     521           0 :             case SgfBitImgMo: return SGF_BITIMAGE;
     522           0 :             case SgfSimpVect: return SGF_SIMPVECT;
     523           0 :             case SgfPostScrp: return SGF_POSTSCRP;
     524           2 :             case SgfStarDraw: return SGF_STARDRAW;
     525           0 :             default         : return SGF_DONTKNOW;
     526             :         }
     527             :     } else {
     528           0 :         return SGF_DONTKNOW;
     529             :     }
     530             : }
     531             : 
     532             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10