2013-05-01 23:53:28 +00:00
|
|
|
/*
|
2013-06-15 11:37:22 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-05-03 14:36:17 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-05-03 14:36:17 +00:00
|
|
|
*/
|
2013-03-10 06:14:32 +00:00
|
|
|
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "../../gfx.h"
|
2013-03-10 06:14:32 +00:00
|
|
|
|
|
|
|
#if GFX_USE_GDISP && GDISP_NEED_TEXT
|
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
#include "mcufont/mcufont.h"
|
2013-03-10 06:14:32 +00:00
|
|
|
|
2016-11-13 23:15:51 +00:00
|
|
|
#define FONT_FLAG_DYNAMIC 0x80 // Custom flag to indicate dynamically allocated font
|
|
|
|
#define FONT_FLAG_UNLISTED 0x40 // Custom flag to indicate font is not currently listed
|
|
|
|
|
|
|
|
static const struct mf_font_list_s *fontList;
|
2013-03-10 06:14:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2013-07-28 07:08:45 +00:00
|
|
|
const struct mf_font_list_s *fp;
|
|
|
|
|
2016-11-13 23:15:51 +00:00
|
|
|
if (!fontList)
|
|
|
|
fontList = mf_get_font_list();
|
|
|
|
|
2013-08-17 13:33:31 +00:00
|
|
|
// Try the long names first
|
2016-11-13 23:15:51 +00:00
|
|
|
for(fp = fontList; fp; fp = fp->next) {
|
2013-08-17 13:33:31 +00:00
|
|
|
if (matchfont(name, fp->font->full_name))
|
|
|
|
return fp->font;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try the short names if no long names match
|
2016-11-13 23:15:51 +00:00
|
|
|
for(fp = fontList; fp; fp = fp->next) {
|
2013-07-28 07:08:45 +00:00
|
|
|
if (matchfont(name, fp->font->short_name))
|
|
|
|
return fp->font;
|
2013-03-10 06:14:32 +00:00
|
|
|
}
|
2013-07-28 07:08:45 +00:00
|
|
|
|
2016-11-13 23:15:51 +00:00
|
|
|
/* Return default builtin font.. better than nothing. */
|
2013-07-28 07:08:45 +00:00
|
|
|
return mf_get_font_list()->font;
|
2013-03-10 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gdispCloseFont(font_t font) {
|
2016-11-13 23:15:51 +00:00
|
|
|
if ((font->flags & (FONT_FLAG_DYNAMIC|FONT_FLAG_UNLISTED)) == (FONT_FLAG_DYNAMIC|FONT_FLAG_UNLISTED)) {
|
2013-07-28 07:08:45 +00:00
|
|
|
/* Make sure that no-one can successfully use font after closing */
|
2016-11-13 23:15:51 +00:00
|
|
|
((struct mf_font_s *)font)->render_character = 0;
|
2013-07-28 07:08:45 +00:00
|
|
|
|
|
|
|
/* Release the allocated memory */
|
2016-11-13 23:15:51 +00:00
|
|
|
gfxFree((void *)font);
|
2013-07-28 07:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
font_t gdispScaleFont(font_t font, uint8_t scale_x, uint8_t scale_y)
|
|
|
|
{
|
2016-11-13 23:15:51 +00:00
|
|
|
struct mf_scaledfont_s *newfont;
|
|
|
|
|
|
|
|
if (!(newfont = gfxAlloc(sizeof(struct mf_scaledfont_s))))
|
|
|
|
return 0;
|
|
|
|
|
2013-07-28 07:08:45 +00:00
|
|
|
mf_scale_font(newfont, font, scale_x, scale_y);
|
2016-11-13 23:15:51 +00:00
|
|
|
((struct mf_font_s *)newfont)->flags |= FONT_FLAG_DYNAMIC|FONT_FLAG_UNLISTED;
|
2013-07-28 07:08:45 +00:00
|
|
|
return (font_t)newfont;
|
2013-03-10 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *gdispGetFontName(font_t font) {
|
2013-07-28 07:08:45 +00:00
|
|
|
return font->short_name;
|
2013-03-10 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-13 23:15:51 +00:00
|
|
|
bool_t gdispAddFont(font_t font) {
|
|
|
|
struct mf_font_list_s *hdr;
|
|
|
|
|
|
|
|
if ((font->flags & (FONT_FLAG_DYNAMIC|FONT_FLAG_UNLISTED)) != (FONT_FLAG_DYNAMIC|FONT_FLAG_UNLISTED))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(hdr = gfxAlloc(sizeof(struct mf_font_list_s))))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!fontList)
|
|
|
|
fontList = mf_get_font_list();
|
|
|
|
hdr->font = (const struct mf_font_s *)font;
|
|
|
|
hdr->next = fontList;
|
|
|
|
((struct mf_font_s *)font)->flags &= ~FONT_FLAG_UNLISTED;
|
|
|
|
fontList = hdr;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-10 06:14:32 +00:00
|
|
|
#endif /* GFX_USE_GDISP && GDISP_NEED_TEXT */
|