Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

PixelForge

Create and edit pixel fonts, and export them to TTF · By Sergi Lazaro

Discussion: Exported TTF Font Sizes Sticky

A topic by Sergi Lazaro created 4 days ago Views: 42 Replies: 3
Viewing posts 1 to 3
Developer(+2)

Hi! Some of you reported that exported fonts come out at a different size than expected (about 133%), and that imported fonts don’t keep their original size and line height after exporting them again. Thanks a lot to all that reported and discussed on the forums!

The change in 0.91 was a deliberate choice, not a bug, but maybe the choice wasn’t ideal. I want to do it properly, but before changing anything I’d like to hear what you think.

How it works now: A font that is N pixels tall (from the lowest descender to the highest ascender) is exported so that it renders pixel-perfect at N pt at 96 DPI. That works nicely in apps where you choose the size in points. But 96 DPI means N pt is N x 4/3 pixels, so in apps where you choose the size in pixels (Godot, Unity, CSS, Photoshop at 72 ppi, etc.) a 9 pixel font has to be used at 12 px. Worse, if the height isn’t a multiple of 3, there’s no whole pixel size where it’s pixel-perfect at 1x (a 7 pixel font would need 9.33 px).

You can’t have both: either the size in points is a clean number, or the size in pixels is, but not both for every font height. Correct me if I’m wrong! I’m no expert either.

Imports: When importing a TTF, PixelForge figures out the pixel grid, but it doesn’t keep the original font’s em size and vertical metrics, so exporting it again changes its size and line height.

Some ideas:

  • A per-font setting for the export size, with the result clearly shown, something like “1:1 at 9 px, which is 6.75 pt at 96 DPI”. It could be “pixel size = font height”, “point size = font height (at 96 DPI)”, or a custom value. This setting would be saved with the PXF file.
  • Existing fonts would keep exporting exactly as they do now, so nothing changes unless you change the setting.
  • New fonts could get a different default, if one makes more sense to most people.
  • Imported fonts would remember the original size and vertical metrics, so that exporting without changes gives you the same size and line height as the original. If the original size doesn’t fit exactly on the pixel grid, it would get rounded slightly, so that pixels stay crisp.

Other questions for you:

Where do you use your fonts (which engines/apps), and do you set the size in pixels or points there? What would you expect as the default for a new font? Is there anything else about the exported metrics (line height, ascent/descent, etc.) that has been a problem for you?

I’m not an expert on all the details of font metrics, so if anything here sounds wrong, please let me know!

(1 edit)

I already gave a lot of feedback in the other post which you saw, so I will only add a few extra details here. I will probably edit this later when I have more time.

  • I verified that the current “points-centric” export size does indeed allow the exported font to be used alongside other non-pixel fonts while keeping the size of both fonts the same. This is verified in Photoshop and in web browsers, so for general use, I think that the current defaults are good. But as mentioned previously, I think having a “Pixel-centric scaling” toggle per font file with extra info about both sizes in the export dialog is ideal.
    • One persistent issue I have noticed is that the line height is too large in these situations. To get pixel-perfect spacing, I have to set the line height to 75% of the font size. So if the font is set to 16pt, the line height must be 12pt or 0.75em to get the desired line spacing. This is NOT the default behavior in Notepad and PIL for Python, where a line spacing of 0 gives the correct result.

Wow, super glad to know this is a recently discussed topic!

Yeah, I tried the tool to add special chars (á, é, í, ó, ú, ñ,  →, ♥, etc...) to an already existing font I am using in a game project (importing the ttf). After exporting, all the font was (non-intentionally) scaled down.

I am not really familiarized with "DPI" terms and stuff. But it would be ideal to have a Scale% (100% by default, or the DPI stuff) variable at the export window so users could decide.

Thanks a lot for the tool you are providing to the community and for listening to us!!!!

In the meantime, you can use this Python script I wrote to manually make exported fonts larger, like you’re expecting: https://gist.github.com/nimaid/b255a861361e2de6e0040e6db668b38c