Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Why does the command line interface's font input mode convert font units to pixels by dividing by 64? #147

Closed TJYSunset closed 4 months ago

TJYSunset commented 2 years ago

Sorry if this have already been mentioned before.

I'm no expert in typography, but if I'm not mistaken -

To be clear, I don't think this behavior needs "fixing" (changing the behavior will only break existing code). It just needs clear documentation in the README.

Chlumsky commented 2 years ago

Can you point out the specific division that you think is incorrect? I believe it is done to convert FreeType's fixed point number format (integer whose most significant 26 bits are the whole part and least significant 6 bits are the fractional part) to floating point.

TJYSunset commented 2 years ago

I believe it's in ftPoint2(), which is called by all the FT_Outline_Decompose callback functions.

According to FreeType docs, FT_Pos (used in FT_Vector) can either be 26.6 pixels or 1:1 font units, which seems to actually be font units in this case.

I tested rendering Fira Sans Bold's capital M with

msdfgen msdf -font .\FiraSans-Bold.otf "'M'" -scale 64 -size 1000 1000 -pxrange 4 -testrender test.png 1000 1000

And the output test render is exactly 720px wide, matching FontForge's telling me this glyph is 720 font units wide.

test.png: test.png

FontForge: Snipaste_2022-03-30_20-07-48

Chlumsky commented 2 years ago

Alright, in that case, I guess it is wrong.

Chlumsky commented 4 months ago

Fixed in bc9f02e156115860e28094565c57d383ab03b761, hopefully with full backwards compatibility.

Use:

If you do not specify any of the above, you will get a warning in the console version, but for now, the old behavior will be kept.