improved API for creating AFM files from scratch
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@134 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
0d51707e72
commit
6175debd67
@ -8,7 +8,7 @@ import re
|
|||||||
import string
|
import string
|
||||||
import types
|
import types
|
||||||
|
|
||||||
__version__ = "$Id: afmLib.py,v 1.2 2001-04-30 14:40:17 Just Exp $"
|
__version__ = "$Id: afmLib.py,v 1.3 2001-06-24 15:11:31 Just Exp $"
|
||||||
|
|
||||||
|
|
||||||
# every single line starts with a "word"
|
# every single line starts with a "word"
|
||||||
@ -189,7 +189,7 @@ class AFM:
|
|||||||
assert len(components) == ncomponents
|
assert len(components) == ncomponents
|
||||||
self._composites[charname] = components
|
self._composites[charname] = components
|
||||||
|
|
||||||
def write(self, path, sep = '\r'):
|
def write(self, path, sep='\r'):
|
||||||
import time
|
import time
|
||||||
lines = [ "StartFontMetrics 2.0",
|
lines = [ "StartFontMetrics 2.0",
|
||||||
"Comment Generated by afmLib, version %s; at %s" %
|
"Comment Generated by afmLib, version %s; at %s" %
|
||||||
@ -281,6 +281,12 @@ class AFM:
|
|||||||
def comments(self):
|
def comments(self):
|
||||||
return self._comments
|
return self._comments
|
||||||
|
|
||||||
|
def addComment(self, comment):
|
||||||
|
self._comments.append(comment)
|
||||||
|
|
||||||
|
def addComposite(self, glyphName, components):
|
||||||
|
self._composites[glyphName] = components
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if self._attrs.has_key(attr):
|
if self._attrs.has_key(attr):
|
||||||
return self._attrs[attr]
|
return self._attrs[attr]
|
||||||
@ -294,19 +300,42 @@ class AFM:
|
|||||||
else:
|
else:
|
||||||
self._attrs[attr] = value
|
self._attrs[attr] = value
|
||||||
|
|
||||||
|
def __delattr__(self, attr):
|
||||||
|
# all attrs *not* starting with "_" are consider to be AFM keywords
|
||||||
|
if attr[:1] == "_":
|
||||||
|
try:
|
||||||
|
del self.__dict__[attr]
|
||||||
|
except KeyError:
|
||||||
|
raise AttributeError, attr
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
del self._attrs[attr]
|
||||||
|
except KeyError:
|
||||||
|
raise AttributeError, attr
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if type(key) == types.TupleType:
|
if type(key) == types.TupleType:
|
||||||
# key is a tuple, return the kernpair
|
# key is a tuple, return the kernpair
|
||||||
if self._kerning.has_key(key):
|
return self._kerning[key]
|
||||||
return self._kerning[key]
|
|
||||||
else:
|
|
||||||
raise KeyError, "no kerning pair: " + str(key)
|
|
||||||
else:
|
else:
|
||||||
# return the metrics instead
|
# return the metrics instead
|
||||||
if self._chars.has_key(key):
|
return self._chars[key]
|
||||||
return self._chars[key]
|
|
||||||
else:
|
def __setitem__(self, key, value):
|
||||||
raise KeyError, "metrics index " + str(key) + " out of range"
|
if type(key) == types.TupleType:
|
||||||
|
# key is a tuple, set kernpair
|
||||||
|
self._kerning[key] = value
|
||||||
|
else:
|
||||||
|
# set char metrics
|
||||||
|
self._chars[key] = value
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
if type(key) == types.TupleType:
|
||||||
|
# key is a tuple, del kernpair
|
||||||
|
del self._kerning[key]
|
||||||
|
else:
|
||||||
|
# del char metrics
|
||||||
|
del self._chars[key]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if hasattr(self, "FullName"):
|
if hasattr(self, "FullName"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user