1 #include "os_helpers.h"
12 #if !defined(HAVE_SE_SCREEN)
18 #define NANOS_FIRST_CHAR 0x20
19 #define NANOS_LAST_CHAR 0x7F
25 const char nanos_characters_width[96] = {
124 #if defined(HAVE_UNICODE_SUPPORT)
126 const unsigned int nanos_unicode_index[] = {
127 0x0000A1, 0x0000BF, 0x0000C9, 0x0000E0, 0x0000E1, 0x0000E2, 0x0000E7,
128 0x0000E8, 0x0000E9, 0x0000EA, 0x0000EB, 0x0000ED, 0x0000EE, 0x0000EF,
129 0x0000F1, 0x0000F3, 0x0000F4, 0x0000F9, 0x0000FA, 0x0000FB
138 const unsigned char nanos_unicode_width[] = {
163 #define DEFAULT_NANOS_UNICODE_WIDTH ((unsigned char) (11 << 4 | 11))
165 #define NB_NANOS_UNICODE_CHARS (sizeof(nanos_unicode_width) / sizeof(nanos_unicode_width[0]))
170 uint8_t se_get_cropped_length(
const char *text,
172 uint32_t width_limit_in_pixels,
177 uint32_t current_width_in_pixels = 0;
179 for (length = 0; length < text_length; length++) {
180 current_char = text[length];
182 if ((text_format & PAGING_FORMAT_NB) == PAGING_FORMAT_NB) {
184 current_width_in_pixels
185 += nanos_characters_width[current_char - NANOS_FIRST_CHAR] & 0x0F;
189 current_width_in_pixels
190 += (nanos_characters_width[current_char - NANOS_FIRST_CHAR] >> 0x04) & 0x0F;
194 if (current_width_in_pixels > width_limit_in_pixels) {
208 unsigned int line_width = 0;
209 #if defined(HAVE_INDEXED_STRINGS)
210 unsigned int width = 0;
211 unsigned char bold_toggle = 0;
214 if ((text_format & PAGING_FORMAT_NB) == PAGING_FORMAT_NB) {
220 while (text_length--) {
221 ch = *(
const unsigned char *) text;
222 #if defined(HAVE_INDEXED_STRINGS)
227 #if defined(HAVE_UNICODE_SUPPORT)
228 unsigned int unicode;
240 if (ch >= 0xF0 && text_length >= 3) {
241 unicode = (ch & 0x07) << 18;
242 unicode |= (*((
const unsigned char *) text + 0) & 0x3F) << 12;
243 unicode |= (*((
const unsigned char *) text + 1) & 0x3F) << 6;
244 unicode |= (*((
const unsigned char *) text + 2) & 0x3F);
250 else if (ch >= 0xE0 && text_length >= 2) {
251 unicode = (ch & 0x0F) << 12;
252 unicode |= (*((
const unsigned char *) text + 0) & 0x3F) << 6;
253 unicode |= (*((
const unsigned char *) text + 1) & 0x3F);
260 else if (ch >= 0xC2 && text_length >= 1) {
261 unicode = (ch & 0x1F) << 6;
262 unicode |= (*((
const unsigned char *) text + 0) & 0x3F);
271 if (ch < NANOS_FIRST_CHAR || ch > NANOS_LAST_CHAR) {
272 #if defined(HAVE_INDEXED_STRINGS)
282 if (text_length >= 1) {
289 if (ch ==
'\n' || ch ==
'\r') {
294 #if defined(HAVE_UNICODE_SUPPORT)
300 for (i = 0; i < NB_NANOS_UNICODE_CHARS; i++) {
301 if (nanos_unicode_index[i] == unicode) {
306 if (i < NB_NANOS_UNICODE_CHARS) {
307 width = nanos_unicode_width[i];
311 width = DEFAULT_NANOS_UNICODE_WIDTH;
317 #if defined(HAVE_INDEXED_STRINGS)
318 ch -= NANOS_FIRST_CHAR;
319 width = nanos_characters_width[ch];
323 if ((text_format & PAGING_FORMAT_NB) == PAGING_FORMAT_NB) {
325 line_width += nanos_characters_width[ch - NANOS_FIRST_CHAR] & 0x0F;
329 line_width += (nanos_characters_width[ch - NANOS_FIRST_CHAR] >> 0x04) & 0x0F;
333 #if defined(HAVE_INDEXED_STRINGS)
350 static bool is_word_delim(
unsigned char c)
355 return c ==
' ' || c ==
'\n' || c ==
'-' || c ==
'_';
359 unsigned int ux_layout_paging_compute(
const char *text_to_split,
360 unsigned int page_to_display,
361 ux_layout_paging_state_t *paging_state,
369 memset(paging_state->offsets, 0,
sizeof(paging_state->offsets));
370 memset(paging_state->lengths, 0,
sizeof(paging_state->lengths));
373 if (page_to_display >= paging_state->count && page_to_display != (
unsigned int) -1) {
378 unsigned int page = 0;
379 unsigned int line = 0;
380 const char *start = (text_to_split ?
STRPIC(text_to_split) :
G_ux.externalText);
381 const char *start2 = start;
382 const char *end = start + strlen(start);
383 while (start < end) {
384 unsigned int len = 0;
385 unsigned int linew = 0;
386 const char *last_word_delim = start;
388 while (start + len < end
390 && linew <= PIXEL_PER_LINE
398 linew = se_compute_line_width_light(start, len + 1,
G_ux.layout_paging.format);
401 if (linew > PIXEL_PER_LINE) {
405 unsigned char c = start[len];
406 if (is_word_delim(c)) {
407 last_word_delim = &start[len];
418 if (start + len < end && last_word_delim != start && len) {
420 if ((!is_word_delim(start[len - 1]) && !is_word_delim(start[len]))) {
421 len = last_word_delim - start;
426 if (page_to_display != (
unsigned int) -1 && page_to_display == page
427 && page_to_display < paging_state->count) {
428 paging_state->offsets[line] = start - start2;
429 paging_state->lengths[line] = len;
432 #if UX_LAYOUT_PAGING_LINE_COUNT > 1
433 if (line >= UX_LAYOUT_PAGING_LINE_COUNT - 1)
447 #
if UX_LAYOUT_PAGING_LINE_COUNT > 1
448 line >= UX_LAYOUT_PAGING_LINE_COUNT &&
#define BAGL_ENCODING_DEFAULT
#define STATIC_IF_NOT_INDEXED