mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-12 17:44:01 +01:00
feat: add fallback font loading and handling for various languages
This commit is contained in:
1 parent
9ae5c93886
commit
5a7927572f
28 files changed
+375
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { FreeTextSystemFontAnnotation } from '@/types';
|
||||
import { needsFontEmbedding } from './freetext-script.js';
|
||||
import { fallbackFontLanguages, loadFallbackFonts } from './font-loader.js';
|
||||
|
||||
export const FPDF_ANNOT_FREETEXT = 3;
|
||||
|
||||
@@ -153,7 +154,7 @@ function buildRuns(
|
||||
return [
|
||||
{
|
||||
text: contents,
|
||||
family: 'Helvetica',
|
||||
family: needsFontEmbedding(contents) ? 'Noto Sans' : 'Helvetica',
|
||||
size,
|
||||
rgba: hexToRgba(style?.fontColor ?? '#000000'),
|
||||
bold: false,
|
||||
@@ -196,6 +197,7 @@ export async function flattenFreeTextToPageText(
|
||||
PdfEngine: {
|
||||
create: () => Promise<EngineLike>;
|
||||
localFonts: Map<string, Uint8Array>;
|
||||
fallbackFonts: Map<string, Uint8Array>;
|
||||
};
|
||||
scriptFallbackFamilies: (cps: number[]) => string[];
|
||||
};
|
||||
@@ -245,6 +247,10 @@ export async function flattenFreeTextToPageText(
|
||||
return { bytes, flattened: 0 };
|
||||
}
|
||||
await primeScriptFonts(mod, found);
|
||||
await loadFallbackFonts(
|
||||
mod.PdfEngine.fallbackFonts,
|
||||
fallbackFontLanguages(found.join('\n'))
|
||||
);
|
||||
|
||||
for (const pageIndex of [...pages].sort((x, y) => x - y)) {
|
||||
if (pageIndex < 0 || pageIndex >= eng.pageCount) continue;
|
||||
|
||||
Reference in new issue
Block a user