home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / Chip_2002-10_cd1.bin / zkuste / delphi / kolekce / d56 / FLEXCEL.ZIP / XLSAdapter / UEscherGraphToBSE.pas < prev    next >
Pascal/Delphi Source File  |  2002-06-10  |  4KB  |  111 lines

  1. unit UEscherGraphToBSE;
  2.  
  3. interface
  4. uses Sysutils, Classes, XlsMessages, UEscherRecords, UMD5, UFlxMessages;
  5. {************************************************************************************}
  6. {**} function ConvertGraphicToBSE(const Data: string; const DataType: TXlsImgTypes;
  7.        const DwgGroupCache: PEscherDwgGroupCache; const DwgCache: PEscherDwgCache):TEscherBSERecord ;
  8. {************************************************************************************}
  9.  
  10. implementation
  11.  
  12.  
  13. type
  14.   TBSEHeader= packed record
  15.    btWin32:        byte;                  // Required type on Win32
  16.    btMacOS:        byte;                  // Required type on Mac
  17.    rgbUid:         TMd5Digest;            // Identifier of blip
  18.    tag:            word;                  // currently unused
  19.    size:           Cardinal;              // Blip size in stream
  20.    cRef:           Cardinal;              // Reference count on the blip
  21.    foDelay:        Cardinal;              // File offset in the delay stream
  22.    usage:          byte;                  // How this blip is used (MSOBLIPUSAGE)
  23.    cbName:         byte;                  // length of the blip name
  24.    unused2:        byte;                  // for the future
  25.    unused3:        byte;                  // for the future
  26.   end;
  27.  
  28.   TWMFBlipHeader = packed Record
  29.     m_rgbUid: TMd5Digest;  { The secondary, or data, UID - should always be set. }
  30.  
  31.     { Metafile Blip overhead = 34 bytes. m_cb gives the number of
  32.      bytes required to store an uncompressed version of the file, m_cbSave
  33.      is the compressed size.  m_mfBounds gives the boundary of all the
  34.      drawing calls within the metafile (this may just be the bounding box
  35.      or it may allow some whitespace, for a WMF this comes from the
  36.      SetWindowOrg and SetWindowExt records of the metafile). }
  37.     m_cb: integer;           // Cache of the metafile size
  38.     m_rcBounds: Array[0..3] of integer;     // Boundary of metafile drawing commands
  39.     m_ptSize: Array[0..1] of integer;       // Size of metafile in EMUs
  40.     m_cbSave: integer;       // Cache of saved size (size of m_pvBits)
  41.     m_fCompression: byte; // MSOBLIPCOMPRESSION
  42.     m_fFilter: byte;      // always msofilterNone
  43.   end;
  44.  
  45. procedure LoadDataBMP(const Data: string; const DataType: TXlsImgTypes; const BlipData: TStream);
  46. var
  47.   Tag: byte;
  48. begin
  49.   Tag:=$FF;
  50.   BlipData.Write(Tag, SizeOf(Tag));
  51.   BlipData.Write(Data[1], Length(Data));
  52. end;
  53.  
  54. procedure LoadDataWMF(const Data: string; const DataType: TXlsImgTypes; const BlipData: TStream);
  55. begin
  56. end;
  57.  
  58. function ConvertGraphicToBSE(const Data: string; const DataType: TXlsImgTypes;
  59.   const DwgGroupCache: PEscherDwgGroupCache; const DwgCache: PEscherDwgCache):TEscherBSERecord;
  60. var
  61.   Eh: TEscherRecordHeader;
  62.   BSEHeader: TBSEHeader;
  63.   Md5Stream: TMd5Stream;
  64.   BlipData: TMemoryStream;
  65.   BlipHeader: TEscherRecordHeader;
  66. begin
  67.   Md5Stream:=TMd5Stream.Create;
  68.   try
  69.     Md5Stream.Write(Data[1], Length(Data));
  70.     BSEHeader.rgbUid:= Md5Stream.Digest;
  71.   finally
  72.     FreeAndNil(Md5Stream);
  73.   end;
  74.  
  75.   FillChar(BSEHeader, SizeOf(BSEHeader), 0);
  76.   BlipData:=TMemoryStream.Create;
  77.   try
  78.     //Common header
  79.     BlipData.Write(BSEHeader.rgbUid, SizeOf(BSEHeader.rgbUid));
  80.  
  81.     // Specific info
  82.     if DataType in [xli_JPEG, xli_PNG] then
  83.       LoadDataBMP(Data, DataType, BlipData) else
  84.       LoadDataWMF(Data, DataType, BlipData);
  85.  
  86.     BSEHeader.btWin32:= XlsImgConv[DataType];
  87.     BSEHeader.btMacOS:= msoblipPICT;
  88.  
  89.     BSEHeader.tag:=$FF;
  90.     BSEHeader.size:= BlipData.Size+ SizeOf(BlipHeader);
  91.     BSEHeader.cRef:=0;
  92.     BSEHeader.foDelay:=0;
  93.  
  94.     Eh.Id:= MsofbtBSE;
  95.     Eh.Pre:=2 + XlsImgConv[DataType] shl 4;
  96.     Eh.Size:=BSEHeader.size + SizeOf(BSEHeader);
  97.     Result:= TEscherBSERecord.Create(Eh, DwgGroupCache, DwgCache, DwgGroupCache.BStore);
  98.  
  99.     BlipHeader.Id:= XlsBlipHeaderConv[DataType];
  100.     BlipHeader.Pre:= XlsBlipSignConv[DataType] shl 4;
  101.     BlipHeader.Size:=BlipData.Size;
  102.  
  103.     BlipData.Position:=0;
  104.     Result.CopyFromData(@BSEHeader, BlipHeader, BlipData);
  105.   finally
  106.     FreeAndNil(BlipData);
  107.   end; //finally
  108. end;
  109.  
  110. end.
  111.