update code base to Marlin 2.0.9.2

This commit is contained in:
Stefan Kalscheuer
2021-10-03 18:57:12 +02:00
parent b9d7ba838e
commit 7077da3591
2617 changed files with 332093 additions and 103438 deletions

180
Marlin/src/lcd/fontutils.cpp Executable file → Normal file
View File

@@ -1,3 +1,25 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* @file fontutils.cpp
* @brief help functions for font and char
@@ -9,8 +31,10 @@
#include "../inc/MarlinConfig.h"
#if HAS_SPI_LCD
#include "ultralcd.h"
#define MAX_UTF8_CHAR_SIZE 4
#if HAS_WIRED_LCD
#include "marlinui.h"
#include "../MarlinCore.h"
#endif
@@ -73,12 +97,19 @@ int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp,
return -1;
}
/* This function gets the character at the pstart position, interpreting UTF8 multybyte sequences
/* Returns true if passed byte is first byte of UTF-8 char sequence */
static inline bool utf8_is_start_byte_of_char(const uint8_t b) {
return 0x80 != (b & 0xC0);
}
/* This function gets the character at the pstart position, interpreting UTF8 multibyte sequences
and returns the pointer to the next character */
uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval) {
uint32_t val = 0;
uint8_t *p = pstart;
#define NEXT_6_BITS() do{ val <<= 6; p++; valcur = cb_read_byte(p); val |= (valcur & 0x3F); }while(0)
uint8_t valcur = cb_read_byte(p);
if (0 == (0x80 & valcur)) {
val = valcur;
@@ -86,74 +117,51 @@ uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t
}
else if (0xC0 == (0xE0 & valcur)) {
val = valcur & 0x1F;
val <<= 6;
p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
NEXT_6_BITS();
p++;
}
else if (0xE0 == (0xF0 & valcur)) {
val = valcur & 0x0F;
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
p++;
}
else if (0xF0 == (0xF8 & valcur)) {
val = valcur & 0x07;
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
p++;
}
else if (0xF8 == (0xFC & valcur)) {
val = valcur & 0x03;
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
p++;
}
else if (0xFC == (0xFE & valcur)) {
val = valcur & 0x01;
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
val <<= 6; p++;
valcur = cb_read_byte(p);
val |= (valcur & 0x3F);
p++;
}
else if (0x80 == (0xC0 & valcur))
for (; 0x80 == (0xC0 & valcur); ) { p++; valcur = cb_read_byte(p); }
#if MAX_UTF8_CHAR_SIZE >= 3
else if (0xE0 == (0xF0 & valcur)) {
val = valcur & 0x0F;
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 4
else if (0xF0 == (0xF8 & valcur)) {
val = valcur & 0x07;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 5
else if (0xF8 == (0xFC & valcur)) {
val = valcur & 0x03;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 6
else if (0xFC == (0xFE & valcur)) {
val = valcur & 0x01;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
else if (!utf8_is_start_byte_of_char(valcur))
for (; !utf8_is_start_byte_of_char(valcur); ) { p++; valcur = cb_read_byte(p); }
else
for (; ((0xFE & valcur) > 0xFC); ) { p++; valcur = cb_read_byte(p); }
for (; 0xFC < (0xFE & valcur); ) { p++; valcur = cb_read_byte(p); }
if (pval) *pval = val;
@@ -161,14 +169,13 @@ uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t
}
static inline uint8_t utf8_strlen_cb(const char *pstart, read_byte_cb_t cb_read_byte) {
uint8_t cnt = 0;
uint8_t *pnext = (uint8_t *)pstart;
for (;;) {
wchar_t ch;
pnext = get_utf8_value_cb(pnext, cb_read_byte, &ch);
if (!ch) break;
cnt++;
uint8_t *p = (uint8_t *)pstart;
if (p) for (;;) {
const uint8_t b = cb_read_byte(p);
if (!b) break;
if (utf8_is_start_byte_of_char(b)) cnt++;
p++;
}
return cnt;
}
@@ -180,3 +187,26 @@ uint8_t utf8_strlen(const char *pstart) {
uint8_t utf8_strlen_P(PGM_P pstart) {
return utf8_strlen_cb(pstart, read_byte_rom);
}
static inline uint8_t utf8_byte_pos_by_char_num_cb(const char *pstart, read_byte_cb_t cb_read_byte, const uint8_t charnum) {
uint8_t *p = (uint8_t *)pstart;
uint8_t char_idx = 0;
uint8_t byte_idx = 0;
for (;;) {
const uint8_t b = cb_read_byte(p + byte_idx);
if (!b) return byte_idx; // Termination byte of string
if (utf8_is_start_byte_of_char(b)) {
char_idx++;
if (char_idx == charnum + 1) return byte_idx;
}
byte_idx++;
}
}
uint8_t utf8_byte_pos_by_char_num(const char *pstart, const uint8_t charnum) {
return utf8_byte_pos_by_char_num_cb(pstart, read_byte_ram, charnum);
}
uint8_t utf8_byte_pos_by_char_num_P(PGM_P pstart, const uint8_t charnum) {
return utf8_byte_pos_by_char_num_cb(pstart, read_byte_rom, charnum);
}