| 1 |
from dataclasses import dataclass, field |
| 2 |
from .BaseObject import BaseObject, I18NDictionary |
| 3 |
|
| 4 |
|
| 5 |
@dataclass |
| 6 |
class _InstanceFields: |
| 7 |
name: I18NDictionary = field(metadata={"description": "The name of this instance."}) |
| 8 |
location: dict = field( |
| 9 |
metadata={ |
| 10 |
"description": """A dictionary mapping axis tags to coordinates in order to locate this instance in the design space.""" |
| 11 |
} |
| 12 |
) |
| 13 |
styleName: I18NDictionary = field( |
| 14 |
default_factory=I18NDictionary, |
| 15 |
metadata={"description": "The style name of this instance."}, |
| 16 |
) |
| 17 |
familyName: I18NDictionary = field( |
| 18 |
default_factory=I18NDictionary, |
| 19 |
metadata={"description": "The family name of this instance."}, |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
@dataclass |
| 24 |
class Instance(BaseObject, _InstanceFields): |
| 25 |
"""An object representing a named or static instance.""" |
| 26 |
|
| 27 |
_write_one_line = True |
| 28 |
|
| 29 |
def __post_init__(self): |
| 30 |
# If they smacked my name with a bare string, replace with I18NDict |
| 31 |
if isinstance(self.name, str): |
| 32 |
self.name = I18NDictionary.with_default(self.name) |
| 33 |
if isinstance(self.styleName, str): |
| 34 |
self.styleName = I18NDictionary.with_default(self.styleName) |
| 35 |
if isinstance(self.familyName, str): |
| 36 |
self.familyName = I18NDictionary.with_default(self.familyName) |
| 37 |
super().__post_init__() |
| 38 |
|
| 39 |
@property |
| 40 |
def localisedStyleName(self): |
| 41 |
return self.styleName.as_fonttools_dict or self.name.as_fonttools_dict |
| 42 |
|
| 43 |
@property |
| 44 |
def postScriptFontName(self): |
| 45 |
return None |