diff --git a/Helpers/CairoHelper.cpp b/Helpers/CairoHelper.cpp index 69b0bfc..93536c6 100644 --- a/Helpers/CairoHelper.cpp +++ b/Helpers/CairoHelper.cpp @@ -45,6 +45,17 @@ CairoHelper::applyScale(cairo_t *cr, cairo_scale(cr, scale.x, scale.y); } +void +CairoHelper::applyScale(cairo_t *cr, + const _XY &scale, + const _XY &origin) +{ + if (!cr || (scale.x == 0. && scale.y == 0.)) { return; } + cairo_translate(cr, origin.x, origin.y); + cairo_scale(cr, scale.x, scale.y); + cairo_translate(cr, -origin.x, -origin.y); +} + void CairoHelper::applySkew(cairo_t *cr, const _XY &skew, @@ -83,7 +94,7 @@ CairoHelper::applyTransform(cairo_t *cr, if (!cr) { return; } if (transform.flip) { applyFlip(cr, transform.height); } if (transform.position) { applyPosition(cr, transform.origin); } - applyScale(cr, transform.scale); + applyScale(cr, transform.scale, transform.origin); applySkew(cr, transform.skew, transform.origin); applyRotate(cr, transform.rotate, transform.origin); } diff --git a/Helpers/CairoHelper.h b/Helpers/CairoHelper.h index 9f3e7e7..3e74d6c 100644 --- a/Helpers/CairoHelper.h +++ b/Helpers/CairoHelper.h @@ -49,6 +49,9 @@ class CairoHelper /** @brief apply scale */ static void applyScale(cairo_t *cr, const _XY &scale); + static void applyScale(cairo_t *cr, + const _XY &scale, + const _XY &origin); /** @brief apply skew */ static void applySkew(cairo_t *cr, const _XY &skew,