Skip to content

fontlab.flModelProducer

flModelProducer

Clipboard operations.

What is flModelProducer?

flModelProducer handles copying and pasting font objects. It can serialise a list of shapes, contours, or glyphs into a binary blob, write that blob to the system clipboard, and later deserialise it back into live objects. All of its methods are static — you never create an instance, you just call the methods directly.

The most common scripting use-case is programmatic copy/paste: capture the shapes of one glyph, then paste them into another, possibly with a transform applied.

Tutorial

from PythonQt.QtGui import QTransform
import fontlab as fl
from fontlab import flModelProducer

# ============================================================
# SCENARIO: Copy the shapes of glyph 'A' and paste them
# into glyph 'B' (moved 100 units to the right).
# ============================================================

font = fl.CurrentFont()

# Step 1: Get the shapes you want to copy.
src_layer = font['A'].layers[0]
shapes_to_copy = list(src_layer.shapes)
print(f"Copying {len(shapes_to_copy)} shape(s) from 'A'")

# Step 2: Serialise them into a binary blob.
blob = flModelProducer.getClipboardData(font.id, font.upm, shapes_to_copy)
print(f"Serialised to {len(blob)} bytes")

# Step 3: Deserialise the blob back into new objects.
# This gives you fresh, independent copies of the shapes.
copies = flModelProducer.getObjectsFromData(blob)
if not copies:
    print("Deserialisation failed.")
    raise SystemExit

print(f"Got {len(copies)} object(s) back")

# Step 4: Apply a transform and add to the destination glyph.
dst_layer = font['B'].layers[0]
for obj in copies:
    # Move 100 units right before adding:
    obj.transformBy(QTransform().translate(100, 0))
    dst_layer.addShape(obj)

fl.Update()
print("Shapes pasted into 'B'.")

# ============================================================
# ALTERNATIVE: Put shapes on the system clipboard so the
# user can paste them into another font with Cmd+V.
# ============================================================

flModelProducer.copyToClipboard(font.id, shapes_to_copy)
print("Shapes are now on the clipboard — use Edit → Paste to paste.")

Common Patterns

# Count glyphs in a blob before deserialising:
count = flModelProducer.countGlyphsInData(blob)
print(f"Blob contains {count} glyph(s)")

# Paste from the clipboard into the current glyph:
pasted = flModelProducer.getObjectsFromClipboard()
if pasted:
    layer = fl.CurrentGlyph().layers[0]
    for obj in pasted:
        layer.addShape(obj)
    fl.Update()

Common Scripting Patterns

Copy shapes from one glyph to another via the clipboard

import fontlab as fl
from fontlab import flModelProducer

font = fl.CurrentFont()
src  = font['A']
dst  = font['B']
if src and dst:
    producer = flModelProducer()
    # Serialise the source layer to clipboard:
    producer.copyLayer(src.layers[0])
    # Paste into the destination:
    producer.pasteLayer(dst.layers[0])
    fl.Update()
    print(f"Copied layer from 'A' to 'B'.")

Serialise a shape to check its JSON representation

import fontlab as fl
from fontlab import flModelProducer

font  = fl.CurrentFont()
glyph = fl.CurrentGlyph()
if glyph:
    producer = flModelProducer()
    layer    = glyph.layers[0]
    if layer.shapes:
        data = producer.shapeToString(layer.shapes[0])
        print(data[:300])   # show first 300 chars

Detached JSON transport

Two static methods expose the existing FontLab object transport without reading or changing the system clipboard:

producer = fontlab.flModelProducer
data = producer.getClipboardDataJson(0, 1000.0, [contour, layer, glyph])
objects = producer.getObjectsFromJsonData(data)

getClipboardDataJson(package_id, upm, objects) returns a QByteArray. getObjectsFromJsonData(data) accepts a wrapped QByteArray, Python bytes, bytearray, or str (encoded as UTF-8). It returns detached native objects, or None when the native reader fails or returns no objects. None and unsupported argument types raise TypeError; incorrect argument counts raise IndexError. Neither method attaches the results to a document or creates a history entry.

This is the existing permissive UI JSON format, not a strict typed flJson API. The reader does not validate the dataType discriminator. The writer omits images and collapses a single-item batch to the singleton wire representation. It is not a general-purpose Font Info converter or a guarantee of reference/image fidelity. Callers must inspect the returned objects and explicitly handle document attachment and change notifications.

All registered methods are static and take positional arguments.

Constructors: flModelProducer() flModelProducer(flModelProducer) flModelProducer(flObject) flModelProducer(flCanvas)

Native bases: object

Captured native MRO: flModelProducer, object

Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.

Supplemental documentation: A model producer. The captured declaration exposes copyToClipboard, getClipboardData, getObjectsFromClipboard, getObjectsFromData, countGlyphsInData. It is created with no captured constructor overloads. It also carries the shared object members changed, clone, cloneObject, getProperty, setProperty, release, remove and update and the shared attributes id, name, type, isValid and isNull.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flModelProducer captured declaration

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
__init__ function (self, /, *args: Any, **kwargs: Any) -> None Initialize self. (shared captured text)
changed function (self) -> Any (shared captured text)
checkInitHistoryState function (self, history_ix: int) -> Any (shared captured text)
clearAboveHistory function (self, history_ix: int) -> Any (shared captured text)
clearFlag function (self, f: int) -> Any (shared captured text)
clearFlags function (self) -> Any (shared captured text)
clone function (self, *args: Any, **kwargs: Any) -> Any Clone the object (shared captured text)
cloneObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
copyToClipboard function (package_id: Any, objects: list[flObject]) -> Any Serialises the given objects and writes the result directly to the system clipboard.
countGlyphsInData function (*args: Any, **kwargs: Any) -> Any Counts how many glyphs are encoded in a binary blob without fully deserialising it.
createObject function (*args: Any, **kwargs: Any) -> Any FlObject/Nothing createObject(int); (shared captured text)
currentHistoryState function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
flObjectFlags attribute dict (shared captured text)
flag function (self, f: int) -> Any (shared captured text)
getClipboardData function (*args: Any, **kwargs: Any) -> Any Serialises the given list of font objects into a binary blob.
getClipboardDataJson function (*args: Any, **kwargs: Any) -> Any
getObjectsFromClipboard function () -> Any
getObjectsFromData function (*args: Any, **kwargs: Any) -> Any
getObjectsFromJsonData function (data: Any) -> Any
getProperties function (self, *args: Any, **kwargs: Any) -> Any Get object's properties list (shared captured text)
getProperty function (self, *args: Any, **kwargs: Any) -> Any Get object property by 'key' or number (shared captured text)
getPropertyFloat function (self, *args: Any, **kwargs: Any) -> Any Get float object property by 'key' (shared captured text)
getPropertyInt function (self, *args: Any, **kwargs: Any) -> Any Get int object property by 'key' (shared captured text)
hasChanges attribute Any (shared captured text)
hasHistoryState function (self, history_ix: int) -> Any (shared captured text)
hasHistoryStates attribute Any (shared captured text)
haveObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
historyStates function (self, accepted_state: bool) -> Any (shared captured text)
id attribute Any Object id (shared captured text)
independedAll function (self) -> Any (shared captured text)
initialHistoryState function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
instanceType function (*args: Any, **kwargs: Any) -> Any (shared captured text)
isChanged attribute Any (shared captured text)
isEqual function (self, arg0: flObject) -> Any (shared captured text)
isNull attribute Any (shared captured text)
isPresent attribute Any (shared captured text)
isReleased attribute Any (shared captured text)
isValid attribute Any (shared captured text)
name attribute Any Object name (shared captured text)
propertyNames function (self, *args: Any, **kwargs: Any) -> Any PropertyNames(): sorted snapshot of dynamic property keys (shared captured text)
refCnt attribute Any Object references count (shared captured text)
release function (self) -> Any (shared captured text)
remove function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
removeChild function (self, arg0: flObject) -> Any (shared captured text)
restoreHistoryState function (self, history_ix: int) -> Any (shared captured text)
setFlag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
setProperty function (self, *args: Any, **kwargs: Any) -> Any Set object property by 'key' or number (shared captured text)
setPropertyFloat function (self, *args: Any, **kwargs: Any) -> Any Set float object property by 'key' (shared captured text)
setPropertyInt function (self, *args: Any, **kwargs: Any) -> Any Set int object property by 'key' (shared captured text)
tag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
type attribute Any Object type (shared captured text)
update function (self) -> Any (shared captured text)