diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-08-20 17:42:53 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-08-20 17:42:53 +1000 |
commit | 0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478 (patch) | |
tree | 3dc625e7dfcfc620e83827ccd18423be1b5334f4 /src/gdisp/gdisp_fonts.c | |
parent | fcbb66a9394eaf4059bc942df6729b4b55a057d8 (diff) | |
download | uGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.tar.gz uGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.tar.bz2 uGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.zip |
Rename lots of files to help prevent compile time name conflicts.
Diffstat (limited to 'src/gdisp/gdisp_fonts.c')
-rw-r--r-- | src/gdisp/gdisp_fonts.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/gdisp/gdisp_fonts.c b/src/gdisp/gdisp_fonts.c new file mode 100644 index 00000000..cdb8e075 --- /dev/null +++ b/src/gdisp/gdisp_fonts.c @@ -0,0 +1,96 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gdisp/gdisp_fonts.c + * @brief GDISP Font Handling. + * + * @addtogroup GDISP + * @{ + */ + +#include "gfx.h" + +#if GFX_USE_GDISP && GDISP_NEED_TEXT + +#include "mcufont/mcufont.h" + +/* Custom flag to indicate dynamically allocated font */ +#define FONT_FLAG_DYNAMIC 0x80 + +/** + * Match a pattern against the font name. + */ +static bool_t matchfont(const char *pattern, const char *name) { + while(1) { + switch (pattern[0]) { + case '*': + if (name[0] == 0) + return pattern[1] == 0; + if (pattern[1] == name[0]) + pattern++; + else + name++; + break; + case 0: + return name[0] == 0; + default: + if (name[0] != pattern[0]) + return FALSE; + pattern++; + name++; + break; + } + } +} + +font_t gdispOpenFont(const char *name) { + const struct mf_font_list_s *fp; + + + // Try the long names first + for(fp = mf_get_font_list(); fp; fp = fp->next) { + if (matchfont(name, fp->font->full_name)) + return fp->font; + } + + // Try the short names if no long names match + for(fp = mf_get_font_list(); fp; fp = fp->next) { + if (matchfont(name, fp->font->short_name)) + return fp->font; + } + + /* Return default font.. better than nothing. */ + return mf_get_font_list()->font; +} + +void gdispCloseFont(font_t font) { + if (font->flags & FONT_FLAG_DYNAMIC) + { + struct mf_font_s *dfont = (struct mf_font_s *)font; + + /* Make sure that no-one can successfully use font after closing */ + dfont->render_character = 0; + + /* Release the allocated memory */ + gfxFree(dfont); + } +} + +font_t gdispScaleFont(font_t font, uint8_t scale_x, uint8_t scale_y) +{ + struct mf_scaledfont_s *newfont = gfxAlloc(sizeof(struct mf_scaledfont_s)); + mf_scale_font(newfont, font, scale_x, scale_y); + return (font_t)newfont; +} + +const char *gdispGetFontName(font_t font) { + return font->short_name; +} + +#endif /* GFX_USE_GDISP && GDISP_NEED_TEXT */ +/** @} */ |