Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix character spacing in fonts using ligatures #1325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 23 additions & 10 deletions apps/deno/tests/test1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -272,15 +277,15 @@ export default async (assets: Assets) => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 300,
y: height - 300,
size: 30,
font: greatVibesFont,
lineHeight: 30,
});

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,
Expand All @@ -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,
Expand All @@ -300,20 +305,28 @@ export default async (assets: Assets) => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 575,
y: height - 575,
size: 15,
font: pressStart2PFont,
lineHeight: 15,
});

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.
Expand Down
1 change: 1 addition & 0 deletions apps/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 23 additions & 10 deletions apps/node/tests/test1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -270,15 +275,15 @@ export default async (assets: Assets) => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 300,
y: height - 300,
size: 30,
font: greatVibesFont,
lineHeight: 30,
});

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,
Expand All @@ -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,
Expand All @@ -298,20 +303,28 @@ export default async (assets: Assets) => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 575,
y: height - 575,
size: 15,
font: pressStart2PFont,
lineHeight: 15,
});

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.
Expand Down
35 changes: 25 additions & 10 deletions apps/rn/src/tests/test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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'),
Expand All @@ -257,19 +263,20 @@ 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,
});

const fantasqueFont = await pdfDoc.embedFont(fantasqueBytes);
page2.drawText(ipsumLines.join('\n'), {
y: size - 105,
y: height - 105,
size: 25,
font: fantasqueFont,
lineHeight: 25,
Expand All @@ -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,
Expand All @@ -289,15 +296,15 @@ export default async () => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 300,
y: height - 300,
size: 30,
font: greatVibesFont,
lineHeight: 30,
});

const appleStormFont = await pdfDoc.embedFont(appleStormBytes);
page2.drawText(ipsumLines.join('\n'), {
y: size - 425,
y: height - 425,
size: 25,
font: appleStormFont,
lineHeight: 25,
Expand All @@ -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,
Expand All @@ -317,20 +324,28 @@ export default async () => {
subset: true,
});
page2.drawText(ipsumLines.join('\n'), {
y: size - 575,
y: height - 575,
size: 15,
font: pressStart2PFont,
lineHeight: 15,
});

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.
Expand Down
Loading