mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-26 14:07:05 +03:00
Update for new nsfont_split expectations. Untested, but code similar to framebuffer. Looks /really/ slow. It only needs to measure the text when it finds a space, not for every character.
This commit is contained in:
parent
e7e5211eb9
commit
97c658fea1
@ -157,17 +157,24 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param fstyle style for this text
|
* \param fstyle style for this text
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string, in bytes
|
||||||
* \param x width available
|
* \param x width available
|
||||||
* \param char_offset updated to offset in string of actual_x, [0..length]
|
* \param char_offset updated to offset in string of actual_x, [1..length]
|
||||||
* \param actual_x updated to x coordinate of character closest to x
|
* \param actual_x updated to x coordinate of character closest to x
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*
|
*
|
||||||
* On exit, [char_offset == 0 ||
|
* On exit, char_offset indicates first character after split point.
|
||||||
* string[char_offset] == ' ' ||
|
*
|
||||||
* char_offset == length]
|
* Note: char_offset of 0 should never be returned.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* char_offset giving split point closest to x, where actual_x <= x
|
||||||
|
* else
|
||||||
|
* char_offset giving split point closest to x, where actual_x > x
|
||||||
|
*
|
||||||
|
* Returning char_offset == length means no split possible
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_split(const plot_font_style_t *fstyle,
|
bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
@ -189,13 +196,13 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
|||||||
int i;
|
int i;
|
||||||
int last_space = 0;
|
int last_space = 0;
|
||||||
font.GetEscapements(string, len, escapements);
|
font.GetEscapements(string, len, escapements);
|
||||||
// slow but it should work
|
// very slow but it should work
|
||||||
for (i = 0; string[index] && i < len; i++) {
|
for (i = 0; string[index] && i < len; i++) {
|
||||||
if (string[index] == ' ') {
|
if (string[index] == ' ') {
|
||||||
last_x = current;
|
last_x = current;
|
||||||
last_space = index;
|
last_space = index;
|
||||||
}
|
}
|
||||||
if (x < current) {
|
if (x < current && last_space != 0) {
|
||||||
*actual_x = (int)last_x;
|
*actual_x = (int)last_x;
|
||||||
*char_offset = last_space;
|
*char_offset = last_space;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user