Add extra font metrics

ugfx_release_2.6
inmarket 2015-10-06 12:02:58 +10:00
parent b9c3ddf839
commit 53cb1af757
2 changed files with 32 additions and 5 deletions

View File

@ -3313,6 +3313,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
case fontCharPadding: return 0; case fontCharPadding: return 0;
case fontMinWidth: return font->min_x_advance; case fontMinWidth: return font->min_x_advance;
case fontMaxWidth: return font->max_x_advance; case fontMaxWidth: return font->max_x_advance;
case fontBaselineX: return font->baseline_x;
case fontBaselineY: return font->baseline_y;
} }
return 0; return 0;
} }
@ -3322,12 +3324,20 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
return mf_character_width(font, c); return mf_character_width(font, c);
} }
coord_t gdispGetStringWidth(const char* str, font_t font) { coord_t gdispGetStringWidthCount(const char* str, font_t font, uint16_t count) {
if (!str) if (!str)
return 0; return 0;
/* No mutex required as we only read static data */ // No mutex required as we only read static data
return mf_get_string_width(font, str, 0, 0); #if GDISP_NEED_TEXT_KERNING
return mf_get_string_width(font, str, count, TRUE);
#else
return mf_get_string_width(font, str, count, FALSE);
#endif
}
coord_t gdispGetStringWidth(const char* str, font_t font) {
return gdispGetStringWidthCount(str, font, 0);
} }
#endif #endif

View File

@ -72,7 +72,9 @@ typedef enum fontmetric {
fontLineSpacing, /**< The line spacing */ fontLineSpacing, /**< The line spacing */
fontCharPadding, /**< The char padding */ fontCharPadding, /**< The char padding */
fontMinWidth, /**< The minimum width */ fontMinWidth, /**< The minimum width */
fontMaxWidth /**< The maximum width */ fontMaxWidth, /**< The maximum width */
fontBaselineX, /**< The base line in x direction */
fontBaselineY /**< The base line in y direction */
} fontmetric_t; } fontmetric_t;
/** /**
@ -976,7 +978,22 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
coord_t gdispGetCharWidth(char c, font_t font); coord_t gdispGetCharWidth(char c, font_t font);
/** /**
* @brief Get the pixel width of a string. * @brief Get the pixel width of a string of a given character length.
* @return The width of the string in pixels.
* @pre GDISP_NEED_TEXT must be TRUE in your gfxconf.h
*
* @note Passing 0 to count has the same effect as calling gdispGetStringWidt()
*
* @param[in] str The string to measure
* @param[in] font The font to use
* @param[in] count The number of characters to take into account
*
* @api
*/
coord_t gdispGetStringWidthCount(const char* str, font_t font, uint16_t count);
/**
* @brief Get the pixel width of an entire string.
* @return The width of the string in pixels. * @return The width of the string in pixels.
* @pre GDISP_NEED_TEXT must be TRUE in your gfxconf.h * @pre GDISP_NEED_TEXT must be TRUE in your gfxconf.h
* *