T_S_I__1.py :  » GUI » TTX-FontTools » fonttools-2.3 » Lib » fontTools » ttLib » tables » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » TTX FontTools 
TTX FontTools » fonttools 2.3 » Lib » fontTools » ttLib » tables » T_S_I__1.py
import DefaultTable
import string

class table_T_S_I__1(DefaultTable.DefaultTable):
  
  extras = {0xfffa: "ppgm", 0xfffb: "cvt", 0xfffc: "reserved", 0xfffd: "fpgm"}
  
  indextable = "TSI0"
  
  def decompile(self, data, ttFont):
    indextable = ttFont[self.indextable]
    self.glyphPrograms = {}
    for i in range(len(indextable.indices)):
      glyphID, textLength, textOffset = indextable.indices[i]
      if textLength == 0x8000:
        # Ugh. Hi Beat!
        textLength = indextable.indices[i+1][1]
      if textLength > 0x8000:
        pass  # XXX Hmmm.
      text = data[textOffset:textOffset+textLength]
      assert len(text) == textLength
      if text:
        self.glyphPrograms[ttFont.getGlyphName(glyphID)] = text
    
    self.extraPrograms = {}
    for i in range(len(indextable.extra_indices)):
      extraCode, textLength, textOffset = indextable.extra_indices[i]
      if textLength == 0x8000:
        if self.extras[extraCode] == "fpgm":  # this is the last one
          textLength = len(data) - textOffset
        else:
          textLength = indextable.extra_indices[i+1][1]
      text = data[textOffset:textOffset+textLength]
      assert len(text) == textLength
      if text:
        self.extraPrograms[self.extras[extraCode]] = text
  
  def compile(self, ttFont):
    if not hasattr(self, "glyphPrograms"):
      self.glyphPrograms = {}
      self.extraPrograms = {}
    data = ''
    indextable = ttFont[self.indextable]
    glyphNames = ttFont.getGlyphOrder()
    
    indices = []
    for i in range(len(glyphNames)):
      if len(data) % 2:
        data = data + "\015"  # align on 2-byte boundaries, fill with return chars. Yum.
      name = glyphNames[i]
      if self.glyphPrograms.has_key(name):
        text = self.glyphPrograms[name]
      else:
        text = ""
      textLength = len(text)
      if textLength >= 0x8000:
        textLength = 0x8000  # XXX ???
      indices.append((i, textLength, len(data)))
      data = data + text
    
    extra_indices = []
    codes = self.extras.items()
    codes.sort()
    for i in range(len(codes)):
      if len(data) % 2:
        data = data + "\015"  # align on 2-byte boundaries, fill with return chars.
      code, name = codes[i]
      if self.extraPrograms.has_key(name):
        text = self.extraPrograms[name]
      else:
        text = ""
      textLength = len(text)
      if textLength >= 0x8000:
        textLength = 0x8000  # XXX ???
      extra_indices.append((code, textLength, len(data)))
      data = data + text
    indextable.set(indices, extra_indices)
    return data
  
  def toXML(self, writer, ttFont):
    names = self.glyphPrograms.keys()
    names.sort()
    writer.newline()
    for name in names:
      text = self.glyphPrograms[name]
      if not text:
        continue
      writer.begintag("glyphProgram", name=name)
      writer.newline()
      writer.write_noindent(string.replace(text, "\r", "\n"))
      writer.newline()
      writer.endtag("glyphProgram")
      writer.newline()
      writer.newline()
    extra_names = self.extraPrograms.keys()
    extra_names.sort()
    for name in extra_names:
      text = self.extraPrograms[name]
      if not text:
        continue
      writer.begintag("extraProgram", name=name)
      writer.newline()
      writer.write_noindent(string.replace(text, "\r", "\n"))
      writer.newline()
      writer.endtag("extraProgram")
      writer.newline()
      writer.newline()
  
  def fromXML(self, (name, attrs, content), ttFont):
    if not hasattr(self, "glyphPrograms"):
      self.glyphPrograms = {}
      self.extraPrograms = {}
    lines = string.split(string.replace(string.join(content, ""), "\r", "\n"), "\n")
    text = string.join(lines[1:-1], "\r")
    if name == "glyphProgram":
      self.glyphPrograms[attrs["name"]] = text
    elif name == "extraProgram":
      self.extraPrograms[attrs["name"]] = text

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.