mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-07-10 13:29:52 -04:00
merge font_getstringnsize and font_measurestring
measure string just needed a bit more to be a replacement Change-Id: I25c760df5edd7224b50c0522b4e44b1f9b574c51
This commit is contained in:
parent
6e27ba80e4
commit
58f75311d8
3 changed files with 22 additions and 32 deletions
|
|
@ -262,7 +262,7 @@ static bool splash_internal(struct screen * screen, const char *fmt, va_list ap,
|
||||||
if (w > width) /* split when it fits */
|
if (w > width) /* split when it fits */
|
||||||
{
|
{
|
||||||
w = width;
|
w = width;
|
||||||
next_len = font_measurestring(next, oldlen, &w, fontnum);
|
next_len = font_measurestring(next, oldlen, w, &w, NULL, fontnum);
|
||||||
store = next + next_len;
|
store = next + next_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ void font_disable_all(void);
|
||||||
void font_enable_all(void);
|
void font_enable_all(void);
|
||||||
|
|
||||||
struct font* font_get(int font);
|
struct font* font_get(int font);
|
||||||
int font_measurestring(const unsigned char *str, size_t maxbytes, int *max_width, int fontnum);
|
int font_measurestring(const unsigned char *str, size_t maxbytes, size_t maxwidth, int *w, int *h, int fontnum);
|
||||||
int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnumber);
|
int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnumber);
|
||||||
int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
|
int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
|
||||||
int font_get_width(struct font* ft, ucschar_t ch);
|
int font_get_width(struct font* ft, ucschar_t ch);
|
||||||
|
|
|
||||||
|
|
@ -1106,16 +1106,20 @@ const unsigned char* font_get_bits(struct font* pf, ucschar_t char_code)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the length (in bytes) of a given NULL terminated string
|
* Returns the length (in bytes) of a given NULL terminated string
|
||||||
* stops after max_width, maxbytes or NULL (\0) whichever occurs first.
|
* stops after maxwidth, maxbytes or NULL (\0) whichever occurs first.
|
||||||
|
* maxbytes = -1 ignores maxbytes and relies on NULL terminator (\0)
|
||||||
|
* to terminate the string
|
||||||
|
* maxwidth = -1 ignores maxwidth
|
||||||
|
* stringsize pixel width and height will be returned in *w and *h
|
||||||
*/
|
*/
|
||||||
int font_measurestring(const unsigned char *str, size_t maxbytes, int *max_width, int fontnum)
|
int font_measurestring(const unsigned char *str, size_t maxbytes, size_t maxwidth, int *w, int *h, int fontnum)
|
||||||
{
|
{
|
||||||
const unsigned char *start = str;
|
const unsigned char *start = str;
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
struct font* pf = font_get(fontnum);
|
struct font* pf = font_get(fontnum);
|
||||||
font_lock( fontnum, true );
|
font_lock( fontnum, true );
|
||||||
ucschar_t ch;
|
ucschar_t ch;
|
||||||
int width = 0;
|
size_t width = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
@ -1127,15 +1131,20 @@ int font_measurestring(const unsigned char *str, size_t maxbytes, int *max_width
|
||||||
}
|
}
|
||||||
if (IS_DIACRITIC(ch))
|
if (IS_DIACRITIC(ch))
|
||||||
continue;
|
continue;
|
||||||
int w = font_get_width(pf,ch);
|
int fw = font_get_width(pf,ch);
|
||||||
if (width + w > *max_width)
|
width += fw;
|
||||||
|
if (width > maxwidth)
|
||||||
{
|
{
|
||||||
|
width -= fw;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
width += w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*max_width = width;
|
if ( h )
|
||||||
|
*h = pf->height;
|
||||||
|
if ( w )
|
||||||
|
*w = width;
|
||||||
|
|
||||||
font_lock( fontnum, false );
|
font_lock( fontnum, false );
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
@ -1149,30 +1158,11 @@ int font_measurestring(const unsigned char *str, size_t maxbytes, int *max_width
|
||||||
*/
|
*/
|
||||||
int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnum)
|
int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnum)
|
||||||
{
|
{
|
||||||
const unsigned char *start = str;
|
|
||||||
size_t bytes;
|
|
||||||
struct font* pf = font_get(fontnum);
|
|
||||||
font_lock( fontnum, true );
|
|
||||||
ucschar_t ch;
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
if (!w)
|
||||||
while (true)
|
w = &width;
|
||||||
{
|
font_measurestring(str, maxbytes, -1, w, h, fontnum);
|
||||||
bytes = str - start;
|
return *w;
|
||||||
str = utf8decode(str, &ch);
|
|
||||||
if (ch == 0 || bytes >= maxbytes)
|
|
||||||
break;
|
|
||||||
if (IS_DIACRITIC(ch))
|
|
||||||
continue;
|
|
||||||
/* get proportional width and glyph bits*/
|
|
||||||
width += font_get_width(pf,ch);
|
|
||||||
}
|
|
||||||
if ( w )
|
|
||||||
*w = width;
|
|
||||||
if ( h )
|
|
||||||
*h = pf->height;
|
|
||||||
font_lock( fontnum, false );
|
|
||||||
return width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue