Download

Custom Bitmap Fonts

I’m having trouble finding any info on whether or not the editor features facilities for importing custom bitmap fonts and defining custom glyphs. I’ve written some tools to support a BMFont > Photoshop > Unity pipeline for bitmap fonts that allows me to produce highly detailed, complex custom typography, and I’d like to adapt that pipe to work with UE4.

Does anyone have any experience with importing/defining custom fonts?

Sorry to bump, still looking for a solution (or a “not possible”) on this one with no luck :frowning:

Hi Boon,

If you can export your bitmap font as a .ttf, you can import it into the engine directly as a UFont. Otherwise, you can import an arbitrary font with the character ranges your font contains, then reimport the baked texture page(s) for the font and replace them with your font pages, and adjust the glyph coordinates (not a great workflow, but it’s possible).

Cheers,
Michael Noland

Thanks Michael, I’ll look into it. I can’t export it as a TTF because it’s a full-colour typographic style, but from what I understand, you’re saying the best way to bring the font in is to generate the bitmaps by importing the font as normal, and then replace the bitmaps with my own?

Currently my process is:

  1. Generate bitmap pages from TTF font in BMFont with preferred settings for styling
  2. Import pages into Photoshop and apply style pass
  3. Export styled font to individual per-glyph PNG files (sprites) for repacking
  4. Repack PNG files to optimise texture space
  5. Create custom font data in Unity associating glyph ASCII code with rectangle on bitmap containing the glyph

The utilities I use export the repacked rectangle data so I have a script which reads in that data and automatically sets up a custom Unity Font using the newly repacked and styled bitmap.

This is a pretty flexible (if slightly monotonous) pipe that allows me to heavily style fonts for detailed title-ready typography, but requires that I can manually define the glyph rectangles on the target bitmap.

If I understand your post correctly, the critical step of being able to manually define glyph rectangles isn’t available as yet in UE4?

Hi Boon,

You can manually define them after a font is created (open Characters array in the font editor, you can define the region per glyph).

Cheers,
Michael Noland

Ahhh! Fantastic! Thanks once again for the reply Michael, exactly what I was looking for :slight_smile:

I’m thinking about making a plugin to import Glyph Designer fnt files, looking at UFont this doesn’t seem like it would be very difficult to do.

Sounds good to me! The current UFont workflow for custom bitmaps isn’t where we’d like it to be, so anything that makes it easier is welcome. I think that long term the Tools team wants to merge UFont and Slate fonts together, but whenever that work happens it’ll include a backwards-compatible conversion path for existing UFonts.

Cheers,
Michael Noland

I could easily create a function to run at runtime to import the file to ufont and expose it in a developer plugin, but if I wanted to go bigger and bolder and try to work it into the editor are there any tutorials or documentation for that?

I don’t know if there are any tutorials but creating a new importing factory isn’t too bad. You create a subclass of UFactory, configuring things like the supported file type in the constructor. If you can create a new asset without having a source file, you implement FactoryCreateNew and set bCreateNew to true. If you can import an asset from disk, implement either FactoryCreateText or FactoryCreateBinary, depending on if your source file is ASCII or not. Most of the editor factories are in the uber-file EditorFactories.cpp, which really needs to be split up :slight_smile:

You can create a UI with options when importing, but ideally that isn’t necessary, since it results in a less ‘fun’ workflow, causes issues when drag-dropping multiple assets at once, etc… For UFont construction, I’d check out UFontFactory and UTrueTypeFontFactory, but it might be worth skimming thru a simpler factory first to get the gist of things.

Later on, you can add support for reimporting by mixing in FReimportHandler and implementing that interface (you’ll also need to store a subclass of UAssetImportData on your asset in order to keep track of the source path/etc…). I haven’t implemented this myself yet, so I’m not 100% on all the details, but let me know if you have any questions.

Cheers,
Michael Noland

One other thing to note is that you should OR in RF_Transactional with Flags when you create your asset UObject in the FactoryCreate method in order to enable Undo/Redo on the resulting asset. We plan on making this one of the defaults in the passed-in Flags (so you have to opt out if you really don’t want it), but that change hasn’t happened yet.

Cheers,
Michael Noland

On a related note: Is there any way of getting glyphs (gamepad buttons etc.) into Slate fonts as of 4.4? Or would we have to just mix and match separate STextBlocks and glyph SImages in a horizontal row for now? Obviously custom glyphs stored in the font would be very useful for console titles (help callouts, prompts etc). ShooterGame doesn’t appear to have any as of 4.4.3 which makes me think it’s not possible.