Browse Source

Support negative baseline_x in a font.

remotes/origin_old/release/v2.9
inmarket 5 years ago
parent
commit
013bac84ce
  1. 28
      src/gdisp/mcufont/mf_font.h
  2. 8
      src/gdisp/mcufont/mf_wordwrap.c

28
src/gdisp/mcufont/mf_font.h

@ -30,35 +30,35 @@ struct mf_font_s
{
/* Full name of the font, comes from the original font file. */
const char *full_name;
/* Short name of the font, comes from file name. */
const char *short_name;
/* Width and height of the character bounding box. */
uint8_t width;
uint8_t height;
/* Minimum and maximum tracking width of characters. */
uint8_t min_x_advance;
uint8_t max_x_advance;
/* Location of the text baseline relative to character. */
uint8_t baseline_x;
int8_t baseline_x;
uint8_t baseline_y;
/* Line height of the font (vertical advance). */
uint8_t line_height;
/* Flags identifying various aspects of the font. */
uint8_t flags;
/* Fallback character to use for missing glyphs. */
uint16_t 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);
/* 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,
@ -80,14 +80,14 @@ struct mf_font_list_s
};
/* Function to decode and render a single character.
*
/* Function to decode and render a single character.
*
* font: Pointer to the font definition.
* x0, y0: Upper left corner of the target area.
* character: The character code (unicode) to render.
* callback: Callback function to write out the pixels.
* state: Free variable for caller to use (can be NULL).
*
*
* Returns width of the character.
*/
MF_EXTERN uint8_t mf_render_character(const struct mf_font_s *font,
@ -102,7 +102,7 @@ MF_EXTERN uint8_t mf_render_character(const struct mf_font_s *font,
*
* font: Pointer to the font definition.
* character: The character code (unicode) to render.
*
*
* Returns width of the character in pixels.
*/
MF_EXTERN uint8_t mf_character_width(const struct mf_font_s *font,

8
src/gdisp/mcufont/mf_wordwrap.c

@ -32,11 +32,11 @@ static bool get_wordlen(const struct mf_font_s *font, mf_str *text,
{
mf_char c;
mf_str prev = *text;
result->word = 0;
result->space = 0;
result->chars = 0;
c = mf_getchar(text);
while (c && !is_wrap_space(c))
{
@ -51,10 +51,8 @@ static bool get_wordlen(const struct mf_font_s *font, mf_str *text,
{
result->chars++;
if (c == ' ')
if (c == ' ' || c == '-')
result->space += mf_character_width(font, c);
else if (c == '-')
result->space += mf_character_width(font, '-');
else if (c == '\t')
result->space += mf_character_width(font, 'm') * MF_TABSIZE;
else if (c == '\n') {

Loading…
Cancel
Save