| | 36 | |
|---|
| | 37 | |
|---|
| | 38 | |
|---|
| | 39 | # the key for the postscript hint data stored in the UFO |
|---|
| | 40 | postScriptHintDataLibKey = "org.robofab.postScriptHintData" |
|---|
| | 41 | |
|---|
| | 42 | |
|---|
| | 43 | class BasePostScriptFontHintValues(object): |
|---|
| | 44 | """ Base class for font-level postscript hinting information. |
|---|
| | 45 | Blues values, stem values. |
|---|
| | 46 | """ |
|---|
| | 47 | |
|---|
| | 48 | _attrs = { |
|---|
| | 49 | # some of these values can have only a certain number of elements |
|---|
| | 50 | 'blueFuzz': {'default': None, 'max':1}, |
|---|
| | 51 | 'blueScale': {'default': None, 'max':1}, |
|---|
| | 52 | 'blueShift': {'default': None, 'max':1}, |
|---|
| | 53 | 'forceBold': {'default': None, 'max':1}, |
|---|
| | 54 | 'blueValues': {'default': None, 'max':13}, |
|---|
| | 55 | 'otherBlues': {'default': None, 'max':9}, |
|---|
| | 56 | 'familyBlues': {'default': None, 'max':13}, |
|---|
| | 57 | 'familyOtherBlues': {'default': None, 'max':9}, |
|---|
| | 58 | 'vStems': {'default': None, 'max':11}, |
|---|
| | 59 | 'hStems': {'default': None, 'max':11}, |
|---|
| | 60 | } |
|---|
| | 61 | |
|---|
| | 62 | def __init__(self): |
|---|
| | 63 | for name in self._attrs.keys(): |
|---|
| | 64 | setattr(self, name, self._attrs[name]) |
|---|
| | 65 | |
|---|
| | 66 | def getParent(self): |
|---|
| | 67 | """this method will be overwritten with a weakref if there is a parent.""" |
|---|
| | 68 | return None |
|---|
| | 69 | |
|---|
| | 70 | def setParent(self, parent): |
|---|
| | 71 | import weakref |
|---|
| | 72 | self.getParent = weakref.ref(parent) |
|---|
| | 73 | |
|---|
| | 74 | def fromDict(self, data): |
|---|
| | 75 | for name in self._attrs: |
|---|
| | 76 | if name in data: |
|---|
| | 77 | setattr(self, name, data[name]) |
|---|
| | 78 | |
|---|
| | 79 | def asDict(self): |
|---|
| | 80 | d = {} |
|---|
| | 81 | for name in self._attrs: |
|---|
| | 82 | try: |
|---|
| | 83 | value = getattr(self, name) |
|---|
| | 84 | except AttributeError: |
|---|
| | 85 | print "%s attribute not supported"%name |
|---|
| | 86 | continue |
|---|
| | 87 | if value is not None or not value: |
|---|
| | 88 | d[name] = getattr(self, name) |
|---|
| | 89 | return d |
|---|
| | 90 | |
|---|
| | 91 | def __repr__(self): |
|---|
| | 92 | return "<PostScript Font Hints Values>" |
|---|