Work-around for HighlightAnnotations without a top-level /ExtGState-entry (issue 13242)

For HighlightAnnotations with a built-in appearance stream, we still rely on it to specify the opacity correctly via a suitable blend mode. However, if the Annotation-drawing operators are placed *within* a /XObject of the /Form-type, the /ExtGState won't apply to the final rendering and the result is that the highlighting obscures the underlying text.

The more *correct* and general solution would likely be to somehow modify the implementation in `src/display/canvas.js`, to special-case handling of /Form-type /XObjects when rendering Annotations. Since we can very easily work-around this problem for now by using the "no appearance stream" code-path, doing *something* here ought to be preferable.

This patch is (obviously) merely a work-around, but given that the referenced issue is (as far as I know) the first case we've seen of this problem a simple solution will hopefully suffice for now.
This commit is contained in:
Jonas Jenwald 2021-05-28 13:30:18 +02:00
parent e499521b78
commit 707a9e3b02
4 changed files with 19 additions and 1 deletions

View File

@ -2676,7 +2676,17 @@ class HighlightAnnotation extends MarkupAnnotation {
null
));
if (quadPoints) {
if (!this.appearance) {
const resources =
this.appearance && this.appearance.dict.get("Resources");
if (!this.appearance || !(resources && resources.has("ExtGState"))) {
if (this.appearance) {
// Workaround for cases where there's no /ExtGState-entry directly
// available, e.g. when the appearance stream contains a /XObject of
// the /Form-type, since that causes the highlighting to completely
// obsure the PDF content below it (fixes issue13242.pdf).
warn("HighlightAnnotation - ignoring built-in appearance stream.");
}
// Default color is yellow in Acrobat Reader
const fillColor = this.color
? Array.from(this.color).map(c => c / 255)

View File

@ -254,6 +254,7 @@
!find_all.pdf
!helloworld-bad.pdf
!zerowidthline.pdf
!issue13242.pdf
!js-colors.pdf
!annotation-line-without-appearance-empty-Rect.pdf
!issue12841_reduced.pdf

BIN
test/pdfs/issue13242.pdf Normal file

Binary file not shown.

View File

@ -2324,6 +2324,13 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "issue13242",
"file": "pdfs/issue13242.pdf",
"md5": "ceb2da908c972087eb90e6bae240bce9",
"rounds": 1,
"type": "eq",
"annotations": true
},
{ "id": "issue7229",
"file": "pdfs/issue7229.pdf",
"md5": "480e51aae0ac271780e4603d1561d15e",