Skip to content
Open
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
16 changes: 4 additions & 12 deletions src/core/xfa/xhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,8 @@ class A extends XhtmlObject {
class B extends XhtmlObject {
constructor(attributes) {
super(attributes, "b");
}

[$pushGlyphs](measure) {
measure.pushFont({ weight: "bold" });
super[$pushGlyphs](measure);
measure.popFont();
// Prepend so explicit styles like font-weight:normal still win.
this.style = `font-weight:bold;${this.style}`;
}
}

Expand Down Expand Up @@ -461,12 +457,8 @@ class Html extends XhtmlObject {
class I extends XhtmlObject {
constructor(attributes) {
super(attributes, "i");
}

[$pushGlyphs](measure) {
measure.pushFont({ posture: "italic" });
super[$pushGlyphs](measure);
measure.popFont();
// Prepend so explicit styles like font-style:normal still win.
this.style = `font-style:italic;${this.style}`;
}
}

Expand Down
43 changes: 43 additions & 0 deletions test/unit/xfa_tohtml_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,47 @@ describe("XFAFactory", function () {
const p = searchHtmlNode(pages, "name", "p");
expect(p.attributes.style.fontSize).toEqual("13.86px");
});

it("should layout rich text containing bold and italic elements", 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"/>
<medium stock="default" short="456pt" long="789pt"/>
<draw y="1pt" w="200pt" x="2pt">
<value>
<exData contentType="text/html">
<body xmlns="http://www.w3.org/1999/xhtml">
<p><b>Important:</b> some <i>italic</i> text</p>
</body>
</exData>
</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(new Map([["xdp:xdp", xml]]));
factory.setFonts([]);

expect(await factory.getNumPages()).toEqual(1);

const pages = await factory.getPages();
const b = searchHtmlNode(pages, "name", "b");
expect(b.value).toEqual("Important:");
expect(b.attributes.style.fontWeight).toEqual("bold");
const i = searchHtmlNode(pages, "name", "i");
expect(i.value).toEqual("italic");
expect(i.attributes.style.fontStyle).toEqual("italic");
});
});
Loading