diff options
Diffstat (limited to 'src/gdisp/mcufont')
-rw-r--r-- | src/gdisp/mcufont/mf_bwfont.c | 30 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_bwfont.h | 34 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_encoding.c | 6 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_encoding.h | 6 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_font.c | 10 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_font.h | 36 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_justify.c | 70 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_justify.h | 14 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_kerning.c | 26 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_kerning.h | 2 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_rlefont.c | 74 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_rlefont.h | 30 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_scaledfont.c | 30 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_scaledfont.h | 16 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_wordwrap.c | 42 | ||||
-rw-r--r-- | src/gdisp/mcufont/mf_wordwrap.h | 4 |
16 files changed, 215 insertions, 215 deletions
diff --git a/src/gdisp/mcufont/mf_bwfont.c b/src/gdisp/mcufont/mf_bwfont.c index a17a1673..b2b17a21 100644 --- a/src/gdisp/mcufont/mf_bwfont.c +++ b/src/gdisp/mcufont/mf_bwfont.c @@ -13,7 +13,7 @@ /* Find the character range and index that contains a given glyph.. */ static const struct mf_bwfont_char_range_s *find_char_range( - const struct mf_bwfont_s *font, uint16_t character, uint16_t *index_ret) + const struct mf_bwfont_s *font, gU16 character, gU16 *index_ret) { unsigned i, index; const struct mf_bwfont_char_range_s *range; @@ -31,7 +31,7 @@ static const struct mf_bwfont_char_range_s *find_char_range( return 0; } -static uint8_t get_width(const struct mf_bwfont_char_range_s *r, uint16_t index) +static gU8 get_width(const struct mf_bwfont_char_range_s *r, gU16 index) { if (r->width) { @@ -43,15 +43,15 @@ static uint8_t get_width(const struct mf_bwfont_char_range_s *r, uint16_t index) } } -static uint8_t render_char(const struct mf_bwfont_char_range_s *r, - int16_t x0, int16_t y0, uint16_t index, +static gU8 render_char(const struct mf_bwfont_char_range_s *r, + gI16 x0, gI16 y0, gU16 index, mf_pixel_callback_t callback, void *state) { - const uint8_t *data, *p; - uint8_t stride, runlen; - uint8_t x, y, height, num_cols; - uint8_t bit, byte, mask; + const gU8 *data, *p; + gU8 stride, runlen; + gU8 x, y, height, num_cols; + gU8 bit, byte, mask; bool oldstate, newstate; if (r->width) @@ -112,15 +112,15 @@ static uint8_t render_char(const struct mf_bwfont_char_range_s *r, return get_width(r, index); } -uint8_t mf_bwfont_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +gU8 mf_bwfont_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state) { const struct mf_bwfont_s *bwfont = (const struct mf_bwfont_s*)font; const struct mf_bwfont_char_range_s *range; - uint16_t index; + gU16 index; range = find_char_range(bwfont, character, &index); if (!range) @@ -129,12 +129,12 @@ uint8_t mf_bwfont_render_character(const struct mf_font_s *font, return render_char(range, x0, y0, index, callback, state); } -uint8_t mf_bwfont_character_width(const struct mf_font_s *font, - uint16_t character) +gU8 mf_bwfont_character_width(const struct mf_font_s *font, + gU16 character) { const struct mf_bwfont_s *bwfont = (const struct mf_bwfont_s*)font; const struct mf_bwfont_char_range_s *range; - uint16_t index; + gU16 index; range = find_char_range(bwfont, character, &index); if (!range) diff --git a/src/gdisp/mcufont/mf_bwfont.h b/src/gdisp/mcufont/mf_bwfont.h index 537ba22e..e8de21a7 100644 --- a/src/gdisp/mcufont/mf_bwfont.h +++ b/src/gdisp/mcufont/mf_bwfont.h @@ -21,37 +21,37 @@ struct mf_bwfont_char_range_s { /* The number of the first character in this range. */ - uint16_t first_char; + gU16 first_char; /* The total count of characters in this range. */ - uint16_t char_count; + gU16 char_count; /* The left and top skips of the characters in this range. * This is the number of empty rows at left and at top. */ - uint8_t offset_x; - uint8_t offset_y; + gU8 offset_x; + gU8 offset_y; /* Column height for glyphs in this range, in bytes and pixels. */ - uint8_t height_bytes; - uint8_t height_pixels; + gU8 height_bytes; + gU8 height_pixels; /* Positive value if the width of all glyphs in this range is the * same, or zero if it is not. */ - uint8_t width; + gU8 width; /* Lookup table for the character widths. NULL if width is specified. */ - const uint8_t *glyph_widths; + const gU8 *glyph_widths; /* Lookup table for the character offsets. Multiply by height_bytes * to get the byte offset. Also allows lookup of the number of columns. * NULL if width is specified. */ - const uint16_t *glyph_offsets; + const gU16 *glyph_offsets; /* Table for the glyph data. * The data for each glyph is column-by-column, with N bytes per each * column. The LSB of the first byte is the top left pixel. */ - const uint8_t *glyph_data; + const gU8 *glyph_data; }; /* Structure for the font */ @@ -60,10 +60,10 @@ struct mf_bwfont_s struct mf_font_s font; /* Version of the font format. */ - const uint8_t version; + const gU8 version; /* Number of character ranges. */ - const uint16_t char_range_count; + const gU16 char_range_count; /* Array of the character ranges */ const struct mf_bwfont_char_range_s *char_ranges; @@ -71,14 +71,14 @@ struct mf_bwfont_s #ifdef MF_BWFONT_INTERNALS /* Internal functions, don't use these directly. */ -MF_EXTERN uint8_t mf_bwfont_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +MF_EXTERN gU8 mf_bwfont_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state); -MF_EXTERN uint8_t mf_bwfont_character_width(const struct mf_font_s *font, - uint16_t character); +MF_EXTERN gU8 mf_bwfont_character_width(const struct mf_font_s *font, + gU16 character); #endif #endif diff --git a/src/gdisp/mcufont/mf_encoding.c b/src/gdisp/mcufont/mf_encoding.c index afa16b18..ba9fc7c0 100644 --- a/src/gdisp/mcufont/mf_encoding.c +++ b/src/gdisp/mcufont/mf_encoding.c @@ -13,9 +13,9 @@ mf_char mf_getchar(mf_str *str) { - uint8_t c; - uint8_t tmp, seqlen; - uint16_t result; + gU8 c; + gU8 tmp, seqlen; + gU16 result; c = **str; if (!c) diff --git a/src/gdisp/mcufont/mf_encoding.h b/src/gdisp/mcufont/mf_encoding.h index 18ffb892..7c49f02a 100644 --- a/src/gdisp/mcufont/mf_encoding.h +++ b/src/gdisp/mcufont/mf_encoding.h @@ -20,9 +20,9 @@ /* Type used to represent characters internally. */ #if MF_ENCODING == MF_ENCODING_ASCII typedef char mf_char; - #define MFCHAR2UINT16(c) ((uint16_t)(uint8_t)(c)) + #define MFCHAR2UINT16(c) ((gU16)(gU8)(c)) #else - typedef uint16_t mf_char; + typedef gU16 mf_char; #define MFCHAR2UINT16(c) (c) #endif @@ -32,7 +32,7 @@ typedef const char * mf_str; #elif MF_ENCODING == MF_ENCODING_UTF8 typedef const char * mf_str; #elif MF_ENCODING == MF_ENCODING_UTF16 -typedef const uint16_t * mf_str; +typedef const gU16 * mf_str; #elif MF_ENCODING == MF_ENCODING_WCHAR #include <stddef.h> typedef const wchar_t * mf_str; diff --git a/src/gdisp/mcufont/mf_font.c b/src/gdisp/mcufont/mf_font.c index 9a313f8c..09182b56 100644 --- a/src/gdisp/mcufont/mf_font.c +++ b/src/gdisp/mcufont/mf_font.c @@ -26,13 +26,13 @@ #include MF_FONT_FILE_NAME /* Include fonts end here */ -uint8_t mf_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, +gU8 mf_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, mf_char character, mf_pixel_callback_t callback, void *state) { - uint8_t width; + gU8 width; width = font->render_character(font, x0, y0, MFCHAR2UINT16(character), callback, state); if (!width) @@ -44,10 +44,10 @@ uint8_t mf_render_character(const struct mf_font_s *font, return width; } -uint8_t mf_character_width(const struct mf_font_s *font, +gU8 mf_character_width(const struct mf_font_s *font, mf_char character) { - uint8_t width; + gU8 width; width = font->character_width(font, MFCHAR2UINT16(character)); if (!width) diff --git a/src/gdisp/mcufont/mf_font.h b/src/gdisp/mcufont/mf_font.h index 1812d576..b69cc782 100644 --- a/src/gdisp/mcufont/mf_font.h +++ b/src/gdisp/mcufont/mf_font.h @@ -22,8 +22,8 @@ * alpha: The "opaqueness" of the pixels, 0 for background, 255 for text. * state: Free variable that was passed to render_character(). */ -typedef void (*mf_pixel_callback_t) (int16_t x, int16_t y, uint8_t count, - uint8_t alpha, void *state); +typedef void (*mf_pixel_callback_t) (gI16 x, gI16 y, gU8 count, + gU8 alpha, void *state); /* General information about a font. */ struct mf_font_s @@ -35,35 +35,35 @@ struct mf_font_s const char *short_name; /* Width and height of the character bounding box. */ - uint8_t width; - uint8_t height; + gU8 width; + gU8 height; /* Minimum and maximum tracking width of characters. */ - uint8_t min_x_advance; - uint8_t max_x_advance; + gU8 min_x_advance; + gU8 max_x_advance; /* Location of the text baseline relative to character. */ - int8_t baseline_x; - uint8_t baseline_y; + gI8 baseline_x; + gU8 baseline_y; /* Line height of the font (vertical advance). */ - uint8_t line_height; + gU8 line_height; /* Flags identifying various aspects of the font. */ - uint8_t flags; + gU8 flags; /* Fallback character to use for missing glyphs. */ - uint16_t fallback_character; + gU16 fallback_character; /* Function to get character width. Should return 0 if character is * not found. */ - uint8_t (*character_width)(const struct mf_font_s *font, uint16_t character); + gU8 (*character_width)(const struct mf_font_s *font, gU16 character); /* Function to render a character. Returns the character width or 0 if * character is not found. */ - uint8_t (*render_character)(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, + gU8 (*render_character)(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state); }; @@ -90,8 +90,8 @@ struct mf_font_list_s * * Returns width of the character. */ -MF_EXTERN uint8_t mf_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, +MF_EXTERN gU8 mf_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, mf_char character, mf_pixel_callback_t callback, void *state); @@ -105,7 +105,7 @@ MF_EXTERN uint8_t mf_render_character(const struct mf_font_s *font, * * Returns width of the character in pixels. */ -MF_EXTERN uint8_t mf_character_width(const struct mf_font_s *font, +MF_EXTERN gU8 mf_character_width(const struct mf_font_s *font, mf_char character); /* Find a font based on name. The name can be either short name or full name. diff --git a/src/gdisp/mcufont/mf_justify.c b/src/gdisp/mcufont/mf_justify.c index 5314ab45..58f87cc3 100644 --- a/src/gdisp/mcufont/mf_justify.c +++ b/src/gdisp/mcufont/mf_justify.c @@ -12,10 +12,10 @@ #if MF_USE_TABS /* Round the X coordinate up to the nearest tab stop. */ -static int16_t mf_round_to_tab(const struct mf_font_s *font, - int16_t x0, int16_t x) +static gI16 mf_round_to_tab(const struct mf_font_s *font, + gI16 x0, gI16 x) { - int16_t tabw, dx; + gI16 tabw, dx; tabw = mf_character_width(font, 'm') * MF_TABSIZE; @@ -30,10 +30,10 @@ static int16_t mf_round_to_tab(const struct mf_font_s *font, } /* Round the X coordinate down to the nearest tab stop. */ -static int16_t mf_round_to_prev_tab(const struct mf_font_s *font, - int16_t x0, int16_t x) +static gI16 mf_round_to_prev_tab(const struct mf_font_s *font, + gI16 x0, gI16 x) { - int16_t tabw, dx; + gI16 tabw, dx; tabw = mf_character_width(font, 'm') * MF_TABSIZE; @@ -48,11 +48,11 @@ static int16_t mf_round_to_prev_tab(const struct mf_font_s *font, } #endif -int16_t mf_get_string_width(const struct mf_font_s *font, mf_str text, - uint16_t count, bool kern) +gI16 mf_get_string_width(const struct mf_font_s *font, mf_str text, + gU16 count, bool kern) { - int16_t result = 0; - uint16_t c1 = 0, c2; + gI16 result = 0; + gU16 c1 = 0, c2; if (!count) count = 0xFFFF; @@ -83,9 +83,9 @@ int16_t mf_get_string_width(const struct mf_font_s *font, mf_str text, } /* Return the length of the string without trailing spaces. */ -static uint16_t strip_spaces(mf_str text, uint16_t count, mf_char *last_char) +static gU16 strip_spaces(mf_str text, gU16 count, mf_char *last_char) { - uint16_t i = 0, result = 0; + gU16 i = 0, result = 0; mf_char tmp = 0; if (!count) @@ -115,12 +115,12 @@ static uint16_t strip_spaces(mf_str text, uint16_t count, mf_char *last_char) /* Render left-aligned string, left edge at x0. */ static void render_left(const struct mf_font_s *font, - int16_t x0, int16_t y0, - mf_str text, uint16_t count, + gI16 x0, gI16 y0, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { - int16_t x; + gI16 x; mf_char c1 = 0, c2; x = x0 - font->baseline_x; @@ -150,13 +150,13 @@ static void render_left(const struct mf_font_s *font, #if !MF_USE_ALIGN void mf_render_aligned(const struct mf_font_s *font, - int16_t x0, int16_t y0, + gI16 x0, gI16 y0, enum mf_align_t align, - mf_str text, uint16_t count, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { - int16_t string_width; + gI16 string_width; count = strip_spaces(text, count, 0); render_left(font, x0, y0, text, count, callback, state); } @@ -165,13 +165,13 @@ void mf_render_aligned(const struct mf_font_s *font, /* Render right-aligned string, right edge at x0. */ static void render_right(const struct mf_font_s *font, - int16_t x0, int16_t y0, - mf_str text, uint16_t count, + gI16 x0, gI16 y0, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { - int16_t x; - uint16_t i; + gI16 x; + gU16 i; mf_char c1, c2 = 0; mf_str tmp; @@ -211,13 +211,13 @@ static void render_right(const struct mf_font_s *font, } void mf_render_aligned(const struct mf_font_s *font, - int16_t x0, int16_t y0, + gI16 x0, gI16 y0, enum mf_align_t align, - mf_str text, uint16_t count, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { - int16_t string_width; + gI16 string_width; count = strip_spaces(text, count, 0); if (align == MF_ALIGN_LEFT) @@ -242,8 +242,8 @@ void mf_render_aligned(const struct mf_font_s *font, #if !MF_USE_JUSTIFY void mf_render_justified(const struct mf_font_s *font, - int16_t x0, int16_t y0, int16_t width, - mf_str text, uint16_t count, + gI16 x0, gI16 y0, gI16 width, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { @@ -255,15 +255,15 @@ void mf_render_justified(const struct mf_font_s *font, /* Returns true if the character is a justification point, i.e. expands * when the text is being justified. */ -static bool is_justify_space(uint16_t c) +static bool is_justify_space(gU16 c) { return c == ' ' || c == 0xA0; } /* Count the number of space characters in string */ -static uint16_t count_spaces(mf_str text, uint16_t count) +static gU16 count_spaces(mf_str text, gU16 count) { - uint16_t spaces = 0; + gU16 spaces = 0; while (count-- && *text) { if (is_justify_space(mf_getchar(&text))) @@ -273,13 +273,13 @@ static uint16_t count_spaces(mf_str text, uint16_t count) } void mf_render_justified(const struct mf_font_s *font, - int16_t x0, int16_t y0, int16_t width, - mf_str text, uint16_t count, + gI16 x0, gI16 y0, gI16 width, + mf_str text, gU16 count, mf_character_callback_t callback, void *state) { - int16_t string_width, adjustment; - uint16_t num_spaces; + gI16 string_width, adjustment; + gU16 num_spaces; mf_char last_char; count = strip_spaces(text, count, &last_char); @@ -296,7 +296,7 @@ void mf_render_justified(const struct mf_font_s *font, num_spaces = count_spaces(text, count); { - int16_t x, tmp; + gI16 x, tmp; mf_char c1 = 0, c2; x = x0 - font->baseline_x; diff --git a/src/gdisp/mcufont/mf_justify.h b/src/gdisp/mcufont/mf_justify.h index 3c7622fc..4e4eda9e 100644 --- a/src/gdisp/mcufont/mf_justify.h +++ b/src/gdisp/mcufont/mf_justify.h @@ -29,7 +29,7 @@ enum mf_align_t * state: Free state variable for use by the callback. * Returns the width of the character. */ -typedef uint8_t (*mf_character_callback_t) (int16_t x0, int16_t y0, +typedef gU8 (*mf_character_callback_t) (gI16 x0, gI16 y0, mf_char character, void *state); /* Get width of a string in pixels. @@ -39,8 +39,8 @@ typedef uint8_t (*mf_character_callback_t) (int16_t x0, int16_t y0, * count: Number of characters on the line or 0 to read until end of string. * kern: True to consider kerning (slower). */ -MF_EXTERN int16_t mf_get_string_width(const struct mf_font_s *font, - mf_str text, uint16_t count, bool kern); +MF_EXTERN gI16 mf_get_string_width(const struct mf_font_s *font, + mf_str text, gU16 count, bool kern); /* Render a single line of aligned text. * @@ -54,9 +54,9 @@ MF_EXTERN int16_t mf_get_string_width(const struct mf_font_s *font, * state: Free variable for use in the callback. */ MF_EXTERN void mf_render_aligned(const struct mf_font_s *font, - int16_t x0, int16_t y0, + gI16 x0, gI16 y0, enum mf_align_t align, - mf_str text, uint16_t count, + mf_str text, gU16 count, mf_character_callback_t callback, void *state); @@ -72,8 +72,8 @@ MF_EXTERN void mf_render_aligned(const struct mf_font_s *font, * state: Free variable for use in the callback. */ MF_EXTERN void mf_render_justified(const struct mf_font_s *font, - int16_t x0, int16_t y0, int16_t width, - mf_str text, uint16_t count, + gI16 x0, gI16 y0, gI16 width, + mf_str text, gU16 count, mf_character_callback_t callback, void *state); diff --git a/src/gdisp/mcufont/mf_kerning.c b/src/gdisp/mcufont/mf_kerning.c index 5a5aa65b..1e29b6e2 100644 --- a/src/gdisp/mcufont/mf_kerning.c +++ b/src/gdisp/mcufont/mf_kerning.c @@ -16,12 +16,12 @@ /* Structure for keeping track of the edge of the glyph as it is rendered. */ struct kerning_state_s { - uint8_t edgepos[MF_KERNING_ZONES]; - uint8_t zoneheight; + gU8 edgepos[MF_KERNING_ZONES]; + gU8 zoneheight; }; /* Pixel callback for analyzing the left edge of a glyph. */ -static void fit_leftedge(int16_t x, int16_t y, uint8_t count, uint8_t alpha, +static void fit_leftedge(gI16 x, gI16 y, gU8 count, gU8 alpha, void *state) { struct kerning_state_s *s = state; @@ -29,21 +29,21 @@ static void fit_leftedge(int16_t x, int16_t y, uint8_t count, uint8_t alpha, if (alpha > 7) { - uint8_t zone = y / s->zoneheight; + gU8 zone = y / s->zoneheight; if (x < s->edgepos[zone]) s->edgepos[zone] = x; } } /* Pixel callback for analyzing the right edge of a glyph. */ -static void fit_rightedge(int16_t x, int16_t y, uint8_t count, uint8_t alpha, +static void fit_rightedge(gI16 x, gI16 y, gU8 count, gU8 alpha, void *state) { struct kerning_state_s *s = state; if (alpha > 7) { - uint8_t zone = y / s->zoneheight; + gU8 zone = y / s->zoneheight; x += count - 1; if (x > s->edgepos[zone]) s->edgepos[zone] = x; @@ -65,16 +65,16 @@ static bool do_kerning(mf_char c) return true; } -//static int16_t min16(int16_t a, int16_t b) { return (a < b) ? a : b; } -static int16_t max16(int16_t a, int16_t b) { return (a > b) ? a : b; } -static int16_t avg16(int16_t a, int16_t b) { return (a + b) / 2; } +//static gI16 min16(gI16 a, gI16 b) { return (a < b) ? a : b; } +static gI16 max16(gI16 a, gI16 b) { return (a > b) ? a : b; } +static gI16 avg16(gI16 a, gI16 b) { return (a + b) / 2; } -int8_t mf_compute_kerning(const struct mf_font_s *font, +gI8 mf_compute_kerning(const struct mf_font_s *font, mf_char c1, mf_char c2) { struct kerning_state_s leftedge, rightedge; - uint8_t w1, w2, i, min_space; - int16_t normal_space, adjust, max_adjust; + gU8 w1, w2, i, min_space; + gI16 normal_space, adjust, max_adjust; if (font->flags & MF_FONT_FLAG_MONOSPACE) return 0; /* No kerning for monospace fonts */ @@ -102,7 +102,7 @@ int8_t mf_compute_kerning(const struct mf_font_s *font, min_space = 255; for (i = 0; i < MF_KERNING_ZONES; i++) { - uint8_t space; + gU8 space; if (leftedge.edgepos[i] == 255 || rightedge.edgepos[i] == 0) continue; /* Outside glyph area. */ diff --git a/src/gdisp/mcufont/mf_kerning.h b/src/gdisp/mcufont/mf_kerning.h index 844d99c3..c6c2dcc7 100644 --- a/src/gdisp/mcufont/mf_kerning.h +++ b/src/gdisp/mcufont/mf_kerning.h @@ -25,7 +25,7 @@ * Returns the offset to add to the x position for c2. */ #if MF_USE_KERNING -MF_EXTERN int8_t mf_compute_kerning(const struct mf_font_s *font, +MF_EXTERN gI8 mf_compute_kerning(const struct mf_font_s *font, mf_char c1, mf_char c2); #else #define mf_compute_kerning(font, c1, c2) 0 diff --git a/src/gdisp/mcufont/mf_rlefont.c b/src/gdisp/mcufont/mf_rlefont.c index db217425..1da265c3 100644 --- a/src/gdisp/mcufont/mf_rlefont.c +++ b/src/gdisp/mcufont/mf_rlefont.c @@ -35,8 +35,8 @@ * through the character ranges. If the character is not found, return * pointer to the default glyph. */ -static const uint8_t *find_glyph(const struct mf_rlefont_s *font, - uint16_t character) +static const gU8 *find_glyph(const struct mf_rlefont_s *font, + gU16 character) { unsigned i, index; const struct mf_rlefont_char_range_s *range; @@ -58,21 +58,21 @@ static const uint8_t *find_glyph(const struct mf_rlefont_s *font, * and also the bounds of the character. */ struct renderstate_r { - int16_t x_begin; - int16_t x_end; - int16_t x; - int16_t y; - int16_t y_end; + gI16 x_begin; + gI16 x_end; + gI16 x; + gI16 y; + gI16 y_end; mf_pixel_callback_t callback; void *state; }; /* Call the callback to write one pixel to screen, and advance to next * pixel position. */ -static void write_pixels(struct renderstate_r *rstate, uint16_t count, - uint8_t alpha) +static void write_pixels(struct renderstate_r *rstate, gU16 count, + gU8 alpha) { - uint8_t rowlen; + gU8 rowlen; /* Write row-by-row if the run spans multiple rows. */ while (rstate->x + count >= rstate->x_end) @@ -93,7 +93,7 @@ static void write_pixels(struct renderstate_r *rstate, uint16_t count, } /* Skip the given number of pixels (0 alpha) */ -static void skip_pixels(struct renderstate_r *rstate, uint16_t count) +static void skip_pixels(struct renderstate_r *rstate, gU16 count) { rstate->x += count; while (rstate->x >= rstate->x_end) @@ -106,15 +106,15 @@ static void skip_pixels(struct renderstate_r *rstate, uint16_t count) /* Decode and write out a RLE-encoded dictionary entry. */ static void write_rle_dictentry(const struct mf_rlefont_s *font, struct renderstate_r *rstate, - uint8_t index) + gU8 index) { - uint16_t offset = font->dictionary_offsets[index]; - uint16_t length = font->dictionary_offsets[index + 1] - offset; - uint16_t i; + gU16 offset = font->dictionary_offsets[index]; + gU16 length = font->dictionary_offsets[index + 1] - offset; + gU16 i; for (i = 0; i < length; i++) { - uint8_t code = font->dictionary_data[offset + i]; + gU8 code = font->dictionary_data[offset + i]; if ((code & RLE_CODEMASK) == RLE_ZEROS) { skip_pixels(rstate, code & RLE_VALMASK); @@ -129,7 +129,7 @@ static void write_rle_dictentry(const struct mf_rlefont_s *font, } else if ((code & RLE_CODEMASK) == RLE_SHADE) { - uint8_t count, alpha; + gU8 count, alpha; count = ((code & RLE_VALMASK) >> 4) + 1; alpha = ((code & RLE_VALMASK) & 0xF) * 0x11; write_pixels(rstate, count, alpha); @@ -138,7 +138,7 @@ static void write_rle_dictentry(const struct mf_rlefont_s *font, } /* Get bit count for the "fill entries" */ -static uint8_t fillentry_bitcount(uint8_t index) +static gU8 fillentry_bitcount(gU8 index) { if (index >= DICT_START2BIT) return 2; @@ -157,11 +157,11 @@ static uint8_t fillentry_bitcount(uint8_t index) /* Decode and write out a direct binary codeword */ static void write_bin_codeword(const struct mf_rlefont_s *font, struct renderstate_r *rstate, - uint8_t code) + gU8 code) { - uint8_t bitcount = fillentry_bitcount(code); - uint8_t byte = code - DICT_START7BIT; - uint8_t runlen = 0; + gU8 bitcount = fillentry_bitcount(code); + gU8 byte = code - DICT_START7BIT; + gU8 runlen = 0; (void) font; while (bitcount--) @@ -191,7 +191,7 @@ static void write_bin_codeword(const struct mf_rlefont_s *font, /* Decode and write out a reference codeword */ static void write_ref_codeword(const struct mf_rlefont_s *font, struct renderstate_r *rstate, - uint8_t code) + gU8 code) { if (code <= 15) { @@ -219,15 +219,15 @@ static void write_ref_codeword(const struct mf_rlefont_s *font, /* Decode and write out a reference encoded dictionary entry. */ static void write_ref_dictentry(const struct mf_rlefont_s *font, struct renderstate_r *rstate, - uint8_t index) + gU8 index) { - uint16_t offset = font->dictionary_offsets[index]; - uint16_t length = font->dictionary_offsets[index + 1] - offset; - uint16_t i; + gU16 offset = font->dictionary_offsets[index]; + gU16 length = font->dictionary_offsets[index + 1] - offset; + gU16 i; for (i = 0; i < length; i++) { - uint8_t code = font->dictionary_data[offset + i]; + gU8 code = font->dictionary_data[offset + i]; write_ref_codeword(font, rstate, code); } } @@ -235,7 +235,7 @@ static void write_ref_dictentry(const struct mf_rlefont_s *font, /* Decode and write out an arbitrary glyph codeword */ static void write_glyph_codeword(const struct mf_rlefont_s *font, struct renderstate_r *rstate, - uint8_t code) + gU8 code) { if (code >= DICT_START + font->rle_entry_count && code < DICT_START + font->dict_entry_count) @@ -249,14 +249,14 @@ static void write_glyph_codeword(const struct mf_rlefont_s *font, } -uint8_t mf_rlefont_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +gU8 mf_rlefont_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state) { - const uint8_t *p; - uint8_t width; + const gU8 *p; + gU8 width; struct renderstate_r rstate; rstate.x_begin = x0; @@ -280,10 +280,10 @@ uint8_t mf_rlefont_render_character(const struct mf_font_s *font, return width; } -uint8_t mf_rlefont_character_width(const struct mf_font_s *font, - uint16_t character) +gU8 mf_rlefont_character_width(const struct mf_font_s *font, + gU16 character) { - const uint8_t *p; + const gU8 *p; p = find_glyph((struct mf_rlefont_s*)font, character); if (!p) return 0; diff --git a/src/gdisp/mcufont/mf_rlefont.h b/src/gdisp/mcufont/mf_rlefont.h index 8978f2a3..be21fe88 100644 --- a/src/gdisp/mcufont/mf_rlefont.h +++ b/src/gdisp/mcufont/mf_rlefont.h @@ -23,16 +23,16 @@ struct mf_rlefont_char_range_s { /* The number of the first character in this range. */ - uint16_t first_char; + gU16 first_char; /* The total count of characters in this range. */ - uint16_t char_count; + gU16 char_count; /* Lookup table with the start indices into glyph_data. */ - const uint16_t *glyph_offsets; + const gU16 *glyph_offsets; /* The encoded glyph data for glyphs in this range. */ - const uint8_t *glyph_data; + const gU8 *glyph_data; }; /* Structure for a single encoded font. */ @@ -41,26 +41,26 @@ struct mf_rlefont_s struct mf_font_s font; /* Version of the font definition used. */ - const uint8_t version; + const gU8 version; /* Big array of the data for all the dictionary entries. */ - const uint8_t *dictionary_data; + const gU8 *dictionary_data; /* Lookup table with the start indices into dictionary_data. * Contains N+1 entries, so that the length of the entry can * be determined by subtracting from the next offset. */ - const uint16_t *dictionary_offsets; + const gU16 *dictionary_offsets; /* Number of dictionary entries using the RLE encoding. * Entries starting at this index use the dictionary encoding. */ - const uint8_t rle_entry_count; + const gU8 rle_entry_count; /* Total number of dictionary entries. * Entries after this are nonexistent. */ - const uint8_t dict_entry_count; + const gU8 dict_entry_count; /* Number of discontinuous character ranges */ - const uint16_t char_range_count; + const gU16 char_range_count; /* Array of the character ranges */ const struct mf_rlefont_char_range_s *char_ranges; @@ -68,14 +68,14 @@ struct mf_rlefont_s #ifdef MF_RLEFONT_INTERNALS /* Internal functions, don't use these directly. */ -MF_EXTERN uint8_t mf_rlefont_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +MF_EXTERN gU8 mf_rlefont_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state); -MF_EXTERN uint8_t mf_rlefont_character_width(const struct mf_font_s *font, - uint16_t character); +MF_EXTERN gU8 mf_rlefont_character_width(const struct mf_font_s *font, + gU16 character); #endif #endif diff --git a/src/gdisp/mcufont/mf_scaledfont.c b/src/gdisp/mcufont/mf_scaledfont.c index b3c70a7f..9e0903cc 100644 --- a/src/gdisp/mcufont/mf_scaledfont.c +++ b/src/gdisp/mcufont/mf_scaledfont.c @@ -13,17 +13,17 @@ struct scaled_renderstate { mf_pixel_callback_t orig_callback; void *orig_state; - uint8_t x_scale; - uint8_t y_scale; - int16_t x0; - int16_t y0; + gU8 x_scale; + gU8 y_scale; + gI16 x0; + gI16 y0; }; -static void scaled_pixel_callback(int16_t x, int16_t y, uint8_t count, - uint8_t alpha, void *state) +static void scaled_pixel_callback(gI16 x, gI16 y, gU8 count, + gU8 alpha, void *state) { struct scaled_renderstate *rstate = state; - uint8_t dy; + gU8 dy; count *= rstate->x_scale; x = rstate->x0 + x * rstate->x_scale; @@ -35,26 +35,26 @@ static void scaled_pixel_callback(int16_t x, int16_t y, uint8_t count, } } -uint8_t mf_scaled_character_width(const struct mf_font_s *font, - uint16_t character) +gU8 mf_scaled_character_width(const struct mf_font_s *font, + gU16 character) { struct mf_scaledfont_s *sfont = (struct mf_scaledfont_s*)font; - uint8_t basewidth; + gU8 basewidth; basewidth = sfont->basefont->character_width(sfont->basefont, character); return sfont->x_scale * basewidth; } -uint8_t mf_scaled_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +gU8 mf_scaled_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state) { struct mf_scaledfont_s *sfont = (struct mf_scaledfont_s*)font; struct scaled_renderstate rstate; - uint8_t basewidth; + gU8 basewidth; rstate.orig_callback = callback; rstate.orig_state = state; @@ -71,7 +71,7 @@ uint8_t mf_scaled_render_character(const struct mf_font_s *font, void mf_scale_font(struct mf_scaledfont_s *newfont, const struct mf_font_s *basefont, - uint8_t x_scale, uint8_t y_scale) + gU8 x_scale, gU8 y_scale) { newfont->font = *basefont; newfont->basefont = basefont; diff --git a/src/gdisp/mcufont/mf_scaledfont.h b/src/gdisp/mcufont/mf_scaledfont.h index c82c2093..da9f47aa 100644 --- a/src/gdisp/mcufont/mf_scaledfont.h +++ b/src/gdisp/mcufont/mf_scaledfont.h @@ -19,24 +19,24 @@ struct mf_scaledfont_s struct mf_font_s font; const struct mf_font_s *basefont; - uint8_t x_scale; - uint8_t y_scale; + gU8 x_scale; + gU8 y_scale; }; MF_EXTERN void mf_scale_font(struct mf_scaledfont_s *newfont, const struct mf_font_s *basefont, - uint8_t x_scale, uint8_t y_scale); + gU8 x_scale, gU8 y_scale); #ifdef MF_SCALEDFONT_INTERNALS /* Internal functions, don't use these directly. */ -MF_EXTERN uint8_t mf_scaled_render_character(const struct mf_font_s *font, - int16_t x0, int16_t y0, - uint16_t character, +MF_EXTERN gU8 mf_scaled_render_character(const struct mf_font_s *font, + gI16 x0, gI16 y0, + gU16 character, mf_pixel_callback_t callback, void *state); -MF_EXTERN uint8_t mf_scaled_character_width(const struct mf_font_s *font, - uint16_t character); +MF_EXTERN gU8 mf_scaled_character_width(const struct mf_font_s *font, + gU16 character); #endif #endif diff --git a/src/gdisp/mcufont/mf_wordwrap.c b/src/gdisp/mcufont/mf_wordwrap.c index 06101b32..0b303ace 100644 --- a/src/gdisp/mcufont/mf_wordwrap.c +++ b/src/gdisp/mcufont/mf_wordwrap.c @@ -10,7 +10,7 @@ #ifndef MF_NO_COMPILE /* Returns true if the line can be broken at this character. */ -static bool is_wrap_space(uint16_t c) +static bool is_wrap_space(gU16 c) { return c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '-'; } @@ -20,9 +20,9 @@ static bool is_wrap_space(uint16_t c) /* Represents a single word and the whitespace after it. */ struct wordlen_s { - int16_t word; /* Length of the word in pixels. */ - int16_t space; /* Length of the whitespace in pixels. */ - uint16_t chars; /* Number of characters in word + space, combined. */ + gI16 word; /* Length of the word in pixels. */ + gI16 space; /* Length of the whitespace in pixels. */ + gU16 chars; /* Number of characters in word + space, combined. */ }; /* Take the next word from the string and compute its width. @@ -76,8 +76,8 @@ static bool get_wordlen(const struct mf_font_s *font, mf_str *text, struct linelen_s { mf_str start; /* Start of the text for line. */ - uint16_t chars; /* Total number of characters on the line. */ - int16_t width; /* Total length of all words + whitespace on the line in pixels. */ + gU16 chars; /* Total number of characters on the line. */ + gI16 width; /* Total length of all words + whitespace on the line in pixels. */ bool linebreak; /* True if line ends in a linebreak */ struct wordlen_s last_word; /* Last word on the line. */ struct wordlen_s last_word_2; /* Second to last word on the line. */ @@ -85,7 +85,7 @@ struct linelen_s /* Append word onto the line if it fits. If it would overflow, don't add and * return false. */ -static bool append_word(const struct mf_font_s *font, int16_t width, +static bool append_word(const struct mf_font_s *font, gI16 width, struct linelen_s *current, mf_str *text) { mf_str tmp = *text; @@ -111,12 +111,12 @@ static bool append_word(const struct mf_font_s *font, int16_t width, } /* Append a character to the line if it fits. */ -static bool append_char(const struct mf_font_s *font, int16_t width, +static bool append_char(const struct mf_font_s *font, gI16 width, struct linelen_s *current, mf_str *text) { mf_str tmp = *text; mf_char c; - uint16_t w; + gU16 w; c = mf_getchar(&tmp); w = mf_character_width(font, c); @@ -134,16 +134,16 @@ static bool append_char(const struct mf_font_s *font, int16_t width, } } -static int32_t sq16(int16_t x) { return (int32_t)x * x; } +static gI32 sq16(gI16 x) { return (gI32)x * x; } /* Try to balance the lines by potentially moving one word from the previous * line to the the current one. */ static void tune_lines(struct linelen_s *current, struct linelen_s *previous, - int16_t max_width) + gI16 max_width) { - int16_t curw1, prevw1; - int16_t curw2, prevw2; - int32_t delta1, delta2; + gI16 curw1, prevw1; + gI16 curw2, prevw2; + gI32 delta1, delta2; /* If the lines are rendered as is */ curw1 = current->width - current->last_word.space; @@ -160,7 +160,7 @@ static void tune_lines(struct linelen_s *current, struct linelen_s *previous, if (delta1 > delta2 && curw2 <= max_width) { /* Do the change. */ - uint16_t chars; + gU16 chars; chars = previous->last_word.chars; previous->chars -= chars; @@ -173,13 +173,13 @@ static void tune_lines(struct linelen_s *current, struct linelen_s *previous, } } -void mf_wordwrap(const struct mf_font_s *font, int16_t width, +void mf_wordwrap(const struct mf_font_s *font, gI16 width, mf_str text, mf_line_callback_t callback, void *state) { struct linelen_s current = { 0 }; struct linelen_s previous = { 0 }; bool full; - uint32_t giveUp = 2048; /* Do while-loop a maximum of x times */ + gU32 giveUp = 2048; /* Do while-loop a maximum of x times */ current.start = text; @@ -236,16 +236,16 @@ void mf_wordwrap(const struct mf_font_s *font, int16_t width, #else -void mf_wordwrap(const struct mf_font_s *font, int16_t width, +void mf_wordwrap(const struct mf_font_s *font, gI16 width, mf_str text, mf_line_callback_t callback, void *state) { mf_str linestart; /* Current line width and character count */ - int16_t lw_cur = 0, cc_cur = 0; + gI16 lw_cur = 0, cc_cur = 0; /* Previous wrap point */ - int16_t cc_prev; + gI16 cc_prev; mf_str ls_prev; linestart = text; @@ -258,7 +258,7 @@ void mf_wordwrap(const struct mf_font_s *font, int16_t width, while (*text) { mf_char c; - int16_t new_width; + gI16 new_width; mf_str tmp; tmp = text; diff --git a/src/gdisp/mcufont/mf_wordwrap.h b/src/gdisp/mcufont/mf_wordwrap.h index a1a051fa..91ac8cad 100644 --- a/src/gdisp/mcufont/mf_wordwrap.h +++ b/src/gdisp/mcufont/mf_wordwrap.h @@ -23,7 +23,7 @@ * * Returns: true to continue, false to stop after this line. */ -typedef bool (*mf_line_callback_t) (mf_str line, uint16_t count, +typedef bool (*mf_line_callback_t) (mf_str line, gU16 count, void *state); /* Word wrap a piece of text. Calls the callback function for each line. @@ -33,7 +33,7 @@ typedef bool (*mf_line_callback_t) (mf_str line, uint16_t count, * text: Pointer to the start of the text to process. * state: Free variable for caller to use (can be NULL). */ -MF_EXTERN void mf_wordwrap(const struct mf_font_s *font, int16_t width, +MF_EXTERN void mf_wordwrap(const struct mf_font_s *font, gI16 width, mf_str text, mf_line_callback_t callback, void *state); #endif |