Options

TrueType font that just contains a bitmap font

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.
«1

Comments

  • Options
    Jens KutilekJens Kutilek Posts: 340
    It should be possible. Is the display of embedded bitmaps enabled in your Linux environment?
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    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.
  • Options
    pthomas505pthomas505 Posts: 54
    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:



  • Options
    Simon CozensSimon Cozens Posts: 724
    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

  • Options
    pthomas505pthomas505 Posts: 54
    Does the same hold true for an OTB font? It is too bad I can't seem to use the BDF font directly.
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    “.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?
  • Options
    pthomas505pthomas505 Posts: 54
    Yes, I am primarily interested in using the font on Linux.
  • Options
    Jens KutilekJens Kutilek Posts: 340
    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 font ;)
  • Options
    pthomas505pthomas505 Posts: 54
    I just changed the extension to .txt in order to be able to upload it, it just needs to be renamed back to .otb.
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    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.)
  • Options
    pthomas505pthomas505 Posts: 54
    edited March 3
    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.
  • Options
    pthomas505pthomas505 Posts: 54
    edited March 3
    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.
  • Options
    pthomas505pthomas505 Posts: 54
    edited March 3
    *deleted*
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    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.  :)
  • Options
    pthomas505pthomas505 Posts: 54
    I think it is a binary file, so must have become more robust. :smile:
  • Options
    pthomas505pthomas505 Posts: 54
    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?
  • Options
    pthomas505pthomas505 Posts: 54
    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.
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    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?
  • Options
    pthomas505pthomas505 Posts: 54
    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?
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    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.
  • Options
    pthomas505pthomas505 Posts: 54
    I see.
  • Options
    pthomas505pthomas505 Posts: 54
    This should be the ufo before removing the overlap.
  • Options
    pthomas505pthomas505 Posts: 54
    edited March 9
    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.

  • Options
    pthomas505pthomas505 Posts: 54
    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.


  • Options
    pthomas505pthomas505 Posts: 54
    I guess the hinting might not be quite as simple as that.
  • Options
    Thomas PhinneyThomas Phinney Posts: 2,754
    Not sure it matters, but FontLab wasn’t able to import the UFO.
  • Options
    pthomas505pthomas505 Posts: 54
    :(
  • Options
    pthomas505pthomas505 Posts: 54
    Is there a way to hint this so that every "pixel" scales in size uniformly, like the hinted "x" does above?
  • Options
    pthomas505pthomas505 Posts: 54
    edited March 9
    I think I need to scale every coordinate dependent on the ppem, but I'm not certain of the exact formula.
Sign In or Register to comment.