fontlabapp.core.history.masters
masters
One native Undo step for font-level edits on one or more masters.
What: commit_masters writes master values (zones, vertical metrics) as ONE
FontLab Undo step. It uses route A of the issue 122 M2 measurement (FontLab
9.0.9790): the history objects of Font Info and "Sync font metrics"
(dlgfontinfo.cpp:2100-2175, mainwindow_edit.cpp:1208-1226):
- Refuse before any native write (
ValueError): a thread other than the GUI thread; no active Font window of this font, or a Glyph window as the active canvas (measured in the Font window only); an unknown, duplicate or empty master list; an empty title. - Read the queued glyph ids once (
edit_guards.pending_updates). Never clear them. checkInitHistoryState(0)on the package and on ONEpackage.mastersContainer()handle.- For each requested master, in font order:
setMaster(name, False),read()andsave()(the values to restore),write(),read()again andverify()that value. setMaster(original, False).- ONE
flItems().notifyChangesApplied(title, [package, container], False). No glyph and no layer is in the list, so no auto layer is notified.
Rollback policy (a decision that differs from history.commit):
history.commit always notifies, also after a failure, and Edit > Undo is
the recovery. Here a failure in steps 3 to 5 (a write callback error, or a
read-back mismatch) comes BEFORE the notification. So the helper restores
every master that it touched, in reverse order, reads each one back, and
notifies nothing. Edit > Undo would revert the user's previous step, so no
error text recommends it. An interrupt (KeyboardInterrupt,
SystemExit) also runs the rollback and the master restore, then is
raised unchanged.
- All values restored: raise
RolledBackError(aValueError: the font is as before, like a refusal). A caller whose restore re-creates native objects passesrestored_textto say so (zone_native). - A restore failed, or the notification failed: raise
UnrestoredError(ahistory.PartialWriteError). Values can remain with no Undo step.
Known host defect (fl#8574, measured on 9.0.9790, issue 122 M2): after Edit > Undo or
Redo of such a step, both masters show only 3 of the 9 font-metric
guidelines (the zone guidelines) until package.updateFontMetrics() runs or
the font is reopened. The saved file is correct. This module does not patch
Undo; it cannot hook the user's Undo.
How to use::
import fly.ap.core.history.masters as font_history
edit = font_history.MasterEdit(save, write, read, verify, restore)
result = font_history.commit_masters(package, "Edit Zones", {"Bold": edit})
edit_guards.disclose(result)
The module imports only the standard library at load time. Offline tests prove the call order only, not native Undo/Redo/reopen behaviour.
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 |
|---|---|---|---|
RESTORED_TEXT |
attribute | ||
THREAD_TEXT |
attribute | ||
UNRESTORED_HINT |
attribute | ||
WINDOW_TEXT |
attribute | ||
commit_masters |
function | (package: Any, title: str, edits: Mapping[str, MasterEdit], *, native: Any=None, restored_text: str=RESTORED_… |
Write <code>edits</code> as ONE native Undo step. |
require_font_window |
function | (package: Any, native: Any=None) -> None |
Refuse unless this runs on the GUI thread with the Font window active. |