Break out font stuff into new module
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/** @file font.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 18 Sep 2011
|
||||
@brief Font lookup.
|
||||
*/
|
||||
|
||||
#include "font.h"
|
||||
|
||||
|
||||
/** Determine if character in font.
|
||||
@param font pointer to font structure
|
||||
@param ch character to check
|
||||
@return non-zero if character is in font. */
|
||||
bool font_contains_p (font_t *font, char ch)
|
||||
{
|
||||
int8_t index;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
index = ch - font->offset;
|
||||
return index >= 0 && index < font->size;
|
||||
}
|
||||
|
||||
|
||||
/** Determine if pixel on or off.
|
||||
@param font pointer to font structure
|
||||
@param ch character to display
|
||||
@param col column of font element
|
||||
@param row row of font element
|
||||
@return 1 if pixel on; if pixel out of bounds return 0. */
|
||||
bool font_pixel_get (font_t *font, char ch, uint8_t col, uint8_t row)
|
||||
{
|
||||
int8_t index;
|
||||
font_data_t *char_data;
|
||||
uint8_t offset;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
/* Check if desired pixel within size of an element. */
|
||||
if (col >= font->width || row >= font->height)
|
||||
return 0;
|
||||
|
||||
/* Find index of font element. */
|
||||
index = ch - font->offset;
|
||||
if (index < 0 || index >= font->size)
|
||||
return 0;
|
||||
|
||||
/* Get start of font element data for ch. */
|
||||
char_data = &font->data[index * font->bytes];
|
||||
|
||||
/* Extract whether pixel should be on or off. */
|
||||
offset = row * font->width + col;
|
||||
return (char_data[offset >> 3] & BIT (offset % 8)) != 0;
|
||||
}
|
||||
|
||||
+14
-5
@@ -1,7 +1,7 @@
|
||||
/** @file font.h
|
||||
@author M. P. Hayes, UCECE
|
||||
@date 1 March 2007
|
||||
@brief Font definition.
|
||||
@brief Font lookup.
|
||||
*/
|
||||
|
||||
#ifndef FONT_H
|
||||
@@ -31,11 +31,20 @@ typedef const struct
|
||||
} font_t;
|
||||
|
||||
|
||||
/** Return the first character in the font. */
|
||||
#define FONT_FIRST(font) ((font)->offset)
|
||||
/** Determine if character in font.
|
||||
@param font pointer to font structure
|
||||
@param ch character to check
|
||||
@return non-zero if character is in font. */
|
||||
bool font_contains_p (font_t *font, char ch);
|
||||
|
||||
/** Return the last character in the font. */
|
||||
#define FONT_LAST(font) ((font)->offset + (font)->size - 1)
|
||||
|
||||
/** Determine if pixel on or off.
|
||||
@param font pointer to font structure
|
||||
@param ch character to display
|
||||
@param col column of font element
|
||||
@param row row of font element
|
||||
@return 1 if pixel on; if pixel out of bounds return 0. */
|
||||
bool
|
||||
font_pixel_get (font_t *font, char ch, uint8_t col, uint8_t row);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-18
@@ -123,24 +123,7 @@ void tinygl_clear (void)
|
||||
@return 1 if pixel on; if pixel out of bounds return 0. */
|
||||
static bool tinygl_font_pixel_get (char ch, uint8_t col, uint8_t row)
|
||||
{
|
||||
int8_t index;
|
||||
font_data_t *char_data;
|
||||
uint8_t offset;
|
||||
|
||||
if (!font || col >= font->width || row >= font->height)
|
||||
return 0;
|
||||
|
||||
/* Find index of font entry. */
|
||||
index = ch - font->offset;
|
||||
if (index < 0 || index >= font->size)
|
||||
return 0;
|
||||
|
||||
/* Get start of font entry data for ch. */
|
||||
char_data = &font->data[index * font->bytes];
|
||||
|
||||
/* Extract whether pixel should be on or off. */
|
||||
offset = row * font->width + col;
|
||||
return (char_data[offset / 8] & BIT (offset % 8)) != 0;
|
||||
return font_pixel_get (font, ch, col, row);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user