| 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 | 423 | bool get_utf32(uint8_t *utf8, uint32_t *utf32, uint32_t ix, uint32_t *next_ix) { | |
| 22 | 423 | uint8_t *u = &utf8[ix]; | |
| 23 | 423 | uint32_t c = 0; | |
| 24 | |||
| 25 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 375 times.
|
423 | if (u[0] == 0) return false; |
| 26 | |||
| 27 |
1/2✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
|
375 | if (!(u[0] & 0x80U)) { |
| 28 | 375 | *utf32 = u[0]; | |
| 29 | 375 | *next_ix = ix + 1; | |
| 30 | ✗ | } else if ((u[0] & 0xe0U) == 0xc0U) { | |
| 31 | ✗ | c = (u[0] & 0x1fU) << 6; | |
| 32 | ✗ | if ((u[1] & 0xc0U) != 0x80U) return false; | |
| 33 | ✗ | *utf32 = c + (u[1] & 0x3fU); | |
| 34 | ✗ | *next_ix = ix + 2; | |
| 35 | ✗ | } else if ((u[0] & 0xf0U) == 0xe0U) { | |
| 36 | ✗ | c = (u[0] & 0x0fU) << 12; | |
| 37 | ✗ | if ((u[1] & 0xc0U) != 0x80U) return false; | |
| 38 | ✗ | c += (u[1] & 0x3fU) << 6; | |
| 39 | ✗ | if ((u[2] & 0xc0U) != 0x80U) return false; | |
| 40 | ✗ | *utf32 = c + (u[2] & 0x3fU); | |
| 41 | ✗ | *next_ix = ix + 3; | |
| 42 | ✗ | } else if ((u[0] & 0xf8U) == 0xf0U) { | |
| 43 | ✗ | c = (u[0] & 0x07U) << 18; | |
| 44 | ✗ | if ((u[1] & 0xc0U) != 0x80U) return false; | |
| 45 | ✗ | c += (u[1] & 0x3fU) << 12; | |
| 46 | ✗ | if ((u[2] & 0xc0U) != 0x80U) return false; | |
| 47 | ✗ | c += (u[2] & 0x3fU) << 6; | |
| 48 | ✗ | if ((u[3] & 0xc0U) != 0x80U) return false; | |
| 49 | ✗ | c += (u[3] & 0x3fU); | |
| 50 | ✗ | if ((c & 0xFFFFF800U) == 0xD800U) return false; | |
| 51 | ✗ | *utf32 = c; | |
| 52 | ✗ | *next_ix = ix + 4; | |
| 53 | ✗ | } else return false; | |
| 54 | 375 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 |