Compare commits

..

No commits in common. "10844326c7e29b563645c454e10c315549523605" and "04eeeec4a484c03c1fee0ce3200f9c82e5719ba4" have entirely different histories.

5 changed files with 66 additions and 63 deletions

View File

@ -1,5 +1,5 @@
{
"stableVersion": "6.0.227",
"baseVersion": "b168293c173b0b9befe462c0b254136cf038c3ef",
"versionPrefix": "6.1."
"baseVersion": "e6e06cf6b5307fe39e0de69c6c884f816b0cb21b",
"versionPrefix": "6.0."
}

View File

@ -81,6 +81,10 @@ import { parseMarkedContentProps } from "./evaluator_utils.js";
import { StringStream } from "./stream.js";
import { XFAFactory } from "./xfa/factory.js";
/**
* @import { Catalog } from "./catalog.js";
*/
class AnnotationFactory {
static createGlobals(pdfManager) {
return Promise.all([
@ -104,7 +108,6 @@ class AnnotationFactory {
globalColorSpaceCache,
]) => ({
pdfManager,
catalog: pdfManager.pdfDocument.catalog,
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
xfaDatasets,
structTreeRoot,
@ -687,8 +690,6 @@ function getTransformMatrix(rect, bbox, matrix) {
}
class Annotation {
appearance = null;
_oc = undefined;
constructor(params) {
@ -1177,6 +1178,8 @@ 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 +1198,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)) {
if (!(as instanceof Name) || !normalAppearanceState.has(as.name)) {
return;
}
const appearance = normalAppearanceState.get(as.name);
@ -1502,25 +1505,6 @@ class Annotation {
return fieldName.join(".");
}
/**
* Encode the embedded content's reference in the id so it can be
* re-fetched from the xref on demand (see `Catalog.attachmentContent`)
* instead of being cached where `cleanup` would wipe it. The file-spec is
* usually indirect; when it's inline its embedded-file stream still isn't
* (streams are always indirect), so fall back to that ref.
*/
_getAttachmentId(fsDict, fsRef, annotationGlobals) {
if (!(fsDict instanceof Dict)) {
return undefined;
}
if (!(fsRef instanceof Ref)) {
fsRef = FileSpec.pickPlatformItem(fsDict.get("EF"), /* raw = */ true);
}
return fsRef instanceof Ref
? annotationGlobals.catalog.getAttachmentIdForAnnotation(fsRef)
: undefined;
}
get width() {
return this.data.rect[2] - this.data.rect[0];
}
@ -3124,7 +3108,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
}
if (startChunk < line.length) {
chunks.push(line.substring(startChunk));
chunks.push(line.substring(startChunk, line.length));
}
return chunks;
@ -5437,15 +5421,33 @@ class FileAttachmentAnnotation extends MarkupAnnotation {
const { annotationGlobals, dict } = params;
const fsDict = dict.get("FS");
const file = new FileSpec(fsDict);
/** @type {{catalog?: Catalog}} */
const { catalog } = annotationGlobals.pdfManager.pdfDocument;
// Encode the embedded content's reference in the id so it can be
// re-fetched from the xref on demand (see `Catalog.attachmentContent`)
// instead of being cached where `cleanup` would wipe it. The file-spec is
// usually indirect; when it's inline its embedded-file stream still isn't
// (streams are always indirect), so fall back to that ref.
let fileId;
if (fsDict instanceof Dict) {
let contentRef = dict.getRaw("FS");
if (!(contentRef instanceof Ref)) {
contentRef = FileSpec.pickPlatformItem(
fsDict.get("EF"),
/* raw = */ true
);
}
if (contentRef instanceof Ref) {
fileId = catalog?.getAttachmentIdForAnnotation(contentRef);
}
}
this.data.hasOwnCanvas = this.data.noRotate;
this.data.noHTML = false;
this.data.fileId = this._getAttachmentId(
fsDict,
dict.getRaw("FS"),
annotationGlobals
);
this.data.file = new FileSpec(fsDict).serializable;
this.data.fileId = fileId;
this.data.file = file.serializable;
const name = dict.get("Name");
this.data.name =
@ -5488,18 +5490,23 @@ class MediaAnnotation extends Annotation {
* when `assetRef` isn't itself a reference.
* @param {string} asset.filename
* @param {string} asset.contentType
* @param {Object} annotationGlobals
* @param {Catalog} [catalog]
*/
_setMediaData(
{ assetRef, assetDict, filename, contentType },
annotationGlobals
) {
_setMediaData({ assetRef, assetDict, filename, contentType }, catalog) {
let contentRef = assetRef;
if (!(contentRef instanceof Ref)) {
contentRef = FileSpec.pickPlatformItem(
assetDict.get("EF"),
/* raw = */ true
);
}
const fileId =
contentRef instanceof Ref
? catalog?.getAttachmentIdForAnnotation(contentRef)
: undefined;
this.data.noHTML = false;
this.data.richMedia = {
fileId: this._getAttachmentId(assetDict, assetRef, annotationGlobals),
filename,
contentType,
};
this.data.richMedia = { fileId, filename, contentType };
}
/**
@ -5570,6 +5577,8 @@ class RichMediaAnnotation extends MediaAnnotation {
super(params);
const { dict, xref, annotationGlobals } = params;
/** @type {{catalog?: Catalog}} */
const { catalog } = annotationGlobals.pdfManager.pdfDocument;
const content = dict.get("RichMediaContent");
if (!(content instanceof Dict)) {
@ -5581,7 +5590,8 @@ class RichMediaAnnotation extends MediaAnnotation {
warn("RichMedia annotation has no playable asset.");
return;
}
this._setMediaData(asset, annotationGlobals);
this._setMediaData(asset, catalog);
}
/**
@ -5665,7 +5675,7 @@ class ScreenAnnotation extends MediaAnnotation {
// a /Movie); such ones simply render their appearance, so don't warn.
return;
}
this._setMediaData(asset, annotationGlobals);
this._setMediaData(asset, annotationGlobals.pdfManager.pdfDocument.catalog);
}
/**
@ -5686,7 +5696,7 @@ class ScreenAnnotation extends MediaAnnotation {
* } | null}
*/
static #findAsset(dict, xref) {
for (const action of this.#renditionActions(dict)) {
for (const action of this.#renditionActions(dict, xref)) {
const asset = this.#findRenditionAsset(
action.get("R"),
xref,
@ -5699,10 +5709,10 @@ class ScreenAnnotation extends MediaAnnotation {
return null;
}
static *#renditionActions(dict) {
static *#renditionActions(dict, xref) {
// The rendition action may be the activation action (/A) or one of the
// additional actions (/AA), e.g. page-open.
const action = dict.get("A");
const action = xref.fetchIfRef(dict.getRaw("A"));
if (
action instanceof Dict &&
isName(action.get("S"), "Rendition") &&
@ -5712,7 +5722,8 @@ class ScreenAnnotation extends MediaAnnotation {
}
const additionalActions = dict.get("AA");
if (additionalActions instanceof Dict) {
for (const [, aa] of additionalActions) {
for (const key of additionalActions.getKeys()) {
const aa = xref.fetchIfRef(additionalActions.getRaw(key));
if (
aa instanceof Dict &&
isName(aa.get("S"), "Rendition") &&

View File

@ -386,7 +386,7 @@ function escapePDFName(str) {
}
if (start < str.length) {
buffer.push(str.substring(start));
buffer.push(str.substring(start, str.length));
}
return buffer.join("");
@ -545,7 +545,7 @@ function encodeToXmlString(str) {
return str;
}
if (start < str.length) {
buffer.push(str.substring(start));
buffer.push(str.substring(start, str.length));
}
return buffer.join("");
}

View File

@ -17,7 +17,6 @@
// https://github.com/mozilla/shumway/blob/16451d8836fa85f4b16eeda8b4bda2fa9e2b22b0/src/avm2/natives/xml.ts
import { encodeToXmlString } from "./core_utils.js";
import { shadow } from "../shared/util.js";
const XMLParserErrorCode = {
NoError: 0,
@ -48,17 +47,12 @@ function isWhitespaceString(s) {
}
class XMLParserBase {
static get _entityRegex() {
return shadow(this, "_entityRegex", /&(?:#x([^;]+)|#([^;]+)|([^;]+));/g);
}
_resolveEntities(s) {
return s.replaceAll(XMLParserBase._entityRegex, (_, hex, dec, entity) => {
if (hex) {
return String.fromCodePoint(parseInt(hex, 16));
}
if (dec) {
return String.fromCodePoint(parseInt(dec, 10));
return s.replaceAll(/&([^;]+);/g, (all, entity) => {
if (entity.substring(0, 2) === "#x") {
return String.fromCodePoint(parseInt(entity.substring(2), 16));
} else if (entity.at(0) === "#") {
return String.fromCodePoint(parseInt(entity.substring(1), 10));
}
switch (entity) {
case "lt":

View File

@ -73,8 +73,6 @@ describe("document", function () {
const pdfDocument = new PDFDocument(pdfManager, stream);
pdfDocument.xref = xref;
pdfDocument.catalog = catalog;
pdfManager.pdfDocument = pdfDocument;
return pdfDocument;
}