Merge pull request #15283 from Snuffleupagus/sort-PopupAnnotation
[api-minor] Sort PopupAnnotations already on the worker-thread (PR 11535 follow-up)
This commit is contained in:
commit
2a84a3078b
@ -4092,4 +4092,5 @@ export {
|
|||||||
AnnotationFactory,
|
AnnotationFactory,
|
||||||
getQuadPoints,
|
getQuadPoints,
|
||||||
MarkupAnnotation,
|
MarkupAnnotation,
|
||||||
|
PopupAnnotation,
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { AnnotationFactory, PopupAnnotation } from "./annotation.js";
|
||||||
import {
|
import {
|
||||||
assert,
|
assert,
|
||||||
FormatError,
|
FormatError,
|
||||||
@ -42,7 +43,6 @@ import {
|
|||||||
} from "./core_utils.js";
|
} from "./core_utils.js";
|
||||||
import { Dict, isName, Name, Ref } from "./primitives.js";
|
import { Dict, isName, Name, Ref } from "./primitives.js";
|
||||||
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
|
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
|
||||||
import { AnnotationFactory } from "./annotation.js";
|
|
||||||
import { BaseStream } from "./base_stream.js";
|
import { BaseStream } from "./base_stream.js";
|
||||||
import { calculateMD5 } from "./crypto.js";
|
import { calculateMD5 } from "./crypto.js";
|
||||||
import { Catalog } from "./catalog.js";
|
import { Catalog } from "./catalog.js";
|
||||||
@ -656,7 +656,32 @@ class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(annotationPromises).then(function (annotations) {
|
return Promise.all(annotationPromises).then(function (annotations) {
|
||||||
return annotations.filter(annotation => !!annotation);
|
if (annotations.length === 0) {
|
||||||
|
return annotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedAnnotations = [];
|
||||||
|
let popupAnnotations;
|
||||||
|
// Ensure that PopupAnnotations are handled last, since they depend on
|
||||||
|
// their parent Annotation in the display layer; fixes issue 11362.
|
||||||
|
for (const annotation of annotations) {
|
||||||
|
if (!annotation) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (annotation instanceof PopupAnnotation) {
|
||||||
|
if (!popupAnnotations) {
|
||||||
|
popupAnnotations = [];
|
||||||
|
}
|
||||||
|
popupAnnotations.push(annotation);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sortedAnnotations.push(annotation);
|
||||||
|
}
|
||||||
|
if (popupAnnotations) {
|
||||||
|
sortedAnnotations.push(...popupAnnotations);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortedAnnotations;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2477,30 +2477,13 @@ class AnnotationLayer {
|
|||||||
|
|
||||||
this.#setDimensions(div, viewport);
|
this.#setDimensions(div, viewport);
|
||||||
|
|
||||||
const sortedAnnotations = [],
|
|
||||||
popupAnnotations = [];
|
|
||||||
// Ensure that Popup annotations are handled last, since they're dependant
|
|
||||||
// upon the parent annotation having already been rendered (please refer to
|
|
||||||
// the `PopupAnnotationElement.render` method); fixes issue 11362.
|
|
||||||
for (const data of annotations) {
|
for (const data of annotations) {
|
||||||
if (!data) {
|
if (data.annotationType !== AnnotationType.POPUP) {
|
||||||
continue;
|
const { width, height } = getRectDims(data.rect);
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
continue; // Ignore empty annotations.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (data.annotationType === AnnotationType.POPUP) {
|
|
||||||
popupAnnotations.push(data);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const { width, height } = getRectDims(data.rect);
|
|
||||||
if (width <= 0 || height <= 0) {
|
|
||||||
continue; // Ignore empty annotations.
|
|
||||||
}
|
|
||||||
sortedAnnotations.push(data);
|
|
||||||
}
|
|
||||||
if (popupAnnotations.length) {
|
|
||||||
sortedAnnotations.push(...popupAnnotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const data of sortedAnnotations) {
|
|
||||||
const element = AnnotationElementFactory.create({
|
const element = AnnotationElementFactory.create({
|
||||||
data,
|
data,
|
||||||
layer: div,
|
layer: div,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user