简体   繁体   中英

Creating a bitmap font for Qt

A client has provided files detailing a bitmap font for a very specific LED device. The size of this device is known and will not vary. In addition, the character set is small (ASCII plus some graphics characters).

Now we already have software which renders on these devices using a standard Linux font (Arial) with code like:

m_font = new QFont("Arial", m_fontHeight);

So, obviously, it would be easier to take that code and simply substitute our font name in place of Arial, having Qt pick it up automagically.

So my question is really to do with how to create a bitmap font in Linux that will be picked up by that. Investigations into tools like FontForge (and indeed the OTF/TTF file formats themselves) seem to indicate that you need to define the fonts in terms of vector graphics, not simple bitmaps.

I see that pathway fraught with conversion issues, especially since we already have the bitmaps we wish to use for individual characters.

Is there an easy way to have Qt (or the underlying Linux font engine) pick up a very simple bitmap-type font file rather than a vector graphics one?

The BDF Format should suit your needs. It is able to store raw bitmaps and is compatible to Qt according to their documentation here .

Qt Documentation

Qt uses the FreeType 2 font engine to produce font output.

...

The FreeType 2 library can support the following font formats:

  • TrueType (TTF)
  • PostScript Type1 (PFA/PFB)
  • Bitmap Distribution Format (BDF)
  • CID-keyed Type1
  • Compact Font Format (CFF)
  • OpenType fonts
  • SFNT-based bitmap fonts
  • Portable Compiled Format (PCF)
  • Microsoft Windows Font File Format (Windows FNT)
  • Portable Font Resource (PFR)
  • Type 42 (limited support)

The future for bitmap fonts is SFNT-based bitmap fonts (basically bitmap glyphs in an OpenType-compatible container). It should work as-is under modern *nix systems, GTK and QT (you may need to make sure no fontconfig rule blacklists bitmap fonts on your target system).

Now the whole "future" for bitmap fonts is bleak and limited, I don't seem them surviving HiDPi and 4K screens . Even though SFNT bitmap fonts are your best target, it's not much of one, I doubt the market for bitmap devices is big enough to support an healthy bitmap font software ecosystem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM