|
|
|
@ -7,25 +7,27 @@
|
|
|
|
|
* @copyright GPL/BSD
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
|
|
#if ENABLED(ULTRA_LCD)
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "fontutils.h"
|
|
|
|
|
#include "u8g_fontutf8.h"
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
#define font_t void
|
|
|
|
|
typedef void font_t;
|
|
|
|
|
|
|
|
|
|
#ifndef PSTR
|
|
|
|
|
#define PSTR(a) a
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
|
memcpy_from_rom(void *dest, const void * rom_src, size_t sz)
|
|
|
|
|
{
|
|
|
|
|
void* memcpy_from_rom(void *dest, const void * rom_src, size_t sz) {
|
|
|
|
|
uint8_t * p;
|
|
|
|
|
uint8_t * s;
|
|
|
|
|
|
|
|
|
|
FU_ASSERT(NULL != dest);
|
|
|
|
|
p = dest;
|
|
|
|
|
s = rom_src;
|
|
|
|
|
p = (uint8_t*)dest;
|
|
|
|
|
s = (uint8_t*)rom_src;
|
|
|
|
|
uint8_t c;
|
|
|
|
|
while ((p - (uint8_t *)dest) < sz) {
|
|
|
|
|
*p = pgm_read_byte(s);
|
|
|
|
@ -79,7 +81,7 @@ static int pf_bsearch_cb_comp_fntifo_pgm (void *userdata, size_t idx, void *data
|
|
|
|
|
uxg_fontinfo_t *fntinfo = (uxg_fontinfo_t*)userdata;
|
|
|
|
|
uxg_fontinfo_t localval;
|
|
|
|
|
memcpy_from_rom(&localval, fntinfo + idx, sizeof(localval));
|
|
|
|
|
return fontinfo_compare(&localval, data_pin);
|
|
|
|
|
return fontinfo_compare(&localval, (uxg_fontinfo_t*)data_pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct _font_group_t {
|
|
|
|
@ -95,7 +97,7 @@ static int fontgroup_init(font_group_t * root, const uxg_fontinfo_t * fntinfo, i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const font_t* fontgroup_find(font_group_t * root, wchar_t val) {
|
|
|
|
|
uxg_fontinfo_t vcmp = {val / 128, val % 128 + 128, val % 128 + 128, 0, 0};
|
|
|
|
|
uxg_fontinfo_t vcmp = {(uint16_t)(val / 128), (uint8_t)(val % 128 + 128), (uint8_t)(val % 128 + 128), 0, 0};
|
|
|
|
|
size_t idx = 0;
|
|
|
|
|
|
|
|
|
|
if (val < 256) return NULL;
|
|
|
|
@ -178,11 +180,11 @@ struct _uxg_drawu8_data_t {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int fontgroup_cb_draw_u8g (void *userdata, const font_t *fnt_current, const char *msg) {
|
|
|
|
|
struct _uxg_drawu8_data_t * pdata = userdata;
|
|
|
|
|
struct _uxg_drawu8_data_t * pdata = (_uxg_drawu8_data_t*)userdata;
|
|
|
|
|
|
|
|
|
|
FU_ASSERT(NULL != userdata);
|
|
|
|
|
if (pdata->fnt_prev != fnt_current) {
|
|
|
|
|
u8g_SetFont(pdata->pu8g, fnt_current);
|
|
|
|
|
u8g_SetFont(pdata->pu8g, (const u8g_fntpgm_uint8_t*)fnt_current);
|
|
|
|
|
//u8g_SetFontPosBottom(pdata->pu8g);
|
|
|
|
|
pdata->fnt_prev = fnt_current;
|
|
|
|
|
}
|
|
|
|
@ -225,7 +227,7 @@ unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t
|
|
|
|
|
data.max_width = max_width;
|
|
|
|
|
data.fnt_prev = NULL;
|
|
|
|
|
fontgroup_drawwchar(group, fnt_default, ch, (void*)&data, fontgroup_cb_draw_u8g);
|
|
|
|
|
u8g_SetFont(pu8g, fnt_default);
|
|
|
|
|
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
|
|
|
|
|
|
|
|
|
|
return data.adv;
|
|
|
|
|
}
|
|
|
|
@ -259,7 +261,7 @@ unsigned int uxg_DrawUtf8Str(u8g_t *pu8g, unsigned int x, unsigned int y, const
|
|
|
|
|
data.max_width = max_width;
|
|
|
|
|
data.fnt_prev = NULL;
|
|
|
|
|
fontgroup_drawstring(group, fnt_default, utf8_msg, strlen(utf8_msg), read_byte_ram, (void*)&data, fontgroup_cb_draw_u8g);
|
|
|
|
|
u8g_SetFont(pu8g, fnt_default);
|
|
|
|
|
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
|
|
|
|
|
|
|
|
|
|
return data.adv;
|
|
|
|
|
}
|
|
|
|
@ -296,18 +298,18 @@ unsigned int uxg_DrawUtf8StrP(u8g_t *pu8g, unsigned int x, unsigned int y, const
|
|
|
|
|
TRACE("call fontgroup_drawstring");
|
|
|
|
|
fontgroup_drawstring(group, fnt_default, utf8_msg, my_strlen_P(utf8_msg), read_byte_rom, (void*)&data, fontgroup_cb_draw_u8g);
|
|
|
|
|
TRACE("restore font");
|
|
|
|
|
u8g_SetFont(pu8g, fnt_default);
|
|
|
|
|
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
|
|
|
|
|
|
|
|
|
|
TRACE("return %d", data.adv);
|
|
|
|
|
return data.adv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int fontgroup_cb_draw_u8gstrlen(void *userdata, const font_t *fnt_current, const char *msg) {
|
|
|
|
|
struct _uxg_drawu8_data_t * pdata = userdata;
|
|
|
|
|
struct _uxg_drawu8_data_t * pdata = (_uxg_drawu8_data_t*)userdata;
|
|
|
|
|
|
|
|
|
|
FU_ASSERT(NULL != userdata);
|
|
|
|
|
if (pdata->fnt_prev != fnt_current) {
|
|
|
|
|
u8g_SetFont(pdata->pu8g, fnt_current);
|
|
|
|
|
u8g_SetFont(pdata->pu8g, (const u8g_fntpgm_uint8_t*)fnt_current);
|
|
|
|
|
u8g_SetFontPosBottom(pdata->pu8g);
|
|
|
|
|
pdata->fnt_prev = fnt_current;
|
|
|
|
|
}
|
|
|
|
@ -339,7 +341,7 @@ int uxg_GetUtf8StrPixelWidth(u8g_t *pu8g, const char *utf8_msg) {
|
|
|
|
|
data.pu8g = pu8g;
|
|
|
|
|
data.adv = 0;
|
|
|
|
|
fontgroup_drawstring(group, fnt_default, utf8_msg, strlen(utf8_msg), read_byte_ram, (void*)&data, fontgroup_cb_draw_u8gstrlen);
|
|
|
|
|
u8g_SetFont(pu8g, fnt_default);
|
|
|
|
|
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
|
|
|
|
|
|
|
|
|
|
return data.adv;
|
|
|
|
|
}
|
|
|
|
@ -367,6 +369,8 @@ int uxg_GetUtf8StrPixelWidthP(u8g_t *pu8g, const char *utf8_msg) {
|
|
|
|
|
data.pu8g = pu8g;
|
|
|
|
|
data.adv = 0;
|
|
|
|
|
fontgroup_drawstring(group, fnt_default, utf8_msg, my_strlen_P(utf8_msg), read_byte_rom, (void*)&data, fontgroup_cb_draw_u8gstrlen);
|
|
|
|
|
u8g_SetFont(pu8g, fnt_default);
|
|
|
|
|
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
|
|
|
|
|
return data.adv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // ENABLED(ULTRA_LCD)
|