You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 20, 2026. It is now read-only.
refactor(fonts): extract via documents.js's extractSourceFontsForFormat
The format-to-FontSourcePackage dispatch (docx/pptx via ooxml.js's
decodePackage, odt/odp/ods/odg via odf.js's) now lives in documents.js's
own extractSourceFontsForFormat, which rejects an unsupported format
(xlsx/pdf/markdown/odf) by throwing UnsupportedFontSourceFormatError
rather than a plain Error -- mapped here to EXIT_USAGE_ERROR, matching
this CLI's existing exit-code convention for a bad invocation choice.
Format validation now happens after the input bytes are read (inside
extractSourceFontsForFormat itself) rather than before, so the
unsupported-format rejection test needs a real (if trivial) input file
instead of a path that was never actually opened.
// extractSourceFontsForFormat (documents.js) validates the format itself rather than the CLI pre-checking it, so the input file is now genuinely read before that rejection fires -- unlike a bare nonexistent path, this needs to exist. Its content is never parsed: the rejection below fires purely on the '.xlsx' extension.
// The only formats `extractSourceFonts` (documents.js's `src/fonts/registry.ts`) knows how to read a source-embedded face from at all: docx/pptx via OOXML's own fontTable.xml/embeddedFontLst, odt/odp/ods/odg via ODF's own office:font-face-decls. xlsx has no OOXML font-embedding vocabulary of its own; pdf/markdown carry no source-package concept to embed a font declaration in; a standalone .odf formula document embeds only the STIX Two Math font pdf-codec itself carries, never a caller-resolvable face; .odb has no font concept at all.
functionisFontSourceFormat(format: DocumentFormat): format is keyoftypeofFONT_SOURCE_FORMATS{
25
-
returnformatinFONT_SOURCE_FORMATS;
26
-
}
27
-
28
-
// docx/pptx dispatch through ooxml.js's own decodePackage (re-exported from documents.js under its own name); odt/odp/ods/odg dispatch through odf.js's decodePackage instead, aliased on import exactly as commands/odb.ts already does to avoid the naming collision between the two same-named functions.
// ProvidedFont (pdf-codec, re-exported by documents.js) carries `bytes` directly, with no `byteLength` field of its own -- computed here rather than exposing the raw font bytes themselves, which no caller of this command's summary output has asked for and which would bloat --json output by however large the embedded face is.
process.stderr.write(`[${command}] cannot infer a document format from '${input}'; expected one of docx, pptx, odt, odp, ods, odg\n`);
52
29
returnEXIT_USAGE_ERROR;
53
30
}
54
-
if(!isFontSourceFormat(format)){
55
-
process.stderr.write(`[${command}] '${format}' documents carry no source-embedded font faces this command can extract; expected one of docx, pptx, odt, odp, ods, odg\n`);
// extractSourceFontsForFormat itself rejects a format with no source-embedded font concept (xlsx, pdf, markdown, odf), naming the six it supports -- no separate isFontSourceFormat guard needed here any more.
Copy file name to clipboardExpand all lines: src/runtime/exit-codes.ts
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ import {
10
10
OdmUnresolvedSectionError,
11
11
PdfEncryptedError,
12
12
PdfParseError,
13
+
UnsupportedFontSourceFormatError,
13
14
}from'documents.js';
14
15
15
16
// Mirrors sysexits.h-style convention loosely: 0 is success, 1 is a generic failure, 2 is a usage error (matching coreutils' own convention for bad invocation), and the two signal-derived codes (124, 130) match `timeout(1)` and 128+SIGINT respectively, so a caller scripting against this CLI sees the same exit codes it would from any other well-behaved Unix tool.
// fonts' own extractSourceFontsForFormat: the given DocumentFormat is a real, recognised format, but not one with a source-embedded-font concept at all (xlsx, pdf, markdown, odf) -- a bad invocation choice, not an unusable file, so this maps like every other usage error rather than EXIT_INPUT_ERROR's "the file itself is the problem".
// PdfEncryptedError extends PdfParseError, so this branch is redundant with the default fall-through below -- kept explicit anyway so the mapping documents its intent (these two error classes are unusable-input failures, not a catch-all) rather than relying on an implicit default to cover a case this function is specifically supposed to name.
0 commit comments