From d1452206d9a381a10bc7ccc48bdfb489fb810f0e Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sat, 15 Jun 2024 17:43:58 +0200 Subject: [PATCH] Compute correctly the unitsPerEm value from the fontMatrix when converting a font (bug 1539074) --- src/core/fonts.js | 8 ++++++-- test/pdfs/.gitignore | 1 + test/pdfs/bug1539074.pdf | Bin 0 -> 6015 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100755 test/pdfs/bug1539074.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index 993d3340bfa94..7959f8ffc118d 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -798,7 +798,9 @@ function createOS2Table(properties, charstrings, override) { const bbox = properties.bbox || [0, 0, 0, 0]; const unitsPerEm = override.unitsPerEm || - 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]; + (properties.fontMatrix + ? 1 / Math.max(...properties.fontMatrix.slice(0, 4)) + : 1000); // if the font units differ to the PDF glyph space units // then scale up the values @@ -3196,7 +3198,9 @@ class Font { properties.seacMap = seacMap; } - const unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]; + const unitsPerEm = properties.fontMatrix + ? 1 / Math.max(...properties.fontMatrix.slice(0, 4)) + : 1000; const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F"); // PostScript Font Program diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 733a26e08e12a..a0991c7193413 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -649,3 +649,4 @@ !tracemonkey_freetext.pdf !issue17998.pdf !pdfjs_wikipedia.pdf +!bug1539074.pdf diff --git a/test/pdfs/bug1539074.pdf b/test/pdfs/bug1539074.pdf new file mode 100755 index 0000000000000000000000000000000000000000..a6ce4906b79b8714c12b9476085662c718d1fe9b GIT binary patch literal 6015 zcmeHLe^?Y{9^VxWobwX33xA!ybzz{gyED79yMt&hKQ>X+1r}T)tYL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iphctqv{(k+C|pu1z@bTvTlhZ zv^IN+LxT}yKI`#d{(!_J45I^bj7Hf((5u&w29jndBOOO+j3N0HsZbhU#vu^I7>j0j zS-D8!SQG-wMh&H*VsQr~*mdZvwt~yFQ}c^6GaSy!25)p z5Rk^k7J^-p03`xslMw#a${@6Wz6GD?(iBsggvLFUf@J-P)khs}G2^j*k7~^79JA+(M z(;_()HBIpGnZ$Z01bPM_2BF2=@LC+nz^F^VfY4^jTuC-!OoY}Ee23P9$CHX!5o;Zz z^+OcS)(rNv{z`)_t-85irU%rexB3f)ONU=m#QhIbqoApZ!)FpIqZYc?%rw#``U?c16itWu$c zreq&!hMddfAAyvBF6}h%J{({q%w-4yNTeJem>k-dBtBS_=(fhw26d%dvwZF GEAekIGm1U{ literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 07ca39da989fb..98eb53829e0f7 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -10081,5 +10081,12 @@ "rounds": 1, "link": true, "type": "eq" + }, + { + "id": "bug1539074", + "file": "pdfs/bug1539074.pdf", + "md5": "73922be020083d54747af18a4d5e0768", + "rounds": 1, + "type": "eq" } ]