home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pypil112.zip / PIL-1.1.2.zip / Lib / site-packages / PIL / PSDraw.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2001-12-25  |  6KB  |  97 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. import EpsImagePlugin
  5. import string
  6.  
  7. class PSDraw:
  8.     
  9.     def __init__(self, fp = None):
  10.         if not fp:
  11.             import sys
  12.             fp = sys.stdout
  13.         
  14.         self.fp = fp
  15.  
  16.     
  17.     def begin_document(self, id = None):
  18.         '''Write Postscript DSC header'''
  19.         self.fp.write('%!PS-Adobe-3.0\nsave\n/showpage { } def\n%%EndComments\n%%BeginDocument\n')
  20.         self.fp.write(EDROFF_PS)
  21.         self.fp.write(VDI_PS)
  22.         self.fp.write('%%EndProlog\n')
  23.         self.isofont = { }
  24.  
  25.     
  26.     def end_document(self):
  27.         '''Write Postscript DSC footer'''
  28.         self.fp.write('%%EndDocument\nrestore showpage\n%%End\n')
  29.         if hasattr(self.fp, 'flush'):
  30.             self.fp.flush()
  31.         
  32.  
  33.     
  34.     def setfont(self, font, size):
  35.         if not self.isofont.has_key(font):
  36.             self.fp.write('/PSDraw-%s ISOLatin1Encoding /%s E\n' % (font, font))
  37.             self.isofont[font] = 1
  38.         
  39.         self.fp.write('/F0 %d /PSDraw-%s F\n' % (size, font))
  40.  
  41.     
  42.     def setink(self, ink):
  43.         print '*** NOT YET IMPLEMENTED ***'
  44.  
  45.     
  46.     def line(self, xy0, xy1):
  47.         xy = xy0 + xy1
  48.         self.fp.write('%d %d %d %d Vl\n' % xy)
  49.  
  50.     
  51.     def rectangle(self, box):
  52.         self.fp.write('%d %d M %d %d 0 Vr\n' % box)
  53.  
  54.     
  55.     def text(self, xy, text):
  56.         text = string.joinfields(string.splitfields(text, '('), '\\(')
  57.         text = string.joinfields(string.splitfields(text, ')'), '\\)')
  58.         xy = xy + (text,)
  59.         self.fp.write('%d %d M (%s) S\n' % xy)
  60.  
  61.     
  62.     def image(self, box, im, dpi = None):
  63.         '''Write an PIL image'''
  64.         if not dpi:
  65.             if im.mode == '1':
  66.                 dpi = 200
  67.             else:
  68.                 dpi = 100
  69.         
  70.         x = float(im.size[0] * 72) / dpi
  71.         y = float(im.size[1] * 72) / dpi
  72.         xmax = box[2] - box[0]
  73.         ymax = box[3] - box[1]
  74.         if x > xmax:
  75.             y = y * xmax / x
  76.             x = xmax
  77.         
  78.         if y > ymax:
  79.             x = x * ymax / y
  80.             y = ymax
  81.         
  82.         dx = (xmax - x) / 2 + box[0]
  83.         dy = (ymax - y) / 2 + box[1]
  84.         self.fp.write('gsize\n%f %f translate\n' % (dx, dy))
  85.         if (x, y) != im.size:
  86.             sx = x / im.size[0]
  87.             sy = y / im.size[1]
  88.             self.fp.write('%f %f scale\n' % (sx, sy))
  89.         
  90.         EpsImagePlugin._save(im, self.fp, None, 0)
  91.         self.fp.write('\ngrestore\n')
  92.  
  93.  
  94. EDROFF_PS = '/S { show } bind def\n/P { moveto show } bind def \n/M { moveto } bind def \n/X { 0 rmoveto } bind def \n/Y { 0 exch rmoveto } bind def \n/E {    findfont\n        dup maxlength dict begin\n        {\n                1 index /FID ne { def } { pop pop } ifelse\n        } forall\n        /Encoding exch def\n        dup /FontName exch def\n        currentdict end definefont pop\n} bind def\n/F {    findfont exch scalefont dup setfont\n        [ exch /setfont cvx ] cvx bind def\n} bind def\n'
  95. VDI_PS = '/Vm { moveto } bind def\n/Va { newpath arcn stroke } bind def\n/Vl { moveto lineto stroke } bind def\n/Vc { newpath 0 360 arc closepath } bind def\n/Vr {   exch dup 0 rlineto\n        exch dup neg 0 exch rlineto\n        exch neg 0 rlineto\n        0 exch rlineto\n        100 div setgray fill 0 setgray } bind def\n/Tm matrix def\n/Ve {   Tm currentmatrix pop\n        translate scale newpath 0 0 .5 0 360 arc closepath\n        Tm setmatrix\n} bind def\n/Vf { currentgray exch setgray fill setgray } bind def\n'
  96. ERROR_PS = '/landscape false def\n/errorBUF 200 string def\n/errorNL { currentpoint 10 sub exch pop 72 exch moveto } def\nerrordict begin /handleerror {\n    initmatrix /Courier findfont 10 scalefont setfont\n    newpath 72 720 moveto $error begin /newerror false def\n    (PostScript Error) show errorNL errorNL\n    (Error: ) show\n        /errorname load errorBUF cvs show errorNL errorNL\n    (Command: ) show\n        /command load dup type /stringtype ne { errorBUF cvs } if show\n        errorNL errorNL\n    (VMstatus: ) show\n        vmstatus errorBUF cvs show ( bytes available, ) show \n        errorBUF cvs show ( bytes used at level ) show\n        errorBUF cvs show errorNL errorNL\n    (Operand stargck: ) show errorNL /ostargck load { \n        dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL\n    } forall errorNL\n    (Execution stargck: ) show errorNL /estargck load {\n        dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL\n    } forall\n    end showpage\n} def end\n'
  97.