diff options
| author | Po Lu | 2023-12-26 14:07:58 +0800 |
|---|---|---|
| committer | Po Lu | 2023-12-26 14:10:57 +0800 |
| commit | cd91ecedcbdf03ae13f45cb173360b11f13a0bc0 (patch) | |
| tree | daa4d9d65f6db42b8a6f924bd50b30132008ee16 | |
| parent | a6ef458e3831001b0acad57cf8fa75b77a4aff3f (diff) | |
| download | emacs-cd91ecedcbdf03ae13f45cb173360b11f13a0bc0.tar.gz emacs-cd91ecedcbdf03ae13f45cb173360b11f13a0bc0.zip | |
Consistently round glyph advances in the SFNT font backend
* src/sfnt.h (SFNT_ROUND_FIXED): New macro.
* src/sfntfont.c (sfntfont_get_glyph_outline): Don't apply
advance width distortion before the glyph is instructed or
decomposed. Round advance width as measured between both
phantom points subsequent to instruction code execution.
(sfntfont_draw): Don't take the advance's ceiling when advancing
origin point.
| -rw-r--r-- | src/sfnt.h | 1 | ||||
| -rw-r--r-- | src/sfntfont.c | 18 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/sfnt.h b/src/sfnt.h index 7baed372212..576d287e8e6 100644 --- a/src/sfnt.h +++ b/src/sfnt.h | |||
| @@ -1455,6 +1455,7 @@ struct sfnt_post_table | |||
| 1455 | 1455 | ||
| 1456 | 1456 | ||
| 1457 | #define SFNT_CEIL_FIXED(fixed) (((fixed) + 0177777) & 037777600000) | 1457 | #define SFNT_CEIL_FIXED(fixed) (((fixed) + 0177777) & 037777600000) |
| 1458 | #define SFNT_ROUND_FIXED(fixed) (((fixed) + 0100000) & 037777600000) | ||
| 1458 | #define SFNT_FLOOR_FIXED(fixed) ((fixed) & 037777600000) | 1459 | #define SFNT_FLOOR_FIXED(fixed) ((fixed) & 037777600000) |
| 1459 | 1460 | ||
| 1460 | 1461 | ||
diff --git a/src/sfntfont.c b/src/sfntfont.c index c626e76b52b..b20a7c91115 100644 --- a/src/sfntfont.c +++ b/src/sfntfont.c | |||
| @@ -2257,9 +2257,6 @@ sfntfont_get_glyph_outline (sfnt_glyph glyph_code, | |||
| 2257 | head, maxp)) | 2257 | head, maxp)) |
| 2258 | goto fail; | 2258 | goto fail; |
| 2259 | 2259 | ||
| 2260 | /* Add the advance width distortion. */ | ||
| 2261 | temp.advance += distortion.advance; | ||
| 2262 | |||
| 2263 | if (interpreter) | 2260 | if (interpreter) |
| 2264 | { | 2261 | { |
| 2265 | if (glyph->simple) | 2262 | if (glyph->simple) |
| @@ -2295,8 +2292,11 @@ sfntfont_get_glyph_outline (sfnt_glyph glyph_code, | |||
| 2295 | 2292 | ||
| 2296 | if (outline) | 2293 | if (outline) |
| 2297 | { | 2294 | { |
| 2298 | /* Save the new advance width. */ | 2295 | /* Save the new advance width. This advance width is |
| 2299 | temp.advance = advance; | 2296 | rounded again, as the instruction code executed might |
| 2297 | have moved both phantom points such that they no | ||
| 2298 | longer measure a fractional distance. */ | ||
| 2299 | temp.advance = SFNT_ROUND_FIXED (advance); | ||
| 2300 | 2300 | ||
| 2301 | /* Finally, adjust the left side bearing of the glyph | 2301 | /* Finally, adjust the left side bearing of the glyph |
| 2302 | metrics by the origin point of the outline, should a | 2302 | metrics by the origin point of the outline, should a |
| @@ -2319,6 +2319,11 @@ sfntfont_get_glyph_outline (sfnt_glyph glyph_code, | |||
| 2319 | sfntfont_get_metrics, | 2319 | sfntfont_get_metrics, |
| 2320 | &dcontext); | 2320 | &dcontext); |
| 2321 | 2321 | ||
| 2322 | /* Add the advance width distortion, which is not applied to | ||
| 2323 | glyph metrics in advance of their being instructed, and thus | ||
| 2324 | has to be applied before the metrics are. */ | ||
| 2325 | temp.advance += distortion.advance; | ||
| 2326 | |||
| 2322 | /* At this point, the glyph metrics are unscaled. Scale them | 2327 | /* At this point, the glyph metrics are unscaled. Scale them |
| 2323 | up. If INTERPRETER is set, use the scale placed within. */ | 2328 | up. If INTERPRETER is set, use the scale placed within. */ |
| 2324 | sfnt_scale_metrics (&temp, scale); | 2329 | sfnt_scale_metrics (&temp, scale); |
| @@ -2328,7 +2333,6 @@ sfntfont_get_glyph_outline (sfnt_glyph glyph_code, | |||
| 2328 | been applied by either instruction code or glyph variation. | 2333 | been applied by either instruction code or glyph variation. |
| 2329 | The left side bearing is the distance from the origin point | 2334 | The left side bearing is the distance from the origin point |
| 2330 | to the left most point on the X axis. */ | 2335 | to the left most point on the X axis. */ |
| 2331 | |||
| 2332 | if (index != -1) | 2336 | if (index != -1) |
| 2333 | temp.lbearing = outline->xmin - outline->origin; | 2337 | temp.lbearing = outline->xmin - outline->origin; |
| 2334 | } | 2338 | } |
| @@ -3707,7 +3711,7 @@ sfntfont_draw (struct glyph_string *s, int from, int to, | |||
| 3707 | if (s->padding_p) | 3711 | if (s->padding_p) |
| 3708 | current_x += 1; | 3712 | current_x += 1; |
| 3709 | else | 3713 | else |
| 3710 | current_x += SFNT_CEIL_FIXED (metrics.advance) / 65536; | 3714 | current_x += metrics.advance / 65536; |
| 3711 | } | 3715 | } |
| 3712 | 3716 | ||
| 3713 | /* Call the window system function to put the glyphs to the | 3717 | /* Call the window system function to put the glyphs to the |