From dba4dab3ef44b94e3255ffffe42978cb0a29aa87 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:41:24 -0600 Subject: [PATCH] [vector-paint] Fold scale_factor into PDF per-glyph cm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to 152aa0fd8c. The SVG branch of hb_vector_paint_glyph divides the instance transform by x_scale_factor/y_scale_factor (via hb_vector_svg_append_instance_transform) so input-space glyph paths land in the pixel-space viewBox. The PDF branch emitted the raw paint matrix, which kept the CTM in input space while the MediaBox lived in pixel space — at any non-identity scale_factor, the glyph rendered entirely outside the page. Divide the matrix columns by sx/sy in the emitted cm so PDF matches SVG. Covers hb-vector's font-size != 20 case and the website's scale_factor = 64 case, where emoji rendered blank at 72 px. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector-paint.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index e0d03348d..54cbed247 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -1370,21 +1370,28 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint, { case HB_VECTOR_FORMAT_PDF: { - /* PDF: emit transform + paint directly, no caching. */ + /* PDF: emit transform + paint directly, no caching. + * The paint transform and pen position are in input + * space; fold in 1/scale_factor here so glyph path + * operators (emitted raw in input space) land in + * pixel space, matching the MediaBox. */ auto &body = paint->current_body (); + unsigned sprec = hb_vector_scale_precision (paint->precision); + float sx = paint->x_scale_factor; + float sy = paint->y_scale_factor; hb_buf_append_str (&body, "q\n"); /* Font and PDF coords are both Y-up; no negation needed. */ - hb_buf_append_num (&body, xx, paint->precision); + hb_buf_append_num (&body, xx / sx, sprec, true); hb_buf_append_c (&body, ' '); - hb_buf_append_num (&body, yx, paint->precision); + hb_buf_append_num (&body, yx / sy, sprec, true); hb_buf_append_c (&body, ' '); - hb_buf_append_num (&body, xy, paint->precision); + hb_buf_append_num (&body, xy / sx, sprec, true); hb_buf_append_c (&body, ' '); - hb_buf_append_num (&body, yy, paint->precision); + hb_buf_append_num (&body, yy / sy, sprec, true); hb_buf_append_c (&body, ' '); - hb_buf_append_num (&body, tx, paint->precision); + hb_buf_append_num (&body, tx / sx, paint->precision); hb_buf_append_c (&body, ' '); - hb_buf_append_num (&body, ty, paint->precision); + hb_buf_append_num (&body, ty / sy, paint->precision); hb_buf_append_str (&body, " cm\n"); hb_bool_t ret = hb_font_paint_glyph_or_fail (font, glyph,