| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | Copyright 2025 Joel Svensson svenssonjoel@yahoo.se | ||
| 3 | |||
| 4 | LispBM is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 3 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | LispBM is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "ttf_backend.h" | ||
| 19 | |||
| 20 | // extract an utf32 value from an utf8 string starting at index ix. | ||
| 21 | 443 | bool get_utf32(uint8_t *utf8, uint32_t *utf32, uint32_t ix, uint32_t *next_ix) { | |
| 22 | 443 | uint8_t *u = &utf8[ix]; | |
| 23 | 443 | uint32_t c = 0; | |
| 24 | |||
| 25 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 394 times.
|
443 | if (u[0] == 0) return false; |
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 377 times.
✓ Branch 1 taken 17 times.
|
394 | if (!(u[0] & 0x80U)) { |
| 28 | 377 | *utf32 = u[0]; | |
| 29 | 377 | *next_ix = ix + 1; | |
| 30 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 13 times.
|
17 | } else if ((u[0] & 0xe0U) == 0xc0U) { |
| 31 | 4 | c = (u[0] & 0x1fU) << 6; | |
| 32 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if ((u[1] & 0xc0U) != 0x80U) return false; |
| 33 | 2 | *utf32 = c + (u[1] & 0x3fU); | |
| 34 | 2 | *next_ix = ix + 2; | |
| 35 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9 times.
|
13 | } else if ((u[0] & 0xf0U) == 0xe0U) { |
| 36 | 4 | c = (u[0] & 0x0fU) << 12; | |
| 37 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if ((u[1] & 0xc0U) != 0x80U) return false; |
| 38 | 3 | c += (u[1] & 0x3fU) << 6; | |
| 39 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if ((u[2] & 0xc0U) != 0x80U) return false; |
| 40 | 2 | *utf32 = c + (u[2] & 0x3fU); | |
| 41 | 2 | *next_ix = ix + 3; | |
| 42 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | } else if ((u[0] & 0xf8U) == 0xf0U) { |
| 43 | 6 | c = (u[0] & 0x07U) << 18; | |
| 44 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
|
6 | if ((u[1] & 0xc0U) != 0x80U) return false; |
| 45 | 5 | c += (u[1] & 0x3fU) << 12; | |
| 46 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
|
5 | if ((u[2] & 0xc0U) != 0x80U) return false; |
| 47 | 4 | c += (u[2] & 0x3fU) << 6; | |
| 48 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if ((u[3] & 0xc0U) != 0x80U) return false; |
| 49 | 3 | c += (u[3] & 0x3fU); | |
| 50 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if ((c & 0xFFFFF800U) == 0xD800U) return false; |
| 51 | 2 | *utf32 = c; | |
| 52 | 2 | *next_ix = ix + 4; | |
| 53 | 3 | } else return false; | |
| 54 | 383 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 |