diff --git a/apps/deno/index.ts b/apps/deno/index.ts index 7c14a367c..6a4765638 100644 --- a/apps/deno/index.ts +++ b/apps/deno/index.ts @@ -76,6 +76,7 @@ const assets = { indie_flower_r: readFont('indie_flower/IndieFlower.ttf'), great_vibes_r: readFont('great_vibes/GreatVibes-Regular.ttf'), nunito: readFont('nunito/Nunito-Regular.ttf'), + lobster: readFont('lobster/Lobster-Regular.ttf'), }, otf: { fantasque_sans_mono_bi: readFont( diff --git a/apps/deno/tests/test1.ts b/apps/deno/tests/test1.ts index fe71ed5c7..c9604bedd 100644 --- a/apps/deno/tests/test1.ts +++ b/apps/deno/tests/test1.ts @@ -231,9 +231,14 @@ export default async (assets: Assets) => { // This page tests placement of text with different fonts - const page2 = pdfDoc.addPage([size, size]); + const height = size + 100; + const page2 = pdfDoc.addPage([size, height]); - page2.drawSquare({ size, color: rgb(253 / 255, 246 / 255, 227 / 255) }); + page2.drawRectangle({ + width: size, + height, + color: rgb(253 / 255, 246 / 255, 227 / 255), + }); page2.setFontColor(rgb(101 / 255, 123 / 255, 131 / 255)); const { fonts } = assets; @@ -242,7 +247,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 20, + y: height - 20, size: 20, font: ubuntuFont, lineHeight: 20, @@ -252,7 +257,7 @@ export default async (assets: Assets) => { fonts.otf.fantasque_sans_mono_bi, ); page2.drawText(ipsumLines.join('\n'), { - y: size - 105, + y: height - 105, size: 25, font: fantasqueFont, lineHeight: 25, @@ -262,7 +267,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 200, + y: height - 200, size: 25, font: indieFlowerFont, lineHeight: 25, @@ -272,7 +277,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 300, + y: height - 300, size: 30, font: greatVibesFont, lineHeight: 30, @@ -280,7 +285,7 @@ export default async (assets: Assets) => { const appleStormFont = await pdfDoc.embedFont(fonts.otf.apple_storm_r); page2.drawText(ipsumLines.join('\n'), { - y: size - 425, + y: height - 425, size: 25, font: appleStormFont, lineHeight: 25, @@ -290,7 +295,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 500, + y: height - 500, size: 15, font: bioRhymeFont, lineHeight: 15, @@ -300,7 +305,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 575, + y: height - 575, size: 15, font: pressStart2PFont, lineHeight: 15, @@ -308,12 +313,20 @@ export default async (assets: Assets) => { const hussar3DFont = await pdfDoc.embedFont(fonts.otf.hussar_3d_r); page2.drawText(ipsumLines.join('\n'), { - y: size - 650, + y: height - 650, size: 25, font: hussar3DFont, lineHeight: 25, }); + const lobsterFont = await pdfDoc.embedFont(fonts.ttf.lobster); + page2.drawText(ipsumLines.join('\n'), { + y: height - 750, + size: 25, + font: lobsterFont, + lineHeight: 25, + }); + /********************** Page 3 **********************/ // This page tests embedding and placing different images. diff --git a/apps/node/index.ts b/apps/node/index.ts index 97b9b47ef..b54633ea5 100644 --- a/apps/node/index.ts +++ b/apps/node/index.ts @@ -74,6 +74,7 @@ const assets = { indie_flower_r: readFont('indie_flower/IndieFlower.ttf'), great_vibes_r: readFont('great_vibes/GreatVibes-Regular.ttf'), nunito: readFont('nunito/Nunito-Regular.ttf'), + lobster: readFont('lobster/Lobster-Regular.ttf'), }, otf: { fantasque_sans_mono_bi: readFont( diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 1fc9f74db..01189ffb7 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -229,9 +229,14 @@ export default async (assets: Assets) => { // This page tests placement of text with different fonts - const page2 = pdfDoc.addPage([size, size]); + const height = size + 100; + const page2 = pdfDoc.addPage([size, height]); - page2.drawSquare({ size, color: rgb(253 / 255, 246 / 255, 227 / 255) }); + page2.drawRectangle({ + width: size, + height, + color: rgb(253 / 255, 246 / 255, 227 / 255), + }); page2.setFontColor(rgb(101 / 255, 123 / 255, 131 / 255)); const { fonts } = assets; @@ -240,7 +245,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 20, + y: height - 20, size: 20, font: ubuntuFont, lineHeight: 20, @@ -250,7 +255,7 @@ export default async (assets: Assets) => { fonts.otf.fantasque_sans_mono_bi, ); page2.drawText(ipsumLines.join('\n'), { - y: size - 105, + y: height - 105, size: 25, font: fantasqueFont, lineHeight: 25, @@ -260,7 +265,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 200, + y: height - 200, size: 25, font: indieFlowerFont, lineHeight: 25, @@ -270,7 +275,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 300, + y: height - 300, size: 30, font: greatVibesFont, lineHeight: 30, @@ -278,7 +283,7 @@ export default async (assets: Assets) => { const appleStormFont = await pdfDoc.embedFont(fonts.otf.apple_storm_r); page2.drawText(ipsumLines.join('\n'), { - y: size - 425, + y: height - 425, size: 25, font: appleStormFont, lineHeight: 25, @@ -288,7 +293,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 500, + y: height - 500, size: 15, font: bioRhymeFont, lineHeight: 15, @@ -298,7 +303,7 @@ export default async (assets: Assets) => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 575, + y: height - 575, size: 15, font: pressStart2PFont, lineHeight: 15, @@ -306,12 +311,20 @@ export default async (assets: Assets) => { const hussar3DFont = await pdfDoc.embedFont(fonts.otf.hussar_3d_r); page2.drawText(ipsumLines.join('\n'), { - y: size - 650, + y: height - 650, size: 25, font: hussar3DFont, lineHeight: 25, }); + const lobsterFont = await pdfDoc.embedFont(fonts.ttf.lobster); + page2.drawText(ipsumLines.join('\n'), { + y: height - 750, + size: 25, + font: lobsterFont, + lineHeight: 25, + }); + /********************** Page 3 **********************/ // This page tests embedding and placing different images. diff --git a/apps/rn/src/tests/test1.js b/apps/rn/src/tests/test1.js index e7ebd36b3..b95369a8b 100644 --- a/apps/rn/src/tests/test1.js +++ b/apps/rn/src/tests/test1.js @@ -234,9 +234,14 @@ export default async () => { // This page tests placement of text with different fonts - const page2 = pdfDoc.addPage([size, size]); + const height = size + 100; + const page2 = pdfDoc.addPage([size, height]); - page2.drawSquare({ size, color: rgb(253 / 255, 246 / 255, 227 / 255) }); + page2.drawRectangle({ + width: size, + height, + color: rgb(253 / 255, 246 / 255, 227 / 255), + }); page2.setFontColor(rgb(101 / 255, 123 / 255, 131 / 255)); const [ @@ -248,6 +253,7 @@ export default async () => { bioRhymeBytes, pressStart2PBytes, hussar3DBytes, + lobsterBytes, ] = await Promise.all([ fetchAsset('fonts/ubuntu/Ubuntu-R.ttf'), fetchAsset('fonts/fantasque/OTF/FantasqueSansMono-BoldItalic.otf'), @@ -257,11 +263,12 @@ export default async () => { fetchAsset('fonts/bio_rhyme/BioRhymeExpanded-Regular.ttf'), fetchAsset('fonts/press_start_2p/PressStart2P-Regular.ttf'), fetchAsset('fonts/hussar_3d/Hussar3DFour.otf'), + fetchAsset('fonts/lobster/Lobster-Regular.ttf'), ]); const ubuntuFont = await pdfDoc.embedFont(ubuntuBytes, { subset: true }); page2.drawText(ipsumLines.join('\n'), { - y: size - 20, + y: height - 20, size: 20, font: ubuntuFont, lineHeight: 20, @@ -269,7 +276,7 @@ export default async () => { const fantasqueFont = await pdfDoc.embedFont(fantasqueBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 105, + y: height - 105, size: 25, font: fantasqueFont, lineHeight: 25, @@ -279,7 +286,7 @@ export default async () => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 200, + y: height - 200, size: 25, font: indieFlowerFont, lineHeight: 25, @@ -289,7 +296,7 @@ export default async () => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 300, + y: height - 300, size: 30, font: greatVibesFont, lineHeight: 30, @@ -297,7 +304,7 @@ export default async () => { const appleStormFont = await pdfDoc.embedFont(appleStormBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 425, + y: height - 425, size: 25, font: appleStormFont, lineHeight: 25, @@ -307,7 +314,7 @@ export default async () => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 500, + y: height - 500, size: 15, font: bioRhymeFont, lineHeight: 15, @@ -317,7 +324,7 @@ export default async () => { subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 575, + y: height - 575, size: 15, font: pressStart2PFont, lineHeight: 15, @@ -325,12 +332,20 @@ export default async () => { const hussar3DFont = await pdfDoc.embedFont(hussar3DBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 650, + y: height - 650, size: 25, font: hussar3DFont, lineHeight: 25, }); + const lobsterFont = await pdfDoc.embedFont(lobsterBytes); + page2.drawText(ipsumLines.join('\n'), { + y: height - 750, + size: 25, + font: lobsterFont, + lineHeight: 25, + }); + /********************** Page 3 **********************/ // This page tests embedding and placing different images. diff --git a/apps/web/test1.html b/apps/web/test1.html index 5b881326d..4985da345 100644 --- a/apps/web/test1.html +++ b/apps/web/test1.html @@ -285,9 +285,14 @@ // This page tests placement of text with different fonts - const page2 = pdfDoc.addPage([size, size]); + const height = size + 100; + const page2 = pdfDoc.addPage([size, height]); - page2.drawSquare({ size, color: rgb(253 / 255, 246 / 255, 227 / 255) }); + page2.drawRectangle({ + width: size, + height, + color: rgb(253 / 255, 246 / 255, 227 / 255), + }); page2.setFontColor(rgb(101 / 255, 123 / 255, 131 / 255)); const [ @@ -299,6 +304,7 @@ bioRhymeBytes, pressStart2PBytes, hussar3DBytes, + lobsterBytes, ] = await Promise.all([ fetchStringAsset('fonts/ubuntu/Ubuntu-R.ttf.base64'), fetchBinaryAsset( @@ -310,11 +316,14 @@ fetchBinaryAsset('fonts/bio_rhyme/BioRhymeExpanded-Regular.ttf'), fetchBinaryAsset('fonts/press_start_2p/PressStart2P-Regular.ttf'), fetchBinaryAsset('fonts/hussar_3d/Hussar3DFour.otf'), + fetchBinaryAsset('fonts/lobster/Lobster-Regular.ttf'), ]); - const ubuntuFont = await pdfDoc.embedFont(ubuntuBase64, { subset: true }); + const ubuntuFont = await pdfDoc.embedFont(ubuntuBase64, { + subset: true, + }); page2.drawText(ipsumLines.join('\n'), { - y: size - 20, + y: height - 20, size: 20, font: ubuntuFont, lineHeight: 20, @@ -322,7 +331,7 @@ const fantasqueFont = await pdfDoc.embedFont(fantasqueBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 105, + y: height - 105, size: 25, font: fantasqueFont, lineHeight: 25, @@ -332,7 +341,7 @@ subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 200, + y: height - 200, size: 25, font: indieFlowerFont, lineHeight: 25, @@ -342,7 +351,7 @@ subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 300, + y: height - 300, size: 30, font: greatVibesFont, lineHeight: 30, @@ -350,7 +359,7 @@ const appleStormFont = await pdfDoc.embedFont(appleStormBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 425, + y: height - 425, size: 25, font: appleStormFont, lineHeight: 25, @@ -360,7 +369,7 @@ subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 500, + y: height - 500, size: 15, font: bioRhymeFont, lineHeight: 15, @@ -370,7 +379,7 @@ subset: true, }); page2.drawText(ipsumLines.join('\n'), { - y: size - 575, + y: height - 575, size: 15, font: pressStart2PFont, lineHeight: 15, @@ -378,12 +387,20 @@ const hussar3DFont = await pdfDoc.embedFont(hussar3DBytes); page2.drawText(ipsumLines.join('\n'), { - y: size - 650, + y: height - 650, size: 25, font: hussar3DFont, lineHeight: 25, }); + const lobsterFont = await pdfDoc.embedFont(lobsterBytes); + page2.drawText(ipsumLines.join('\n'), { + y: height - 750, + size: 25, + font: lobsterFont, + lineHeight: 25, + }); + /********************** Page 3 **********************/ // This page tests embedding and placing different images. diff --git a/assets/fonts/lobster/Lobster-Regular.ttf b/assets/fonts/lobster/Lobster-Regular.ttf new file mode 100644 index 000000000..21c0073fd Binary files /dev/null and b/assets/fonts/lobster/Lobster-Regular.ttf differ diff --git a/src/core/embedders/CustomFontEmbedder.ts b/src/core/embedders/CustomFontEmbedder.ts index f8d215a6f..fe4602218 100644 --- a/src/core/embedders/CustomFontEmbedder.ts +++ b/src/core/embedders/CustomFontEmbedder.ts @@ -237,10 +237,9 @@ class CustomFontEmbedder { } private allGlyphsInFontSortedById = (): Glyph[] => { - const glyphs: Glyph[] = new Array(this.font.characterSet.length); + const glyphs: Glyph[] = new Array(this.font.numGlyphs); for (let idx = 0, len = glyphs.length; idx < len; idx++) { - const codePoint = this.font.characterSet[idx]; - glyphs[idx] = this.font.glyphForCodePoint(codePoint); + glyphs[idx] = this.font.getGlyph(idx); } return sortedUniq(glyphs.sort(byAscendingId), (g) => g.id); };