summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-11-14 00:09:43 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-11-13 23:38:37 +0100
commit7b8f630db30ee0066a9f4b6e540368d2fcad7fa8 (patch)
treee40626d45db8a228defeca6e66aba9055974d0a6 /libreofficekit
parent44f20abf66ce3f9806ad95522d7d9ae698350499 (diff)
Use o3tl::convert
Change-Id: I78db3001d602ec1a0847785b3c127b9d345f5af7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125173 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx28
-rw-r--r--libreofficekit/source/gtk/tilebuffer.cxx7
-rw-r--r--libreofficekit/source/gtk/tilebuffer.hxx2
3 files changed, 13 insertions, 24 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
index a67d3427eae5..4d889645b2fc 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
@@ -20,6 +20,8 @@
#include "gtv-lok-dialog.hxx"
#include <com/sun/star/awt/Key.hpp>
+
+#include <o3tl/unit_conversion.hxx>
#include <vcl/event.hxx>
namespace {
@@ -83,20 +85,6 @@ getPrivate(GtvLokDialog* dialog)
return static_cast<GtvLokDialogPrivate*>(gtv_lok_dialog_get_instance_private(dialog));
}
-static float
-pixelToTwip(float fInput)
-{
- return (fInput / 96 / 1.0 /* zoom */) * 1440.0f;
-}
-
-#if 0
-static float
-twipToPixel(float fInput)
-{
- return fInput / 1440.0f * 96 * 1.0 /* zoom */;
-}
-#endif
-
static void
gtv_lok_dialog_draw(GtkWidget* pDialogDrawingArea, cairo_t* pCairo, gpointer)
{
@@ -235,8 +223,8 @@ gtv_lok_dialog_signal_motion(GtkWidget* pDialogDrawingArea, GdkEventButton* pEve
g_info("lok_dialog_signal_motion: %d, %d (in twips: %d, %d)",
static_cast<int>(pEvent->x), static_cast<int>(pEvent->y),
- static_cast<int>(pixelToTwip(pEvent->x)),
- static_cast<int>(pixelToTwip(pEvent->y)));
+ static_cast<int>(o3tl::toTwips(pEvent->x, o3tl::Length::px)),
+ static_cast<int>(o3tl::toTwips(pEvent->y, o3tl::Length::px)));
pDocument->pClass->postWindowMouseEvent(pDocument,
priv->dialogid,
@@ -531,8 +519,8 @@ gtv_lok_dialog_floating_win_signal_button(GtkWidget* /*pDialogChildDrawingArea*/
g_info("lok_dialog_floating_win_signal_button (type: %s): %d, %d (in twips: %d, %d)",
aEventType.c_str(),
static_cast<int>(pEvent->x), static_cast<int>(pEvent->y),
- static_cast<int>(pixelToTwip(pEvent->x)),
- static_cast<int>(pixelToTwip(pEvent->y)));
+ static_cast<int>(o3tl::toTwips(pEvent->x, o3tl::Length::px)),
+ static_cast<int>(o3tl::toTwips(pEvent->y, o3tl::Length::px)));
switch (pEvent->type)
{
@@ -614,8 +602,8 @@ gtv_lok_dialog_floating_win_signal_motion(GtkWidget* /*pDialogDrawingArea*/, Gdk
g_info("lok_dialog_floating_win_signal_motion: %d, %d (in twips: %d, %d)",
static_cast<int>(pEvent->x), static_cast<int>(pEvent->y),
- static_cast<int>(pixelToTwip(pEvent->x)),
- static_cast<int>(pixelToTwip(pEvent->y)));
+ static_cast<int>(o3tl::toTwips(pEvent->x, o3tl::Length::px)),
+ static_cast<int>(o3tl::toTwips(pEvent->y, o3tl::Length::px)));
pDocument->pClass->postWindowMouseEvent(pDocument,
priv->m_nChildId,
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 6836031661bc..3c73c9dddf83 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -9,19 +9,22 @@
#include "tilebuffer.hxx"
+#include <o3tl/unit_conversion.hxx>
+
/* ------------------
Utility functions
------------------
*/
+// We know that VirtualDevices use a DPI of 96.
float pixelToTwip(float fInput, float zoom)
{
- return (fInput / DPI / zoom) * 1440.0f;
+ return o3tl::toTwips(fInput / zoom, o3tl::Length::px);
}
float twipToPixel(float fInput, float zoom)
{
- return fInput / 1440.0f * DPI * zoom;
+ return o3tl::convert(fInput * zoom, o3tl::Length::twip, o3tl::Length::px);
}
/* ----------------------------
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 79fa48c555db..239482e34625 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -18,8 +18,6 @@
#define LOK_TILEBUFFER_ERROR (LOKTileBufferErrorQuark())
-// We know that VirtualDevices use a DPI of 96.
-const int DPI = 96;
// Lets use a square of side 256 pixels for each tile.
const int nTileSizePixels = 256;