Skip to content

Commit

Permalink
Take the absolute value of the font size when the annotation contents…
Browse files Browse the repository at this point in the history
… is in xhtml (bug 1938087)
  • Loading branch information
calixteman committed Dec 18, 2024
1 parent 8985d80 commit 723ee9b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/xfa/xhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
],
Expand Down
41 changes: 41 additions & 0 deletions test/unit/xfa_tohtml_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<?xml version="1.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
<subform name="root" mergeMode="matchTemplate">
<pageSet>
<pageArea>
<contentArea x="0pt" w="456pt" h="789pt"/>
<draw y="1pt" w="11pt" h="22pt" x="2pt">
<value>
<text>
<body xmlns="http://www.w3.org/1999/xhtml">
<p style="foo: bar; text-indent:0.5in; line-height:11px;font-size: -14.0pt; bar:foo;tab-stop: left 0.5in;">
The first line of this paragraph is indented a half-inch.<br/>
Successive lines are not indented.<br/>
This is the last line of the paragraph.<br/>
</p>
</body>
</text>
</value>
</draw>
</pageArea>
</pageSet>
</subform>
</template>
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
</xfa:data>
</xfa:datasets>
</xdp:xdp>
`;
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");
});
});

0 comments on commit 723ee9b

Please sign in to comment.