Skip to content

Commit 9a0605b

Browse files
authored
Merge pull request #662 from embedpdf/fix/font-fallback-null
Allow null to disable font fallback
2 parents ef3d044 + b60ba30 commit 9a0605b

9 files changed

Lines changed: 27 additions & 11 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@embedpdf/snippet": patch
3+
"@embedpdf/engines": patch
4+
---
5+
6+
Fix `fontFallback: null` not disabling the default jsDelivr CDN font fallback. The snippet previously stripped `null` with a truthy filter before it reached the worker, so the worker fell back to the CDN config. The value is now forwarded correctly (preserving `null` while still omitting an unset option), and the `fontFallback` type is widened to `FontFallbackConfig | null` across the engine hooks/options so the documented airgapped opt-out is type-correct end to end.

packages/engines/src/lib/orchestrator/remote-executor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ export interface RemoteExecutorOptions {
5959
*/
6060
logger?: Logger;
6161
/**
62-
* Font fallback configuration for handling missing fonts
62+
* Font fallback configuration for handling missing fonts.
63+
* Set to `null` to disable the fallback entirely (no external font requests).
6364
*/
64-
fontFallback?: FontFallbackConfig;
65+
fontFallback?: FontFallbackConfig | null;
6566
}
6667

6768
const LOG_SOURCE = 'RemoteExecutor';

packages/engines/src/lib/pdfium/engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ export interface PdfiumEngineOptions {
192192
* Font fallback configuration for handling missing fonts in PDFs.
193193
* When enabled, PDFium will request fallback fonts from configured URLs
194194
* when it encounters text that requires fonts not embedded in the PDF.
195+
* Set to `null` to disable the fallback entirely (no external font requests).
195196
*/
196-
fontFallback?: FontFallbackConfig;
197+
fontFallback?: FontFallbackConfig | null;
197198
}
198199

199200
/**

packages/engines/src/lib/pdfium/web/direct-engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export interface CreatePdfiumEngineOptions {
2121
* Font fallback configuration for handling missing fonts in PDFs.
2222
* When enabled, PDFium will request fallback fonts from configured URLs
2323
* when it encounters text that requires fonts not embedded in the PDF.
24+
* Set to `null` to disable the fallback entirely (no external font requests).
2425
*/
25-
fontFallback?: FontFallbackConfig;
26+
fontFallback?: FontFallbackConfig | null;
2627
}
2728

2829
/**

packages/engines/src/lib/pdfium/web/worker-engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export interface CreatePdfiumEngineOptions {
2727
* Font fallback configuration for handling missing fonts in PDFs.
2828
* When enabled, PDFium will request fallback fonts from configured URLs
2929
* when it encounters text that requires fonts not embedded in the PDF.
30+
* Set to `null` to disable the fallback entirely (no external font requests).
3031
*/
31-
fontFallback?: FontFallbackConfig;
32+
fontFallback?: FontFallbackConfig | null;
3233
}
3334

3435
/**

packages/engines/src/shared/hooks/use-pdfium-engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ interface UsePdfiumEngineProps {
1111
encoderPoolSize?: number;
1212
/**
1313
* Font fallback configuration for handling missing fonts in PDFs.
14+
* Set to `null` to disable the fallback entirely (no external font requests).
1415
*/
15-
fontFallback?: FontFallbackConfig;
16+
fontFallback?: FontFallbackConfig | null;
1617
}
1718

1819
export function usePdfiumEngine(config?: UsePdfiumEngineProps) {

packages/engines/src/svelte/hooks/use-pdfium-engine.svelte.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ export interface UsePdfiumEngineProps {
1010
logger?: Logger;
1111
/**
1212
* Font fallback configuration for handling missing fonts in PDFs.
13+
* Set to `null` to disable the fallback entirely (no external font requests).
1314
*/
14-
fontFallback?: FontFallbackConfig;
15+
fontFallback?: FontFallbackConfig | null;
1516
}
1617

1718
export function usePdfiumEngine(config?: UsePdfiumEngineProps) {

packages/engines/src/vue/composables/use-pdfium-engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ interface UsePdfiumEngineProps {
1111
logger?: Logger;
1212
/**
1313
* Font fallback configuration for handling missing fonts in PDFs.
14+
* Set to `null` to disable the fallback entirely (no external font requests).
1415
*/
15-
fontFallback?: FontFallbackConfig;
16+
fontFallback?: FontFallbackConfig | null;
1617
}
1718

1819
interface UsePdfiumEngineResult {

viewers/snippet/src/components/app.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,11 @@ export interface PDFViewerConfig {
233233
wasmUrl?: string;
234234
/** Enable debug logging. Default: false */
235235
log?: boolean;
236-
/** Font fallback configuration. Defaults to CDN fonts from jsDelivr. */
237-
fontFallback?: FontFallbackConfig;
236+
/**
237+
* Font fallback configuration. Defaults to CDN fonts from jsDelivr.
238+
* Set to `null` to disable the fallback entirely (no external font requests).
239+
*/
240+
fontFallback?: FontFallbackConfig | null;
238241

239242
// === Global Permissions ===
240243
/**
@@ -570,7 +573,7 @@ const logger = new AllLogger([new ConsoleLogger(), new PerfLogger()]);
570573
export function PDFViewer({ config, onRegistryReady }: PDFViewerProps) {
571574
const { engine, isLoading } = usePdfiumEngine({
572575
...(config.wasmUrl && { wasmUrl: config.wasmUrl }),
573-
...(config.fontFallback && { fontFallback: config.fontFallback }),
576+
...(config.fontFallback !== undefined && { fontFallback: config.fontFallback }),
574577
worker: config.worker,
575578
logger: config.log ? logger : undefined,
576579
});

0 commit comments

Comments
 (0)