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:
Julie Marchant 2019-06-03 22:36:03 -04:00
parent 0a522faea6
commit c798d0d7ec
3 changed files with 15 additions and 27 deletions

View File

@ -39,10 +39,10 @@ PKG_CHECK_EXISTS([SDL2_mixer], [
STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DNOSOUND"
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"
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])

View File

@ -6,8 +6,8 @@
bin_PROGRAMS = starfighter
starfighter_CPPFLAGS = $(STARFIGHTER_CFLAGS) -DDATADIR=\"$(pkgdatadir)\" -Wall
starfighter_CFLAGS = $(SDL_CFLAGS) $(UTF8PROC_CFLAGS) -lm
starfighter_LDADD = $(SDL_LIBS) $(UTF8PROC_LIBS)
starfighter_CFLAGS = $(SDL_CFLAGS) $(PANGO_CFLAGS) -lm
starfighter_LDADD = $(SDL_LIBS) $(PANGO_LIBS)
starfighter_SOURCES = \
Starfighter.c \

View File

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NOFONT
#include "SDL_ttf.h"
#include "utf8proc.h"
#include "pango.h"
#endif
#include "defs.h"
@ -236,12 +236,12 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
SDL_Color color;
int w, h;
int changed;
utf8proc_int32_t buf;
utf8proc_int32_t prev;
int breakPoints[STRMAX];
int nBreakPoints;
char testStr[STRMAX];
const char testStr[STRMAX];
char remainingStr[STRMAX];
PangoLogAttr logAttrs[STRMAX];
int nLogAttrs;
int state;
int i, j;
SDL_Rect area;
@ -261,29 +261,17 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
changed = 1;
while (changed && (w > dest->w))
{
i = 0;
j = 0;
prev = '\0';
state = 0;
nLogAttrs = strlen(remainingStr) + 1;
pango_get_log_attrs(remainingStr, strlen(remainingStr), -1, NULL, logAttrs, nLogAttrs);
nBreakPoints = 0;
while (i < strlen(remainingStr))
for (i = 0; i < nLogAttrs; i++)
{
j = utf8proc_iterate((utf8proc_uint8_t*)(&remainingStr[i]), -1, &buf);
if (buf < 0)
if (logAttrs[i].is_line_break)
{
printf("WARNING: Unicode string \"%s\" contains an invalid character!\n", remainingStr);
break;
breakPoints[nBreakPoints] = i;
nBreakPoints++;
}
else
{
if (utf8proc_grapheme_break_stateful(prev, buf, &state))
{
breakPoints[nBreakPoints] = i + 1;
nBreakPoints++;
}
}
i += j;
prev = buf;
}
changed = 0;