Skip to content

Commit 6c28834

Browse files
committed
🐛 Work around pdf-core expecting padded tags
The `scriptTag` and `langSysTag` properties in the shape options are expected by `pdf-core` to be 4-character tags. Tags that are shorter than 4 characters won't be recognized correctly. This commit adds padding to these tags to ensure they are 4 characters long, which is a workaround for the current behavior of `pdf-core`. An example for setting the `language` property to select alternative glyphs is added to the `examples/text.ts`.
1 parent f5d1a8f commit 6c28834

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

examples/text.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const document = {
9797
fontKerning: 'none',
9898
fontVariantLigatures: 'none',
9999
}),
100+
text([text('Cyrillic default: '), text('бгдпт', { fontStyle: 'italic' })]),
101+
text([text('Serbian: '), text('бгдпт', { fontStyle: 'italic', language: 'sr' })]),
100102
],
101103
{ margin: { y: 10 } },
102104
),

src/text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ export function buildShapeOptions(
304304
const hasLangSysTag = langSysTag != null;
305305
if (!hasFeatures && !hasScriptTag && !hasLangSysTag) return undefined;
306306
return {
307-
...(hasScriptTag ? { scriptTag } : undefined),
308-
...(hasLangSysTag ? { langSysTag } : undefined),
307+
// TODO: workaround for pdf-core expecting 4-character tags. Remove padding once that is fixed.
308+
...(hasScriptTag ? { scriptTag: scriptTag.padEnd(4, ' ') } : undefined),
309+
...(hasLangSysTag ? { langSysTag: langSysTag.padEnd(4, ' ') } : undefined),
309310
...(hasFeatures ? { features } : undefined),
310311
};
311312
}

0 commit comments

Comments
 (0)