Skip to content

Fix raster glyph positioning and sizing in PNG and SVG export - #8440

Merged
laurmaedje merged 3 commits into
mainfrom
fix-glyph-stretch
Jun 9, 2026
Merged

laurmaedje merged 3 commits into
mainfrom
fix-glyph-stretch

Conversation

@saecki

@saecki saecki commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #8372.

This even preceeded #7679 (at least for PNGs). This is in line with the other draw_glyph functions, which also don't scale their offsets.

The aspect ratio is now applied to the width of the raster image not the height. Which makes sense to me because it's computed from width / height. Also it seemed like the height of the glyph should be retained when stretching it.

@saecki
saecki force-pushed the fix-glyph-stretch branch 2 times, most recently from 6956885 to 31800f8 Compare June 5, 2026 14:28
@saecki saecki changed the title Fix raster glyph frame position Fix raster glyph frame position and aspect ratio Jun 5, 2026
@saecki
saecki marked this pull request as draft June 5, 2026 14:42
@saecki
saecki force-pushed the fix-glyph-stretch branch 2 times, most recently from 236bbd1 to f72c1b4 Compare June 5, 2026 16:01
@saecki

saecki commented Jun 5, 2026 •

Copy link
Copy Markdown
Member Author

Ok so I did some more digging + trial and error and this looks correct when compared to the COLR version.
I don't have any idea if this is actually correct, and the PDF produced by krilla still has a different offset because it computes a scale factor from upem and raster_imatge.pixels_per_em (we already apply the upem scaling in external transforms, so it would probably only have to be some application of the latter one, if at all). Any input from @LaurenzV would be appreciated :)
These are the results (the upper is the CBDT version, the lower the COLR one):

issue-8372-stretched-glyphs eb42aacace2524cdde8a776a93b8129a_issue-8372-stretched-glyphs

6ba5f79ad09028de045047c55b489741_issue-8372-stretched-glyphs.pdf

@saecki
saecki marked this pull request as ready for review June 5, 2026 17:27
@saecki
saecki force-pushed the fix-glyph-stretch branch from f72c1b4 to 5ecfcbe Compare June 8, 2026 22:34
@saecki saecki changed the title Fix raster glyph frame position and aspect ratio Fix raster glyph frame position and size Jun 8, 2026
@saecki

saecki commented Jun 8, 2026 •

Copy link
Copy Markdown
Member Author

The problem here is that the CBDT glyph has a different bounding box than the COLR glyph, which increased the lineheight and affected what exactly was centered in the outlined block. Here is an image from the new test that shows what's going on (left CBDT and right COLR):

49c58d52a09c8a0e2941f0c9b3e02a26_issue-8372-stretched-glyphs

The behavior now mirrors what krilla an chrome seem to do.

The second commit was a cleanup that seemed reasonable, and only changed a few SVGs, because now a translate is applied inside the reused image glyphs instead of the use sites.

By replicate the same behavior as krilla
@laurmaedje laurmaedje changed the title Fix raster glyph frame position and size Fix raster glyph positioning and sizing in PNG and SVG export Jun 9, 2026
@laurmaedje laurmaedje added svg Anything about the file format for people who like to have fun. png Related to PNG export. fix A bug fix. labels Jun 9, 2026
@saecki
saecki force-pushed the fix-glyph-stretch branch from 5a59ec1 to 92e79f2 Compare June 9, 2026 11:45
@laurmaedje
laurmaedje enabled auto-merge June 9, 2026 11:47
@laurmaedje
laurmaedje added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit d654845 Jun 9, 2026
17 checks passed
@saecki
saecki deleted the fix-glyph-stretch branch June 9, 2026 11:56
@laurmaedje laurmaedje mentioned this pull request Jun 9, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 10, 2026
Nightly Release at [dev: add crate-local mock harnesses for vfs, world,
and project tests
(#2503)](4e93d9f),
using [ParaN3xus/typst branch
nightly](ParaN3xus/typst@6743cf2),
a.k.a. [typst/typst Fix raster glyph positioning and sizing in PNG and
SVG export
(typst/typst#8440)](typst/typst@d654845).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix. png Related to PNG export. svg Anything about the file format for people who like to have fun.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Noto Color Emoji is shrinked in SVG with typst main

2 participants