Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break the language barrier of TFT Color UI #25073

Merged
merged 8 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,15 @@
//#define TFT_LVGL_UI

#if ENABLED(TFT_COLOR_UI)
/**
* TFT Font for Color_UI. Choose one of the following:
*
* NOTOSANS - Default font with antialiasing. Supports Latin Extended and non-Latin characters.
* UNIFONT - Lightweight font, no antialiasing. Supports Latin Extended and non-Latin characters.
* HELVETICA - Lightweight font, no antialiasing. Supports Basic Latin (0x0020-0x007F) and Latin-1 Supplement (0x0080-0x00FF) characters only.
*/
#define TFT_FONT NOTOSANS

//#define TFT_SHARED_SPI // SPI is shared between TFT display and other devices. Disable async data transfer
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/SAMD21/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {

}
else if (timer_config[timer_num].type==TimerType::tcc) {

Tcc * const tc = timer_config[timer_num].pTcc;

PM->APBCMASK.reg |= PM_APBCMASK_TCC0;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3327,7 +3327,7 @@
#endif

// Number of VFAT entries used. Each entry has 13 UTF-16 characters
#if EITHER(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2)
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
#define MAX_VFAT_ENTRIES (5)
#else
#define MAX_VFAT_ENTRIES (2)
Expand Down
18 changes: 16 additions & 2 deletions Marlin/src/lcd/tft/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

uint16_t CANVAS::width, CANVAS::height;
uint16_t CANVAS::startLine, CANVAS::endLine;
uint16_t CANVAS::background_color;
uint16_t *CANVAS::buffer = TFT::buffer;

void CANVAS::New(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
Expand Down Expand Up @@ -61,18 +62,31 @@ void CANVAS::SetBackground(uint16_t color) {
uint32_t count = ((endLine - startLine) * width + 1) >> 1;
uint32_t *pointer = (uint32_t *)buffer;
while (count--) *pointer++ = two_pixels;
background_color = color;
}

void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, uint16_t maxWidth) {
extern uint16_t gradient(uint16_t colorA, uint16_t colorB, uint16_t factor);

void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint16_t *string, uint16_t maxWidth) {
if (endLine < y || startLine > y + GetFontHeight()) return;

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

uint16_t colors[16];
uint16_t stringWidth = 0;
for (uint16_t i = 0 ; *(string + i) ; i++) {
glyph_t *glyph = Glyph(string + i);
if (stringWidth + glyph->BBXWidth > maxWidth) break;
AddImage(x + stringWidth + glyph->BBXOffsetX, y + Font()->FontAscent - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE1, ((uint8_t *)glyph) + sizeof(glyph_t), &color);
switch (GetFontType()) {
case FONT_MARLIN_GLYPHS_1BPP:
AddImage(x + stringWidth + glyph->BBXOffsetX, y + GetFontAscent() - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE1, ((uint8_t *)glyph) + sizeof(glyph_t), &color);
break;
case FONT_MARLIN_GLYPHS_2BPP:
for (uint8_t i = 0; i < 3; i++)
colors[i] = gradient(color, background_color, ((i+1) << 8) / 3);
AddImage(x + stringWidth + glyph->BBXOffsetX, y + GetFontAscent() - glyph->BBXHeight - glyph->BBXOffsetY, glyph->BBXWidth, glyph->BBXHeight, GREYSCALE2, ((uint8_t *)glyph) + sizeof(glyph_t), colors);
break;
}
stringWidth += glyph->DWidth;
}
}
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/tft/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

class CANVAS {
private:
static uint16_t background_color;
static uint16_t width, height;
static uint16_t startLine, endLine;
static uint16_t *buffer;

inline static font_t *Font() { return TFT_String::font(); }
inline static glyph_t *Glyph(uint8_t *character) { return TFT_String::glyph(character); }
inline static glyph_t *Glyph(uint16_t *character) { return TFT_String::glyph(character); }
inline static uint16_t GetFontType() { return TFT_String::font_type(); }
inline static uint16_t GetFontAscent() { return TFT_String::font_ascent(); }
inline static uint16_t GetFontHeight() { return TFT_String::font_height(); }

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);
Expand All @@ -47,7 +49,7 @@ class CANVAS {
static bool ToScreen();

static void SetBackground(uint16_t color);
static void AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, uint16_t maxWidth);
static void AddText(uint16_t x, uint16_t y, uint16_t color, uint16_t *string, uint16_t maxWidth);
static void AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors);

static void AddRectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
Expand Down
440 changes: 440 additions & 0 deletions Marlin/src/lcd/tft/fontdata/Helvetica/Helvetica_19.cpp

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Marlin/src/lcd/tft/fontdata/Helvetica/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 1984-1989, 1994 Adobe Systems Incorporated.
Copyright 1988, 1994 Digital Equipment Corporation.

Adobe is a trademark of Adobe Systems Incorporated which may be
registered in certain jurisdictions.
Permission to use these trademarks is hereby granted only in
association with the images described in this file.

Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notices appear in all
copies and that both those copyright notices and this permission
notice appear in supporting documentation, and that the names of
Adobe Systems and Digital Equipment Corporation not be used in
advertising or publicity pertaining to distribution of the software
without specific, written prior permission. Adobe Systems and
Digital Equipment Corporation make no representations about the
suitability of this software for any purpose. It is provided "as
is" without express or implied warranty.
Loading