feat: warn when a PDF export replaces characters it cannot draw

The hand-written PDF writer uses the standard Courier fonts
(WinAnsiEncoding), so any character outside CP1252 - a Polish, Greek,
Cyrillic or CJK script - was silently written as '?'. Render now
collects the characters it had to replace and returns them, and the
export dialog lists them in a warning once the file is written.

Embedding a TrueType font (e.g. Courier Prime) with a CID/ToUnicode
map would fix the root cause; the warning keeps the zero-dependency
trade-off honest in the meantime.
This commit is contained in:
Kharec committed 2026-10-15 17:49:53 +02:00
1 parent 5e7ae97b57
commit e80ad634ef
7 files changed
+125 -35

No files matched your search

+9 -1
View File
@@ -144,13 +144,21 @@ export interface ExportOptions {
revisions: boolean
}
/** A written PDF export. */
export interface ExportResult {
/** Empty when the user cancelled the dialog. */
path: string
/** Characters the standard PDF fonts cannot draw, written as "?" in the file. */
replaced?: string[]
}
interface GoApp {
NewDocument(): Promise<ScriptDocument>
InitialFile(): Promise<OpenResult | null>
Open(): Promise<OpenResult | null>
Save(doc: ScriptDocument, path: string): Promise<string>
SaveAs(doc: ScriptDocument, current: string): Promise<string>
ExportPDF(doc: ScriptDocument, opts: ExportOptions, current: string): Promise<string>
ExportPDF(doc: ScriptDocument, opts: ExportOptions, current: string): Promise<ExportResult>
ExportFDX(doc: ScriptDocument, current: string): Promise<string>
Paginate(doc: ScriptDocument): Promise<LayoutInfo>
ParseFountain(text: string): Promise<Element[] | null>
+9 -1
View File
@@ -947,7 +947,15 @@ const actions: Record<string, () => unknown> = {
renderPaper()
settingsChanged()
}
await api.ExportPDF(script(), chosen, app.path).catch(reportError)
const res = await api.ExportPDF(script(), chosen, app.path).catch(reportError)
if (res?.replaced?.length) {
const list = res.replaced.map((c) => `"${c}"`).join(' ')
await messageBox({
title: 'Characters replaced in the PDF',
text: `The standard PDF fonts cannot draw these characters: ${list}. Each one is written as "?" in the exported file.`,
ok: 'OK',
})
}
}
dialog.showModal()
},