summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-07-12 14:59:16 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-07-12 14:59:16 +0000
commitddbfffb2173630b16b5ddafaa6449cad8709bf83 (patch)
tree995b2c19565c1b5a12743288ee8c98283d334e73 /apps
parent8e68e223a4a672060775493f253afc9e6d9c46f5 (diff)
downloadrockbox-ddbfffb2173630b16b5ddafaa6449cad8709bf83.tar.gz
rockbox-ddbfffb2173630b16b5ddafaa6449cad8709bf83.zip
improve displaying of string containing diacritic characters. add some characters to determine the position to break line.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27401 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/lib/simple_viewer.c25
-rw-r--r--apps/plugins/lrcplayer.c35
2 files changed, 54 insertions, 6 deletions
diff --git a/apps/plugins/lib/simple_viewer.c b/apps/plugins/lib/simple_viewer.c
index 13fdc32c2f..09144b645b 100644
--- a/apps/plugins/lib/simple_viewer.c
+++ b/apps/plugins/lib/simple_viewer.c
@@ -39,6 +39,22 @@ struct view_info {
39 int start; /* possition of first line in text */ 39 int start; /* possition of first line in text */
40}; 40};
41 41
42static bool isbrchr(const unsigned char *str, int len)
43{
44 const unsigned char *p = "!,-.:;? 、。!,.:;?―";
45 if (isspace(*str))
46 return true;
47
48 while(*p)
49 {
50 int n = rb->utf8seek(p, 1);
51 if (len == n && !rb->strncmp(p, str, len))
52 return true;
53 p += n;
54 }
55 return false;
56}
57
42static const char* get_next_line(const char *text, struct view_info *info) 58static const char* get_next_line(const char *text, struct view_info *info)
43{ 59{
44 const char *ptr = text; 60 const char *ptr = text;
@@ -53,10 +69,13 @@ static const char* get_next_line(const char *text, struct view_info *info)
53#else 69#else
54 unsigned short ch; 70 unsigned short ch;
55 n = ((long)rb->utf8decode(ptr, &ch) - (long)ptr); 71 n = ((long)rb->utf8decode(ptr, &ch) - (long)ptr);
56 w = rb->font_get_width(info->pf, ch); 72 if (rb->is_diacritic(ch, NULL))
73 w = 0;
74 else
75 w = rb->font_get_width(info->pf, ch);
57#endif 76#endif
58 if (isspace(*ptr)) 77 if (isbrchr(ptr, n))
59 space = ptr+n; 78 space = ptr+(isspace(*ptr) || total + w <= info->vp.width? n: 0);
60 if (*ptr == '\n') 79 if (*ptr == '\n')
61 { 80 {
62 ptr += n; 81 ptr += n;
diff --git a/apps/plugins/lrcplayer.c b/apps/plugins/lrcplayer.c
index 7cc9f92b52..cf5c07bfc6 100644
--- a/apps/plugins/lrcplayer.c
+++ b/apps/plugins/lrcplayer.c
@@ -415,6 +415,24 @@ static const char *lrc_skip_space(const char *str)
415 return str; 415 return str;
416} 416}
417 417
418#ifdef HAVE_LCD_BITMAP
419static bool isbrchr(const unsigned char *str, int len)
420{
421 const unsigned char *p = "!,-.:;? 、。!,.:;?―";
422 if (isspace(*str))
423 return true;
424
425 while(*p)
426 {
427 int n = rb->utf8seek(p, 1);
428 if (len == n && !rb->strncmp(p, str, len))
429 return true;
430 p += n;
431 }
432 return false;
433}
434#endif
435
418/* calculate how many lines is needed to display and store it. 436/* calculate how many lines is needed to display and store it.
419 * create cache if there is enough space in lrc_buffer. */ 437 * create cache if there is enough space in lrc_buffer. */
420static struct lrc_brpos *calc_brpos(struct lrc_line *lrc_line, int i) 438static struct lrc_brpos *calc_brpos(struct lrc_line *lrc_line, int i)
@@ -518,17 +536,28 @@ static struct lrc_brpos *calc_brpos(struct lrc_line *lrc_line, int i)
518 w = 1; 536 w = 1;
519#else 537#else
520 c = ((long)rb->utf8decode(cr.str, &ch) - (long)cr.str); 538 c = ((long)rb->utf8decode(cr.str, &ch) - (long)cr.str);
521 w = rb->font_get_width(pf, ch); 539 if (rb->is_diacritic(ch, NULL))
522 if (cr.count && isspace(*cr.str)) 540 w = 0;
541 else
542 w = rb->font_get_width(pf, ch);
543 if (cr.count && prefs.wrap && isbrchr(cr.str, c))
523 { 544 {
524 /* remember position of last space */ 545 /* remember position of last space */
525 rb->memcpy(&sp, &cr, sizeof(struct snap)); 546 rb->memcpy(&sp, &cr, sizeof(struct snap));
526 sp.word_count = lrc_word->count; 547 sp.word_count = lrc_word->count;
527 sp.word_width = lrc_word->width; 548 sp.word_width = lrc_word->width;
549 if (!isspace(*cr.str) && cr.width+w <= vp_lyrics[i].width)
550 {
551 sp.count += c;
552 sp.width += w;
553 sp.word_count += c;
554 sp.word_width += w;
555 sp.str += c;
556 }
528 } 557 }
529 if (cr.count && cr.width+w > vp_lyrics[i].width) 558 if (cr.count && cr.width+w > vp_lyrics[i].width)
530 { 559 {
531 if (prefs.wrap && sp.str != NULL) /* wrap */ 560 if (sp.str != NULL) /* wrap */
532 { 561 {
533 rb->memcpy(&cr, &sp, sizeof(struct snap)); 562 rb->memcpy(&cr, &sp, sizeof(struct snap));
534 lrc_word = lrc_line->words+cr.nword; 563 lrc_word = lrc_line->words+cr.nword;