TrueType font that just contains a bitmap font
pthomas505
Posts: 54
Is it possible to create a TrueType font that just contains a bitmap font and no vector outlines? I have been attempting to create one using a bdf font in FontForge on Ubuntu, but it doesn't seem to be working. The generated TTF file gives an illegible preview. The bdf font is here. I am hoping to find a way to somehow use it in Visual Studio Code on Ubuntu.
0
Comments
-
It should be possible. Is the display of embedded bitmaps enabled in your Linux environment?0
-
Maybe this helps? https://fontforge.org/docs/techref/bitmaponlysfnt.html#x11-unix-linux0
-
> but it doesn't seem to be working. The generated TTF file gives an illegible preview
I imagine the preview is going to be at some arbitrary size… which might not be the size at which the bitmap(s) are optimized for.
Worse, many modern rendering environments don’t even support embedded bitmaps in TTF, these days. In some cases the embedded bitmaps get removed before rasterizing, for example with Chrome and Firefox, they run the OpenType Sanitizer which specifically removes the EBDT and EBLC tables (that is, the bitmaps).
VS Code uses Electron and therefore Chromium (not Chrome) for rendering, and Chromium uses Blink. I expect Blink uses either FreeType (old!) or Harfbuzz (newer evolution of the same rendering code). Both FreeType and Harfbuzz supported bitmap-only TrueType fonts last time I checked, but that does not mean that every client environment does.0 -
I tried generating an OTB font from the BDF using "fonttosfnt -b -c -g 2 -m 2 -o mono_size1.otb mono_size1.bdf" according to https://askubuntu.com/questions/1244175/how-can-i-activate-bitmap-fonts-on-20-04. I used the version of fonttosfnt compiled from the source in https://gitlab.freedesktop.org/xorg/app/fonttosfnt.git.I think the letter spacing is being set incorrectly. This is the preview of the OTB font:
0 -
The OpenType spec does not (sadly) say so explicitly, but it is heavily implied that there must be at least one outline format:Other data provide descriptions of glyphs as TrueType or Compact Font Format (CFF) outlines. Still other data can provide monochromatic or color bitmaps or SVG documents as alternate glyph descriptions. [my emphasis]
OpenType fonts that contain TrueType outlines should use the value of 0x00010000 for the sfntVersion. OpenType fonts containing CFF data (version 1 or 2) should use 0x4F54544F ('OTTO', when re-interpreted as a Tag) for sfntVersion. [So which magic number would you use for one which contains neither?]
Whether TrueType or CFF outlines are used in an OpenType font...
OpenType fonts may also contain bitmaps of glyphs, in addition to outlines. [my emphasis]
All from https://learn.microsoft.com/en-us/typography/opentype/spec/otff
0 -
Does the same hold true for an OTB font? It is too bad I can't seem to use the BDF font directly.
0 -
“.otb” is an “OpenType bitmap font.” Good description here: https://fontforge.org/docs/techref/bitmaponlysfnt.html along with some other info on bitmap fonts in SFNT wrappers.
“.otb” is an invention of the X Consortium; you could call it an unofficial extension as it is not part of the OpenType spec. I would not expect non-Linux environments to support it, but it might work for you?0 -
Yes, I am primarily interested in using the font on Linux.
0 -
I've tried to convert your BDF font with the system-installed version of fonttosfnt on Debian Bookworm, but the resulting OTB looks severely broken (from a technical standpoint, I can't even get a preview of the font). It has no horizontal glyph metrics, no cmap entries, weird vertical metrics. The bitmap tables are also empty. Maybe I'm doing something wrong.
Maybe you could share your own OTB here to see if it is any different? It seems the distorted shapes you get in the preview at least have a relation to the letters in the original font0 -
I just changed the extension to .txt in order to be able to upload it, it just needs to be renamed back to .otb.
0 -
Sadly, you can’t do that with binary files.
(OK, I mean, you can DO it, but the file content will not survive the experience intact.)0 -
I'm not sure I understand. I didn't open it and save it as a text file. I just renamed it in the filesystem. I tried downloading it and changing the extension back and was still able to open it.
1 -
I just tried regenerating the .otb file, making a copy, changing the extension of the copy to .txt, and doing a byte comparison of the two using 'cmp'. It didn't report any change.
0 -
*deleted*
0 -
I stand corrected, then! Either the OTB format isn’t binary file, or file handling has become much more robust than it used to be.0
-
I think it is a binary file, so must have become more robust.
0 -
I "cheated" and wrote a script to translate a bdf to a ufo by creating a square vector contour for each black pixel. I then used FontForge to remove the overlaps and generate a ttf. Is there a tool I could use to autohint the ttf in both the horizontal and vertical directions? It seems that Visual TrueType only autohints in the vertical direction?
0 -
One issue is that it has self intersecting contours on the corners of diagonally adjacent "pixels". I'm not sure of a good way to generate it that avoids that.
0 -
Seems like a problem in your overlap removal? It is at least possible that some other tool will do better. If you posted the UFO, pre–overlap-removal, people could try out other tools on it?0
-
I think it is just a result of the geometry of tracing a staircase pattern. Each pixel at the connected corners of adjacent "steps" are going to overlap. One option might be to remove a portion of each corner in the outline and put it back in hinting?
0 -
I guess it depends on your definition of “overlap”—two pixels that are corner-adjacent will share a corner coordinate. There are multiple ways to trace that outline, depending on whether the algorithm prefers continuous outlines vs more separate contours.
In the rather specialized case of pixel fonts, having separate contours when two pixels only touch at a corner is almost certainly preferable, IMO. I am suggesting one could try different apps to see whether one or another does that.0 -
I see.
0 -
This should be the ufo before removing the overlap.
0 -
I was able to create a script to generate the separate contours. It doesn't handle fully enclosed interior points like in the hash symbol, but that seems to be a rare issue.0
-
The generated fonts are simple enough that I might be able to create a script to autohint them. It would be nice to find an existing tool though, if anyone knows of one? I tried ttfautohint, but I wasn't able to get it to do this, probably because I don't understand the options. I think I just need to link each stem in sequence starting from the character origin and align the remaining points? This seemed to work when I did it manually for the 'x' glyph.0
-
I guess the hinting might not be quite as simple as that.
0 -
Not sure it matters, but FontLab wasn’t able to import the UFO.0
-
0 -
Is there a way to hint this so that every "pixel" scales in size uniformly, like the hinted "x" does above?
0 -
I think I need to scale every coordinate dependent on the ppem, but I'm not certain of the exact formula.
0
Categories
- All Categories
- 43 Introductions
- 3.7K Typeface Design
- 803 Font Technology
- 1K Technique and Theory
- 622 Type Business
- 444 Type Design Critiques
- 542 Type Design Software
- 30 Punchcutting
- 136 Lettering and Calligraphy
- 83 Technique and Theory
- 53 Lettering Critiques
- 485 Typography
- 303 History of Typography
- 114 Education
- 68 Resources
- 499 Announcements
- 80 Events
- 105 Job Postings
- 148 Type Releases
- 165 Miscellaneous News
- 270 About TypeDrawers
- 53 TypeDrawers Announcements
- 116 Suggestions and Bug Reports