parent
b9647d1296
commit
223d1b20fb
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
static uint8_t convert_char(const uint8_t c) {
|
||||
static char last_was_utf8 = 0;
|
||||
|
||||
// non-printable ASCII character
|
||||
if (c < ' ') {
|
||||
last_was_utf8 = 0;
|
||||
return 0x7F;
|
||||
}
|
||||
|
||||
// regular ASCII character
|
||||
if (c < 0x80) {
|
||||
last_was_utf8 = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
// UTF-8 handling: https://en.wikipedia.org/wiki/UTF-8#Encoding
|
||||
|
||||
// bytes 11xxxxxx are first bytes of UTF-8 characters
|
||||
if (c >= 0xC0) {
|
||||
last_was_utf8 = 1;
|
||||
return 0x7F;
|
||||
}
|
||||
|
||||
if (last_was_utf8) {
|
||||
// bytes 10xxxxxx can be successive UTF-8 characters ...
|
||||
return 0; // skip glyph
|
||||
} else {
|
||||
// ... or they are just non-printable ASCII characters
|
||||
return 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
int font_height(int font) {
|
||||
switch (font) {
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
case FONT_NORMAL:
|
||||
return FONT_NORMAL_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
case FONT_MEDIUM:
|
||||
return FONT_MEDIUM_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
case FONT_BOLD:
|
||||
return FONT_BOLD_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
case FONT_MONO:
|
||||
return FONT_MONO_HEIGHT;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int font_max_height(int font) {
|
||||
switch (font) {
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
case FONT_NORMAL:
|
||||
return FONT_NORMAL_MAX_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
case FONT_MEDIUM:
|
||||
return FONT_MEDIUM_MAX_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
case FONT_BOLD:
|
||||
return FONT_BOLD_MAX_HEIGHT;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
case FONT_MONO:
|
||||
return FONT_MONO_MAX_HEIGHT;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int font_baseline(int font) {
|
||||
switch (font) {
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
case FONT_NORMAL:
|
||||
return FONT_NORMAL_BASELINE;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
case FONT_MEDIUM:
|
||||
return FONT_MEDIUM_BASELINE;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
case FONT_BOLD:
|
||||
return FONT_BOLD_BASELINE;
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
case FONT_MONO:
|
||||
return FONT_MONO_BASELINE;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t *font_get_glyph(int font, uint8_t c) {
|
||||
c = convert_char(c);
|
||||
if (!c) return 0;
|
||||
|
||||
// printable ASCII character
|
||||
if (c >= ' ' && c < 0x7F) {
|
||||
switch (font) {
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
case FONT_NORMAL:
|
||||
return FONT_NORMAL_DATA[c - ' '];
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
case FONT_MEDIUM:
|
||||
return FONT_MEDIUM_DATA[c - ' '];
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
case FONT_BOLD:
|
||||
return FONT_BOLD_DATA[c - ' '];
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
case FONT_MONO:
|
||||
return FONT_MONO_DATA[c - ' '];
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// non-printable character
|
||||
#define PASTER(s) s##_glyph_nonprintable
|
||||
#define NONPRINTABLE_GLYPH(s) PASTER(s)
|
||||
|
||||
switch (font) {
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
case FONT_NORMAL:
|
||||
return NONPRINTABLE_GLYPH(FONT_NORMAL_DATA);
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
case FONT_MEDIUM:
|
||||
return NONPRINTABLE_GLYPH(FONT_MEDIUM_DATA);
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
case FONT_BOLD:
|
||||
return NONPRINTABLE_GLYPH(FONT_BOLD_DATA);
|
||||
#endif
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
case FONT_MONO:
|
||||
return NONPRINTABLE_GLYPH(FONT_MONO_DATA);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _FONTS_H
|
||||
#define _FONTS_H
|
||||
|
||||
#include "fonts/font_bitmap.h"
|
||||
|
||||
#if defined TREZOR_MODEL_T
|
||||
#define TREZOR_FONT_BPP 4
|
||||
#elif defined TREZOR_MODEL_1
|
||||
#define TREZOR_FONT_BPP 1
|
||||
#elif defined TREZOR_MODEL_R
|
||||
#define TREZOR_FONT_BPP 1
|
||||
#else
|
||||
#error Unknown Trezor model
|
||||
#endif
|
||||
|
||||
#define COMPOSE(font_name, suffix) font_name##suffix
|
||||
#define FONT_DEFINE(s, suffix) COMPOSE(s, suffix)
|
||||
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
#define FONT_NORMAL (-1)
|
||||
#include TREZOR_FONT_NORMAL_INCLUDE
|
||||
#define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_ENABLE
|
||||
#define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _HEIGHT)
|
||||
#define FONT_NORMAL_MAX_HEIGHT \
|
||||
FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _MAX_HEIGHT)
|
||||
#define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _BASELINE)
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
#include TREZOR_FONT_MEDIUM_INCLUDE
|
||||
#define FONT_MEDIUM (-5)
|
||||
#define FONT_MEDIUM_DATA TREZOR_FONT_MEDIUM_ENABLE
|
||||
#define FONT_MEDIUM_HEIGHT FONT_DEFINE(TREZOR_FONT_MEDIUM_ENABLE, _HEIGHT)
|
||||
#define FONT_MEDIUM_MAX_HEIGHT \
|
||||
FONT_DEFINE(TREZOR_FONT_MEDIUM_ENABLE, _MAX_HEIGHT)
|
||||
#define FONT_MEDIUM_BASELINE FONT_DEFINE(TREZOR_FONT_MEDIUM_ENABLE, _BASELINE)
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
#include TREZOR_FONT_MONO_INCLUDE
|
||||
#define FONT_MONO (-3)
|
||||
#define FONT_MONO_DATA TREZOR_FONT_MONO_ENABLE
|
||||
#define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _HEIGHT)
|
||||
#define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _MAX_HEIGHT)
|
||||
#define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _BASELINE)
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
#include TREZOR_FONT_BOLD_INCLUDE
|
||||
#define FONT_BOLD (-2)
|
||||
#define FONT_BOLD_DATA TREZOR_FONT_BOLD_ENABLE
|
||||
#define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _HEIGHT)
|
||||
#define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _MAX_HEIGHT)
|
||||
#define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _BASELINE)
|
||||
#endif
|
||||
|
||||
#define MAX_FONT_H(A, B) ((A) > (B) ? (A) : (B))
|
||||
|
||||
#define FONT_MAX_HEIGHT_1 0
|
||||
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
||||
#define FONT_MAX_HEIGHT_2 MAX_FONT_H(FONT_NORMAL_MAX_HEIGHT, FONT_MAX_HEIGHT_1)
|
||||
#else
|
||||
#define FONT_MAX_HEIGHT_2 FONT_MAX_HEIGHT_1
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_BOLD_ENABLE
|
||||
#define FONT_MAX_HEIGHT_3 MAX_FONT_H(FONT_BOLD_MAX_HEIGHT, FONT_MAX_HEIGHT_2)
|
||||
#else
|
||||
#define FONT_MAX_HEIGHT_3 FONT_MAX_HEIGHT_2
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_MEDIUM_ENABLE
|
||||
#define FONT_MAX_HEIGHT_4 MAX_FONT_H(FONT_MEDIUM_MAX_HEIGHT, FONT_MAX_HEIGHT_3)
|
||||
#else
|
||||
#define FONT_MAX_HEIGHT_4 FONT_MAX_HEIGHT_3
|
||||
#endif
|
||||
|
||||
#ifdef TREZOR_FONT_MONO_ENABLE
|
||||
#define FONT_MAX_HEIGHT MAX_FONT_H(FONT_MONO_MAX_HEIGHT, FONT_MAX_HEIGHT_4)
|
||||
#else
|
||||
#define FONT_MAX_HEIGHT FONT_MAX_HEIGHT_4
|
||||
#endif
|
||||
|
||||
int font_height(int font);
|
||||
int font_max_height(int font);
|
||||
int font_baseline(int font);
|
||||
const uint8_t *font_get_glyph(int font, uint8_t c);
|
||||
|
||||
#endif //_FONTS_H
|
@ -0,0 +1,11 @@
|
||||
|
||||
def add_font(font_name, font, defines, sources):
|
||||
if font is not None:
|
||||
defines += [
|
||||
'TREZOR_FONT_' + font_name + '_ENABLE=' + font,
|
||||
'TREZOR_FONT_' + font_name + '_INCLUDE=\\"' + font.lower() + '.h\\"',
|
||||
]
|
||||
sourcefile = 'embed/extmod/modtrezorui/fonts/' + font.lower() + '.c'
|
||||
if sourcefile not in sources:
|
||||
sources.append(sourcefile)
|
||||
|
Loading…
Reference in new issue