Skip to content

Commit fca1929

Browse files
authored
✨⚡️ UTF support for TFT Color UI (#25073)
1 parent 88242e0 commit fca1929

File tree

92 files changed

+19808
-2337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+19808
-2337
lines changed

Marlin/Configuration.h

+9
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,15 @@
31333133
//#define TFT_LVGL_UI
31343134

31353135
#if ENABLED(TFT_COLOR_UI)
3136+
/**
3137+
* TFT Font for Color_UI. Choose one of the following:
3138+
*
3139+
* NOTOSANS - Default font with antialiasing. Supports Latin Extended and non-Latin characters.
3140+
* UNIFONT - Lightweight font, no antialiasing. Supports Latin Extended and non-Latin characters.
3141+
* HELVETICA - Lightweight font, no antialiasing. Supports Basic Latin (0x0020-0x007F) and Latin-1 Supplement (0x0080-0x00FF) characters only.
3142+
*/
3143+
#define TFT_FONT NOTOSANS
3144+
31363145
//#define TFT_SHARED_SPI // SPI is shared between TFT display and other devices. Disable async data transfer
31373146
#endif
31383147

Marlin/src/HAL/SAMD21/timers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
135135

136136
}
137137
else if (timer_config[timer_num].type==TimerType::tcc) {
138-
138+
139139
Tcc * const tc = timer_config[timer_num].pTcc;
140140

141141
PM->APBCMASK.reg |= PM_APBCMASK_TCC0;

Marlin/src/inc/Conditionals_post.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@
33273327
#endif
33283328

33293329
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
3330-
#if EITHER(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2)
3330+
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
33313331
#define MAX_VFAT_ENTRIES (5)
33323332
#else
33333333
#define MAX_VFAT_ENTRIES (2)

Marlin/src/lcd/tft/canvas.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
uint16_t CANVAS::width, CANVAS::height;
3030
uint16_t CANVAS::startLine, CANVAS::endLine;
31+
uint16_t CANVAS::background_color;
3132
uint16_t *CANVAS::buffer = TFT::buffer;
3233

3334
void CANVAS::New(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
@@ -61,18 +62,31 @@ void CANVAS::SetBackground(uint16_t color) {
6162
uint32_t count = ((endLine - startLine) * width + 1) >> 1;
6263
uint32_t *pointer = (uint32_t *)buffer;
6364
while (count--) *pointer++ = two_pixels;
65+
background_color = color;
6466
}
6567

66-
void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, uint16_t maxWidth) {
68+
extern uint16_t gradient(uint16_t colorA, uint16_t colorB, uint16_t factor);
69+
70+
void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint16_t *string, uint16_t maxWidth) {
6771
if (endLine < y || startLine > y + GetFontHeight()) return;
6872

6973
if (maxWidth == 0) maxWidth = width - x;
7074

75+
uint16_t colors[16];
7176
uint16_t stringWidth = 0;
7277
for (uint16_t i = 0 ; *(string + i) ; i++) {
7378
glyph_t *glyph = Glyph(string + i);
7479
if (stringWidth + glyph->BBXWidth > maxWidth) break;
75-
AddImage(x + stringWidth + glyph->BBXOffsetX, y + Font()->FontAscent - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE1, ((uint8_t *)glyph) + sizeof(glyph_t), &color);
80+
switch (GetFontType()) {
81+
case FONT_MARLIN_GLYPHS_1BPP:
82+
AddImage(x + stringWidth + glyph->BBXOffsetX, y + GetFontAscent() - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE1, ((uint8_t *)glyph) + sizeof(glyph_t), &color);
83+
break;
84+
case FONT_MARLIN_GLYPHS_2BPP:
85+
for (uint8_t i = 0; i < 3; i++)
86+
colors[i] = gradient(color, background_color, ((i+1) << 8) / 3);
87+
AddImage(x + stringWidth + glyph->BBXOffsetX, y + GetFontAscent() - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE2, ((uint8_t *)glyph) + sizeof(glyph_t), colors);
88+
break;
89+
}
7690
stringWidth += glyph->DWidth;
7791
}
7892
}

Marlin/src/lcd/tft/canvas.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030

3131
class CANVAS {
3232
private:
33+
static uint16_t background_color;
3334
static uint16_t width, height;
3435
static uint16_t startLine, endLine;
3536
static uint16_t *buffer;
3637

37-
inline static font_t *Font() { return TFT_String::font(); }
38-
inline static glyph_t *Glyph(uint8_t *character) { return TFT_String::glyph(character); }
38+
inline static glyph_t *Glyph(uint16_t *character) { return TFT_String::glyph(character); }
39+
inline static uint16_t GetFontType() { return TFT_String::font_type(); }
40+
inline static uint16_t GetFontAscent() { return TFT_String::font_ascent(); }
3941
inline static uint16_t GetFontHeight() { return TFT_String::font_height(); }
4042

4143
static void AddImage(int16_t x, int16_t y, uint8_t image_width, uint8_t image_height, colorMode_t color_mode, uint8_t *data, uint16_t *colors);
@@ -47,7 +49,7 @@ class CANVAS {
4749
static bool ToScreen();
4850

4951
static void SetBackground(uint16_t color);
50-
static void AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, uint16_t maxWidth);
52+
static void AddText(uint16_t x, uint16_t y, uint16_t color, uint16_t *string, uint16_t maxWidth);
5153
static void AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors);
5254

5355
static void AddRectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);

Marlin/src/lcd/tft/fontdata/Helvetica/Helvetica_19.cpp

+440
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 1984-1989, 1994 Adobe Systems Incorporated.
2+
Copyright 1988, 1994 Digital Equipment Corporation.
3+
4+
Adobe is a trademark of Adobe Systems Incorporated which may be
5+
registered in certain jurisdictions.
6+
Permission to use these trademarks is hereby granted only in
7+
association with the images described in this file.
8+
9+
Permission to use, copy, modify, distribute and sell this software
10+
and its documentation for any purpose and without fee is hereby
11+
granted, provided that the above copyright notices appear in all
12+
copies and that both those copyright notices and this permission
13+
notice appear in supporting documentation, and that the names of
14+
Adobe Systems and Digital Equipment Corporation not be used in
15+
advertising or publicity pertaining to distribution of the software
16+
without specific, written prior permission. Adobe Systems and
17+
Digital Equipment Corporation make no representations about the
18+
suitability of this software for any purpose. It is provided "as
19+
is" without express or implied warranty.

0 commit comments

Comments
 (0)