diff options
| author | YAMAMOTO Mitsuharu | 2022-09-26 09:57:23 +0900 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2022-09-26 09:57:23 +0900 |
| commit | 9ed03040d5bfb228c8d41f1df44e74a824d0cd44 (patch) | |
| tree | d78886a50ca7af750960a61893cef8f3feb67653 /src | |
| parent | 76b7a593675c95910881b6551b94ddd23f3b1656 (diff) | |
| download | emacs-9ed03040d5bfb228c8d41f1df44e74a824d0cd44.tar.gz emacs-9ed03040d5bfb228c8d41f1df44e74a824d0cd44.zip | |
Make average width computation on ftcr more permissive (Bug#43058)
* src/ftcrfont.c (ftcrfont_open): Use only non-zero width glyphs for
computing average width.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ftcrfont.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/ftcrfont.c b/src/ftcrfont.c index a02ff99870e..dc765e5aee4 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c | |||
| @@ -233,6 +233,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 233 | cairo_glyph_t stack_glyph; | 233 | cairo_glyph_t stack_glyph; |
| 234 | font->min_width = font->max_width = 0; | 234 | font->min_width = font->max_width = 0; |
| 235 | font->average_width = font->space_width = 0; | 235 | font->average_width = font->space_width = 0; |
| 236 | int n = 0; | ||
| 236 | for (char c = 32; c < 127; c++) | 237 | for (char c = 32; c < 127; c++) |
| 237 | { | 238 | { |
| 238 | cairo_glyph_t *glyphs = &stack_glyph; | 239 | cairo_glyph_t *glyphs = &stack_glyph; |
| @@ -252,17 +253,20 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size) | |||
| 252 | stack_glyph.index = 0; | 253 | stack_glyph.index = 0; |
| 253 | } | 254 | } |
| 254 | int this_width = ftcrfont_glyph_extents (font, stack_glyph.index, NULL); | 255 | int this_width = ftcrfont_glyph_extents (font, stack_glyph.index, NULL); |
| 255 | if (this_width > 0 | 256 | if (this_width > 0) |
| 256 | && (! font->min_width | 257 | { |
| 257 | || font->min_width > this_width)) | 258 | if (! font->min_width || font->min_width > this_width) |
| 258 | font->min_width = this_width; | 259 | font->min_width = this_width; |
| 259 | if (this_width > font->max_width) | 260 | if (this_width > font->max_width) |
| 260 | font->max_width = this_width; | 261 | font->max_width = this_width; |
| 261 | if (c == 32) | 262 | if (c == 32) |
| 262 | font->space_width = this_width; | 263 | font->space_width = this_width; |
| 263 | font->average_width += this_width; | 264 | font->average_width += this_width; |
| 265 | n++; | ||
| 266 | } | ||
| 264 | } | 267 | } |
| 265 | font->average_width /= 95; | 268 | if (n) |
| 269 | font->average_width /= n; | ||
| 266 | 270 | ||
| 267 | cairo_scaled_font_extents (ftcrfont_info->cr_scaled_font, &extents); | 271 | cairo_scaled_font_extents (ftcrfont_info->cr_scaled_font, &extents); |
| 268 | font->ascent = lround (extents.ascent); | 272 | font->ascent = lround (extents.ascent); |