el h / SimpleGUI

Fork of SimpleGUI by Duncan McIntyre

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FastFont.cpp Source File

FastFont.cpp

00001 
00002 #include "FastFont.h"
00003 
00004 FastFont::FastFont(uint8_t* fastFont)
00005     : _font(fastFont)
00006 {
00007     _totalBytesPerGlyph = dataBytesPerGlyph() + 1;
00008     _bytesPerRow = dataBytesPerGlyph() / height();
00009 }
00010 
00011 /***************************************
00012 * Implementation of the Font interface
00013 ***************************************/
00014 uint8_t FastFont::firstAscii()
00015 {
00016     return _font[FAST_FONT_FIRST_ASCII];
00017 }
00018 
00019 uint8_t FastFont::lastAscii()
00020 {
00021     return _font[FAST_FONT_LAST_ASCII];
00022 }
00023 
00024 /**
00025 * The unzoomed width of the character. Includes a following pixel
00026 **/
00027  uint8_t  FastFont::widthOf(char c)
00028 {
00029     if(c < _font[FAST_FONT_FIRST_ASCII] || c > _font[FAST_FONT_LAST_ASCII]) {
00030         return 0;
00031     }
00032 
00033     return _font[FAST_FONT_DATA + ((c - _font[FAST_FONT_FIRST_ASCII]) * _totalBytesPerGlyph)];
00034 }
00035 
00036 uint8_t FastFont::zoomedWidthOf(char c) {
00037     return (widthOf(c) * _zoomX);
00038 }
00039 
00040 /**
00041 * The unzoomed height of a character
00042 **/
00043  uint8_t  FastFont::height()
00044 {
00045     return _font[FAST_FONT_HEIGHT];
00046 }
00047 
00048  uint8_t FastFont::zoomedHeight()
00049 {
00050     return _zoomY * _font[FAST_FONT_HEIGHT];
00051 }
00052 
00053  bool FastFont::isProportional()
00054 {
00055     return _font[FAST_FONT_PROPORTIONAL];
00056 }
00057 
00058 
00059 /***************************************
00060 * Custom methods for this class
00061 ***************************************/
00062 
00063 uint8_t FastFont::totalBytesPerGlyph()
00064 {
00065     return _totalBytesPerGlyph;
00066 }
00067 
00068 
00069 uint8_t FastFont::dataBytesPerGlyph()
00070 {
00071     return _font[FAST_FONT_DATA_BYTES_PER_GLYPH];
00072 }
00073 
00074 uint8_t FastFont::bytesPerRow()
00075 {
00076     return _bytesPerRow;
00077 }
00078 
00079 uint8_t* FastFont::glyph(char c)
00080 {
00081     if(c < _font[FAST_FONT_FIRST_ASCII] || c > _font[FAST_FONT_LAST_ASCII]) {
00082         return 0;
00083     }
00084     
00085     return _font + FAST_FONT_DATA + ((c - _font[FAST_FONT_FIRST_ASCII]) * _totalBytesPerGlyph) + 1;
00086 }