Compare commits

...

3 Commits

Author SHA1 Message Date
Oliver Sander
8e89c78936 Merge branch 'phabricator-d9615-textannotation-size' into 'master'
Fix calculation of TextAnnotation size

See merge request graphics/okular!412
2024-06-24 17:06:51 +00:00
Pratham Gandhi
e5900f9a4f created global qobject 2024-06-24 10:39:38 +05:30
Tobias Deiminger
6fe14f381e Fix calculation of TextAnnotation size
... so that select/move rectangle fits exactly around icons
regardless of PDF page size and DPI settings
2022-03-15 15:55:45 +01:00
6 changed files with 54 additions and 12 deletions

View File

@ -487,6 +487,7 @@ if (TARGET Qt6::Qml)
core/script/js_util.cpp
core/script/js_event.cpp
core/script/js_ocg.cpp
core/script/js_global.cpp
)
target_link_libraries(okularcore PRIVATE Qt6::Qml)
endif()

View File

@ -20,6 +20,7 @@
#include "js_event_p.h"
#include "js_field_p.h"
#include "js_fullscreen_p.h"
#include "js_global_p.h"
#include "js_ocg_p.h"
#include "js_spell_p.h"
#include "js_util_p.h"
@ -71,6 +72,7 @@ void ExecutorJSPrivate::initTypes()
m_interpreter.globalObject().setProperty(QStringLiteral("display"), m_interpreter.newQObject(new JSDisplay));
m_interpreter.globalObject().setProperty(QStringLiteral("spell"), m_interpreter.newQObject(new JSSpell));
m_interpreter.globalObject().setProperty(QStringLiteral("util"), m_interpreter.newQObject(new JSUtil));
m_interpreter.globalObject().setProperty(QStringLiteral("global"), m_interpreter.newQObject(new JSGlobal));
}
ExecutorJS::ExecutorJS(DocumentPrivate *doc)

16
core/script/js_global.cpp Normal file
View File

@ -0,0 +1,16 @@
/*
SPDX-FileCopyrightText: 2024 Pratham Gandhi <ppg.1382@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "js_global_p.h"
using namespace Okular;
JSGlobal::JSGlobal(QObject *parent)
: QObject(parent)
{
}
JSGlobal::~JSGlobal() = default;

25
core/script/js_global_p.h Normal file
View File

@ -0,0 +1,25 @@
/*
SPDX-FileCopyrightText: 2024 Pratham Gandhi <ppg.1382@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef OKULAR_SCRIPT_JS_GLOBAL_P_H
#define OKULAR_SCRIPT_JS_GLOBAL_P_H
#include <QObject>
namespace Okular
{
class JSGlobal : public QObject
{
Q_OBJECT
public:
explicit JSGlobal(QObject *parent = nullptr);
~JSGlobal() override;
};
}
#endif

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. */