mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
[api-minor] Sort PopupAnnotations already on the worker-thread (PR 11535 follow-up)
By doing this in the worker-thread this code will only need to run *once*, whereas currently re-rendering of a page forces this to be repeated (e.g. after it's been scrolled out-of-view and then back into view again).
This commit is contained in:
parent
d6d4653d80
commit
876a02a504
3 changed files with 33 additions and 24 deletions
|
@ -13,6 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AnnotationFactory, PopupAnnotation } from "./annotation.js";
|
||||
import {
|
||||
assert,
|
||||
FormatError,
|
||||
|
@ -42,7 +43,6 @@ import {
|
|||
} from "./core_utils.js";
|
||||
import { Dict, isName, Name, Ref } from "./primitives.js";
|
||||
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
|
||||
import { AnnotationFactory } from "./annotation.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
import { calculateMD5 } from "./crypto.js";
|
||||
import { Catalog } from "./catalog.js";
|
||||
|
@ -656,7 +656,32 @@ class Page {
|
|||
}
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue