tdf#96513: Limit LOKDocView's zoom in [0.25, 5.0]

Change-Id: Ibee485909dca1ea4a3774fca7a840afbf2d9883c
Reviewed-on: https://gerrit.libreoffice.org/20819
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: David Tardon <dtardon@redhat.com>
This commit is contained in:
Pranav Kant
2015-12-19 20:36:47 +05:30
committed by David Tardon
parent 4200a678fb
commit ba539fa91f
2 changed files with 30 additions and 3 deletions

View File

@@ -107,7 +107,9 @@ LibreOfficeKitDocument* lok_doc_view_get_document (LOKDocView*
* @pDocView: The #LOKDocView instance
* @fZoom: The new zoom level that pDocView must set it into.
*
* Sets the new zoom level for the widget.
* Sets the new zoom level for the widget. Does nothing if fZoom is equal to
* existing zoom level. Values outside the range [0.25, 5.0] are clamped into
* the nearest allowed value in the interval.
*/
void lok_doc_view_set_zoom (LOKDocView* pDocView,
float fZoom);

View File

@@ -38,6 +38,10 @@
#define CURSOR_HANDLE_DIR "/android/source/res/drawable/"
// Number of handles around a graphic selection.
#define GRAPHIC_HANDLE_COUNT 8
// Maximum Zoom allowed
#define MAX_ZOOM 5.0f
// Minimum Zoom allowed
#define MIN_ZOOM 0.25f
/// Private struct used by this GObject type
struct LOKDocViewPrivateImpl
@@ -124,8 +128,8 @@ struct LOKDocViewPrivateImpl
m_aDocPath(nullptr),
m_nLoadProgress(0),
m_bIsLoading(false),
m_bCanZoomIn(false),
m_bCanZoomOut(false),
m_bCanZoomIn(true),
m_bCanZoomOut(true),
m_pOffice(nullptr),
m_pDocument(nullptr),
lokThreadPool(nullptr),
@@ -2475,6 +2479,13 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
LOKDocViewPrivate& priv = getPrivate(pDocView);
GError* error = nullptr;
// Clamp the input value in [MIN_ZOOM, MAX_ZOOM]
fZoom = fZoom < MIN_ZOOM ? MIN_ZOOM : fZoom;
fZoom = fZoom > MAX_ZOOM ? MAX_ZOOM : fZoom;
if (fZoom == priv->m_fZoom)
return;
priv->m_fZoom = fZoom;
long nDocumentWidthPixels = twipToPixel(priv->m_nDocumentWidthTwips, fZoom);
long nDocumentHeightPixels = twipToPixel(priv->m_nDocumentHeightTwips, fZoom);
@@ -2489,6 +2500,20 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_ZOOM]);
// set properties to indicate if view can be further zoomed in/out
bool bCanZoomIn = priv->m_fZoom < MAX_ZOOM;
bool bCanZoomOut = priv->m_fZoom > MIN_ZOOM;
if (bCanZoomIn != priv->m_bCanZoomIn)
{
priv->m_bCanZoomIn = bCanZoomIn;
g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_IN]);
}
if (bCanZoomOut != priv->m_bCanZoomOut)
{
priv->m_bCanZoomOut = bCanZoomOut;
g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_OUT]);
}
// Update the client's view size
GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr);
LOEvent* pLOEvent = new LOEvent(LOK_SET_CLIENT_ZOOM);