This repository has been archived on 2025-10-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
inter-font/misc/pylib/extractor/tools.py
2017-11-28 17:11:48 -08:00

32 lines
929 B
Python
Executable file

from ufoLib import fontInfoAttributesVersion3, validateFontInfoVersion3ValueForAttribute
class RelaxedInfo(object):
"""
This object that sets only valid info values
into the given info object.
"""
def __init__(self, info):
self._object = info
def __getattr__(self, attr):
if attr in fontInfoAttributesVersion3:
return getattr(self._object, attr)
else:
return super(RelaxedInfo, self).__getattr__(attr)
def __setattr__(self, attr, value):
if attr in fontInfoAttributesVersion3:
if validateFontInfoVersion3ValueForAttribute(attr, value):
setattr(self._object, attr, value)
else:
super(RelaxedInfo, self).__setattr__(attr, value)
def copyAttr(src, srcAttr, dest, destAttr):
if not hasattr(src, srcAttr):
return
value = getattr(src, srcAttr)
setattr(dest, destAttr, value)