public class FontConverter extends Object
In order to conserve resources on resource-limited devices (such as the Raspberry Pi), this utility can be used manually during development to generate font files in the lightweight format used by LEDFont, which in turn can be used during runtime to render text using the font.
Note that most standard desktop fonts look terrible, and often illegible, when rendered at tiny sizes for which they were not designed. However, if you look around you can find a dozen or two fonts that were designed specifically for tiny sizes and will look good even in a target font height of e.g. 5 pixels. Some of these are categorized as pixel fonts.
You may need to try various point sizes, one at a time, until you find the one that looks best for your target font height in pixels. For example, several fonts look best when rendered at a size of 8 points and cropped to a target height of 5 pixels (due ascent/descent spaces, etc.)
Please check the licensing terms of the fonts you use. Most of them are free for personal use, and many are also free for commercial use, but you'll need to verify compliance on a case-by-case basis. If you create your own fonts, please consider sharing them freely as well!
The -d or -t command line arguments can be used to print
the converted font glyphs to the console to quickly assess how it looks.
The font pixel data is currently stored using one byte per column, i.e. there is a font height limit of 8 pixels.
| Constructor and Description |
|---|
FontConverter() |
| Modifier and Type | Method and Description |
|---|---|
static LEDFont |
convert(Font font,
int height,
int offset)
Converts the given font to ledfont format written to a LEDFont.
|
static void |
convert(Font font,
int height,
int offset,
File out)
Converts the given font to ledfont format written to a file.
|
static void |
convertFromPython(File in,
int height,
File out)
Converts a python script defining a font data structure to a LEDFont.
|
static Font |
loadTTF(String filename)
Loads a TrueType (TTF) font from file or resource as an AWT Font.
|
static void |
main(String[] args)
The main command-line utility entry point.
|
static LEDFont |
parsePython(InputStream in,
int height)
Parses a python script defining a font data structure.
|
public static Font loadTTF(String filename) throws IOException
filename - the file (or resource) nameIOException - if an error occurspublic static LEDFont convert(Font font, int height, int offset) throws IOException
font - the AWT font to convertheight - the target height in pixelsoffset - an offset by which all glyphs should be raised or lowered
relative to the font baseline (this should usually be zero)IOException - if an error occurspublic static void convert(Font font, int height, int offset, File out) throws IOException
font - the AWT font to convertheight - the target height in pixelsoffset - an offset by which all glyphs should be raised or lowered
relative to the font baseline (this can usually be left at zero)out - the file to which the ledfont data is writtenIOException - if an error occurspublic static LEDFont parsePython(InputStream in, int height) throws IOException
in - the input stream containing the python scriptheight - the font heightIOException - if an error occurspublic static void convertFromPython(File in, int height, File out) throws IOException
in - the input file containing the python scriptheight - the font heightout - the file to which the ledfont data is writtenIOException - if an error occurspublic static void main(String[] args) throws IOException
args - the argumentsIOException - if an error occursCopyright © 2017 freeutils.net. All rights reserved.