Arduino Graphic LCD Library
GlcdBitmapFont Class Reference

#include <GlcdBitmapFont.h>

Collaboration diagram for GlcdBitmapFont:

Classes

struct  Header
 Font header. More...

Public Member Functions

 GlcdBitmapFont (SeekableInputStream *inputStream)
unsigned char getInfo ()
unsigned char getCharacterWidth ()
unsigned char getCharacterHeight ()
unsigned char getSequenceCount ()
unsigned char getGlyphLength ()
virtual unsigned char readGlyphData (unsigned char *buf, char c)

Protected Member Functions

virtual unsigned int getGlyphOffset (char c)

Protected Attributes

Header header
unsigned char glyphLength
SeekableInputStream * inputStream
unsigned int dataOffset

Detailed Description

Arduino Graphic LCD Library.

GlcdBitmapFont.h

The representation of a glcd font.

Glcd bitmap font is an array which represents the font glyph as a bitmap.

This font has fixed glyph size.

The first bytes specify the font's information and glyph sequences;

Header example:

unsigned char info;
unsigned char characterWidth;
unsigned char characterHeight;
unsigned char sequenceCount;
0x00, 0xww, 0xhh, 0xnn
 |     |     |     |___ Sequence count
 |     |     |_________ Character height (in bits)
 |     |_______________ Character width (in bits)
 |_____________________ Into

The next bytes, after the head, specify the sequences information, each sequence have 3 information:

unsigned char first;
unsigned char last;
unsigned char offset[msb];
unsigned char offset[lsb];

The sequence informations are followed one by another. Example: Considering a font with 2 sequences, this could be the sequence bytes:

0x20, 0x22, 0x00, 0xff,
0x40, 0x43, 0x0d, 0xff,

which means we have a sequence that starts with the 0x20 char and goes to the 0x22, and the glyph data are stored at the 0x00ff offset. Another sequence starts with the 0x40 char and goes to the 0x43, and the glyph data are stored at the 0x0dff offset.

File structure

Header organization:

+-------------------------+
|      Font info          | \
+-------------------------+  \   
|   Character width       |   \
+-------------------------+    } Header
|   Character height      |   /
+-------------------------+  /
|   Sequence count        | /
+-------------------------+
|   First character       | \
+-------------------------+  \
|   Last character        |   \
+-------------------------+    } Sequence #0
|   Offset MSB            |   /
+-------------------------+  /
|   Offset LSB            | /
+-------------------------+
|   First character       | \
+-------------------------+  \
|   Last character        |   \
+-------------------------+    } Sequence #n
|   Offset MSB            |   /
+-------------------------+  /
|   Offset LSB            | /
+-------------------------+
|                         | 0b00000000
|                         | 0b00000000
|                         | 0b00000000
|        FONT DATA        | 0b00000000
|     ARRAY OF BYTES      | 0b00000000
|                         | 0b00000000
|                         | 0b00000000
|                         | 0b00000000
+-------------------------+

Font data

Each character could have any multiple by 8 height. For characters which is 8 bits height, they are just made by bytes in sequence, as follows:

          L    L    L    L    L
          i    i    i    i    i
          n    n    n    n    n
          e    e    e    e    e
          0    1    2    3    4    ...
        +------------------------...
        | b7 | b7 | b7 | b7 | b7 |
        | b6 | b6 | b6 | b6 | b6 |
        | b5 | b5 | b5 | b5 | b5 |
        | b4 | b4 | b4 | b4 | b4 |
        | b3 | b3 | b3 | b3 | b3 |
        | b2 | b2 | b2 | b2 | b2 |
        | b1 | b1 | b1 | b1 | b1 |
        | b0 | b0 | b0 | b0 | b0 |
        +------------------------...

Or, this is a character with width equals 5 and height equals 8: (can be the "T" letter)

        +-+-+-+-+-+-+
        |1|1|1|1|1|1| -> the MSB
        |1|1|1|1|1|1|
        |0|0|1|1|0|0|
        |0|0|1|1|0|0|
        |0|0|1|1|0|0|
        |0|0|1|1|0|0|
        |0|0|1|1|0|0|
        |0|0|0|0|0|0| -> the LSB
        +-+-+-+-+-+-+

Just when a character which has the height bigger than 8 that the things comes more difficult. For example, imagine if the above letter with w: 10 and h: 16.

 
        +-+-+-+-+-+-+-+-+-+-+-+-+       +-+-+-+-+-+-+-+-+-+-+-+-+
        |1|1|1|1|1|1|1|1|1|1|1|1|       |0|0|0|0|1|1|1|1|0|0|0|0| -> the MSB
        |1|1|1|1|1|1|1|1|1|1|1|1|       |0|0|0|0|1|1|1|1|0|0|0|0|
        |1|1|1|1|1|1|1|1|1|1|1|1|       |0|0|0|0|1|1|1|1|0|0|0|0|
        |1|1|1|1|1|1|1|1|1|1|1|1|       |0|0|0|0|1|1|1|1|0|0|0|0|
        |0|0|0|0|1|1|1|1|0|0|0|0|       |0|0|0|0|1|1|1|1|0|0|0|0|
        |0|0|0|0|1|1|1|1|0|0|0|0|       |0|0|0|0|0|0|0|0|0|0|0|0|
        |0|0|0|0|1|1|1|1|0|0|0|0|       |0|0|0|0|0|0|0|0|0|0|0|0|
        |0|0|0|0|1|1|1|1|0|0|0|0|       |0|0|0|0|0|0|0|0|0|0|0|0| -> the LSB
        +-+-+-+-+-+-+-+-+-+-+-+-+       +-+-+-+-+-+-+-+-+-+-+-+-+

The first 10 bytes are the top part of the character, and the las 10 bytes are the bottom part of the character.

Author
Dalmir da Silva dalmi.nosp@m.rdas.nosp@m.ilva@.nosp@m.gmai.nosp@m.l.com

Definition at line 161 of file GlcdBitmapFont.h.

Constructor & Destructor Documentation

GlcdBitmapFont::GlcdBitmapFont ( SeekableInputStream *  inputStream)

Public constructor.

Parameters
inputStreamThe associated input stream.

Definition at line 16 of file GlcdBitmapFont.cpp.

Member Function Documentation

unsigned char GlcdBitmapFont::getCharacterHeight ( )

Gets the character height.

Returns
The heigh of a char.

Definition at line 34 of file GlcdBitmapFont.cpp.

unsigned char GlcdBitmapFont::getCharacterWidth ( )

Gets the character width.

Returns
The width of a char.

Definition at line 30 of file GlcdBitmapFont.cpp.

unsigned char GlcdBitmapFont::getGlyphLength ( )

Gets the glyph length.

Returns
The length of the glyph.

Definition at line 42 of file GlcdBitmapFont.cpp.

unsigned int GlcdBitmapFont::getGlyphOffset ( char  c)
protectedvirtual

Gets the offset to the given character.

Parameters
cThe character to be used.
Returns
The offset.

Definition at line 55 of file GlcdBitmapFont.cpp.

unsigned char GlcdBitmapFont::getInfo ( )

Gets the font info.

Returns
Font info entry.

Definition at line 26 of file GlcdBitmapFont.cpp.

unsigned char GlcdBitmapFont::getSequenceCount ( )

Gets the sequence count.

Returns
The number of sequences.

Definition at line 38 of file GlcdBitmapFont.cpp.

unsigned char GlcdBitmapFont::readGlyphData ( unsigned char *  buf,
char  c 
)
virtual

Gets the array of bytes representing the given character.

Parameters
bufThe buffer.
cThe character.
Returns
The number of bytes read.

Definition at line 46 of file GlcdBitmapFont.cpp.

Member Data Documentation

unsigned int GlcdBitmapFont::dataOffset
protected

Data offset.

It is the point when the header ends.

Definition at line 188 of file GlcdBitmapFont.h.

unsigned char GlcdBitmapFont::glyphLength
protected

Glyph length.

Definition at line 178 of file GlcdBitmapFont.h.

Header GlcdBitmapFont::header
protected

Definition at line 173 of file GlcdBitmapFont.h.

SeekableInputStream* GlcdBitmapFont::inputStream
protected

Input stream which font data comes from.

Definition at line 183 of file GlcdBitmapFont.h.


The documentation for this class was generated from the following files: