aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-12-19 13:41:16 +0800
committerPo Lu2023-12-19 13:41:16 +0800
commitf2693751dd20caa790aa8f0216d50499653f61d4 (patch)
tree5ad7c9c69f73005f2e8454d17b623d9e1b0ef5cd /src
parent20e39a12e491ce82ee581b6d99a4e2770218e0c6 (diff)
downloademacs-f2693751dd20caa790aa8f0216d50499653f61d4.tar.gz
emacs-f2693751dd20caa790aa8f0216d50499653f61d4.zip
Further corrections to font scaling
* src/sfnt.c (sfnt_dot_fix_14): Correct typo in final division. (sfnt_compute_phantom_points): New parameters S1 and S2, into which unrounded phantom point coordinates are saved. (sfnt_interpret_simple_glyph, sfnt_interpret_compound_glyph_2) (sfnt_interpret_compound_glyph_1): Adjust correspondingly. * src/sfntfont.c (sfntfont_get_glyph_outline): Delete redundant branch.
Diffstat (limited to 'src')
-rw-r--r--src/sfnt.c63
-rw-r--r--src/sfntfont.c22
2 files changed, 47 insertions, 38 deletions
diff --git a/src/sfnt.c b/src/sfnt.c
index 131b4fd409c..1b4cdf38bd0 100644
--- a/src/sfnt.c
+++ b/src/sfnt.c
@@ -10499,7 +10499,7 @@ sfnt_dot_fix_14 (int32_t ax, int32_t ay, int bx, int by)
10499 yy = xx >> 63; 10499 yy = xx >> 63;
10500 xx += 0x2000 + yy; 10500 xx += 0x2000 + yy;
10501 10501
10502 return (int32_t) (xx / (2 << 14)); 10502 return (int32_t) (xx / (1 << 14));
10503#endif 10503#endif
10504} 10504}
10505 10505
@@ -12227,17 +12227,20 @@ sfnt_build_instructed_outline (struct sfnt_instructed_outline *instructed)
12227 scale SCALE. 12227 scale SCALE.
12228 12228
12229 Place the X and Y coordinates of the first phantom point in *X1 and 12229 Place the X and Y coordinates of the first phantom point in *X1 and
12230 *Y1, and those of the second phantom point in *X2 and *Y2. */ 12230 *Y1, and those of the second phantom point in *X2 and *Y2.
12231
12232 Place the unrounded X coordinates of both phantom points in *S1 and
12233 *S2 respectively. */
12231 12234
12232static void 12235static void
12233sfnt_compute_phantom_points (struct sfnt_glyph *glyph, 12236sfnt_compute_phantom_points (struct sfnt_glyph *glyph,
12234 struct sfnt_glyph_metrics *metrics, 12237 struct sfnt_glyph_metrics *metrics,
12235 sfnt_fixed scale, 12238 sfnt_fixed scale,
12236 sfnt_f26dot6 *x1, sfnt_f26dot6 *y1, 12239 sfnt_f26dot6 *x1, sfnt_f26dot6 *y1,
12237 sfnt_f26dot6 *x2, sfnt_f26dot6 *y2) 12240 sfnt_f26dot6 *x2, sfnt_f26dot6 *y2,
12241 sfnt_f26dot6 *s1, sfnt_f26dot6 *s2)
12238{ 12242{
12239 sfnt_fword f1, f2; 12243 sfnt_fword f1, f2;
12240 sfnt_fixed s1, s2;
12241 12244
12242 /* Two ``phantom points'' are appended to each outline by the scaler 12245 /* Two ``phantom points'' are appended to each outline by the scaler
12243 prior to instruction interpretation. One of these points 12246 prior to instruction interpretation. One of these points
@@ -12255,14 +12258,14 @@ sfnt_compute_phantom_points (struct sfnt_glyph *glyph,
12255 f2 += glyph->advance_distortion; 12258 f2 += glyph->advance_distortion;
12256 12259
12257 /* Next, scale both up. */ 12260 /* Next, scale both up. */
12258 s1 = sfnt_mul_f26dot6_fixed (f1 * 64, scale); 12261 *s1 = sfnt_mul_f26dot6_fixed (f1 * 64, scale);
12259 s2 = sfnt_mul_f26dot6_fixed (f2 * 64, scale); 12262 *s2 = sfnt_mul_f26dot6_fixed (f2 * 64, scale);
12260 12263
12261 /* While not expressly provided in the manual, the phantom points 12264 /* While not expressly provided in the manual, the phantom points
12262 (at times termed the advance and origin points) represent pixel 12265 (at times termed the advance and origin points) represent pixel
12263 coordinates within the raster, and are therefore rounded. */ 12266 coordinates within the raster, and are therefore rounded. */
12264 *x1 = sfnt_round_f26dot6 (s1); 12267 *x1 = sfnt_round_f26dot6 (*s1);
12265 *x2 = sfnt_round_f26dot6 (s2); 12268 *x2 = sfnt_round_f26dot6 (*s2);
12266 12269
12267 /* Clear y1 and y2. */ 12270 /* Clear y1 and y2. */
12268 *y1 = 0; 12271 *y1 = 0;
@@ -12285,9 +12288,7 @@ sfnt_interpret_simple_glyph (struct sfnt_glyph *glyph,
12285 size_t zone_size, temp, outline_size, i; 12288 size_t zone_size, temp, outline_size, i;
12286 struct sfnt_interpreter_zone *zone; 12289 struct sfnt_interpreter_zone *zone;
12287 struct sfnt_interpreter_zone *volatile preserved_zone; 12290 struct sfnt_interpreter_zone *volatile preserved_zone;
12288 sfnt_f26dot6 phantom_point_1_x;
12289 sfnt_f26dot6 phantom_point_1_y; 12291 sfnt_f26dot6 phantom_point_1_y;
12290 sfnt_f26dot6 phantom_point_2_x;
12291 sfnt_f26dot6 phantom_point_2_y; 12292 sfnt_f26dot6 phantom_point_2_y;
12292 sfnt_f26dot6 tem; 12293 sfnt_f26dot6 tem;
12293 volatile bool zone_was_allocated; 12294 volatile bool zone_was_allocated;
@@ -12349,16 +12350,18 @@ sfnt_interpret_simple_glyph (struct sfnt_glyph *glyph,
12349 zone->x_current[i] = tem; 12350 zone->x_current[i] = tem;
12350 } 12351 }
12351 12352
12352 /* Compute phantom points. */ 12353 /* Compute and load phantom points. */
12353 sfnt_compute_phantom_points (glyph, metrics, interpreter->scale, 12354 sfnt_compute_phantom_points (glyph, metrics, interpreter->scale,
12354 &phantom_point_1_x, &phantom_point_1_y, 12355 &zone->x_current[i], &phantom_point_1_y,
12355 &phantom_point_2_x, &phantom_point_2_y); 12356 &zone->x_current[i + 1], &phantom_point_2_y,
12356 12357 /* Phantom points are rounded to the
12357 /* Load phantom points. */ 12358 pixel grid once they are inserted
12358 zone->x_points[i] = phantom_point_1_x; 12359 into the glyph zone, but the
12359 zone->x_points[i + 1] = phantom_point_2_x; 12360 original coordinates must remain
12360 zone->x_current[i] = phantom_point_1_x; 12361 untouched, as fonts rely on this to
12361 zone->x_current[i + 1] = phantom_point_2_x; 12362 interpolate points by this
12363 scale. */
12364 &zone->x_points[i], &zone->x_points[i + 1]);
12362 12365
12363 /* Load y_points and y_current, along with flags. */ 12366 /* Load y_points and y_current, along with flags. */
12364 for (i = 0; i < glyph->simple->number_of_points; ++i) 12367 for (i = 0; i < glyph->simple->number_of_points; ++i)
@@ -12553,6 +12556,11 @@ sfnt_transform_f26dot6 (struct sfnt_compound_glyph_component *component,
12553 In addition, CONTEXT also contains two additional ``phantom 12556 In addition, CONTEXT also contains two additional ``phantom
12554 points'' supplying the left and right side bearings of GLYPH. 12557 points'' supplying the left and right side bearings of GLYPH.
12555 12558
12559 S1 and S2 are the unrounded values of the last two phantom points,
12560 which supply the original values saved into the glyph zone. In
12561 practical terms, they are set as the last two values of the glyph
12562 zone's original position array.
12563
12556 Value is NULL upon success, or a description of the error upon 12564 Value is NULL upon success, or a description of the error upon
12557 failure. */ 12565 failure. */
12558 12566
@@ -12561,7 +12569,8 @@ sfnt_interpret_compound_glyph_2 (struct sfnt_glyph *glyph,
12561 struct sfnt_interpreter *interpreter, 12569 struct sfnt_interpreter *interpreter,
12562 struct sfnt_compound_glyph_context *context, 12570 struct sfnt_compound_glyph_context *context,
12563 size_t base_index, size_t base_contour, 12571 size_t base_index, size_t base_contour,
12564 struct sfnt_glyph_metrics *metrics) 12572 struct sfnt_glyph_metrics *metrics,
12573 sfnt_f26dot6 s1, sfnt_f26dot6 s2)
12565{ 12574{
12566 size_t num_points, num_contours, i; 12575 size_t num_points, num_contours, i;
12567 size_t zone_size, temp; 12576 size_t zone_size, temp;
@@ -12651,6 +12660,11 @@ sfnt_interpret_compound_glyph_2 (struct sfnt_glyph *glyph,
12651 & ~SFNT_POINT_TOUCHED_BOTH); 12660 & ~SFNT_POINT_TOUCHED_BOTH);
12652 } 12661 }
12653 12662
12663 /* Copy S1 and S2 into the glyph zone. */
12664 assert (num_points >= 2);
12665 zone->x_points[num_points - 1] = s2;
12666 zone->x_points[num_points - 2] = s1;
12667
12654 /* Load the compound glyph program. */ 12668 /* Load the compound glyph program. */
12655 interpreter->IP = 0; 12669 interpreter->IP = 0;
12656 interpreter->SP = interpreter->stack; 12670 interpreter->SP = interpreter->stack;
@@ -12756,6 +12770,8 @@ sfnt_interpret_compound_glyph_1 (struct sfnt_glyph *glyph,
12756 sfnt_f26dot6 phantom_point_1_y; 12770 sfnt_f26dot6 phantom_point_1_y;
12757 sfnt_f26dot6 phantom_point_2_x; 12771 sfnt_f26dot6 phantom_point_2_x;
12758 sfnt_f26dot6 phantom_point_2_y; 12772 sfnt_f26dot6 phantom_point_2_y;
12773 sfnt_f26dot6 phantom_point_1_s;
12774 sfnt_f26dot6 phantom_point_2_s;
12759 12775
12760 error = NULL; 12776 error = NULL;
12761 12777
@@ -13096,7 +13112,8 @@ sfnt_interpret_compound_glyph_1 (struct sfnt_glyph *glyph,
13096 /* Compute phantom points. */ 13112 /* Compute phantom points. */
13097 sfnt_compute_phantom_points (glyph, metrics, interpreter->scale, 13113 sfnt_compute_phantom_points (glyph, metrics, interpreter->scale,
13098 &phantom_point_1_x, &phantom_point_1_y, 13114 &phantom_point_1_x, &phantom_point_1_y,
13099 &phantom_point_2_x, &phantom_point_2_y); 13115 &phantom_point_2_x, &phantom_point_2_y,
13116 &phantom_point_1_s, &phantom_point_2_s);
13100 13117
13101 /* Grow various arrays to include those points. */ 13118 /* Grow various arrays to include those points. */
13102 rc = sfnt_expand_compound_glyph_context (context, 13119 rc = sfnt_expand_compound_glyph_context (context,
@@ -13123,7 +13140,9 @@ sfnt_interpret_compound_glyph_1 (struct sfnt_glyph *glyph,
13123 error = sfnt_interpret_compound_glyph_2 (glyph, interpreter, 13140 error = sfnt_interpret_compound_glyph_2 (glyph, interpreter,
13124 context, base_index, 13141 context, base_index,
13125 base_contour, 13142 base_contour,
13126 metrics); 13143 metrics,
13144 phantom_point_1_s,
13145 phantom_point_2_s);
13127 } 13146 }
13128 13147
13129 return error; 13148 return error;
diff --git a/src/sfntfont.c b/src/sfntfont.c
index 0a8797bfb3b..cecdbeafb8d 100644
--- a/src/sfntfont.c
+++ b/src/sfntfont.c
@@ -2290,22 +2290,12 @@ sfntfont_get_glyph_outline (sfnt_glyph glyph_code,
2290 } 2290 }
2291 2291
2292 if (!outline) 2292 if (!outline)
2293 { 2293 outline = sfnt_build_glyph_outline (glyph, scale,
2294 if (!interpreter) 2294 &temp,
2295 outline = sfnt_build_glyph_outline (glyph, scale, 2295 sfntfont_get_glyph,
2296 &temp, 2296 sfntfont_free_glyph,
2297 sfntfont_get_glyph, 2297 sfntfont_get_metrics,
2298 sfntfont_free_glyph, 2298 &dcontext);
2299 sfntfont_get_metrics,
2300 &dcontext);
2301 else
2302 outline = sfnt_build_glyph_outline (glyph, scale,
2303 &temp,
2304 sfntfont_get_glyph,
2305 sfntfont_free_glyph,
2306 sfntfont_get_metrics,
2307 &dcontext);
2308 }
2309 2299
2310 /* At this point, the glyph metrics are unscaled. Scale them up. 2300 /* At this point, the glyph metrics are unscaled. Scale them up.
2311 If INTERPRETER is set, use the scale placed within. */ 2301 If INTERPRETER is set, use the scale placed within. */