Starting to fix the core problem.
Using Pango's pango_get_log_attrs function. Not finished yet, but this is the start of it.
This commit is contained in:
parent
0a522faea6
commit
c798d0d7ec
|
@ -39,10 +39,10 @@ PKG_CHECK_EXISTS([SDL2_mixer], [
|
||||||
STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DNOSOUND"
|
STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DNOSOUND"
|
||||||
echo "Note: SDL_mixer not found; audio will not be supported."
|
echo "Note: SDL_mixer not found; audio will not be supported."
|
||||||
])
|
])
|
||||||
PKG_CHECK_MODULES([UTF8PROC], [libutf8proc], [
|
PKG_CHECK_MODULES([PANGO], [pango], [
|
||||||
], [
|
], [
|
||||||
STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DNOFONT"
|
STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DNOFONT"
|
||||||
echo "Note: utf8proc not found; Unicode will not be supported."
|
echo "Note: Pango not found; Unicode will not be supported."
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_ARG_VAR([SF_SCREEN_WIDTH], [The width of the game window in pixels])
|
AC_ARG_VAR([SF_SCREEN_WIDTH], [The width of the game window in pixels])
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
bin_PROGRAMS = starfighter
|
bin_PROGRAMS = starfighter
|
||||||
|
|
||||||
starfighter_CPPFLAGS = $(STARFIGHTER_CFLAGS) -DDATADIR=\"$(pkgdatadir)\" -Wall
|
starfighter_CPPFLAGS = $(STARFIGHTER_CFLAGS) -DDATADIR=\"$(pkgdatadir)\" -Wall
|
||||||
starfighter_CFLAGS = $(SDL_CFLAGS) $(UTF8PROC_CFLAGS) -lm
|
starfighter_CFLAGS = $(SDL_CFLAGS) $(PANGO_CFLAGS) -lm
|
||||||
starfighter_LDADD = $(SDL_LIBS) $(UTF8PROC_LIBS)
|
starfighter_LDADD = $(SDL_LIBS) $(PANGO_LIBS)
|
||||||
|
|
||||||
starfighter_SOURCES = \
|
starfighter_SOURCES = \
|
||||||
Starfighter.c \
|
Starfighter.c \
|
||||||
|
|
34
src/gfx.c
34
src/gfx.c
|
@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef NOFONT
|
#ifndef NOFONT
|
||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
#include "utf8proc.h"
|
#include "pango.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
@ -236,12 +236,12 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
|
||||||
SDL_Color color;
|
SDL_Color color;
|
||||||
int w, h;
|
int w, h;
|
||||||
int changed;
|
int changed;
|
||||||
utf8proc_int32_t buf;
|
|
||||||
utf8proc_int32_t prev;
|
|
||||||
int breakPoints[STRMAX];
|
int breakPoints[STRMAX];
|
||||||
int nBreakPoints;
|
int nBreakPoints;
|
||||||
char testStr[STRMAX];
|
const char testStr[STRMAX];
|
||||||
char remainingStr[STRMAX];
|
char remainingStr[STRMAX];
|
||||||
|
PangoLogAttr logAttrs[STRMAX];
|
||||||
|
int nLogAttrs;
|
||||||
int state;
|
int state;
|
||||||
int i, j;
|
int i, j;
|
||||||
SDL_Rect area;
|
SDL_Rect area;
|
||||||
|
@ -261,29 +261,17 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
|
||||||
changed = 1;
|
changed = 1;
|
||||||
while (changed && (w > dest->w))
|
while (changed && (w > dest->w))
|
||||||
{
|
{
|
||||||
i = 0;
|
nLogAttrs = strlen(remainingStr) + 1;
|
||||||
j = 0;
|
pango_get_log_attrs(remainingStr, strlen(remainingStr), -1, NULL, logAttrs, nLogAttrs);
|
||||||
prev = '\0';
|
|
||||||
state = 0;
|
|
||||||
nBreakPoints = 0;
|
nBreakPoints = 0;
|
||||||
while (i < strlen(remainingStr))
|
for (i = 0; i < nLogAttrs; i++)
|
||||||
{
|
{
|
||||||
j = utf8proc_iterate((utf8proc_uint8_t*)(&remainingStr[i]), -1, &buf);
|
if (logAttrs[i].is_line_break)
|
||||||
if (buf < 0)
|
|
||||||
{
|
{
|
||||||
printf("WARNING: Unicode string \"%s\" contains an invalid character!\n", remainingStr);
|
breakPoints[nBreakPoints] = i;
|
||||||
break;
|
nBreakPoints++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (utf8proc_grapheme_break_stateful(prev, buf, &state))
|
|
||||||
{
|
|
||||||
breakPoints[nBreakPoints] = i + 1;
|
|
||||||
nBreakPoints++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i += j;
|
|
||||||
prev = buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = 0;
|
changed = 0;
|
||||||
|
|
Loading…
Reference in New Issue