--- pyemf.py.orig 2006-01-01 17:00:35 +0300 +++ pyemf.py 2007-10-08 00:01:22 +0400 @@ -501,6 +501,17 @@ MWT_IDENTITY = 1 MWT_LEFTMULTIPLY = 2 MWT_RIGHTMULTIPLY = 3 +## added by frob +# GdiComment values: +GDICOMMENT_IDENTIFIER = 0x43494447 +GDICOMMENT_WINDOWS_METAFILE = 0x80000001 +GDICOMMENT_BEGINGROUP = 2 +GDICOMMENT_ENDGROUP = 3 +GDICOMMENT_MULTIFORMATS = 0x40000004 +GDICOMMENT_UNICODE_STRING = 0x40 +GDICOMMENT_UNICODE_END = 0x80 +EPS_SIGNATURE = 0x46535045 +## end of frob addition def _round4(num): """Round to the nearest multiple of 4 greater than or equal to the @@ -866,7 +877,8 @@ class _EMR_UNKNOWN(object): # extend fro self.iType=itype self.nSize=nsize else: - (self.iType,self.nSize)=struct.unpack("8: self.datasize=self.nSize-8 self.data=fh.read(self.datasize) @@ -1737,7 +1749,41 @@ class _EMR: emr_id=68 pass +## Added by frob + class _GDICOMMENT(_EMR_UNKNOWN): + """Comment can contain a lot of significant information.""" + emr_id=70 + emr_typedef=[ + ('i','DataSize'), + ('i','Ident'), ## for public comments has to be always GDICOMMENT_IDENTIFIER + ('i','iComment') ## encode type of comment + ] + def __init__(self): + _EMR_UNKNOWN.__init__(self) +## if iComment == GDICOMMENT_WINDOWS_METAFILE: +## ('i','nVersion'), +## ('i','nChecksum'), +## ('i','fFlags'), +## ('i','cbWinMetaFile') ## size of embedded WMF + +## if iComment == GDICOMMENT_BEGINGROUP: +## ('i','rclBox_left'), +## ('i','rclBox_top'), +## ('i','rclBox_right'), +## ('i','rclBox_bottom'), +## ('i','nDescription') ## Num of chars in optional Unicode description +## if iComment == GDICOMMENT_ENDGROUP: +## pass ## there is no more fields for EndGroup, just 'Ident' and 'iComment' + +## if iComment == GDICOMMENT_MULTIFORMATS: +## ('i','rclBox_left'), +## ('i','rclBox_top'), +## ('i','rclBox_right'), +## ('i','rclBox_bottom'), +## ('i','nFormats'), ## numb of formats in the comment +## (EMRFORMAT aemrformat[1]) ## array of EMRFORMAT structures + #define EMR_GDICOMMENT 70 #define EMR_FILLRGN 71 #define EMR_FRAMERGN 72 @@ -2123,6 +2169,18 @@ integer coordinates. int(self.dc.width/100.0*self.dc.ref_pixelwidth/self.dc.ref_width), int(self.dc.height/100.0*self.dc.ref_pixelheight/self.dc.ref_height)) + def loadmem(self,membuf=None): + """ +Read an existing buffer with EMF file. If any records exist in the current +object, they will be overwritten by the records from this buffer. + +@param membuf: buffer to load +@type membuf: string +@returns: True for success, False for failure. +@rtype: Boolean + """ + fh = StringIO(membuf) + self._load(fh) def load(self,filename=None): """ @@ -2139,8 +2197,11 @@ object, they will be overwritten by the if self.filename: fh=open(self.filename) + self._load(fh) + + def _load(self,filehandler=None): self.records=[] - self._unserialize(fh) + self._unserialize(filehandler) self.scaleheader=False # get DC from header record self.dc.getBounds(self.records[0])