public class LEDFont extends Object
The ledfont format and this font implementation are lightweight and quite efficient for tiny fixed-size fonts, such as the ones that would be used in an embedded device or a LED matrix.
Current limitations:
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
data |
protected int |
height |
protected Map<Integer,Integer> |
lookup |
static byte[] |
MAGIC |
protected int |
used |
| Modifier | Constructor and Description |
|---|---|
|
LEDFont(byte[] data)
Constructs a LEDFont from a byte array containing data in ledfont format.
|
|
LEDFont(InputStream in)
Constructs a LEDFont from a stream containing data in ledfont format.
|
protected |
LEDFont(int height)
Constructs an empty LEDFont.
|
|
LEDFont(String filename)
Constructs a LEDFont from a file or resource in ledfont format.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addChar(int c,
byte[] data,
int offset,
int length)
Adds a character to this font.
|
int |
getHeight()
Returns the font height in pixels.
|
int |
getMaxWidth(char[] chars)
Returns the maximum glyph width among
all of the given characters.
|
Set<Integer> |
getSupportedChars()
Returns the sorted set of Unicode code points supported by this font.
|
String |
getSupportedCharsAsString()
Returns a string of Unicode code points supported by this font.
|
int |
getWidth(char[] chars,
int start,
int len)
Returns the width in pixels of the given characters.
|
int |
getWidth(int c)
Returns the width in pixels of the given code point.
|
int |
getWidth(String s)
Returns the width in pixels of the given string.
|
static void |
main(String[] args)
The main command-line utility entry point.
|
protected void |
parse(byte[] data)
Parses data in the ledfont format.
|
protected void |
save(File out)
Saves this font into the given file in the ledfont format.
|
protected void |
save(OutputStream out)
Saves this font into the given stream in the ledfont format.
|
String |
toAsciiArt(String s,
int lineWidth)
Writes the glyphs for the given sequence of characters into
an ASCII-art string.
|
int |
write(char[] chars,
int start,
int len,
byte[] buf,
int offset)
Writes the glyphs for the given characters into an array.
|
int |
write(int c,
byte[] buf,
int offset)
Writes the glyph for the given code point into an array.
|
byte[] |
write(String s)
Writes the glyphs for the given string.
|
int |
write(String s,
byte[] buf,
int offset)
Writes the glyphs for the given string into an array.
|
public static byte[] MAGIC
protected int height
protected byte[] data
protected int used
protected LEDFont(int height)
height - the font heightpublic LEDFont(String filename) throws IOException
filename - the file (or resource) nameIOException - if an error occurspublic LEDFont(InputStream in) throws IOException
in - the stream from which the ledfont data is readIOException - if an error occurspublic LEDFont(byte[] data)
data - the data in ledfont formatpublic int getHeight()
public Set<Integer> getSupportedChars()
public String getSupportedCharsAsString()
protected void parse(byte[] data)
data - the data in ledfont formatprotected void save(OutputStream out) throws IOException
out - the stream to save toIOException - if an error occursprotected void save(File out) throws IOException
out - the file to save toIOException - if an error occurspublic int getMaxWidth(char[] chars)
chars - the code pointsprotected void addChar(int c,
byte[] data,
int offset,
int length)
c - the Unicode code pointdata - an array containing the glyph dataoffset - the offset within the array where the glyph data startslength - the length of the glyph data (the glyph width)public int getWidth(int c)
c - a code pointpublic int getWidth(char[] chars,
int start,
int len)
chars - a sequence of charactersstart - the start index of the character sequencelen - the length of the character sequencepublic int getWidth(String s)
s - a sequence of characterspublic int write(int c,
byte[] buf,
int offset)
c - a code pointbuf - an array into which the glyph is writtenoffset - the offset within the array at which to writepublic int write(char[] chars,
int start,
int len,
byte[] buf,
int offset)
chars - a sequence of charactersstart - the index of the first character to writelen - the length of the character sequence to writebuf - an array into which the glyphs are writtenoffset - the offset within the array at which to writepublic int write(String s, byte[] buf, int offset)
s - a sequence of charactersbuf - an array into which the glyphs are writtenoffset - the offset within the array at which to writepublic byte[] write(String s)
s - a sequence of characterspublic String toAsciiArt(String s, int lineWidth)
s - a sequence of characterslineWidth - the maximum width of the ASCII-art line
in pixels (after which a new line will be started)public static void main(String[] args) throws IOException
args - the argumentsIOException - if an error occursCopyright © 2017 freeutils.net. All rights reserved.