el h / SimpleGUI

Fork of SimpleGUI by Duncan McIntyre

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UGFont.cpp Source File

UGFont.cpp

00001 #include "UGFont.h"
00002 
00003 UGFont::UGFont(uint8_t* font, const uint8_t firstAsciiCode, const uint8_t lastAsciiCode, const bool proportional)
00004     : Font(), _font(&font[UNIGRAPHIC_FONT_DATA_OFFSET]), _firstAscii(firstAsciiCode), _lastAscii(lastAsciiCode), _proportional(proportional)
00005 {
00006     // read font parameter from start of array in format understood by UniGraphics.
00007     // font[0] and font[3] are unused.
00008     // Data starts at font[4]
00009     // Data is laid out in column-order
00010     _width = font[1];
00011     _height = font[2];
00012     _bytesPerCol = (_height + 7) >> 3; // bytes per column
00013     _bytesPerGlyph = 1 + (_width * _bytesPerCol); // 1 byte for the width + actual data
00014 }
00015 
00016 uint8_t UGFont::firstAscii()
00017 {
00018     return _firstAscii;
00019 }
00020 
00021 uint8_t UGFont::lastAscii()
00022 {
00023     return _lastAscii;
00024 }
00025 
00026 uint8_t UGFont::widthOf(char c)
00027 {
00028 
00029     if(c < _firstAscii || c > _lastAscii) {
00030         return 0;
00031     }
00032 
00033     return _font[((c - _firstAscii) * _bytesPerGlyph)];
00034 }
00035 
00036 uint8_t UGFont::zoomedWidthOf(char c)
00037 {
00038 
00039     if(!_proportional) {
00040         return _width * _zoomX;
00041     }
00042 
00043     return widthOf(c) * _zoomX;
00044 }
00045 
00046 uint8_t UGFont::height()
00047 {
00048     return _height;
00049 }
00050 
00051 uint8_t UGFont::zoomedHeight()
00052 {
00053     return _zoomY * _height;
00054 }
00055 
00056 bool UGFont::isProportional() {
00057     return _proportional;
00058 }
00059 
00060 uint8_t* UGFont::getGlyphData(char c)
00061 {
00062     if(c < _firstAscii || c > _lastAscii) {
00063         return NULL;
00064     }
00065     return &_font[((c - _firstAscii) * _bytesPerGlyph) + 1];
00066 }
00067 
00068 uint8_t UGFont::bytesPerCol()
00069 {
00070     return _bytesPerCol;
00071 }
00072 
00073 uint8_t UGFont::bytesPerGlyph()
00074 {
00075     return _bytesPerGlyph;
00076 }