Blame SOURCES/0015-lokdocview-move-commonly-used-functions-and-variable.patch

135360
From b4886f6f3f809212c97fb93cb7e7e7375b5f188a Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Thu, 4 Jun 2015 13:56:46 +0530
135360
Subject: [PATCH 015/398] lokdocview: move commonly used functions and
135360
 variables to common header
135360
135360
twipToPixel and pixelToTwip are also being used by the new TileBuffer
135360
clsas. Lets move these utility functions to a common header,
135360
tilebuffer.hxx
135360
135360
The variables for DPI and tileSize are also moved to tilebuffer.hxx
135360
135360
Change-Id: I9d0bec7f2aefe412df232040a7a9abc6db3e4ccb
135360
(cherry picked from commit a5d3efa4a02bed357d43960913a7c946c8b12aff)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 125 +++++++++++++------------------
135360
 libreofficekit/source/gtk/tilebuffer.cxx |   6 +-
135360
 libreofficekit/source/gtk/tilebuffer.hxx |   9 +++
135360
 3 files changed, 65 insertions(+), 75 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 3b894f765faa..bfb414f0909c 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -37,11 +37,6 @@
135360
 // Number of handles around a graphic selection.
135360
 #define GRAPHIC_HANDLE_COUNT 8
135360
 
135360
-// We know that VirtualDevices use a DPI of 96.
135360
-static const int DPI = 96;
135360
-// Lets use a square of side 256 pixels.
135360
-static const int nTileSizePixels = 256;
135360
-
135360
 namespace {
135360
 
135360
 /// Sets rWidth and rHeight from a "width, height" string.
135360
@@ -145,10 +140,6 @@ struct LOKDocView_Impl
135360
     static void destroy(LOKDocView* pDocView, gpointer pData);
135360
     /// Connected to the expose-event of the GtkDrawingArea
135360
     static void on_exposed(GtkWidget *widget, GdkEvent *event, gpointer user_data);
135360
-    /// Converts from screen pixels to document coordinates.
135360
-    float pixelToTwip(float fInput);
135360
-    /// Converts from document coordinates to screen pixels.
135360
-    float twipToPixel(float fInput);
135360
     /// Receives a key press or release event.
135360
     void signalKey(GdkEventKey* pEvent);
135360
     /**
135360
@@ -316,16 +307,6 @@ void LOKDocView_Impl::on_exposed(GtkWidget* /*widget*/, GdkEvent* /*event*/, gpo
135360
     pDocView->m_pImpl->renderDocument(0);
135360
 }
135360
 
135360
-float LOKDocView_Impl::pixelToTwip(float fInput)
135360
-{
135360
-    return (fInput / DPI / m_fZoom) * 1440.0f;
135360
-}
135360
-
135360
-float LOKDocView_Impl::twipToPixel(float fInput)
135360
-{
135360
-    return fInput / 1440.0f * DPI * m_fZoom;
135360
-}
135360
-
135360
 void LOKDocView_Impl::signalKey(GdkEventKey* pEvent)
135360
 {
135360
     int nCharCode = 0;
135360
@@ -390,7 +371,7 @@ gboolean LOKDocView_Impl::signalButton(GtkWidget* /*pEventBox*/, GdkEventButton*
135360
 /// Receives a button press event.
135360
 gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
 {
135360
-    g_info("LOKDocView_Impl::signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x), (int)pixelToTwip(pEvent->y));
135360
+    g_info("LOKDocView_Impl::signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x, m_fZoom), (int)pixelToTwip(pEvent->y, m_fZoom));
135360
 
135360
     if (pEvent->type == GDK_BUTTON_RELEASE)
135360
     {
135360
@@ -419,7 +400,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
             {
135360
                 g_info("LOKDocView_Impl::signalButton: end of drag graphic handle #%d", i);
135360
                 m_bInDragGraphicHandles[i] = false;
135360
-                m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
135360
+                m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
135360
                 return FALSE;
135360
             }
135360
         }
135360
@@ -428,7 +409,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
         {
135360
             g_info("LOKDocView_Impl::signalButton: end of drag graphic selection");
135360
             m_bInDragGraphicSelection = false;
135360
-            m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
135360
+            m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
135360
             return FALSE;
135360
         }
135360
     }
135360
@@ -469,8 +450,8 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
                     m_bInDragGraphicHandles[i] = true;
135360
                     m_pDocument->pClass->setGraphicSelection(m_pDocument,
135360
                                                              LOK_SETGRAPHICSELECTION_START,
135360
-                                                             pixelToTwip(m_aGraphicHandleRects[i].x + m_aGraphicHandleRects[i].width / 2),
135360
-                                                             pixelToTwip(m_aGraphicHandleRects[i].y + m_aGraphicHandleRects[i].height / 2));
135360
+                                                             pixelToTwip(m_aGraphicHandleRects[i].x + m_aGraphicHandleRects[i].width / 2, m_fZoom),
135360
+                                                             pixelToTwip(m_aGraphicHandleRects[i].y + m_aGraphicHandleRects[i].height / 2, m_fZoom));
135360
                     return FALSE;
135360
                 }
135360
             }
135360
@@ -488,7 +469,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
         if ((pEvent->time - m_nLastButtonPressTime) < 250)
135360
             nCount++;
135360
         m_nLastButtonPressTime = pEvent->time;
135360
-        m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount);
135360
+        m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), nCount);
135360
         break;
135360
     }
135360
     case GDK_BUTTON_RELEASE:
135360
@@ -497,7 +478,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
135360
         if ((pEvent->time - m_nLastButtonReleaseTime) < 250)
135360
             nCount++;
135360
         m_nLastButtonReleaseTime = pEvent->time;
135360
-        m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount);
135360
+        m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), nCount);
135360
         break;
135360
     }
135360
     default:
135360
@@ -534,21 +515,21 @@ gboolean LOKDocView_Impl::signalMotionImpl(GdkEventButton* pEvent)
135360
     {
135360
         g_info("lcl_signalMotion: dragging the middle handle");
135360
         LOKDocView_Impl::getDragPoint(&m_aHandleMiddleRect, pEvent, &aPoint);
135360
-        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_RESET, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
135360
+        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_RESET, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
135360
         return FALSE;
135360
     }
135360
     if (m_bInDragStartHandle)
135360
     {
135360
         g_info("lcl_signalMotion: dragging the start handle");
135360
         LOKDocView_Impl::getDragPoint(&m_aHandleStartRect, pEvent, &aPoint);
135360
-        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_START, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
135360
+        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_START, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
135360
         return FALSE;
135360
     }
135360
     if (m_bInDragEndHandle)
135360
     {
135360
         g_info("lcl_signalMotion: dragging the end handle");
135360
         LOKDocView_Impl::getDragPoint(&m_aHandleEndRect, pEvent, &aPoint);
135360
-        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
135360
+        m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
135360
         return FALSE;
135360
     }
135360
     for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
135360
@@ -566,20 +547,20 @@ gboolean LOKDocView_Impl::signalMotionImpl(GdkEventButton* pEvent)
135360
     }
135360
 
135360
     GdkRectangle aMotionInTwipsInTwips;
135360
-    aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x);
135360
-    aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y);
135360
+    aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x, m_fZoom);
135360
+    aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y, m_fZoom);
135360
     aMotionInTwipsInTwips.width = 1;
135360
     aMotionInTwipsInTwips.height = 1;
135360
     if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &m_aGraphicSelection, 0))
135360
     {
135360
         g_info("lcl_signalMotion: start of drag graphic selection");
135360
         m_bInDragGraphicSelection = true;
135360
-        m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_START, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
135360
+        m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_START, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
135360
         return FALSE;
135360
     }
135360
 
135360
     // Otherwise a mouse move, as on the desktop.
135360
-    m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEMOVE, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), 1);
135360
+    m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEMOVE, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), 1);
135360
 
135360
     return FALSE;
135360
 }
135360
@@ -602,10 +583,10 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
135360
 
135360
         cairo_set_source_rgb(pCairo, 0, 0, 0);
135360
         cairo_rectangle(pCairo,
135360
-                        twipToPixel(m_aVisibleCursor.x),
135360
-                        twipToPixel(m_aVisibleCursor.y),
135360
-                        twipToPixel(m_aVisibleCursor.width),
135360
-                        twipToPixel(m_aVisibleCursor.height));
135360
+                        twipToPixel(m_aVisibleCursor.x, m_fZoom),
135360
+                        twipToPixel(m_aVisibleCursor.y, m_fZoom),
135360
+                        twipToPixel(m_aVisibleCursor.width, m_fZoom),
135360
+                        twipToPixel(m_aVisibleCursor.height, m_fZoom));
135360
         cairo_fill(pCairo);
135360
     }
135360
 
135360
@@ -624,10 +605,10 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
135360
             // Blue with 75% transparency.
135360
             cairo_set_source_rgba(pCairo, ((double)0x43)/255, ((double)0xac)/255, ((double)0xe8)/255, 0.25);
135360
             cairo_rectangle(pCairo,
135360
-                            twipToPixel(rRectangle.x),
135360
-                            twipToPixel(rRectangle.y),
135360
-                            twipToPixel(rRectangle.width),
135360
-                            twipToPixel(rRectangle.height));
135360
+                            twipToPixel(rRectangle.x, m_fZoom),
135360
+                            twipToPixel(rRectangle.y, m_fZoom),
135360
+                            twipToPixel(rRectangle.width, m_fZoom),
135360
+                            twipToPixel(rRectangle.height, m_fZoom));
135360
             cairo_fill(pCairo);
135360
         }
135360
 
135360
@@ -674,10 +655,10 @@ void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor,
135360
     nHandleWidth = cairo_image_surface_get_width(pHandle);
135360
     nHandleHeight = cairo_image_surface_get_height(pHandle);
135360
     // We want to scale down the handle, so that its height is the same as the cursor caret.
135360
-    fHandleScale = twipToPixel(rCursor.height) / nHandleHeight;
135360
+    fHandleScale = twipToPixel(rCursor.height, m_fZoom) / nHandleHeight;
135360
     // We want the top center of the handle bitmap to be at the bottom center of the cursor rectangle.
135360
-    aCursorBottom.x = twipToPixel(rCursor.x) + twipToPixel(rCursor.width) / 2 - (nHandleWidth * fHandleScale) / 2;
135360
-    aCursorBottom.y = twipToPixel(rCursor.y) + twipToPixel(rCursor.height);
135360
+    aCursorBottom.x = twipToPixel(rCursor.x, m_fZoom) + twipToPixel(rCursor.width, m_fZoom) / 2 - (nHandleWidth * fHandleScale) / 2;
135360
+    aCursorBottom.y = twipToPixel(rCursor.y, m_fZoom) + twipToPixel(rCursor.height, m_fZoom);
135360
     cairo_save(pCairo);
135360
     cairo_translate(pCairo, aCursorBottom.x, aCursorBottom.y);
135360
     cairo_scale(pCairo, fHandleScale, fHandleScale);
135360
@@ -700,10 +681,10 @@ void LOKDocView_Impl::renderGraphicHandle(cairo_t* pCairo, const GdkRectangle& r
135360
     nHandleWidth = cairo_image_surface_get_width(pHandle);
135360
     nHandleHeight = cairo_image_surface_get_height(pHandle);
135360
 
135360
-    aSelection.x = twipToPixel(rSelection.x);
135360
-    aSelection.y = twipToPixel(rSelection.y);
135360
-    aSelection.width = twipToPixel(rSelection.width);
135360
-    aSelection.height = twipToPixel(rSelection.height);
135360
+    aSelection.x = twipToPixel(rSelection.x, m_fZoom);
135360
+    aSelection.y = twipToPixel(rSelection.y, m_fZoom);
135360
+    aSelection.width = twipToPixel(rSelection.width, m_fZoom);
135360
+    aSelection.height = twipToPixel(rSelection.height, m_fZoom);
135360
 
135360
     for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
135360
     {
135360
@@ -781,8 +762,8 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
     GdkRectangle visibleArea;
135360
     lok_docview_get_visarea (m_pDocView, &visibleArea);
135360
 
135360
-    long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips);
135360
-    long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips);
135360
+    long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips, m_fZoom);
135360
+    long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips, m_fZoom);
135360
     // Total number of rows / columns in this document.
135360
     guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
135360
     guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
135360
@@ -809,10 +790,10 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
                 aTileRectanglePixels.height = nTileSizePixels;
135360
 
135360
             // Determine size and position of the tile in document coordinates, so we can decide if we can skip painting for partial rendering.
135360
-            aTileRectangleTwips.x = pixelToTwip(nTileSizePixels) * nColumn;
135360
-            aTileRectangleTwips.y = pixelToTwip(nTileSizePixels) * nRow;
135360
-            aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width);
135360
-            aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height);
135360
+            aTileRectangleTwips.x = pixelToTwip(nTileSizePixels, m_fZoom) * nColumn;
135360
+            aTileRectangleTwips.y = pixelToTwip(nTileSizePixels, m_fZoom) * nRow;
135360
+            aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width, m_fZoom);
135360
+            aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height, m_fZoom);
135360
             if (pPartial && !gdk_rectangle_intersect(pPartial, &aTileRectangleTwips, 0))
135360
                 bPaint = false;
135360
 
135360
@@ -826,7 +807,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
                 Tile& currentTile = m_pTileBuffer->tile_buffer_get_tile(nRow, nColumn);
135360
                 GdkPixbuf* pPixBuf = currentTile.tile_get_buffer();
135360
 
135360
-                gdk_cairo_set_source_pixbuf (pcairo, pPixBuf, twipToPixel(aTileRectangleTwips.x), twipToPixel(aTileRectangleTwips.y));
135360
+                gdk_cairo_set_source_pixbuf (pcairo, pPixBuf, twipToPixel(aTileRectangleTwips.x, m_fZoom), twipToPixel(aTileRectangleTwips.y, m_fZoom));
135360
                 cairo_paint(pcairo);
135360
             }
135360
         }
135360
@@ -935,10 +916,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
135360
         {
135360
             GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
135360
             GdkRectangle aRectanglePixels;
135360
-            aRectanglePixels.x = twipToPixel(aRectangle.x);
135360
-            aRectanglePixels.y = twipToPixel(aRectangle.y);
135360
-            aRectanglePixels.width = twipToPixel(aRectangle.width);
135360
-            aRectanglePixels.height = twipToPixel(aRectangle.height);
135360
+            aRectanglePixels.x = twipToPixel(aRectangle.x, m_fZoom);
135360
+            aRectanglePixels.y = twipToPixel(aRectangle.y, m_fZoom);
135360
+            aRectanglePixels.width = twipToPixel(aRectangle.width, m_fZoom);
135360
+            aRectanglePixels.height = twipToPixel(aRectangle.height, m_fZoom);
135360
             int rowStart = aRectanglePixels.y / nTileSizePixels;
135360
             int colStart = aRectanglePixels.x / nTileSizePixels;
135360
             int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
135360
@@ -963,10 +944,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
135360
         m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
135360
         m_bCursorOverlayVisible = true;
135360
         GdkRectangle aRectanglePixels;
135360
-        aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x);
135360
-        aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y);
135360
-        aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width);
135360
-        aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height);
135360
+        aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x, m_fZoom);
135360
+        aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y, m_fZoom);
135360
+        aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width, m_fZoom);
135360
+        aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height, m_fZoom);
135360
         int rowStart = aRectanglePixels.y / nTileSizePixels;
135360
         int colStart = aRectanglePixels.x / nTileSizePixels;
135360
         int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
135360
@@ -1246,10 +1227,11 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, c
135360
         pDocView->m_pImpl->m_pDocument->pClass->getDocumentSize(pDocView->m_pImpl->m_pDocument, &pDocView->m_pImpl->m_nDocumentWidthTwips, &pDocView->m_pImpl->m_nDocumentHeightTwips);
135360
         g_timeout_add(600, &LOKDocView_Impl::handleTimeout, pDocView);
135360
 
135360
+        float zoom = pDocView->m_pImpl->m_fZoom;
135360
         long nDocumentWidthTwips = pDocView->m_pImpl->m_nDocumentWidthTwips;
135360
         long nDocumentHeightTwips = pDocView->m_pImpl->m_nDocumentHeightTwips;
135360
-        long nDocumentWidthPixels = pDocView->m_pImpl->twipToPixel(nDocumentWidthTwips);
135360
-        long nDocumentHeightPixels = pDocView->m_pImpl->twipToPixel(nDocumentHeightTwips);
135360
+        long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom);
135360
+        long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom);
135360
         // Total number of rows / columns in this document.
135360
         guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
135360
         guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
135360
@@ -1271,8 +1253,8 @@ SAL_DLLPUBLIC_EXPORT LibreOfficeKitDocument* lok_docview_get_document(LOKDocView
135360
 SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZoom )
135360
 {
135360
     pDocView->m_pImpl->m_fZoom = fZoom;
135360
-    long nDocumentWidthPixels = pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_nDocumentWidthTwips);
135360
-    long nDocumentHeightPixels = pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_nDocumentHeightTwips);
135360
+    long nDocumentWidthPixels = twipToPixel(pDocView->m_pImpl->m_nDocumentWidthTwips, fZoom);
135360
+    long nDocumentHeightPixels = twipToPixel(pDocView->m_pImpl->m_nDocumentHeightTwips, fZoom);
135360
     // Total number of rows / columns in this document.
135360
     guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
135360
     guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
135360
@@ -1350,12 +1332,13 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventK
135360
 
135360
 SAL_DLLPUBLIC_EXPORT void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea)
135360
 {
135360
+    float zoom = pThis->m_pImpl->m_fZoom;
135360
     GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pThis));
135360
-    pArea->x = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_value(pHAdjustment));
135360
-    pArea->width = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_page_size(pHAdjustment));
135360
+    pArea->x = pixelToTwip(gtk_adjustment_get_value(pHAdjustment),zoom);
135360
+    pArea->width = pixelToTwip(gtk_adjustment_get_page_size(pHAdjustment), zoom);
135360
     GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pThis));
135360
-    pArea->y = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_value(pVAdjustment));
135360
-    pArea->height = pThis->m_pImpl->pixelToTwip(gtk_adjustment_get_page_size(pVAdjustment));
135360
+    pArea->y = pixelToTwip(gtk_adjustment_get_value(pVAdjustment), zoom);
135360
+    pArea->height = pixelToTwip(gtk_adjustment_get_page_size(pVAdjustment), zoom);
135360
 }
135360
 
135360
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
135360
index e13f5b034c1d..3e5e01f8d686 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.cxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
135360
@@ -9,14 +9,12 @@
135360
 
135360
 #include "tilebuffer.hxx"
135360
 
135360
-static const int DPI = 96;
135360
-
135360
-static float pixelToTwip(float fInput, float zoom)
135360
+float pixelToTwip(float fInput, float zoom)
135360
 {
135360
     return (fInput / DPI / zoom) * 1440.0f;
135360
 }
135360
 
135360
-static float twipToPixel(float fInput, float zoom)
135360
+float twipToPixel(float fInput, float zoom)
135360
 {
135360
     return fInput / 1440.0f * DPI * zoom;
135360
 }
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
135360
index 088df93ca6b6..15b276f238aa 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.hxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
135360
@@ -19,6 +19,15 @@
135360
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
135360
 #include <LibreOfficeKit/LibreOfficeKitGtk.h>
135360
 
135360
+// We know that VirtualDevices use a DPI of 96.
135360
+const int DPI = 96;
135360
+// Lets use a square of side 256 pixels for each tile.
135360
+const int nTileSizePixels = 256;
135360
+
135360
+float pixelToTwip(float fInput, float zoom);
135360
+
135360
+float twipToPixel(float fInput, float zoom);
135360
+
135360
 /*
135360
   This class represents a single tile in the tile buffer.
135360
   TODO: Extend it to support features like double buffering
135360
-- 
135360
2.12.0
135360