Rasura

The fidelity contract

Every operation reports how well it did. You can refuse anything below a rung you name.

The four rungs

exact

The glyphs were already in the embedded font. Nothing was approximated and nothing about the page changed except the characters you asked to change.

reembedded

A glyph was injected into the document’s own font program from a typeface you supplied. The shapes are right and the file carries one font, not two.

substituted

A different face was used. The text is correct; the letterforms are not the original. Metrics will differ, so lines may break elsewhere.

overlaid

The old content was covered and new content drawn on top. A last resort: the original text is still in the file underneath.

Setting a floor

JavaScript
// The floor is set when the session opens, and holds for every edit in it.
const session = doc.edit({ requireFidelity: 'exact' })
try {
await session.replaceText(p.id, range, 'Ω')
} catch (e) {
if (e.code === 'fidelity-below-required') {
// The font has no omega. Supply one, or accept a lower rung.
await doc.registerFont(font, { matchFor: 'Helvetica' })
await session.replaceText(p.id, range, 'Ω') // now reembedded
}
}

Why it works this way

The alternative is what every other tool does: substitute a font, or draw a box over the old text, and return success. The document looks edited and is quietly wrong, and the caller finds out when a reader complains that one word is in a different typeface.

Making degradation a value rather than an exception means the common case stays one line of code, and the caller who cares can branch on it. Making it refusable means the caller who must not degrade can say so once, at the top.