Skip to content

Commit

Permalink
Merge pull request #19461 from Snuffleupagus/autolinking-lazy-borderS…
Browse files Browse the repository at this point in the history
…tyle

Create the `borderStyle` of inferred links lazily (PR 19110 follow-up)
  • Loading branch information
Snuffleupagus authored Feb 10, 2025
2 parents de1c214 + fba5f3c commit 29fbed3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
20 changes: 20 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,8 @@ class AnnotationLayer {
parent: this,
};
for (const data of annotations) {
data.borderStyle ||= AnnotationLayer._defaultBorderStyle;

elementParams.data = data;
const element = AnnotationElementFactory.create(elementParams);

Expand Down Expand Up @@ -3329,6 +3331,24 @@ class AnnotationLayer {
getEditableAnnotation(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 {
Expand Down
2 changes: 0 additions & 2 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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

export {
AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer,
AnnotationEditorParamsType,
AnnotationEditorType,
Expand Down
2 changes: 0 additions & 2 deletions test/unit/pdf_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import {
AbortException,
AnnotationBorderStyleType,
AnnotationEditorParamsType,
AnnotationEditorType,
AnnotationMode,
Expand Down Expand Up @@ -69,7 +68,6 @@ import { XfaLayer } from "../../src/display/xfa_layer.js";

const expectedAPI = Object.freeze({
AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer,
AnnotationEditorParamsType,
AnnotationEditorType,
Expand Down
19 changes: 4 additions & 15 deletions web/autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
* limitations under the License.
*/

import {
AnnotationBorderStyleType,
AnnotationType,
createValidAbsoluteUrl,
Util,
} from "pdfjs-lib";
import { AnnotationType, createValidAbsoluteUrl, Util } from "pdfjs-lib";
import { getOriginalIndex, normalize } from "./pdf_find_controller.js";

function DOMRectToPDF({ width, height, left, top }, pdfPageView) {
Expand Down Expand Up @@ -89,15 +84,9 @@ function createLinkAnnotation({ url, index, length }, pdfPageView, id) {
annotationType: AnnotationType.LINK,
rotation: 0,
...calculateLinkPosition(range, pdfPageView),
// This is just the default for AnnotationBorderStyle.
borderStyle: {
width: 1,
rawWidth: 1,
style: AnnotationBorderStyleType.SOLID,
dashArray: [3],
horizontalCornerRadius: 0,
verticalCornerRadius: 0,
},
// Populated in the annotationLayer to avoid unnecessary object creation,
// since most inferred links overlap existing LinkAnnotations:
borderStyle: null,
};
}

Expand Down
2 changes: 0 additions & 2 deletions web/pdfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

const {
AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer,
AnnotationEditorParamsType,
AnnotationEditorType,
Expand Down Expand Up @@ -65,7 +64,6 @@ const {

export {
AbortException,
AnnotationBorderStyleType,
AnnotationEditorLayer,
AnnotationEditorParamsType,
AnnotationEditorType,
Expand Down

0 comments on commit 29fbed3

Please sign in to comment.