You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Visually it's hard to see much difference once rendered and here is the space saving for a 0-255 range:
master 43124 bytes
compress-more 23208 bytes
This is a nice boost we can get now roughly for free since it doesn't affect the format/integrating projects -- later we may try other encodings for the bitmap (PNG, etc.) but those will be format-breaking.
Next actions
Try this and other settings (4 and 2? 16 is where I started to see artifacts...) with a variety of different fonts
This could be variable/env based so if you want a very high quality SDF you can set your settings that way
This should likely be configurable by font. Simple serif and sans-serif fonts render quite cleanly with significantly reduced granularity, but curvy, swooping fonts like Mister K Pro Regular degrade in quality more quickly.
granularity
bytes
image
1
34290
2
28780
4
23552
8
18864
I may have the style mixed up a bit through, as I was trying to render Mister K at a larger size and even the rendering without reduced granularity appears much lower quality than @amyleew's. Is the screenshot below from a Mapnik rendering or GL? Could this particular font simply be ill-suited for SDF rendering?
Looks like 48px SDFs with granularity 4 is the sweet spot for this font, granularity 8 looks a bit lighter than full quality. The 24px SDFs (even at granularity 1) are woefully inadequate for this font.
So 48px SDFs at granularity 4 look great for rendering curvy fonts like Mister K (even at large font sizes like 72px), but unecessarily bloat the SDFs for simpler fonts like Open Sans Regular at more typical font sizes.
Interesting results! We should definitely explore more here and make the font size configurable (currently it is hard coded to 24px). We could also explore not computing the SDF on the server, but on the client, and just send the antialiased glyph to the client. Similarly, another paper describes how to use the gradients in the distance field to compute sharper outlines and corners.
I need to try a 48px CJK font, where to change the granularity param now? If distmap.c was moved into sdf-glyph-foundry? I just found the font scale ratio param , while i'm not sure if it is for the font size.
Btw, no need to modify mapbox-gl-js to use generated 48px glyphs, right?
This should likely be made consistent to use the same variable instead of hardcoding values twice, and possibly made more modular, as the file size/clarity tradeoff can be different for more complex font styles.
Btw, no need to modify mapbox-gl-js to use generated 48px glyphs, right?
I don't remember, there may be some logic in there expecting glyphs of a certain size, or it could be reading those metrics from the protobufs. If this was made modular, would need to ensure the frontend rendering displayed glyphs as expected independent of node-fontnik render params.
Activity
mikemorris commentedon Jul 1, 2014
mourner commentedon Jul 1, 2014
8 looks great to me
mikemorris commentedon Jul 1, 2014
This should likely be configurable by font. Simple serif and sans-serif fonts render quite cleanly with significantly reduced granularity, but curvy, swooping fonts like Mister K Pro Regular degrade in quality more quickly.
I may have the style mixed up a bit through, as I was trying to render Mister K at a larger size and even the rendering without reduced granularity appears much lower quality than @amyleew's. Is the screenshot below from a Mapnik rendering or GL? Could this particular font simply be ill-suited for SDF rendering?
mikemorris commentedon Jul 1, 2014
Mister K Onstage Pro Regular
Looks like 48px SDFs with granularity 4 is the sweet spot for this font, granularity 8 looks a bit lighter than full quality. The 24px SDFs (even at granularity 1) are woefully inadequate for this font.
amyleew commentedon Jul 1, 2014
@mikemorris Was testing the FF Font - Mister K. Screenshot directly from TM2.
mikemorris commentedon Jul 2, 2014
So 48px SDFs at granularity 4 look great for rendering curvy fonts like Mister K (even at large font sizes like 72px), but unecessarily bloat the SDFs for simpler fonts like Open Sans Regular at more typical font sizes.
Open Sans Regular
Maybe this calls for investigating 2-channel signed distance fields?
/cc @yhahn @kkaefer
kkaefer commentedon Jul 3, 2014
Interesting results! We should definitely explore more here and make the font size configurable (currently it is hard coded to 24px). We could also explore not computing the SDF on the server, but on the client, and just send the antialiased glyph to the client. Similarly, another paper describes how to use the gradients in the distance field to compute sharper outlines and corners.
mikemorris commentedon Oct 3, 2016
You may find this interesting @rasagy, refs mapbox/mapbox-gl-js#3286
initialdmg commentedon Aug 28, 2019
I need to try a 48px CJK font, where to change the granularity param now? If
distmap.cwas moved into sdf-glyph-foundry? I just found the font scale ratio param , while i'm not sure if it is for the font size.Btw, no need to modify mapbox-gl-js to use generated 48px glyphs, right?
mikemorris commentedon Aug 28, 2019
IIRC the font size you're looking for is hardcoded as
24atnode-fontnik/src/glyphs.cpp
Line 322 in d65c204
It looks like it's also passed in to
sdf_glyph_foundryhardcoded separately a few lines below atnode-fontnik/src/glyphs.cpp
Line 335 in d65c204
This should likely be made consistent to use the same variable instead of hardcoding values twice, and possibly made more modular, as the file size/clarity tradeoff can be different for more complex font styles.
I don't remember, there may be some logic in there expecting glyphs of a certain size, or it could be reading those metrics from the protobufs. If this was made modular, would need to ensure the frontend rendering displayed glyphs as expected independent of node-fontnik render params.
jcary741 commentedon Oct 13, 2026
Closing as stale.