mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-28 17:23:09 +03:00
Bring nsfont_split up to core expectations. Slightly bodged.
This commit is contained in:
parent
f6703dcbaa
commit
d78777276c
48
amiga/font.c
48
amiga/font.c
@ -131,13 +131,10 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
struct TextExtent extent;
|
||||
struct TextFont *tfont;
|
||||
uint16 *utf16 = NULL, *outf16 = NULL;
|
||||
uint16 utf16next = 0;
|
||||
FIXED kern = 0;
|
||||
struct OutlineFont *ofont, *ufont = NULL;
|
||||
struct GlyphMap *glyph;
|
||||
uint32 tx=0,i=0;
|
||||
size_t len, utf8len = 0;
|
||||
uint8 *utf8;
|
||||
@ -222,33 +219,38 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||
* \param string UTF-8 string to measure
|
||||
* \param length length of string
|
||||
* \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
|
||||
* \return true on success, false on error and error reported
|
||||
*
|
||||
* On exit, [char_offset == 0 ||
|
||||
* string[char_offset] == ' ' ||
|
||||
* char_offset == length]
|
||||
* On exit, char_offset indicates first character after split point.
|
||||
*
|
||||
* 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,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
struct TextExtent extent;
|
||||
ULONG co;
|
||||
char *ostr = (char *)string;
|
||||
struct TextFont *tfont;
|
||||
uint16 *utf16 = NULL,*outf16 = NULL;
|
||||
uint16 utf16next = 0;
|
||||
FIXED kern = 0;
|
||||
int utf16charlen = 0;
|
||||
struct OutlineFont *ofont, *ufont = NULL;
|
||||
struct GlyphMap *glyph;
|
||||
uint32 tx=0,i=0;
|
||||
size_t len;
|
||||
int utf8len, utf8clen = 0;
|
||||
int32 tempx = 0;
|
||||
size_t coffset = 0;
|
||||
ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size);
|
||||
|
||||
len = utf8_bounded_length(string, length);
|
||||
@ -270,16 +272,18 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
||||
|
||||
utf16next = utf16[utf16charlen];
|
||||
|
||||
if(x < tx)
|
||||
{
|
||||
i = length+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(string[utf8clen] == ' ') //*utf16 == 0x0020)
|
||||
{
|
||||
if(x < tx) {
|
||||
/* If we've run out of space, and no space has been found, tell the core to split here.
|
||||
* This shouldn't work, but it does. Without it we randomly get non-split lines. */
|
||||
if(coffset == 0) {
|
||||
*actual_x = tx;
|
||||
*char_offset = utf8clen;
|
||||
coffset = utf8clen;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if(*utf16 == 0x0020) {
|
||||
*actual_x = tx;
|
||||
coffset = utf8clen;
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,6 +315,12 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
||||
|
||||
free(outf16);
|
||||
|
||||
if(coffset == 0) {
|
||||
*char_offset = length;
|
||||
} else {
|
||||
*char_offset = coffset;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user