Skip to content

Commit

Permalink
CairoHelper: fix scale
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jun 11, 2024
1 parent 00ef270 commit 84ea912
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Helpers/CairoHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions Helpers/CairoHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 84ea912

Please sign in to comment.