Boy was I wrong...

Not surprising. Anyway, made some further progress.
This commit is contained in:
Julie Marchant 2019-06-02 17:40:32 -04:00
parent f23307f34c
commit 1af6cfd75b
1 changed files with 43 additions and 36 deletions

View File

@ -233,12 +233,14 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
int nCharList; int nCharList;
int breakPoints[STRMAX]; int breakPoints[STRMAX];
int nBreakPoints; int nBreakPoints;
char newStr[STRMAX];
char testStr[STRMAX]; char testStr[STRMAX];
char currentLine[STRMAX];
int nCurrentLine;
char remainingStr[STRMAX];
int state; int state;
int errorcode; int errorcode;
int i, j; int i, j;
int offset; int done_rendering;
int nextline_y = y; int nextline_y = y;
color.r = fontColor & 0xff0000; color.r = fontColor & 0xff0000;
@ -252,13 +254,15 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
engine_error(TTF_GetError()); engine_error(TTF_GetError());
} }
if (w > dest->w) remainingStr = strcpy(in);
while (w > dest->w)
{ {
nCharList = 0; nCharList = 0;
i = 0; i = 0;
while (i < STRMAX) while (i < STRMAX)
{ {
i += utf8proc_iterate(&in[i], -1, &buf); i += utf8proc_iterate(&remainingStr[i], -1, &buf);
if (buf < 0) if (buf < 0)
{ {
printf("WARNING: Unicode string \"%s\" contains invalid characters!", in); printf("WARNING: Unicode string \"%s\" contains invalid characters!", in);
@ -286,10 +290,6 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
} }
} }
newStr = strcpy(in);
while (w > dest->w)
{
for (i = nBreakPoints - 1; i >= 0; i--) for (i = nBreakPoints - 1; i >= 0; i--)
{ {
testStr = ""; testStr = "";
@ -307,28 +307,35 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
} }
if (w <= dest->w) if (w <= dest->w)
{ {
offset = 0; currentLine = "";
nCurrentLine = 0;
done_rendering = 0;
for (j = 0; j < nCharList - 1; j++) for (j = 0; j < nCharList - 1; j++)
{ {
utf8proc_encode_char(charList[j], &newStr[j + offset]); if (done_rendering)
{
utf8proc_encode_char(charList[j], &remainingStr[j - nCurrentLine]);
}
else
utf8proc_encode_char(charList[j], &currentLine[j]);
if (j == breakPoints[i]) if (j == breakPoints[i])
{ {
offset++; done_rendering = 1;
newStr[j + offset] = '\n';
} }
} }
textSurf = TTF_RenderUTF8_Solid(gfx_unicodeFont, currentLine, color);
# TODO
break; break;
} }
} }
if (TTF_SizeUTF8(gfx_unicodeFont, newStr, &w, &h) < 0) if (TTF_SizeUTF8(gfx_unicodeFont, remainingStr, &w, &h) < 0)
{ {
engine_error(TTF_GetError()); engine_error(TTF_GetError());
} }
} }
} }
textSurf = TTF_RenderUTF8_Solid(gfx_unicodeFont, in, color);
}
} }
int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest) int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest)