Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087) #19238

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});
Loading