Merge pull request #19461 from Snuffleupagus/autolinking-lazy-borderStyle

Create the `borderStyle` of inferred links lazily (PR 19110 follow-up)
This commit is contained in:
Jonas Jenwald 2025-02-10 16:32:12 +01:00 committed by GitHub
commit 29fbed384a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 21 deletions

View File

@ -3254,6 +3254,8 @@ class AnnotationLayer {
parent: this, parent: this,
}; };
for (const data of annotations) { for (const data of annotations) {
data.borderStyle ||= AnnotationLayer._defaultBorderStyle;
elementParams.data = data; elementParams.data = data;
const element = AnnotationElementFactory.create(elementParams); const element = AnnotationElementFactory.create(elementParams);
@ -3329,6 +3331,24 @@ class AnnotationLayer {
getEditableAnnotation(id) { getEditableAnnotation(id) {
return this.#editableAnnotations.get(id); return this.#editableAnnotations.get(id);
} }
/**
* @private
*/
static get _defaultBorderStyle() {
return shadow(
this,
"_defaultBorderStyle",
Object.freeze({
width: 1,
rawWidth: 1,
style: AnnotationBorderStyleType.SOLID,
dashArray: [3],
horizontalCornerRadius: 0,
verticalCornerRadius: 0,
})
);
}
} }
export { export {

View File

@ -24,7 +24,6 @@
import { import {
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,
AnnotationMode, AnnotationMode,
@ -92,7 +91,6 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING || GENERIC")) {
export { export {
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer, AnnotationEditorLayer,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,

View File

@ -15,7 +15,6 @@
import { import {
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,
AnnotationMode, AnnotationMode,
@ -69,7 +68,6 @@ import { XfaLayer } from "../../src/display/xfa_layer.js";
const expectedAPI = Object.freeze({ const expectedAPI = Object.freeze({
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer, AnnotationEditorLayer,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,

View File

@ -13,12 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { AnnotationType, createValidAbsoluteUrl, Util } from "pdfjs-lib";
AnnotationBorderStyleType,
AnnotationType,
createValidAbsoluteUrl,
Util,
} from "pdfjs-lib";
import { getOriginalIndex, normalize } from "./pdf_find_controller.js"; import { getOriginalIndex, normalize } from "./pdf_find_controller.js";
function DOMRectToPDF({ width, height, left, top }, pdfPageView) { function DOMRectToPDF({ width, height, left, top }, pdfPageView) {
@ -89,15 +84,9 @@ function createLinkAnnotation({ url, index, length }, pdfPageView, id) {
annotationType: AnnotationType.LINK, annotationType: AnnotationType.LINK,
rotation: 0, rotation: 0,
...calculateLinkPosition(range, pdfPageView), ...calculateLinkPosition(range, pdfPageView),
// This is just the default for AnnotationBorderStyle. // Populated in the annotationLayer to avoid unnecessary object creation,
borderStyle: { // since most inferred links overlap existing LinkAnnotations:
width: 1, borderStyle: null,
rawWidth: 1,
style: AnnotationBorderStyleType.SOLID,
dashArray: [3],
horizontalCornerRadius: 0,
verticalCornerRadius: 0,
},
}; };
} }

View File

@ -15,7 +15,6 @@
const { const {
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer, AnnotationEditorLayer,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,
@ -65,7 +64,6 @@ const {
export { export {
AbortException, AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer, AnnotationEditorLayer,
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,