Fix calculation of TextAnnotation size

... so that select/move rectangle fits exactly around icons
regardless of PDF page size and DPI settings
This commit is contained in:
Tobias Deiminger 2021-03-20 21:56:46 +01:00 committed by Oliver Sander
parent ad6426be52
commit 6fe14f381e
2 changed files with 10 additions and 12 deletions

View file

@ -39,6 +39,7 @@
#include "core/document.h"
#include "core/page.h"
#include "core/signatureutils.h"
#include "core/utils.h"
#include "editannottooldialog.h"
#include "gui/debug_ui.h"
#include "gui/guiutils.h"
@ -224,12 +225,14 @@ public:
ann = ta;
ta->setTextType(Okular::TextAnnotation::Linked);
ta->setTextIcon(iconName);
// ta->window.flags &= ~(Okular::Annotation::Hidden);
const double iconhei = 0.03;
// Calculate annotation width so that icon will be 1/3 inch (i.e., 24 pts) on screen.
// This is required so that painted rectangles match around icons rendered by Poppler.
// Poppler enforces 24x24 pts for embedded appearance icons regardless of what we set here.
double iconWidth = Okular::Utils::realDpi(nullptr).width() / (3. * pagewidth);
rect.left = point.x;
rect.top = point.y;
rect.right = rect.left + iconhei;
rect.bottom = rect.top + iconhei * xscale / yscale;
rect.right = rect.left + iconWidth;
rect.bottom = rect.top + iconWidth * xscale / yscale;
ta->window().setSummary(i18n("Pop-up Note"));
}
// create StampAnnotation from path

View file

@ -236,14 +236,9 @@ void MouseAnnotation::routePaint(QPainter *painter, const QRect paintRect)
if (!isFocused()) {
return;
}
/*
* Get annotation bounding rectangle in uncropped page coordinates.
* Distinction between AnnotationUtils::annotationGeometry() and AnnotationObjectRect::boundingRect() is,
* that boundingRect would enlarge the QRect to a minimum size of 14 x 14.
* This is useful for getting focus an a very small annotation,
* but for drawing and modification we want the real size.
*/
const QRect boundingRect = Okular::AnnotationUtils::annotationGeometry(m_focusedAnnotation.annotation, m_focusedAnnotation.pageViewItem->uncroppedWidth(), m_focusedAnnotation.pageViewItem->uncroppedHeight());
/* Get annotation bounding rectangle in uncropped page coordinates */
const QRect boundingRect = m_focusedAnnotation.annotation->transformedBoundingRectangle().geometry(m_focusedAnnotation.pageViewItem->uncroppedWidth(), m_focusedAnnotation.pageViewItem->uncroppedHeight());
if (!paintRect.intersects(boundingRect.translated(m_focusedAnnotation.pageViewItem->uncroppedGeometry().topLeft()).adjusted(-handleSizeHalf, -handleSizeHalf, handleSizeHalf, handleSizeHalf))) {
/* Our selection rectangle is not in a region that needs to be (re-)drawn. */