mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 10:15:37 +02:00
[api-minor] Change the format of the fontName
-property, in defaultAppearanceData
, on Annotation-instances (PR 12831 follow-up)
Currently the `fontName`-property contains an actual /Name-instance, which is a problem given that its fallback value is an empty string; seeca7f546828/src/core/default_appearance.js (L35)
The reason that this is a problem can be seen inca7f546828/src/core/primitives.js (L30-L34)
, since an empty string short-circuits the cache. Essentially, in PDF documents, a /Name-instance cannot be empty and the way that the `DefaultAppearanceEvaluator` does things is unfortunately not entirely correct. Hence the `fontName`-property is changed to instead contain a string, rather than a /Name-instance, which simplifies the code overall. *Please note:* I'm tagging this patch with "[api-minor]", since PR 12831 is included in the current pre-release (although we're not using the `fontName`-property in the display-layer).
This commit is contained in:
parent
ca7f546828
commit
0eb1433c78
4 changed files with 18 additions and 23 deletions
|
@ -1470,7 +1470,7 @@ class WidgetAnnotation extends Annotation {
|
|||
const { fontName, fontSize } = this.data.defaultAppearanceData;
|
||||
await evaluator.handleSetFont(
|
||||
this._fieldResources.mergedResources,
|
||||
[fontName, fontSize],
|
||||
[fontName && Name.get(fontName), fontSize],
|
||||
/* fontRef = */ null,
|
||||
operatorList,
|
||||
task,
|
||||
|
@ -1565,26 +1565,26 @@ class WidgetAnnotation extends Annotation {
|
|||
acroFormResources,
|
||||
} = this._fieldResources;
|
||||
|
||||
const fontNameStr =
|
||||
const fontName =
|
||||
this.data.defaultAppearanceData &&
|
||||
this.data.defaultAppearanceData.fontName.name;
|
||||
if (!fontNameStr) {
|
||||
this.data.defaultAppearanceData.fontName;
|
||||
if (!fontName) {
|
||||
return localResources || Dict.empty;
|
||||
}
|
||||
|
||||
for (const resources of [localResources, appearanceResources]) {
|
||||
if (resources instanceof Dict) {
|
||||
const localFont = resources.get("Font");
|
||||
if (localFont instanceof Dict && localFont.has(fontNameStr)) {
|
||||
if (localFont instanceof Dict && localFont.has(fontName)) {
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (acroFormResources instanceof Dict) {
|
||||
const acroFormFont = acroFormResources.get("Font");
|
||||
if (acroFormFont instanceof Dict && acroFormFont.has(fontNameStr)) {
|
||||
if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) {
|
||||
const subFontDict = new Dict(xref);
|
||||
subFontDict.set(fontNameStr, acroFormFont.getRaw(fontNameStr));
|
||||
subFontDict.set(fontName, acroFormFont.getRaw(fontName));
|
||||
|
||||
const subResourcesDict = new Dict(xref);
|
||||
subResourcesDict.set("Font", subFontDict);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue