home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / XLSAdapter / UEscherGraphToBSE.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-03  |  4.2 KB  |  112 lines

  1. unit UEscherGraphToBSE;
  2.  
  3. interface
  4. uses Sysutils, Classes, XlsMessages, UEscherRecords, UXlsMD5, 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. {************************************************************************************}
  59. function ConvertGraphicToBSE(const Data: string; const DataType: TXlsImgTypes;
  60.   const DwgGroupCache: PEscherDwgGroupCache; const DwgCache: PEscherDwgCache):TEscherBSERecord;
  61. var
  62.   Eh: TEscherRecordHeader;
  63.   BSEHeader: TBSEHeader;
  64.   Md5Stream: TMd5Stream;
  65.   BlipData: TMemoryStream;
  66.   BlipHeader: TEscherRecordHeader;
  67. begin
  68.   Md5Stream:=TMd5Stream.Create;
  69.   try
  70.     Md5Stream.Write(Data[1], Length(Data));
  71.     BSEHeader.rgbUid:= Md5Stream.GetDigest;
  72.   finally
  73.     FreeAndNil(Md5Stream);
  74.   end;
  75.  
  76.   FillChar(BSEHeader, SizeOf(BSEHeader), 0);
  77.   BlipData:=TMemoryStream.Create;
  78.   try
  79.     //Common header
  80.     BlipData.Write(BSEHeader.rgbUid, SizeOf(BSEHeader.rgbUid));
  81.  
  82.     // Specific info
  83.     if DataType in [xli_JPEG, xli_PNG, xli_BMP] then
  84.       LoadDataBMP(Data, DataType, BlipData) else
  85.       LoadDataWMF(Data, DataType, BlipData);
  86.  
  87.     BSEHeader.btWin32:= XlsImgConv[DataType];
  88.     BSEHeader.btMacOS:= msoblipPICT;
  89.  
  90.     BSEHeader.tag:=$FF;
  91.     BSEHeader.size:= BlipData.Size+ SizeOf(BlipHeader);
  92.     BSEHeader.cRef:=0;
  93.     BSEHeader.foDelay:=0;
  94.  
  95.     Eh.Id:= MsofbtBSE;
  96.     Eh.Pre:=2 + XlsImgConv[DataType] shl 4;
  97.     Eh.Size:=BSEHeader.size + SizeOf(BSEHeader);
  98.     Result:= TEscherBSERecord.Create(Eh, DwgGroupCache, DwgCache, DwgGroupCache.BStore);
  99.  
  100.     BlipHeader.Id:= XlsBlipHeaderConv[DataType];
  101.     BlipHeader.Pre:= XlsBlipSignConv[DataType] shl 4;
  102.     BlipHeader.Size:=BlipData.Size;
  103.  
  104.     BlipData.Position:=0;
  105.     Result.CopyFromData(@BSEHeader, BlipHeader, BlipData);
  106.   finally
  107.     FreeAndNil(BlipData);
  108.   end; //finally
  109. end;
  110.  
  111. end.
  112.