mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-10-10 08:03:04 -04:00
[Bugfix] splash adjust string split logic, tab justify
only split a long word across lines if it is larger than screen width also consider \0 as a valid place to split so we still run through the space finding loop make /t left justify the splash window (in RTL langs it right justifies) Change-Id: Id2955878a178c66cb0a1c644e62f943247666d8b
This commit is contained in:
parent
1beafb9290
commit
21fe45caad
1 changed files with 22 additions and 19 deletions
|
|
@ -83,6 +83,7 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
char *buf = splash_buf;
|
char *buf = splash_buf;
|
||||||
const char *next, *store;
|
const char *next, *store;
|
||||||
|
|
||||||
|
bool has_tabs = false;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
int x = 0, w = 0;
|
int x = 0, w = 0;
|
||||||
int y;
|
int y;
|
||||||
|
|
@ -100,25 +101,32 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
font_getstringsize(" ", &space_w, &chr_h, fontnum);
|
font_getstringsize(" ", &space_w, &chr_h, fontnum);
|
||||||
y = (addl_lines * chr_h);
|
y = (addl_lines * chr_h);
|
||||||
|
|
||||||
int res = vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap); /*-1 to prevent sanitizer issues */
|
int res = vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (res <= 0)
|
if (res <= 0)
|
||||||
{
|
{
|
||||||
#ifdef SIMULATOR
|
#ifdef SIMULATOR
|
||||||
printf("ERR\n");
|
printf("%s ERROR %d\n", __func__, res);
|
||||||
#endif
|
#endif
|
||||||
return false; /* nothing to display */
|
return false; /* nothing to display */
|
||||||
}
|
}
|
||||||
/* break splash string into display lines, doing proper word wrap */
|
|
||||||
const char *lastbreak = splash_buf;
|
const char *lastbreak = splash_buf;
|
||||||
while(true)
|
if (*lastbreak == '\f') /* only as first character - Reset splash box size */
|
||||||
|
{
|
||||||
|
maxw = 0;
|
||||||
|
maxh = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(true) /* break splash string into display lines, doing proper word wrap */
|
||||||
{
|
{
|
||||||
while (*lastbreak != '\0') /* handle escape chars*/
|
while (*lastbreak != '\0') /* handle escape chars*/
|
||||||
{
|
{
|
||||||
switch (*lastbreak) /* all chars in matchstr */
|
switch (*lastbreak) /* all chars in matchstr */
|
||||||
{
|
{
|
||||||
case '\t': /*fallthrough*/
|
case '\t': /*fallthrough*/
|
||||||
|
has_tabs = true; /* left justify (right justify for RTL)*/
|
||||||
case '\n':
|
case '\n':
|
||||||
{
|
{
|
||||||
if (lines[line].len > 0 || *lastbreak != '\t')
|
if (lines[line].len > 0 || *lastbreak != '\t')
|
||||||
|
|
@ -143,16 +151,7 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '\f':
|
case '\f': /*fallthrough*/
|
||||||
{
|
|
||||||
if (lastbreak == splash_buf) /* only as first character */
|
|
||||||
{
|
|
||||||
/* Reset splash box size */
|
|
||||||
maxw = 0;
|
|
||||||
maxh = 0;
|
|
||||||
}
|
|
||||||
break; /* acts the same as a space character */
|
|
||||||
}
|
|
||||||
case '\v': /*fallthrough*/
|
case '\v': /*fallthrough*/
|
||||||
case '\r':
|
case '\r':
|
||||||
break; /* acts the same as a space character */
|
break; /* acts the same as a space character */
|
||||||
|
|
@ -199,20 +198,22 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
if (w > width)
|
if (w > width)
|
||||||
{
|
{
|
||||||
const char *nxp, *nx = next;
|
const char *nxp, *nx = next;
|
||||||
int nw, newlen, oldlen = next_len;
|
int nw, newlen;
|
||||||
|
int oldlen = next_len;
|
||||||
|
|
||||||
while (nx - next < oldlen) /* try to split at a space char */
|
while (nx - next < oldlen) /* try to split at a space char */
|
||||||
{
|
{
|
||||||
nxp = nx;
|
nxp = nx;
|
||||||
nx++;
|
nx++;
|
||||||
if (*nxp != ' ')
|
if (*nxp != ' ' && *nx != '\0') /* split on space or EOL */
|
||||||
continue;
|
continue;
|
||||||
newlen = nxp - next;
|
newlen = nxp - next;
|
||||||
nw = font_getstringnsize(next, newlen, NULL, NULL, fontnum);
|
nw = font_getstringnsize(next, newlen, NULL, NULL, fontnum);
|
||||||
|
|
||||||
if (nw > width)
|
if (nw > width)
|
||||||
{
|
{
|
||||||
/* is room left on this line & next word large enough? */
|
/* is next word larger than max width & room left on this line? */
|
||||||
if (w + space_w * 5 < width && nw - space_w * 8 > w)
|
if (nw - w > width && w + space_w * 8 < width)
|
||||||
w = nw;
|
w = nw;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -246,10 +247,12 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
if (height > vp->height)
|
if (height > vp->height)
|
||||||
height = vp->height;
|
height = vp->height;
|
||||||
|
|
||||||
|
/* center the vp in the screen area */
|
||||||
vp->x += (vp->width - width) / 2;
|
vp->x += (vp->width - width) / 2;
|
||||||
vp->y += (vp->height - height) / 2;
|
vp->y += (vp->height - height) / 2;
|
||||||
vp->width = width;
|
vp->width = width;
|
||||||
vp->height = height;
|
vp->height = height;
|
||||||
|
if (!has_tabs)
|
||||||
vp->flags |= VP_FLAG_ALIGN_CENTER;
|
vp->flags |= VP_FLAG_ALIGN_CENTER;
|
||||||
|
|
||||||
/* prevent artifacts by locking to max width & height observed on repeated calls */
|
/* prevent artifacts by locking to max width & height observed on repeated calls */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue