diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index b9b4efbd2fc69..b48fce42217ec 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -692,3 +692,4 @@ !issue19182.pdf !issue18911.pdf !issue19207.pdf +!link.pdf \ No newline at end of file diff --git a/test/pdfs/link.pdf b/test/pdfs/link.pdf new file mode 100644 index 0000000000000..54e80411fad1f Binary files /dev/null and b/test/pdfs/link.pdf differ diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 8c4653ad6e990..82c9515b00b22 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -121,10 +121,15 @@ class AnnotationLayerBuilder { const uniqueLinks = linkAnnotations.filter(link => { for (const annotation of annotations) { + function area(rect) { + return Math.abs(rect[2] - rect[0]) * Math.abs(rect[3] - rect[1]); + } + const intersect = Util.intersect(annotation.rect, link.rect); // Find the intersection between the annotation and the link. if ( annotation.subtype === "Link" && annotation.url === link.url && - Util.intersect(annotation.rect, link.rect) !== null + intersect !== null && + area(intersect) / area(link.rect) > 0.5 // If the overlap is more than 50%. ) { return false; } diff --git a/web/autolinker.js b/web/autolinker.js index 3906129aeab78..fc643c4029779 100644 --- a/web/autolinker.js +++ b/web/autolinker.js @@ -3,7 +3,7 @@ import { getOriginalIndex, normalize } from "./pdf_find_controller.js"; class Autolinker { static #urlRegex = - /\b(?:https?:\/\/|mailto:|www.)(?:[[\S--\[]--\p{P}]|\/|[\p{P}--\[]+[[\S--\[]--\p{P}])+/gmv; + /\b(?:https?:\/\/|mailto:|www.)(?:[[\S--\[]--\p{P}]|\/|[\p{P}--\[]+[[\S--\[]--\p{P}])+/gmv; // Regex can be tested and verified at https://regex101.com/r/zuMeQX/3. static #addLinkAnnotations(url, index, length, pdfPageView) { // TODO refactor out the logic for a single match from this function