|
12 | 12 | from extractor.stream import InstructionStream
|
13 | 13 | from extractor.tools import RelaxedInfo, copyAttr
|
14 | 14 |
|
| 15 | + |
| 16 | +TRUETYPE_INSTRUCTIONS_KEY = "public.truetype.instructions" |
| 17 | +TRUETYPE_ROUND_KEY = "public.truetype.roundOffsetToGrid" |
| 18 | +TRUETYPE_METRICS_KEY = "public.truetype.useMyMetrics" |
| 19 | +TRUETYPE_OVERLAP_KEY = "public.truetype.overlap" |
| 20 | +OBJECT_LIBS_KEY = "public.objectLibs" |
| 21 | + |
15 | 22 | # ----------------
|
16 | 23 | # Public Functions
|
17 | 24 | # ----------------
|
@@ -93,7 +100,7 @@ def extractInstructions(source, destination):
|
93 | 100 | if "glyf" not in source:
|
94 | 101 | return
|
95 | 102 |
|
96 |
| - lib = destination.lib["public.truetype.instructions"] = { |
| 103 | + lib = destination.lib[TRUETYPE_INSTRUCTIONS_KEY] = { |
97 | 104 | "formatVersion": 1,
|
98 | 105 | "maxFunctionDefs": 0,
|
99 | 106 | "maxInstructionDefs": 0,
|
@@ -149,7 +156,7 @@ def extractGlyphPrograms(source, destination):
|
149 | 156 |
|
150 | 157 | hash_pen = HashPointPen(dest_glyph.width, destination)
|
151 | 158 | dest_glyph.drawPoints(hash_pen)
|
152 |
| - lib = dest_glyph.lib["public.truetype.instructions"] = { |
| 159 | + lib = dest_glyph.lib[TRUETYPE_INSTRUCTIONS_KEY] = { |
153 | 160 | "formatVersion": "1",
|
154 | 161 | "id": hash_pen.hash,
|
155 | 162 | }
|
@@ -192,33 +199,24 @@ def _byteCodeToTtxAssembly(program):
|
192 | 199 |
|
193 | 200 | def _extractCompositeFlags(glyph, dest_glyph):
|
194 | 201 | # Find the lib key or add it
|
195 |
| - if ( |
196 |
| - "public.objectLibs" not in dest_glyph.lib |
197 |
| - or "public.objectIdentifiers" |
198 |
| - not in dest_glyph.lib["public.objectLibs"] |
199 |
| - ): |
200 |
| - dest_glyph.lib["public.objectLibs"] = { |
201 |
| - "public.objectIdentifiers": {} |
202 |
| - } |
203 |
| - object_ids = dest_glyph.lib["public.objectLibs"][ |
204 |
| - "public.objectIdentifiers" |
205 |
| - ] |
| 202 | + if OBJECT_LIBS_KEY not in dest_glyph.lib: |
| 203 | + dest_glyph.lib[OBJECT_LIBS_KEY] = {} |
| 204 | + object_libs = dest_glyph.lib[OBJECT_LIBS_KEY] |
206 | 205 |
|
207 | 206 | for ci, c in enumerate(glyph.components):
|
208 | 207 | flags = {}
|
209 |
| - if c.flags & ROUND_XY_TO_GRID: |
210 |
| - flags["round"] = True |
211 |
| - if c.flags & USE_MY_METRICS: |
212 |
| - flags["useMyMetrics"] = True |
213 |
| - if c.flags & OVERLAP_COMPOUND: |
214 |
| - flags["overlap"] = True |
| 208 | + flags[TRUETYPE_ROUND_KEY] = bool(c.flags & ROUND_XY_TO_GRID) |
| 209 | + flags[TRUETYPE_METRICS_KEY] = bool(c.flags & USE_MY_METRICS) |
215 | 210 |
|
216 | 211 | if flags:
|
217 | 212 | identifier = f"component{ci}"
|
218 | 213 | dest_glyph.components[ci].identifier = identifier
|
219 |
| - object_ids[identifier] = { |
220 |
| - "public.truetype.instructions": flags |
221 |
| - } |
| 214 | + object_libs[identifier] = flags |
| 215 | + |
| 216 | + # Overlap is stored directly in the glyph lib |
| 217 | + dest_glyph.lib["public.truetype.overlap"] = bool( |
| 218 | + c.flags & OVERLAP_COMPOUND |
| 219 | + ) |
222 | 220 |
|
223 | 221 |
|
224 | 222 | # ----
|
|
0 commit comments