From 0b91bb09fb183a44ac60d685ab28c691e4fe05d4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 2 Apr 2026 20:21:49 -0600 Subject: [PATCH] [vector] Fix PDF coordinate system Font and PDF coordinates are both Y-up, so no Y-flip is needed in the path data. The pen position from the SVG-space layout is the only thing that needs negating. Remove the Y negation from append_xy and the CTM from the content stream. Set the glyph transform to identity with negated pen_y. Assisted-by: Claude --- src/hb-vector-draw.hh | 2 -- src/hb-vector-svg-draw.cc | 13 ++++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/hb-vector-draw.hh b/src/hb-vector-draw.hh index 33971f23a..e9294bdd2 100644 --- a/src/hb-vector-draw.hh +++ b/src/hb-vector-draw.hh @@ -32,8 +32,6 @@ struct hb_vector_draw_t { float tx, ty; hb_svg_transform_point (transform, x_scale_factor, y_scale_factor, x, y, &tx, &ty); - if (format == HB_VECTOR_FORMAT_PDF) - ty = -ty; /* PDF is Y-up; negate here to preserve winding. */ hb_svg_append_num (&path, tx, precision); hb_svg_append_c (&path, format == HB_VECTOR_FORMAT_PDF ? ' ' : ','); hb_svg_append_num (&path, ty, precision); diff --git a/src/hb-vector-svg-draw.cc b/src/hb-vector-svg-draw.cc index fd47a9337..4b5309ef5 100644 --- a/src/hb-vector-svg-draw.cc +++ b/src/hb-vector-svg-draw.cc @@ -548,15 +548,10 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw, if (draw->format == HB_VECTOR_FORMAT_PDF) { - /* PDF: always inline, use transform to position. */ + /* PDF: always inline. Pen position is in SVG space (Y-down); + * negate it since font/PDF coords are Y-up. */ hb_transform_t<> saved = draw->transform; - float xx = draw->transform.xx; - float yx = draw->transform.yx; - float xy = draw->transform.xy; - float yy = draw->transform.yy; - float tx = draw->transform.x0 + xx * pen_x + xy * pen_y; - float ty = draw->transform.y0 + yx * pen_x + yy * pen_y; - draw->transform = {xx, yx, xy, yy, tx, ty}; + draw->transform = {1, 0, 0, 1, pen_x, -pen_y}; draw->path.clear (); hb_font_draw_glyph (font, glyph, hb_vector_draw_funcs_get (), draw); @@ -692,7 +687,7 @@ hb_vector_draw_render_pdf (hb_vector_draw_t *draw) hb_vector_t stream; stream.alloc (draw->body.length + draw->path.length + 128); - /* Y is negated in append_xy, so no CTM needed. */ + /* Path coords are in font space (Y-up); no CTM needed. */ if (draw->body.length) hb_svg_append_len (&stream, draw->body.arrayZ, draw->body.length);