home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2120 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.8 KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import Image
  5. import FontFile
  6. import string
  7. bdf_slant = {
  8.     'R': 'Roman',
  9.     'I': 'Italic',
  10.     'O': 'Oblique',
  11.     'RI': 'Reverse Italic',
  12.     'RO': 'Reverse Oblique',
  13.     'OT': 'Other' }
  14. bdf_spacing = {
  15.     'P': 'Proportional',
  16.     'M': 'Monospaced',
  17.     'C': 'Cell' }
  18.  
  19. def bdf_char(f):
  20.     while None:
  21.         s = f.readline()
  22.         if not s:
  23.             return None
  24.         if s[:9] == 'STARTCHAR':
  25.             break
  26.             continue
  27.         continue
  28.         id = string.strip(s[9:])
  29.         props = { }
  30.         while None:
  31.             s = f.readline()
  32.             if not s or s[:6] == 'BITMAP':
  33.                 break
  34.             
  35.             i = string.find(s, ' ')
  36.             props[s[:i]] = s[i + 1:-1]
  37.             continue
  38.             bitmap = []
  39.             while None:
  40.                 s = f.readline()
  41.                 if not s or s[:7] == 'ENDCHAR':
  42.                     break
  43.                 
  44.                 continue
  45.                 bitmap = string.join(bitmap, '')
  46.                 (x, y, l, d) = map(int, string.split(props['BBX']))
  47.                 (dx, dy) = map(int, string.split(props['DWIDTH']))
  48.                 bbox = ((dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y))
  49.                 
  50.                 try:
  51.                     im = Image.fromstring('1', (x, y), bitmap, 'hex', '1')
  52.                 except ValueError:
  53.                     im = Image.new('1', (x, y))
  54.  
  55.                 return (id, int(props['ENCODING']), bbox, im)
  56.  
  57.  
  58. class BdfFontFile(FontFile.FontFile):
  59.     
  60.     def __init__(self, fp):
  61.         FontFile.FontFile.__init__(self)
  62.         s = fp.readline()
  63.         if s[:13] != 'STARTFONT 2.1':
  64.             raise SyntaxError, 'not a valid BDF file'
  65.         s[:13] != 'STARTFONT 2.1'
  66.         props = { }
  67.         comments = []
  68.         while None:
  69.             s = fp.readline()
  70.             if not s or s[:13] == 'ENDPROPERTIES':
  71.                 break
  72.             
  73.             i = string.find(s, ' ')
  74.             props[s[:i]] = s[i + 1:-1]
  75.             if s[:i] in ('COMMENT', 'COPYRIGHT'):
  76.                 if string.find(s, 'LogicalFontDescription') < 0:
  77.                     comments.append(s[i + 1:-1])
  78.                 
  79.             continue
  80.             font = string.split(props['FONT'], '-')
  81.             font[4] = bdf_slant[string.upper(font[4])]
  82.             font[11] = bdf_spacing[string.upper(font[11])]
  83.             ascent = int(props['FONT_ASCENT'])
  84.             descent = int(props['FONT_DESCENT'])
  85.             fontname = string.join(font[1:], ';')
  86.             font = []
  87.             while None:
  88.                 c = bdf_char(fp)
  89.                 if not c:
  90.                     break
  91.                 
  92.                 (xy, dst, src) = (id, ch)
  93.                 im = c
  94.                 if ch >= 0 and ch < len(self.glyph):
  95.                     self.glyph[ch] = (xy, dst, src, im)
  96.                     continue
  97.                 continue
  98.                 return None
  99.  
  100.  
  101.