mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #12508 from calixteman/button_fallback_font
Fallback font for buttons must be ZapfDingbats.
This commit is contained in:
commit
b4ca3d55b8
6 changed files with 109 additions and 5 deletions
|
@ -26,6 +26,7 @@ import {
|
|||
getModificationDate,
|
||||
isString,
|
||||
OPS,
|
||||
shadow,
|
||||
stringToPDFString,
|
||||
unreachable,
|
||||
Util,
|
||||
|
@ -281,6 +282,8 @@ class Annotation {
|
|||
rect: this.rectangle,
|
||||
subtype: params.subtype,
|
||||
};
|
||||
|
||||
this._fallbackFontDict = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -576,6 +579,7 @@ class Annotation {
|
|||
task,
|
||||
resources,
|
||||
operatorList: opList,
|
||||
fallbackFontDict: this._fallbackFontDict,
|
||||
})
|
||||
.then(() => {
|
||||
opList.addOp(OPS.endAnnotation, []);
|
||||
|
@ -1873,6 +1877,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
if (this.uncheckedAppearance) {
|
||||
this._streams.push(this.uncheckedAppearance);
|
||||
}
|
||||
this._fallbackFontDict = this.fallbackFontDict;
|
||||
}
|
||||
|
||||
_processRadioButton(params) {
|
||||
|
@ -1912,6 +1917,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
if (this.uncheckedAppearance) {
|
||||
this._streams.push(this.uncheckedAppearance);
|
||||
}
|
||||
this._fallbackFontDict = this.fallbackFontDict;
|
||||
}
|
||||
|
||||
_processPushButton(params) {
|
||||
|
@ -1954,6 +1960,16 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
type,
|
||||
};
|
||||
}
|
||||
|
||||
get fallbackFontDict() {
|
||||
const dict = new Dict();
|
||||
dict.set("BaseFont", Name.get("ZapfDingbats"));
|
||||
dict.set("Type", Name.get("FallbackType"));
|
||||
dict.set("Subtype", Name.get("FallbackType"));
|
||||
dict.set("Encoding", Name.get("ZapfDingbatsEncoding"));
|
||||
|
||||
return shadow(this, "fallbackFontDict", dict);
|
||||
}
|
||||
}
|
||||
|
||||
class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
||||
|
|
|
@ -777,7 +777,15 @@ class PartialEvaluator {
|
|||
});
|
||||
}
|
||||
|
||||
handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
|
||||
handleSetFont(
|
||||
resources,
|
||||
fontArgs,
|
||||
fontRef,
|
||||
operatorList,
|
||||
task,
|
||||
state,
|
||||
fallbackFontDict = null
|
||||
) {
|
||||
// TODO(mack): Not needed?
|
||||
var fontName,
|
||||
fontSize = 0;
|
||||
|
@ -787,7 +795,7 @@ class PartialEvaluator {
|
|||
fontSize = fontArgs[1];
|
||||
}
|
||||
|
||||
return this.loadFont(fontName, fontRef, resources)
|
||||
return this.loadFont(fontName, fontRef, resources, fallbackFontDict)
|
||||
.then(translated => {
|
||||
if (!translated.font.isType3Font) {
|
||||
return translated;
|
||||
|
@ -978,7 +986,7 @@ class PartialEvaluator {
|
|||
});
|
||||
}
|
||||
|
||||
loadFont(fontName, font, resources) {
|
||||
loadFont(fontName, font, resources, fallbackFontDict = null) {
|
||||
const errorFont = async () => {
|
||||
return new TranslatedFont({
|
||||
loadedName: "g_font_error",
|
||||
|
@ -1020,7 +1028,11 @@ class PartialEvaluator {
|
|||
|
||||
// Falling back to a default font to avoid completely broken rendering,
|
||||
// but note that there're no guarantees that things will look "correct".
|
||||
fontRef = PartialEvaluator.fallbackFontDict;
|
||||
if (fallbackFontDict) {
|
||||
fontRef = fallbackFontDict;
|
||||
} else {
|
||||
fontRef = PartialEvaluator.fallbackFontDict;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fontCache.has(fontRef)) {
|
||||
|
@ -1353,6 +1365,7 @@ class PartialEvaluator {
|
|||
resources,
|
||||
operatorList,
|
||||
initialState = null,
|
||||
fallbackFontDict = null,
|
||||
}) {
|
||||
// Ensure that `resources`/`initialState` is correctly initialized,
|
||||
// even if the provided parameter is e.g. `null`.
|
||||
|
@ -1533,7 +1546,8 @@ class PartialEvaluator {
|
|||
null,
|
||||
operatorList,
|
||||
task,
|
||||
stateManager.state
|
||||
stateManager.state,
|
||||
fallbackFontDict
|
||||
)
|
||||
.then(function (loadedName) {
|
||||
operatorList.addDependency(loadedName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue