Skip to content

Commit

Permalink
Minimal backport of #985 (rotated text baselines)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Sep 7, 2017
1 parent 615f80e commit c19edb8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/CanvasRenderingContext2d.cc
Expand Up @@ -1794,18 +1794,20 @@ Context2d::setTextPath(const char *str, double x, double y) {
break;
}

double yScale = sqrt(matrix.yx * matrix.yx + matrix.yy * matrix.yy);

switch (state->textBaseline) {
case TEXT_BASELINE_ALPHABETIC:
metrics = PANGO_LAYOUT_GET_METRICS(_layout);
y -= (pango_font_metrics_get_ascent(metrics) / PANGO_SCALE) * matrix.yy;
y -= (pango_font_metrics_get_ascent(metrics) / PANGO_SCALE) * yScale;
break;
case TEXT_BASELINE_MIDDLE:
metrics = PANGO_LAYOUT_GET_METRICS(_layout);
y -= ((pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics))/(2.0 * PANGO_SCALE)) * matrix.yy;
y -= ((pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics))/(2.0 * PANGO_SCALE)) * yScale;
break;
case TEXT_BASELINE_BOTTOM:
metrics = PANGO_LAYOUT_GET_METRICS(_layout);
y -= ((pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics)) / PANGO_SCALE) * matrix.yy;
y -= ((pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics)) / PANGO_SCALE) * yScale;
break;
}

Expand Down

0 comments on commit c19edb8

Please sign in to comment.