Skip to content

Commit ded3af8

Browse files
committed
use strikethrough position for middle`
1 parent 2b5e1f3 commit ded3af8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/CanvasRenderingContext2d.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,11 +2403,16 @@ NAN_METHOD(Context2d::StrokeText) {
24032403
inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
24042404
PangoRectangle logical_rect;
24052405
PangoLayout* measureLayout = pango_layout_copy(layout);
2406+
PangoFontMetrics *metrics;
24062407
pango_layout_set_text(measureLayout, "gjĮ測試ÅÊ", -1);
24072408
pango_layout_line_get_extents(pango_layout_get_line(measureLayout, 0), NULL, &logical_rect);
2409+
metrics = PANGO_LAYOUT_GET_METRICS(measureLayout);
2410+
int strike_thickness = pango_font_metrics_get_strikethrough_thickness(metrics);
2411+
int strike_position = pango_font_metrics_get_strikethrough_position(metrics);
24082412
double scale = 1.0 / PANGO_SCALE;
24092413
double ascent = scale * pango_layout_get_baseline(measureLayout);
24102414
double descent = scale * logical_rect.height - ascent;
2415+
double middle = ascent - (scale * strike_position) + (scale * strike_thickness / 2);
24112416
// 0.072 is a constant that has been chosen comparing the canvas output
24122417
// if some code change, this constant can be changed too to keep results aligned
24132418
double correction_factor = scale * logical_rect.height * 0.072;

0 commit comments

Comments
 (0)