Skip to content

fontlabapp.objects.json_data · declarations 001

Back to fontlabapp.objects.json_data

DATA_TYPE module-attribute

DATA_TYPE

GLYPHS_UNDO_TEXT module-attribute

GLYPHS_UNDO_TEXT

Item module-attribute

Item

KINDS module-attribute

KINDS

MIME_TYPE module-attribute

MIME_TYPE

NEEDS_91 module-attribute

NEEDS_91

PARTIAL_TEXT module-attribute

PARTIAL_TEXT

SHAPES_UNDO_TEXT module-attribute

SHAPES_UNDO_TEXT

as_qbytearray

as_qbytearray(data: Any, qt: Any = None) -> Any

Return a QByteArray for data; a QByteArray passes unchanged.

available

available(fl: Any = None) -> bool

True when this FontLab has the object JSON API (9.1 or later).

copy_objects

copy_objects(package: Any, objects: Sequence[Any], *, fl: Any = None, qt: Any = None) -> bytes

Copy objects to the clipboard so FontLab's Edit > Paste accepts them.

Uses flModelProducer.copyToClipboard when FontLab has it. It writes FontLab's own vic/objects formats plus application/json, the same as FontLab's Copy. Live on 9.1.9812, Edit > Paste then added a copied glyph in both masters, in the Font window and in a Glyph window. Without it, the JSON goes on the clipboard through copy_to_clipboard, which FontLab's Paste may not accept. Returns the copied JSON. Reads only: the font does not change and nothing is recorded for Undo.

copy_to_clipboard

copy_to_clipboard(data: Any, *, qt: Any = None) -> None

Put object JSON on the clipboard as application/json and as plain text.

current_layer

current_layer(fl: Any = None) -> tuple[Any, Any]

Return (flGlyph, flLayer) of the current glyph, or (None, None).

fontlab.CurrentGlyph() returns an fgGlyph whose activeLayer is FontGate data. This wraps it as fontlab.flGlyph and reads that glyph's activeLayer property (not a method), the live layer that paste_shapes and the selection code need. Used by vfjo.paste and the Scripts/Objects demos.

decode

decode(data: Any, *, fl: Any = None, qt: Any = None) -> list[Any]

Return new detached objects read from object JSON.

data: an Envelope, a dict, JSON bytes/str or a QByteArray. Anything but a QByteArray is checked by Envelope.parse first and then wrapped, because Python bytes crash FontLab here. Raises ValueError when FontLab returns None.

describe

describe(envelope: Envelope) -> list[str]

Return one line per item: kind, name, layers, widths and counts.

drop_unicodes

drop_unicodes(envelope: Envelope, names: Iterable[str] | None = None) -> Envelope

Remove the unicode value from all glyph items, or from the named ones.

export

export(package: Any, objects: Sequence[Any], *, fl: Any = None) -> bytes

Return FontLab's JSON for objects (glyphs, layers, shapes or contours).

Reads only: the font does not change and nothing is recorded for Undo.

filter_layers

filter_layers(envelope: Envelope, names: Iterable[str]) -> Envelope

Keep only the layers named in names: inside glyphs and as layer items.

load_file

load_file(path: str | Path) -> bytes

Read object JSON from path; raise ValueError when it is not object JSON.

only_glyphs

only_glyphs(envelope: Envelope) -> Envelope

Return a copy holding only the glyph items.

paste_glyphs

paste_glyphs(package: Any, data: Any, *, facts: Any, on_conflict: str = 'rename', masters: Sequence[str] | None = None, allow_rebuild: bool = False, title: str = 'Paste JSON Glyphs', fl: Any = None, qt: Any = None) -> Pasted

Create new glyphs from the glyph items of object JSON, with Undo.

Names are made unique against the font (on_conflict="rename") or taken glyphs are skipped ("skip"). Each master gets the width, outlines, anchors, guidelines and hints of the JSON layer of the same name; with no name match and one JSON layer, that layer is used for every master. Unmatched JSON layers and non-glyph items are listed in skipped. Renamed glyphs lose their Unicode values; a kept value that is already in the font or earlier in this paste is dropped with a note. A layer without advanceWidth gets width 0 with a note.

Automatic glyphs: a new name that creation.auto_candidates says may make FontLab rebuild automatic glyphs is skipped with a note unless allow_rebuild=True, which is passed on to create_glyphs. Skipping keeps the rest of the paste instead of refusing all of it.

Every glyph is decoded once before any glyph is created (see _decoded_layers), so a decode failure or bad data changes nothing. create_glyphs may raise history.PartialWriteError after the first glyph exists; callers must report it with the Undo hint.

paste_shapes

paste_shapes(layer: Any, glyph: Any, data: Any, *, facts: Any, title: str = 'Paste JSON Shapes', fl: Any = None, qt: Any = None) -> Pasted

Add the shapes of object JSON to one live layer of glyph as one Undo step.

Element items paste as shapes; layer items paste all their shapes; contour items are joined into one new shape. Glyph items are skipped.

read_clipboard

read_clipboard(*, qt: Any = None) -> bytes | None

Return object JSON from the clipboard, or None when it holds none.

application/json (FontLab's Copy and ours) is read first, then the older application/x-fontlab-objects+json, then plain text; each counts only when it parses as an object JSON envelope.

rename_glyphs

rename_glyphs(envelope: Envelope, rename: Mapping[str, str] | Callable[[str], str]) -> Envelope

Return a copy whose glyph items carry new names from a mapping or a function.

Names missing from a mapping stay. Unicode values stay; use drop_unicodes when the renamed glyph must not claim them.

require_available

require_available(fl: Any = None) -> None

Raise RuntimeError(NEEDS_91) on FontLab 9.0 or outside FontLab.

save_file

save_file(path: str | Path, data: Any) -> Path

Write object JSON to path as pretty-printed UTF-8; return the path.

set_advance_width

set_advance_width(envelope: Envelope, width: float, layers: Iterable[str] | None = None) -> Envelope

Set advanceWidth on glyph layers and layer items (all, or the named ones).

unicodes

unicodes(payload: Mapping[str, Any]) -> tuple[int, ...]

Return the code points of a glyph payload's unicode hex text ("006f").

unique_glyph_names

unique_glyph_names(envelope: Envelope, existing: Container[str]) -> tuple[Envelope, dict[str, str]]

Rename glyph items so no name is in existing or repeated in the data.

Return the edited copy and {old: new} for the renamed glyphs, in item order. A renamed glyph keeps its Unicode values.

unique_name

unique_name(name: str, existing: Container[str]) -> str

Return name, or name.1, name.2, ... the first not in existing.