Simplify the Annotation.prototype.setAppearance method a tiny bit

It's not necessary to check if the /AS entry exists first, and it can just be fetched directly, since in that case the existing "is stream"-check won't be true anyway.

Also, move the `appearance` field definition to the top of the class instead.
This commit is contained in:
Jonas Jenwald 2026-06-23 10:22:08 +02:00
parent f07a106529
commit 8a2c112c20

View File

@ -687,6 +687,8 @@ function getTransformMatrix(rect, bbox, matrix) {
}
class Annotation {
appearance = null;
_oc = undefined;
constructor(params) {
@ -1175,8 +1177,6 @@ class Annotation {
* @param {Dict} dict - The annotation's data dictionary
*/
setAppearance(dict) {
this.appearance = null;
const appearanceStates = dict.get("AP");
if (!(appearanceStates instanceof Dict)) {
return;
@ -1195,7 +1195,7 @@ class Annotation {
// In case the normal appearance is a dictionary, the `AS` entry provides
// the key of the stream in this dictionary.
const as = dict.get("AS");
if (!(as instanceof Name) || !normalAppearanceState.has(as.name)) {
if (!(as instanceof Name)) {
return;
}
const appearance = normalAppearanceState.get(as.name);