def StretchDIBits(emf, num, page): cmd = mfpage.cmd() cmd.type = 81 cmd.args = emf.records[num].xDest,emf.records[num].yDest,emf.records[num].cxSrc,emf.records[num].cySrc, emf.records[num].nSize-58,\ emf.records[num].cbBmiSrc+14,emf.records[num].cxDest,emf.records[num].cyDest,emf.records[num].dwRop,\ emf.records[num].data[72:] page.cmds.append(cmd)
def SetPolyfillMode(emf,num,page): cmd = mfpage.cmd() cmd.type = 262 if emf.records[num].iMode == 2: cmd.args = 0 else: cmd.args = 1 page.cmds.append(cmd)
def SetPolyfillMode(emf, num, page): cmd = mfpage.cmd() cmd.type = 19 if emf.records[num].iMode == 2: cmd.args = 0 else: cmd.args = 1 page.cmds.append(cmd)
def TextOut(emf, num, page): cmd = mfpage.cmd() cmd.type = 1313 count = emf.records[num].values[0] text = emf.records[num].data[2:2 + count] [y] = struct.unpack('>h', emf.records[num].data[2 + count:4 + count]) [x] = struct.unpack('>h', emf.records[num].data[4 + count:6 + count]) cmd.args = x, y, text, '' page.cmds.append(cmd)
def TextOut(emf,num,page): cmd = mfpage.cmd() cmd.type = 1313 count = emf.records[num].values[0] text = emf.records[num].data[2:2+count] [y] = struct.unpack('>h',emf.records[num].data[2+count:4+count]) [x] = struct.unpack('>h',emf.records[num].data[4+count:6+count]) cmd.args = x,y,text,'' page.cmds.append(cmd)
def PolyPolygone(emf,num,page): cmd = mfpage.cmd() cmd.type = 1336 nPolys = emf.records[num].nPolys erd = emf.records[num].data[2:] aptl = {} for i in range(nPolys): [aptl[i]] = struct.unpack('<h',erd[i*2:i*2+2]) cmd.args = nPolys,aptl,erd[nPolys*2:] page.cmds.append(cmd)
def SetBKColor(emf, num, page): cmd = mfpage.cmd() cmd.type = 25 bkColor = emf.records[num].crColor f = (bkColor >> 24) & 0xFF b = (bkColor >> 16) & 0xFF g = (bkColor >> 8) & 0xFF r = bkColor & 0xFF cmd.args = r, g, b, f page.cmds.append(cmd)
def SetBKColor(emf,num,page): cmd = mfpage.cmd() cmd.type = 513 bkColor = emf.records[num].bkColor f = (bkColor>>24)&0xFF b = (bkColor>>16)&0xFF g = (bkColor>>8)&0xFF r = bkColor&0xFF cmd.args = r,g,b,f page.cmds.append(cmd)
def SetTextColor(emf,num,page): cmd = mfpage.cmd() cmd.type = 521 crColor = emf.records[num].crColor f = (crColor>>24)&0xFF b = (crColor>>16)&0xFF g = (crColor>>8)&0xFF r = crColor&0xFF cmd.args = r,g,b,f page.cmds.append(cmd)
def PolyPolygone(emf, num, page): cmd = mfpage.cmd() cmd.type = 1336 nPolys = emf.records[num].nPolys erd = emf.records[num].data[2:] aptl = {} for i in range(nPolys): [aptl[i]] = struct.unpack('<h', erd[i * 2:i * 2 + 2]) cmd.args = nPolys, aptl, erd[nPolys * 2:] page.cmds.append(cmd)
def ExtTextOutW(emf, num, page): cmd = mfpage.cmd() cmd.type = 84 er = emf.records[num] text = er.string x = er.values[0] y = er.values[1] xscl = er.values[5] yscl = er.values[6] text = unicode(text, 'utf-16').encode('utf-8') ## start,dx = er.unserializeList("i",er.nChars,er.data,er.unserializeOffset(er.offDx)) cmd.args = x, y, text, '', xscl, yscl page.cmds.append(cmd)
def CreatePatternBrush(emf, num, page): cmd = mfpage.cmd() cmd.type = 505 i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: cmd.args = emf.records[num].data page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreatePalette(emf,num,page): cmd = mfpage.cmd() cmd.type = 247 i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: cmd.args = i,emf.records[num].lpltNumofclr, emf.records[num].data[4:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreatePatternBrush(emf,num,page): cmd = mfpage.cmd() cmd.type = 505 i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: cmd.args = emf.records[num].data page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreatePen(emf, num, page): cmd = mfpage.cmd() cmd.type = 38 handle = emf.records[num].handle lbColor = emf.records[num].lopn_color width = emf.records[num].lopn_width style = emf.records[num].lopn_style f = (lbColor >> 24) & 0xFF b = (lbColor >> 16) & 0xFF g = (lbColor >> 8) & 0xFF r = lbColor & 0xFF cmd.args = handle, r, g, b, f, width * 1., style page.cmds.append(cmd)
def CreateBrushIndirect(emf, num, page): cmd = mfpage.cmd() cmd.type = 39 handle = emf.records[num].handle lbStyle = emf.records[num].lbStyle lbColor = emf.records[num].lbColor lbHatch = emf.records[num].lbHatch f = (lbColor >> 24) & 0xFF b = (lbColor >> 16) & 0xFF g = (lbColor >> 8) & 0xFF r = lbColor & 0xFF cmd.args = handle, r, g, b, f, lbStyle, lbHatch page.cmds.append(cmd)
def CreatePalette(emf, num, page): cmd = mfpage.cmd() cmd.type = 247 i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: cmd.args = i, emf.records[num].lpltNumofclr, emf.records[num].data[ 4:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def ExtTextOut(emf, num, page): cmd = mfpage.cmd() cmd.type = 2610 y = emf.records[num].values[0] x = emf.records[num].values[1] count = emf.records[num].values[2] flag = emf.records[num].values[3] shift = 8 if flag & 4: shift = 16 text = emf.records[num].data[shift:shift + count] dx = emf.records[num].data[shift + count:] cmd.args = x, y, text, dx page.cmds.append(cmd)
def CreateFontIndirect(emf, num, page): cmd = mfpage.cmd() cmd.type = 763 i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: er = emf.records[num] cmd.args = i, er.values, er.data[18:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def StretchDIBits(emf, num, page): cmd = mfpage.cmd() cmd.type = 3907 er = emf.records[num] bd = er.bmpDepth bshift = palsize[bd] + 54 cmd.args = er.topDest,er.leftDest,\ er.rightSrc-er.leftSrc,\ er.topSrc-er.bottomSrc,\ er.nSize-14,bshift,\ er.cxDest,\ er.cyDest,\ er.dwRop,er.data[22:] page.cmds.append(cmd)
def StretchDIBits(emf,num,page): cmd = mfpage.cmd() cmd.type = 3907 er = emf.records[num] bd = er.bmpDepth bshift = palsize[bd]+54 cmd.args = er.topDest,er.leftDest,\ er.rightSrc-er.leftSrc,\ er.topSrc-er.bottomSrc,\ er.nSize-14,bshift,\ er.cxDest,\ er.cyDest,\ er.dwRop,er.data[22:] page.cmds.append(cmd)
def ExtTextOut(emf,num,page): cmd = mfpage.cmd() cmd.type = 2610 y = emf.records[num].values[0] x = emf.records[num].values[1] count = emf.records[num].values[2] flag = emf.records[num].values[3] shift = 8 if flag&4: shift = 16 text = emf.records[num].data[shift:shift+count] dx = emf.records[num].data[shift+count:] cmd.args = x,y,text,dx page.cmds.append(cmd)
def CreateFontIndirect(emf,num,page): cmd = mfpage.cmd() cmd.type = 763 i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: er = emf.records[num] cmd.args = i,er.values,er.data[18:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def DibCreatePatternBrush(emf,num,page): cmd = mfpage.cmd() cmd.type = 322 i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: ern = emf.records[num] bd = ern.biDepth bshift = palsize[bd]+54 cmd.args = i,ern.biWidth,ern.biHeight,ern.nSize+4,bshift,ern.data[4:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def DibCreatePatternBrush(emf, num, page): cmd = mfpage.cmd() cmd.type = 322 i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: ern = emf.records[num] bd = ern.biDepth bshift = palsize[bd] + 54 cmd.args = i, ern.biWidth, ern.biHeight, ern.nSize + 4, bshift, ern.data[ 4:] page.mfobjs[i] = 0 page.cmds.append(cmd) break
def parse(page): counter = 0 wmf = page.file for i in range(len(wmf.records)): id = wmf.records[i].mr_id if mr_ids.has_key(id): if mr_cmds.has_key(id): print i,mr_ids[id] mr_cmds[id](wmf,i,page) else: cmd = mfpage.cmd() cmd.type = id page.cmds.append(cmd) counter+=1 print i,'UNSUPPORTED COMMAND!', mr_ids[id] else: print 'Unknown key: ',id print 'Unknown commands: ',counter
def parse(page): counter = 0 wmf = page.file for i in range(len(wmf.records)): id = wmf.records[i].mr_id if mr_ids.has_key(id): if mr_cmds.has_key(id): print i, mr_ids[id] mr_cmds[id](wmf, i, page) else: cmd = mfpage.cmd() cmd.type = id page.cmds.append(cmd) counter += 1 print i, 'UNSUPPORTED COMMAND!', mr_ids[id] else: print 'Unknown key: ', id print 'Unknown commands: ', counter
def CreateBrushIndirect(emf,num,page): cmd = mfpage.cmd() cmd.type = 764 lbStyle = emf.records[num].lbStyle lbColor = emf.records[num].lbColor lbHatch = emf.records[num].lbHatch f = (lbColor>>24)&0xFF b = (lbColor>>16)&0xFF g = (lbColor>>8)&0xFF r = lbColor&0xFF i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: cmd.args = i,r,g,b,f,lbStyle,lbHatch page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreatePenIndirect(emf, num, page): cmd = mfpage.cmd() cmd.type = 762 lbColor = emf.records[num].lopnColor width = emf.records[num].lopnWidth style = emf.records[num].lopnStyle f = (lbColor >> 24) & 0xFF b = (lbColor >> 16) & 0xFF g = (lbColor >> 8) & 0xFF r = lbColor & 0xFF i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: cmd.args = i, r, g, b, f, width * 1., style page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreatePenIndirect(emf,num,page): cmd = mfpage.cmd() cmd.type = 762 lbColor = emf.records[num].lopnColor width = emf.records[num].lopnWidth style = emf.records[num].lopnStyle f = (lbColor>>24)&0xFF b = (lbColor>>16)&0xFF g = (lbColor>>8)&0xFF r = lbColor&0xFF i = 0 while i<page.maxobj: try: data = page.mfobjs[i] i+=1 except: cmd.args = i,r,g,b,f,width*1.,style page.mfobjs[i] = 0 page.cmds.append(cmd) break
def CreateBrushIndirect(emf, num, page): cmd = mfpage.cmd() cmd.type = 764 lbStyle = emf.records[num].lbStyle lbColor = emf.records[num].lbColor lbHatch = emf.records[num].lbHatch f = (lbColor >> 24) & 0xFF b = (lbColor >> 16) & 0xFF g = (lbColor >> 8) & 0xFF r = lbColor & 0xFF i = 0 while i < page.maxobj: try: data = page.mfobjs[i] i += 1 except: cmd.args = i, r, g, b, f, lbStyle, lbHatch page.mfobjs[i] = 0 page.cmds.append(cmd) break
def parse(page): emf = page.file page.width = emf.records[0].values[2] ##*emf.records[0].values[6] page.height = emf.records[0].values[3] ##*emf.records[0].values[7] page.scale = emf.records[0].values[18] * 1. / emf.records[0].values[20] counter = 0 for i in range(len(emf.records)): id = emf.records[i].emr_id if emr_ids.has_key(id): if cmds.has_key(id): cmds[id](emf, i, page) else: cmd = mfpage.cmd() cmd.type = id page.cmds.append(cmd) counter += 1 print 'UNSUPPORTED COMMAND! ', emr_ids[id] else: print 'Unknown key: ', id print 'Unknown commands: ', counter return page
def SelectClipPath(emf, num, page): cmd = mfpage.cmd() cmd.type = 67 page.cmds.append(cmd)
def SetTextAlign(emf,num,page): cmd = mfpage.cmd() cmd.type = 302 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def SetStretchBltMode(emf,num,page): cmd = mfpage.cmd() cmd.type = 263 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def SetRop2(emf, num, page): cmd = mfpage.cmd() cmd.type = 20 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def SelectObject(emf,num,page): cmd = mfpage.cmd() cmd.type = 301 cmd.args = emf.records[num].handle page.cmds.append(cmd)
def SetTextAlign(emf, num, page): cmd = mfpage.cmd() cmd.type = 22 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def IntersectClipRect(emf,num,page): cmd = mfpage.cmd() cmd.type = 1046 cmd.args = emf.records[num].values page.cmds.append(cmd)
def Polyline(emf,num,page): cmd = mfpage.cmd() cmd.type = 805 cmd.args = emf.records[num].aptl page.cmds.append(cmd)
def SetICMMode(emf, num, page): cmd = mfpage.cmd() cmd.type = 98 cmd.args = emf.records[num].values page.cmds.append(cmd)
def SaveDC(emf,num,page): cmd = mfpage.cmd() cmd.type = 30 page.cmds.append(cmd)
def DeleteObject(emf,num,page): cmd = mfpage.cmd() cmd.type = 496 cmd.args = emf.records[num].handle del page.mfobjs[emf.records[num].handle] page.cmds.append(cmd)
def Aldus_Header(emf,num,page): cmd = mfpage.cmd() cmd.type = 1 cmd.args = emf.records[num].values page.cmds.append(cmd)
def ExtCreateFontIndirectW(emf, num, page): cmd = mfpage.cmd() cmd.type = 82 cmd.args = emf.records[num].values page.cmds.append(cmd)
def SelectPalette(emf,num,page): cmd = mfpage.cmd() cmd.type = 564 cmd.args = emf.records[num].values page.cmds.append(cmd)
def SetStretchBltMode(emf, num, page): cmd = mfpage.cmd() cmd.type = 21 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def SetBKMode(emf,num,page): cmd = mfpage.cmd() cmd.type = 258 cmd.args = emf.records[num].values page.cmds.append(cmd)
def RestoreDC(emf,num,page): cmd = mfpage.cmd() cmd.type = 295 page.cmds.append(cmd)
def SetROP2(emf,num,page): cmd = mfpage.cmd() cmd.type = 260 cmd.args = emf.records[num].iMode page.cmds.append(cmd)
def PolylineTo(emf, num, page): cmd = mfpage.cmd() cmd.type = 6 cmd.args = emf.records[num].aptl page.cmds.append(cmd)
def Polygone(emf, num, page): cmd = mfpage.cmd() cmd.type = 3 ## x,y = emf.records[num].values[0],emf.records[num].values[3] cmd.args = emf.records[num].aptl page.cmds.append(cmd)
def SelectPalette(emf, num, page): cmd = mfpage.cmd() cmd.type = 48 cmd.args = emf.records[num].values page.cmds.append(cmd)
def LineTo(emf,num,page): cmd = mfpage.cmd() cmd.type = 531 cmd.args = emf.records[num].values page.cmds.append(cmd)
def IntersectClipRect(emf, num, page): cmd = mfpage.cmd() cmd.type = 30 cmd.args = emf.records[num].values page.cmds.append(cmd)
def Arc(emf,num,page): cmd = mfpage.cmd() cmd.type = 2071 cmd.args = emf.records[num].values page.cmds.append(cmd)
def PolybezierTo(emf, num, page): cmd = mfpage.cmd() cmd.type = 5 cmd.args = emf.records[num].aptl page.cmds.append(cmd)
def Ellipse(emf,num,page): cmd = mfpage.cmd() cmd.type = 1048 cmd.args = emf.records[num].values page.cmds.append(cmd)
def PolyPolyline(emf, num, page): cmd = mfpage.cmd() cmd.type = 7 x, y = emf.records[num].values[0], emf.records[num].values[3] cmd.args = emf.records[num].aPolyCounts, emf.records[num].aptl, (x, y) page.cmds.append(cmd)
def SetViewportOrgEx(emf,num,page): cmd = mfpage.cmd() cmd.type = 525 cmd.args = emf.records[num].values page.cmds.append(cmd)