summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2022-01-18 08:19:25 +0100
committerThomas Holder <thomas@thomas-holder.de>2022-01-18 08:19:25 +0100
commite6343ede2f0b9d9663fd25c8fc156cd03a033fdf (patch)
treec15656c263856e8110c489025af73a2537731e6e
parent98e4cce3a1041d17148547bd75ecd617bcbe5916 (diff)
Surface device scale convenience overloads
-rw-r--r--cairomm/surface.cc7
-rw-r--r--cairomm/surface.h12
-rw-r--r--tests/test-surface.cc5
3 files changed, 24 insertions, 0 deletions
diff --git a/cairomm/surface.cc b/cairomm/surface.cc
index 8e7d076..9982625 100644
--- a/cairomm/surface.cc
+++ b/cairomm/surface.cc
@@ -173,6 +173,13 @@ void Surface::get_device_scale(double& x_scale, double& y_scale) const
cairo_surface_get_device_scale(const_cast<cobject*>(cobj()), &x_scale, &y_scale);
}
+double Surface::get_device_scale() const
+{
+ double x_scale = 1, y_scale = 1;
+ get_device_scale(x_scale, y_scale);
+ return (x_scale + y_scale) / 2;
+}
+
void Surface::set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch)
{
cairo_surface_set_fallback_resolution(cobj(), x_pixels_per_inch, y_pixels_per_inch);
diff --git a/cairomm/surface.h b/cairomm/surface.h
index 5d5d5dc..65d7cea 100644
--- a/cairomm/surface.h
+++ b/cairomm/surface.h
@@ -446,10 +446,22 @@ public:
*/
void set_device_scale(double x_scale, double y_scale);
+ /** Sets x and y scale to the same value.
+ * See set_device_scale(double, double) for details.
+ *
+ * @param scale a scale factor in the X and Y direction
+ */
+ inline void set_device_scale(double scale) { set_device_scale(scale, scale); }
+
/** Returns a previous device scale set by set_device_scale().
*/
void get_device_scale(double& x_scale, double& y_scale) const;
+ /** Returns the x and y average of a previous device scale set by
+ * set_device_scale().
+ */
+ double get_device_scale() const;
+
/**
* Set the horizontal and vertical resolution for image fallbacks.
*
diff --git a/tests/test-surface.cc b/tests/test-surface.cc
index fa78048..152787c 100644
--- a/tests/test-surface.cc
+++ b/tests/test-surface.cc
@@ -98,6 +98,11 @@ BOOST_AUTO_TEST_CASE(test_device_scale)
surface->get_device_scale(x, y);
BOOST_CHECK_EQUAL(x, new_x);
BOOST_CHECK_EQUAL(y, new_y);
+ // average x/y scaling
+ BOOST_CHECK_EQUAL(4.0, surface->get_device_scale());
+ // uniform scaling
+ surface->set_device_scale(2);
+ BOOST_CHECK_EQUAL(2.0, surface->get_device_scale());
}
BOOST_AUTO_TEST_CASE(test_fallback_resolution)