From 37ebea4d3b2c8b4d131ee6c344e274498bbbfbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yao=20Wei=20=28=E9=AD=8F=E9=8A=98=E5=BB=B7=29?= Date: Sat, 19 Jun 2021 20:53:24 +0800 Subject: [PATCH] use en_US to decide metrics --- src/render/context.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/render/context.rs b/src/render/context.rs index f5231d63..b708c202 100644 --- a/src/render/context.rs +++ b/src/render/context.rs @@ -87,7 +87,9 @@ struct FontMetrix { impl FontMetrix { pub fn new(pango_context: pango::Context, line_space: i32) -> Self { - let font_metrics = pango_context.metrics(None, None).unwrap(); + let font_metrics = pango_context + .metrics(None, Some(&pango::Language::from_string("en_US"))) + .unwrap(); let font_desc = pango_context.font_description().unwrap(); FontMetrix { @@ -128,9 +130,8 @@ impl CellMetrics { let strikethrough_position = (f64::from(font_metrics.strikethrough_position()) / f64::from(pango::SCALE)).ceil(); - let strikethrough_thickness = (f64::from(font_metrics.strikethrough_thickness()) - / f64::from(pango::SCALE)) - .ceil(); + let strikethrough_thickness = + (f64::from(font_metrics.strikethrough_thickness()) / f64::from(pango::SCALE)).ceil(); CellMetrics { pango_ascent: font_metrics.ascent(), @@ -138,8 +139,7 @@ impl CellMetrics { pango_char_width: font_metrics.approximate_char_width(), ascent, line_height: ascent + descent + f64::from(line_space), - char_width: f64::from(font_metrics.approximate_char_width()) - / f64::from(pango::SCALE), + char_width: f64::from(font_metrics.approximate_char_width()) / f64::from(pango::SCALE), underline_position: ascent - underline_position + underline_thickness / 2.0, underline_thickness, strikethrough_position: ascent - strikethrough_position + strikethrough_thickness / 2.0,