-
Hi, First of all, I would like to sincerely thank the creators and supporters of the stb libraries for their fantastic work. I am a user of the stb_truetype library and have encountered a problem that I hope someone could help me with. My issue concerns font rendering. I am using the "Courier New" font with a size of 12, but I've noticed that the rendered font in my application is significantly smaller compared to the same font size in other applications. To achieve a comparable visual size, I have to set the font size to 18 in my code. Could someone please explain what I might be doing wrong, or suggest how I can improve the scaling of the font to match the expected sizes? https://github.com/dev-harbour/hbgl/blob/main/src/truetype.c#L193 Thank you in advance for any help and suggestions. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
As is documented, BakeFontBitmap takes the desired height of the text in pixels, not the classic "point size". If you want to use point size with stbtt font baking, switch to the advance font baking API which begins with |
Beta Was this translation helpful? Give feedback.
There isn't actually a guaranteed simple ratio, as the two are computed via different mechanisms.
stbtt_ScaleForPixelHeight
(used by BakeFontBitmap) looks at the (reported) font bounding box info and is guaranteed to produce reasonable results (as long as the bounding box info is correct, which it basically always is).stbtt_ScaleForMappingEmToPixels
(used for STBTT_POINT_SIZE) uses the reported "unitsPerEm" field of the font, which I found through experience was sometimes wildly wrong in amateur fonts. This can be seen in programs that use traditional font units; as you cycle through fonts in photoshop, you may see the text size change radically if you've installed non-standard fonts.Si…