[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 <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-07 20:12:59 -06:00
1 parent 4faf03e9e9
commit 0b91bb09fb
2 files changed
+4 -11

No files matched your search

-2
View File
@@ -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);
+4 -9
View File
@@ -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<char> 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);