Debian Codegraph @

src/babelfont/Names.py

raw
1 from .BaseObject import BaseObject, I18NDictionary
2 from dataclasses import dataclass, asdict
3
4 OPENTYPE_NAMES = [
5 "copyright",
6 "familyName",
7 "preferredSubfamilyName",
8 "uniqueID",
9 "fullName", # XXX?
10 "version",
11 "postscriptName",
12 "trademark",
13 "manufacturer",
14 "designer",
15 "description",
16 "manufacturerURL",
17 "designerURL",
18 "license",
19 "licenseURL",
20 "reserved",
21 "typographicFamily",
22 "typographicSubfamily",
23 "compatibleFullName",
24 "sampleText",
25 "postscriptCIDname", # XXX?
26 "WWSFamilyName",
27 "WWSSubfamilyName",
28 ]
29
30
31 @dataclass
32 class Names(BaseObject):
33 """A table of global, localizable names for the font."""
34
35 familyName: I18NDictionary = None
36 designer: I18NDictionary = None
37 designerURL: I18NDictionary = None
38 manufacturer: I18NDictionary = None
39 manufacturerURL: I18NDictionary = None
40 license: I18NDictionary = None
41 licenseURL: I18NDictionary = None
42 version: I18NDictionary = None
43 uniqueID: I18NDictionary = None
44 postscriptName: I18NDictionary = None
45 fullName: I18NDictionary = None
46 description: I18NDictionary = None
47 typographicFamily: I18NDictionary = None
48 typographicSubfamily: I18NDictionary = None
49 compatibleFullName: I18NDictionary = None
50 sampleText: I18NDictionary = None
51 WWSFamilyName: I18NDictionary = None
52 WWSSubfamilyName: I18NDictionary = None
53 copyright: I18NDictionary = None
54 styleMapFamilyName: I18NDictionary = None
55 styleMapStyleName: I18NDictionary = None
56 styleName: I18NDictionary = None
57 trademark: I18NDictionary = None
58 preferredSubfamilyName: I18NDictionary = None
59
60 def __post_init__(self):
61 for k in self.__dataclass_fields__.keys():
62 if not getattr(self, k):
63 setattr(self, k, I18NDictionary())
64
65 def as_nametable_dict(self):
66 rv = {}
67 ft_names = {
68 "manufacturerURL": "vendorURL",
69 "license": "licenseDescription",
70 "licenseURL": "licenseInfoURL",
71 }
72 for k, v in asdict(self).items():
73 if not v:
74 continue
75 rv[ft_names.get(k, k)] = v.default_or_dict()
76 return rv