Skip to content

Commit

Permalink
fix font embedding
Browse files Browse the repository at this point in the history
the font embedder was dropping alternate glyphs, which broke (in our
case) tnum rendering. fixed via someone else's PR:

Hopding#1325
  • Loading branch information
duncanwerner committed Jun 8, 2023
1 parent a411df8 commit f96dac6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/core/embedders/CustomFontEmbedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ class CustomFontEmbedder {
}

protected computeWidths(): (number | number[])[] {

/*
let flag = false;
if (/firasans-regular/i.test(this.fontName)) {
console.info("Calling computeWidths", this);
flag = true;
}
*/

const glyphs = this.glyphCache.access();

const widths: (number | number[])[] = [];
Expand All @@ -228,6 +237,12 @@ class CustomFontEmbedder {
currSection = [];
}

/*
if (flag && currGlyph.codePoints[0] === 48) {
console.info('48', currGlyph);
}
*/

currSection.push(currGlyph.advanceWidth * this.scale);
}

Expand All @@ -236,6 +251,7 @@ class CustomFontEmbedder {
return widths;
}

/*
private allGlyphsInFontSortedById = (): Glyph[] => {
const glyphs: Glyph[] = new Array(this.font.characterSet.length);
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
Expand All @@ -244,6 +260,20 @@ class CustomFontEmbedder {
}
return sortedUniq(glyphs.sort(byAscendingId), (g) => g.id);
};
*/

/**
* thanks to @phipla, see
* https://github.com/Hopding/pdf-lib/pull/1325
*/
private allGlyphsInFontSortedById = (): Glyph[] => {
const glyphs: Glyph[] = new Array(this.font.numGlyphs);
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
glyphs[idx] = this.font.getGlyph(idx);
}
return sortedUniq(glyphs.sort(byAscendingId), (g) => g.id);
};

}

export default CustomFontEmbedder;

0 comments on commit f96dac6

Please sign in to comment.