Support negative baseline_x in a font.

This commit is contained in:
inmarket 2018-01-09 17:53:30 +10:00
parent c41cbd05e9
commit 013bac84ce
2 changed files with 17 additions and 19 deletions

View File

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

View File

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