[XFA] Add alt text for images. (bug 1723418)
Not many XFA PDFs have alt text. Some examples: bug1723422.pdf xfa_bug1718670_1.pdf xfa_issue13611.pdf xfa_issue13633.pdf xfa_issue13634.pdf
This commit is contained in:
parent
6cf1ee3251
commit
3e003245b1
@ -3312,12 +3312,14 @@ class Image extends StringObject {
|
||||
};
|
||||
break;
|
||||
}
|
||||
const parent = this[$getParent]();
|
||||
return HTMLResult.success({
|
||||
name: "img",
|
||||
attributes: {
|
||||
class: ["xfaImage"],
|
||||
style,
|
||||
src: URL.createObjectURL(blob),
|
||||
alt: parent ? ariaLabel(parent[$getParent]()) : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { isNodeJS } from "../../src/shared/is_node.js";
|
||||
import { XFAFactory } from "../../src/core/xfa/factory.js";
|
||||
|
||||
describe("XFAFactory", function () {
|
||||
@ -138,6 +139,44 @@ describe("XFAFactory", function () {
|
||||
);
|
||||
});
|
||||
|
||||
it("should have an alt attribute from toolTip", function () {
|
||||
if (isNodeJS) {
|
||||
pending("Image is not supported in Node.js.");
|
||||
}
|
||||
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 name="BA-Logo" y="5.928mm" x="128.388mm" w="71.237mm" h="9.528mm">
|
||||
<value>
|
||||
<image contentType="image/png">iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=</image>
|
||||
</value>
|
||||
<assist><toolTip>alt text</toolTip></assist>
|
||||
</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(factory.numberPages).toEqual(1);
|
||||
|
||||
const pages = factory.getPages();
|
||||
const field = searchHtmlNode(pages, "name", "img");
|
||||
|
||||
expect(field.attributes.alt).toEqual("alt text");
|
||||
});
|
||||
|
||||
it("should have a maxLength property", function () {
|
||||
const xml = `
|
||||
<?xml version="1.0"?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user