From 723ee9bc8c5da98dda42621a6930257ef72efc07 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 18 Dec 2024 17:00:45 +0100 Subject: [PATCH] Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087) --- src/core/xfa/xhtml.js | 3 ++- test/unit/xfa_tohtml_spec.js | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/core/xfa/xhtml.js b/src/core/xfa/xhtml.js index 3e9847c7beb88..1c1eab989cfd5 100644 --- a/src/core/xfa/xhtml.js +++ b/src/core/xfa/xhtml.js @@ -94,7 +94,8 @@ const StyleMapping = new Map([ [ "font-size", (value, original) => { - value = original.fontSize = getMeasurement(value); + // The font size must be positive. + value = original.fontSize = Math.abs(getMeasurement(value)); return measureToString(0.99 * value); }, ], diff --git a/test/unit/xfa_tohtml_spec.js b/test/unit/xfa_tohtml_spec.js index e4284963926b0..615ba3c123d75 100644 --- a/test/unit/xfa_tohtml_spec.js +++ b/test/unit/xfa_tohtml_spec.js @@ -642,4 +642,45 @@ describe("XFAFactory", function () { expect(a.attributes.href).toEqual("https://github.com/allizom/pdf.js"); expect(a.attributes.newWindow).toEqual(false); }); + + it("should take the absolute value of the font size", async () => { + const xml = ` + + + + + + + + + `; + const factory = new XFAFactory({ "xdp:xdp": xml }); + + expect(await factory.getNumPages()).toEqual(1); + + const pages = await factory.getPages(); + const p = searchHtmlNode(pages, "name", "p"); + expect(p.attributes.style.fontSize).toEqual("13.86px"); + }); });