Skip to content

Commit e54405c

Browse files
committed
1.0.10
1 parent 132140c commit e54405c

File tree

5 files changed

+43
-50
lines changed

5 files changed

+43
-50
lines changed

RELEASES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## 1.0.10
4+
5+
* Improved UTF-8 and UTF-16 decoder logic.
6+
37
## 1.0.9
48

59
* Added MR_COLOR sample colors.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcu-renderer",
3-
"version": "1.0.7",
3+
"version": "1.0.10",
44
"keywords": "antialiased, color-displays, display-driver, embedded-systems, font, graphics-library, lcd-display, microcontrollers, monochrome-displays, oled-display, renderer, text, tft-display",
55
"description": "A C-language graphics library, focused on rendering non-flickering, anti-aliased text with low resource use on both monochrome and color LCD displays.",
66
"license": "MIT",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=mcu-renderer
2-
version=1.0.7
2+
version=1.0.10
33
author=Gissio
44
maintainer=Gissio
55
sentence=A low-resource graphics library, focused on rendering non-flickering, anti-aliased text on both monochrome and color LCD displays.

src/mcu-renderer.c

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,89 +39,78 @@ typedef struct
3939

4040
static mr_charcode mr_decode_c_string(uint8_t **strp)
4141
{
42-
mr_charcode charcode = **strp;
43-
42+
uint8_t *str = *strp;
4443
*strp += 1;
4544

46-
return charcode;
45+
return *str;
4746
}
4847

4948
static mr_charcode mr_decode_utf8(uint8_t **strp)
5049
{
5150
uint8_t *str = *strp;
52-
mr_charcode value;
51+
uint8_t lead = str[0];
52+
uint32_t length;
53+
mr_charcode codepoint;
5354

54-
if (str[0] < 0x80)
55+
if (!(lead >> 7))
5556
{
56-
value = str[0];
57-
58-
*strp += 1;
57+
length = 1;
58+
codepoint = lead & 0x7f;
5959
}
60-
else if ((str[0] & 0xe0) == 0xc0)
60+
else if ((lead >> 5) == 0x06)
6161
{
62-
value = ((str[0] & 0x1f) << 6) |
63-
((str[1] & 0x3f) << 0);
64-
65-
*strp += 2;
62+
length = 2;
63+
codepoint = lead & 0x1f;
6664
}
67-
else if ((str[0] & 0xf0) == 0xe0)
65+
else if ((lead >> 4) == 0x0e)
6866
{
69-
value = ((str[0] & 0x0f) << 12) |
70-
((str[1] & 0x3f) << 6) |
71-
((str[2] & 0x3f) << 0);
72-
73-
*strp += 3;
67+
length = 3;
68+
codepoint = lead & 0x0f;
7469
}
75-
else if ((str[0] & 0xf8) == 0xf0 && (str[0] <= 0xf4))
70+
else if ((lead >> 4) == 0x0e)
7671
{
77-
value = ((str[0] & 0x07) << 18) |
78-
((str[1] & 0x3f) << 12) |
79-
((str[2] & 0x3f) << 6) |
80-
((str[3] & 0x3f) << 0);
81-
82-
*strp += 4;
72+
length = 4;
73+
codepoint = lead & 0x07;
8374
}
8475
else
85-
{
86-
// Invalid
87-
88-
value = -1;
76+
return 0;
8977

90-
*strp += 1;
78+
for (uint32_t i = 1; i < length; i++)
79+
{
80+
if ((str[i] >> 6) != 0x02)
81+
return 0;
82+
codepoint = (codepoint << 6) | (str[i] & 0x3f);
9183
}
9284

93-
return value;
85+
*strp += length;
86+
87+
return codepoint;
9488
}
9589

9690
static mr_charcode mr_decode_utf16(uint8_t **strp)
9791
{
9892
uint16_t *str = (uint16_t *)*strp;
93+
uint16_t highSurrogate = str[0];
9994
mr_charcode value;
10095

101-
if ((str[0] < 0xd800) || (str[0] >= 0xe000))
96+
if ((highSurrogate >> 11) != 0x1b)
10297
{
103-
value = str[0];
104-
10598
*strp += 2;
106-
}
107-
else if ((str[0] >= 0xd800) && (str[0] < 0xdc00) &&
108-
(str[1] >= 0xdc00) && (str[1] <= 0xde00))
109-
{
110-
value = 0x00010000 +
111-
(((str[0] & 0x03ff) << 10) |
112-
((str[1] & 0x03ff) << 0));
11399

114-
*strp += 4;
100+
return highSurrogate;
115101
}
116102
else
117103
{
118-
// Invalid
119-
value = -1;
104+
uint16_t lowSurrogate = str[1];
105+
if (((highSurrogate >> 10) != 0x36) &&
106+
((lowSurrogate >> 10) != 0x37))
107+
return 0;
120108

121109
*strp += 2;
122-
}
123110

124-
return value;
111+
return (highSurrogate & 0x3ff) << 10 |
112+
(lowSurrogate & 0x3ff);
113+
}
125114
}
126115

127116
// Data decoding

src/mcu-renderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ typedef struct
113113
uint8_t advance;
114114
} mr_glyph_t;
115115

116-
typedef int32_t mr_charcode;
116+
typedef uint32_t mr_charcode;
117117

118118
typedef mr_charcode (*mr_get_charcode_callback_t)(uint8_t **str);
119119

0 commit comments

Comments
 (0)