ftsf / nico

a Game Framework in Nim inspired by Pico-8.
MIT License
624 stars 35 forks source link

Current font png format calculation limitations #115

Closed TakWolf closed 7 months ago

TakWolf commented 1 year ago

Prerequisite: https://github.com/ftsf/nico/pull/114

Now nico use the font png format like this:

image

But not this:

image

What's different?

In case 2, there is 1px alpha border on the bottom and right in glyph rect, but not in case 1.

Actually in nico:

advanceWidth =  font.rects["x"].w * scale + scale 
lineHeight = fontHeight() * scale + scale 

The + scale is the charGap and lineGap. (If scale = 1px, the gap is 1px)

What's the problem?

Generally, the font glyph width include the char gap. It makes sense. For example, the Box Drawing chars They need a compact layout. See: https://ark-pixel-font.takwolf.com/alphabet-10px-monospaced.html

image

Pixel style fonts usually control this margin themself instead of a layout engine to avoid this issue.

(Opentype font lineGap usually is 0, and advanceWidth include charGap)

Font Tools:

https://github.com/TakWolf/nico-font-tool https://github.com/TakWolf/nico-font-tool.python

Demo fonts:

https://littlelimit.net/misaki.htm https://github.com/TakWolf/ark-pixel-font https://github.com/TakWolf/fusion-pixel-font https://github.com/quiple/galmuri https://diaowinner.itch.io/galmuri-extended