1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

implement utf8, part 22 (bug fixes)

This commit is contained in:
IntelOrca
2015-07-31 19:05:00 +01:00
parent 7fe54661b9
commit de7088cb25
2 changed files with 25 additions and 5 deletions

View File

@@ -202,6 +202,12 @@ SDL_Surface *_ttf_surface_cache_get_or_add(TTF_Font *font, const utf8 *text);
void scrolling_text_set_bitmap_for_ttf(utf8 *text, int scroll, uint8 *bitmap, sint16 *scrollPositionOffsets)
{
TTFFontDescriptor *fontDesc = ttf_get_font_from_sprite_base(FONT_SPRITE_BASE_TINY);
if (fontDesc->font == NULL) {
scrolling_text_set_bitmap_for_sprite(text, scroll, bitmap, scrollPositionOffsets);
return;
}
// Currently only supports one colour
uint8 colour = 0;
@@ -225,7 +231,6 @@ void scrolling_text_set_bitmap_for_ttf(utf8 *text, int scroll, uint8 *bitmap, si
colour = RCT2_GLOBAL(0x009FF048, uint8*)[(colour - FORMAT_COLOUR_CODE_START) * 4];
}
TTFFontDescriptor *fontDesc = ttf_get_font_from_sprite_base(FONT_SPRITE_BASE_TINY);
SDL_Surface *surface = _ttf_surface_cache_get_or_add(fontDesc->font, text);
if (surface == NULL) {
return;

View File

@@ -179,10 +179,12 @@ int gfx_wrap_string(utf8 *text, int width, int *outNumLines, int *outFontHeight)
utf8 *firstCh = text;
utf8 *nextCh;
int codepoint;
int numCharactersOnLine = 0;
while ((codepoint = utf8_get_next(ch, &nextCh)) != 0) {
if (codepoint == ' ') {
currentWord = ch;
currentWidth = lineWidth;
numCharactersOnLine++;
} else if (codepoint == FORMAT_NEWLINE) {
*ch++ = 0;
maxWidth = max(maxWidth, lineWidth);
@@ -190,6 +192,7 @@ int gfx_wrap_string(utf8 *text, int width, int *outNumLines, int *outFontHeight)
lineWidth = 0;
currentWord = NULL;
firstCh = ch;
numCharactersOnLine = 0;
continue;
} else if (utf8_is_format_code(codepoint)) {
ch = nextCh;
@@ -202,8 +205,9 @@ int gfx_wrap_string(utf8 *text, int width, int *outNumLines, int *outFontHeight)
lineWidth = gfx_get_string_width(firstCh);
*nextCh = saveCh;
if (lineWidth <= width) {
if (lineWidth <= width || numCharactersOnLine == 0) {
ch = nextCh;
numCharactersOnLine++;
} else if (currentWord == NULL) {
// Single word is longer than line, insert null terminator
ch += utf8_insert_codepoint(ch, 0);
@@ -212,6 +216,7 @@ int gfx_wrap_string(utf8 *text, int width, int *outNumLines, int *outFontHeight)
lineWidth = 0;
currentWord = NULL;
firstCh = ch;
numCharactersOnLine = 0;
} else {
ch = currentWord;
*ch++ = 0;
@@ -221,6 +226,7 @@ int gfx_wrap_string(utf8 *text, int width, int *outNumLines, int *outFontHeight)
lineWidth = 0;
currentWord = NULL;
firstCh = ch;
numCharactersOnLine = 0;
}
}
@@ -889,8 +895,7 @@ bool ttf_initialise()
fontDesc->font = TTF_OpenFont(fontPath, fontDesc->ptSize);
if (fontDesc->font == NULL) {
TTF_Quit();
return false;
log_error("Unable to load '%s'", fontPath);
}
}
@@ -936,6 +941,8 @@ typedef struct {
int startY;
int x;
int y;
int maxX;
int maxY;
int flags;
uint8 palette[8];
uint16 font_sprite_base;
@@ -971,6 +978,10 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
return;
TTFFontDescriptor *fontDesc = ttf_get_font_from_sprite_base(info->font_sprite_base);
if (fontDesc->font == NULL) {
return ttf_draw_string_raw_sprite(dpi, text, info);
}
if (info->flags & TEXT_DRAW_FLAG_NO_DRAW) {
info->x += _ttf_getwidth_cache_get_or_add(fontDesc->font, text);
return;
@@ -1198,6 +1209,8 @@ static void ttf_process_string(rct_drawpixelinfo *dpi, const utf8 *text, text_dr
} else {
ch = ttf_process_glyph_run(dpi, ch, info);
}
info->maxX = max(info->maxX, info->x);
info->maxY = max(info->maxY, info->y);
}
}
@@ -1286,11 +1299,13 @@ static int ttf_get_string_width(const utf8 *text)
info.startY = 0;
info.x = 0;
info.y = 0;
info.maxX = 0;
info.maxY = 0;
info.flags |= TEXT_DRAW_FLAG_NO_DRAW;
if (gUseTrueTypeFont) info.flags |= TEXT_DRAW_FLAG_TTF;
ttf_process_string(NULL, text, &info);
return info.x;
return info.maxX;
}