[util/vector] Apply margin in pixel units

The other utils (hb-view, hb-raster) treat --margin as pixels, but
hb-vector was applying it directly to the upem-space extents.  For a
font with upem=1000 rendered at font-size=72, the default 16-pixel
margin came out as 16/1000*72 = ~1.15 pixels per side, much smaller
than expected.

Convert margin from pixels to upem before adding it to the extents,
matching the per-axis x_scale/y_scale used elsewhere in the file.

Now hb-vector and hb-raster produce matching surface dimensions for
the same input (e.g. NotoNastaliqUrdu "اردو" at 72px: 137x213 in both).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-16 14:35:58 -06:00
1 parent dba4dab3ef
commit 5ce8f73bad
1 file changed
+8 -4
+8 -4
View File
@@ -428,10 +428,14 @@ struct vector_output_t : output_options_t<>, view_options_t
if (y2 <= y1)
y2 = y1 + 1;
x1 -= (float) margin.l;
y1 -= (float) margin.t;
x2 += (float) margin.r;
y2 += (float) margin.b;
/* Margin is specified in pixels (matching the other utils);
* the surrounding extents are in upem units, so convert. */
float upem_per_pixel_x = (float) upem * scalbnf (1.f, (int) subpixel_bits) / (float) x_scale;
float upem_per_pixel_y = (float) upem * scalbnf (1.f, (int) subpixel_bits) / (float) y_scale;
x1 -= (float) margin.l * upem_per_pixel_x;
y1 -= (float) margin.t * upem_per_pixel_y;
x2 += (float) margin.r * upem_per_pixel_x;
y2 += (float) margin.b * upem_per_pixel_y;
extents->x = x1;
extents->y = y1;