1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

XFA - Support non-embedded fonts without a Widths entry

- some pdf use some fonts which are not embedded or they don't have any width array or don't have any css info (e.g. for standard fonts or Arial).
  - so add widths arrays for Liberation fonts in order to compute the ones for other fonts in using scale factors array.
This commit is contained in:
Calixte Denizet 2021-06-28 19:03:47 +02:00
parent ff3a5382ee
commit 70bb672dcd
11 changed files with 464 additions and 59 deletions

View file

@ -16,6 +16,7 @@
import {
$acceptWhitespace,
$childrenToHTML,
$clean,
$content,
$extra,
$getChildren,
@ -144,18 +145,23 @@ function mapStyle(styleStr, fontFinder) {
return style;
}
function checkStyle(style) {
if (!style) {
function checkStyle(node) {
if (!node.style) {
return "";
}
// Remove any non-allowed keys.
return style
return node.style
.trim()
.split(/\s*;\s*/)
.filter(s => !!s)
.map(s => s.split(/\s*:\s*/, 2))
.filter(([key]) => VALID_STYLES.has(key))
.filter(([key, value]) => {
if (key === "font-family") {
node[$globalData].usedTypefaces.add(value);
}
return VALID_STYLES.has(key);
})
.map(kv => kv.join(":"))
.join(";");
}
@ -165,7 +171,12 @@ const NoWhites = new Set(["body", "html"]);
class XhtmlObject extends XmlObject {
constructor(attributes, name) {
super(XHTML_NS_ID, name);
this.style = checkStyle(attributes.style);
this.style = attributes.style || "";
}
[$clean](builder) {
super[$clean](builder);
this.style = checkStyle(this);
}
[$acceptWhitespace]() {