Skip to content

Commit

Permalink
Fix Postscript name in font to avoid bug when saving in pdf
Browse files Browse the repository at this point in the history
  - for xfa rendering, fonts are loaded and used in html;
  - when printed and saved in pdf, on linux, Firefox uses cairo backend
  - when subsetting a font, cairo uses the font postscript name and when this one is empty that leads to a bug
    (the append at https://github.com/freedesktop/cairo/blob/63f0d6268469dcd12316ea405a026f4be900dd79/src/cairo-cff-subset.c#L2049 is failing because of null length)
  - so this patch adds a postscript name to the font to make cairo happy.
  • Loading branch information
calixteman committed May 26, 2021
1 parent 4d26623 commit d497471
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,11 @@ function createPostTable(properties) {
); // maxMemType1
}

function makePostscriptName(name) {
// See https://docs.microsoft.com/en-us/typography/opentype/spec/recom#name.
return name.replace(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
}

function createNameTable(name, proto) {
if (!proto) {
proto = [[], []]; // no strings and unicode strings
Expand All @@ -734,7 +739,7 @@ function createNameTable(name, proto) {
proto[0][3] || "uniqueID", // 3.Unique ID
proto[0][4] || name, // 4.Full font name
proto[0][5] || "Version 0.11", // 5.Version
proto[0][6] || "", // 6.Postscript name
proto[0][6] || makePostscriptName(name), // 6.Postscript name
proto[0][7] || "Unknown", // 7.Trademark
proto[0][8] || "Unknown", // 8.Manufacturer
proto[0][9] || "Unknown", // 9.Designer
Expand Down

0 comments on commit d497471

Please sign in to comment.