fontlabapp.vfjo._data
_data
The Objects root: FontLab 9.1 object JSON as a guarded python-box tree.
What: loads validates object JSON with json_data.Envelope.parse and
casts it onto a Box subclass, so objs.data.glyph.layers[0].advanceWidth
reads like Python. Objects wraps that tree (Objects.data) and adds
helpers that are not JSON keys: kind, glyphs, glyph_names,
to_dict, to_bytes, envelope, describe, save,
copy_to_clipboard, paste and copy.
How: every level of the tree is a _Data box. Reading a missing key
raises UnknownKeyError (a KeyError and AttributeError).
Existing keys can be written freely. A new key is refused on the known
levels (root, glyph, layer, element, ...) unless it is in KNOWN_KEYS,
so a misspelt advanceWidht fails instead of being saved silently.
add_key(box, key, value) adds any key on purpose. The level of a box
comes from the key that holds it; levels not listed (hints, lib)
accept any key.
Lists are guarded too: an item added by append, extend, insert,
+= or lst[i] = ... becomes a _Data box locked at the level its
list implies (a dict appended to glyph.layers is a layer). A dict or list
assigned to a key is locked at that key's level the same way. Every key of
such an added mapping, at every depth, is checked against KNOWN_KEYS
first, so anchors += [{"nmae": "top", ...}] raises UnknownKeyError
and nothing is stored. Data loaded from FontLab and boxes moved within a
guarded tree are not rechecked. update, |= and setdefault go
through the same check as box[key] = value.
Limits: Box and dict method names (items, keys, values,
copy, update, get, to_dict, ...) shadow JSON keys of the
same name in attribute access; use x["items"] for those. Keys are used
exactly as FontLab writes them: no dotted paths and no converted names
(lib["a-b"] is not reachable as lib.a_b).
Classes
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
KNOWN_KEYS |
attribute | dict[str, frozenset[str]] |
Keys a known level accepts as new keys; other new keys need <code>add_key</code>. |
add_key |
function | (box: Box, key: str, value: Any) -> Box |
Add <code>key</code><code> to </code><code>box</code><code> even when its level does not know it; return </code><code>box</code>. |
from_clipboard |
function | () -> Objects | None |
Return the object JSON on the clipboard, or <code>None</code> when there is none. |
from_glyphs |
function | (glyphs: Any=None, font: Any=None) -> Objects |
Export glyphs (names or <code>flGlyph</code><code>) of </code><code>font</code><code> as </code><code>Objects</code>. |
load |
function | (path: str | Path) -> Objects |
Read object JSON from a file. |
loads |
function | (data: Any) -> Objects |
Return <code>Objects</code><code> from object JSON bytes, text, a mapping or </code><code>Objects</code>. |