Skip to content

Commit 79297ad

Browse files
committed
Adding font for Armenian PDF generation.
1 parent ce328ed commit 79297ad

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

202 KB
Binary file not shown.

wiktionary_pron/scripts/pdf_export.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function toPdf(lines, layoutType, darkMode, transcriptionLang) {
1616

1717
let fonts = [];
1818

19-
async function fetchFonts() {
19+
async function fetchFonts(transcriptionLang) {
2020
if (fonts.length) {
2121
return fonts;
2222
}
@@ -25,8 +25,12 @@ async function fetchFonts() {
2525
.then((res) => res.arrayBuffer())
2626
.then((res) => new Uint8Array(res));
2727

28+
const textFontUrl =
29+
transcriptionLang.indexOf("Armenian") === -1
30+
? "fonts/EBGaramond-Regular.ttf"
31+
: "fonts/FreeMono.woff2";
2832
const [GaramondBytes, VocesBytes] = await Promise.all([
29-
fetchAsset("fonts/EBGaramond-Regular.ttf"),
33+
fetchAsset(textFontUrl),
3034
fetchAsset(
3135
"https://cdn.jsdelivr.net/gh/hellpanderrr/hellpanderrr.github.io/wiktionary_pron/fonts/Voces-Regular.ttf",
3236
),
@@ -44,7 +48,7 @@ async function main(lines, layoutType, darkMode, transcriptionLang) {
4448
const fillDoc = async (lines, pdfDoc, layoutType, darkMode) => {
4549
pdfDoc.registerFontkit(fontkit);
4650

47-
const [GaramondBytes, VocesBytes] = await fetchFonts();
51+
const [GaramondBytes, VocesBytes] = await fetchFonts(transcriptionLang);
4852

4953
const Garamond = await pdfDoc.embedFont(GaramondBytes);
5054
const Voces = await pdfDoc.embedFont(VocesBytes);
@@ -113,8 +117,12 @@ async function main(lines, layoutType, darkMode, transcriptionLang) {
113117
font: Garamond,
114118
x: x,
115119
y: y,
116-
size: fontSize,
120+
size:
121+
transcriptionLang.indexOf("Armenian") === -1
122+
? fontSize
123+
: fontSize - 2,
117124
color: color,
125+
opacity: transcriptionLang.indexOf("Armenian") === -1 ? 1 : 0.8,
118126
});
119127
page.drawText(ipa, {
120128
font: Voces,

0 commit comments

Comments
 (0)