PDF compliance: Always respect Annot Rect
Submitted by Tobias Deiminger
Assigned to poppler-bugs
To be compliant to ISO 32k, we always have to respect the geometry of Annot /Rect. See . Currently there are cases where poppler draws annotations at another size. Namely this happens when poppler generates appearances at runtime to substitute missing AP entries for AnnotText, AnnotLine, AnnotTextMarkup, AnnotPolygon and AnnotInk (e.g. , ).
For example, you can end up with a popup note drawn as 24 x 24 pts even if Annot Rect says 16 x 16 pts. Poppler does not update Annot Rect, it keeps telling 16 x 16. Therefore the new size is also not reflected in public APIs. So the bug is not only about PDF non-conformance, but it also leaves clients unaware of the actually rendered size .
ISO 32k contains a detailed description about how to fit appearance streams into Annot Rect. See "Algorithm: Appearance streams" from ISO 32000-1:2008, 12.5.5. To sum up: a) make a quadrilateral from AP BBox by applying apperances transformation Matrix, and calculate a temporary transformed AP BBox that encompasses the quadrilateral b) calculate a temporary Matrix A that scales the transformed AP BBox into Annot Rect c) use this Matrix A to draw the appearance
The existing method Gfx::drawAnnot nicely implements this algorithm. We just have to call Gfx::drawAnnot with the original Annot Rect size instead passing other values.
Patches will follow, comments are appreciated in advance.
 https://lists.freedesktop.org/archives/poppler/2018-March/012909.html  https://cgit.freedesktop.org/poppler/poppler/tree/poppler/Annot.cc?h=poppler-0.63.0#n2486  https://cgit.freedesktop.org/poppler/poppler/tree/poppler/Annot.cc?h=poppler-0.63.0#n5890  https://cgit.freedesktop.org/poppler/poppler/tree/poppler/Gfx.cc?h=poppler-0.63.0#n5125  https://bugs.kde.org/show_bug.cgi?id=388458