Skip to content

Commit

Permalink
Support Annotations, without appearance streams, with bogus /Rect-ent…
Browse files Browse the repository at this point in the history
…ries (issue 13447)

This extends PR 13106 to apply not only to empty /Rect-entries, but also to bogus /Rect-entries for various Annotation-types.
  • Loading branch information
Snuffleupagus committed May 27, 2021
1 parent a6447f2 commit 52c1332
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
assert,
escapeString,
getModificationDate,
isArrayEqual,
isAscii,
isString,
OPS,
Expand Down Expand Up @@ -2422,17 +2421,19 @@ class LineAnnotation extends MarkupAnnotation {
}
const fillAlpha = fillColor ? strokeAlpha : null;

const borderWidth = this.borderStyle.width;
const borderWidth = this.borderStyle.width || 1,
borderAdjust = 2 * borderWidth;

// If the /Rect-entry is empty, create a fallback rectangle such that we
// get similar rendering/highlighting behaviour as in Adobe Reader.
if (isArrayEqual(this.rectangle, [0, 0, 0, 0])) {
this.rectangle = [
this.data.lineCoordinates[0] - 2 * borderWidth,
this.data.lineCoordinates[1] - 2 * borderWidth,
this.data.lineCoordinates[2] + 2 * borderWidth,
this.data.lineCoordinates[3] + 2 * borderWidth,
];
// If the /Rect-entry is empty/wrong, create a fallback rectangle so that
// we get similar rendering/highlighting behaviour as in Adobe Reader.
const bbox = [
this.data.lineCoordinates[0] - borderAdjust,
this.data.lineCoordinates[1] - borderAdjust,
this.data.lineCoordinates[2] + borderAdjust,
this.data.lineCoordinates[3] + borderAdjust,
];
if (!Util.intersect(this.rectangle, bbox)) {
this.rectangle = bbox;
}

this._setDefaultAppearance({
Expand Down Expand Up @@ -2603,7 +2604,21 @@ class PolylineAnnotation extends MarkupAnnotation {
: [0, 0, 0];
const strokeAlpha = parameters.dict.get("CA");

const borderWidth = this.borderStyle.width || 1;
const borderWidth = this.borderStyle.width || 1,
borderAdjust = 2 * borderWidth;

// If the /Rect-entry is empty/wrong, create a fallback rectangle so that
// we get similar rendering/highlighting behaviour as in Adobe Reader.
const bbox = [Infinity, Infinity, -Infinity, -Infinity];
for (const vertex of this.data.vertices) {
bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
}
if (!Util.intersect(this.rectangle, bbox)) {
this.rectangle = bbox;
}

this._setDefaultAppearance({
xref: parameters.xref,
Expand Down Expand Up @@ -2675,7 +2690,23 @@ class InkAnnotation extends MarkupAnnotation {
: [0, 0, 0];
const strokeAlpha = parameters.dict.get("CA");

const borderWidth = this.borderStyle.width || 1;
const borderWidth = this.borderStyle.width || 1,
borderAdjust = 2 * borderWidth;

// If the /Rect-entry is empty/wrong, create a fallback rectangle so that
// we get similar rendering/highlighting behaviour as in Adobe Reader.
const bbox = [Infinity, Infinity, -Infinity, -Infinity];
for (const inkLists of this.data.inkLists) {
for (const vertex of inkLists) {
bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
}
}
if (!Util.intersect(this.rectangle, bbox)) {
this.rectangle = bbox;
}

this._setDefaultAppearance({
xref: parameters.xref,
Expand Down

0 comments on commit 52c1332

Please sign in to comment.