mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
8e68e223a4
commit
ddbfffb217
2 changed files with 54 additions and 6 deletions
|
@ -39,6 +39,22 @@ struct view_info {
|
||||||
int start; /* possition of first line in text */
|
int start; /* possition of first line in text */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool isbrchr(const unsigned char *str, int len)
|
||||||
|
{
|
||||||
|
const unsigned char *p = "!,-.:;? 、。!,.:;?―";
|
||||||
|
if (isspace(*str))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while(*p)
|
||||||
|
{
|
||||||
|
int n = rb->utf8seek(p, 1);
|
||||||
|
if (len == n && !rb->strncmp(p, str, len))
|
||||||
|
return true;
|
||||||
|
p += n;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static const char* get_next_line(const char *text, struct view_info *info)
|
static const char* get_next_line(const char *text, struct view_info *info)
|
||||||
{
|
{
|
||||||
const char *ptr = text;
|
const char *ptr = text;
|
||||||
|
@ -53,10 +69,13 @@ static const char* get_next_line(const char *text, struct view_info *info)
|
||||||
#else
|
#else
|
||||||
unsigned short ch;
|
unsigned short ch;
|
||||||
n = ((long)rb->utf8decode(ptr, &ch) - (long)ptr);
|
n = ((long)rb->utf8decode(ptr, &ch) - (long)ptr);
|
||||||
|
if (rb->is_diacritic(ch, NULL))
|
||||||
|
w = 0;
|
||||||
|
else
|
||||||
w = rb->font_get_width(info->pf, ch);
|
w = rb->font_get_width(info->pf, ch);
|
||||||
#endif
|
#endif
|
||||||
if (isspace(*ptr))
|
if (isbrchr(ptr, n))
|
||||||
space = ptr+n;
|
space = ptr+(isspace(*ptr) || total + w <= info->vp.width? n: 0);
|
||||||
if (*ptr == '\n')
|
if (*ptr == '\n')
|
||||||
{
|
{
|
||||||
ptr += n;
|
ptr += n;
|
||||||
|
|
|
@ -415,6 +415,24 @@ static const char *lrc_skip_space(const char *str)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
static bool isbrchr(const unsigned char *str, int len)
|
||||||
|
{
|
||||||
|
const unsigned char *p = "!,-.:;? 、。!,.:;?―";
|
||||||
|
if (isspace(*str))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while(*p)
|
||||||
|
{
|
||||||
|
int n = rb->utf8seek(p, 1);
|
||||||
|
if (len == n && !rb->strncmp(p, str, len))
|
||||||
|
return true;
|
||||||
|
p += n;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* calculate how many lines is needed to display and store it.
|
/* calculate how many lines is needed to display and store it.
|
||||||
* create cache if there is enough space in lrc_buffer. */
|
* create cache if there is enough space in lrc_buffer. */
|
||||||
static struct lrc_brpos *calc_brpos(struct lrc_line *lrc_line, int i)
|
static 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)
|
||||||
w = 1;
|
w = 1;
|
||||||
#else
|
#else
|
||||||
c = ((long)rb->utf8decode(cr.str, &ch) - (long)cr.str);
|
c = ((long)rb->utf8decode(cr.str, &ch) - (long)cr.str);
|
||||||
|
if (rb->is_diacritic(ch, NULL))
|
||||||
|
w = 0;
|
||||||
|
else
|
||||||
w = rb->font_get_width(pf, ch);
|
w = rb->font_get_width(pf, ch);
|
||||||
if (cr.count && isspace(*cr.str))
|
if (cr.count && prefs.wrap && isbrchr(cr.str, c))
|
||||||
{
|
{
|
||||||
/* remember position of last space */
|
/* remember position of last space */
|
||||||
rb->memcpy(&sp, &cr, sizeof(struct snap));
|
rb->memcpy(&sp, &cr, sizeof(struct snap));
|
||||||
sp.word_count = lrc_word->count;
|
sp.word_count = lrc_word->count;
|
||||||
sp.word_width = lrc_word->width;
|
sp.word_width = lrc_word->width;
|
||||||
|
if (!isspace(*cr.str) && cr.width+w <= vp_lyrics[i].width)
|
||||||
|
{
|
||||||
|
sp.count += c;
|
||||||
|
sp.width += w;
|
||||||
|
sp.word_count += c;
|
||||||
|
sp.word_width += w;
|
||||||
|
sp.str += c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (cr.count && cr.width+w > vp_lyrics[i].width)
|
if (cr.count && cr.width+w > vp_lyrics[i].width)
|
||||||
{
|
{
|
||||||
if (prefs.wrap && sp.str != NULL) /* wrap */
|
if (sp.str != NULL) /* wrap */
|
||||||
{
|
{
|
||||||
rb->memcpy(&cr, &sp, sizeof(struct snap));
|
rb->memcpy(&cr, &sp, sizeof(struct snap));
|
||||||
lrc_word = lrc_line->words+cr.nword;
|
lrc_word = lrc_line->words+cr.nword;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue