diff --git a/LICENSES b/LICENSES index 9b4cac4..3bcdb3a 100644 --- a/LICENSES +++ b/LICENSES @@ -1,10 +1,30 @@ -data/* +data/credits.txt mac/* License: GNU GPLv3 or later ------------------------------------------------------------------------ +data/DroidSansFallbackFull.ttf + +Source: https://packages.debian.org/sid/fonts-droid-fallback + +Copyright © 2006, 2007, 2008, 2009, 2010 Google Corp. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +------------------------------------------------------------------------ + gfx/alienDevice.png gfx/prlogo.png gfx/sflogo.png diff --git a/data/DroidSansFallbackFull.ttf b/data/DroidSansFallbackFull.ttf new file mode 100644 index 0000000..89959f5 Binary files /dev/null and b/data/DroidSansFallbackFull.ttf differ diff --git a/src/cutscene.c b/src/cutscene.c index d5004eb..62f083f 100644 --- a/src/cutscene.c +++ b/src/cutscene.c @@ -36,7 +36,7 @@ along with this program. If not, see . typedef struct Message_ { int face; - char message[255]; + char message[STRMAX]; } Message; diff --git a/src/defs.h b/src/defs.h index 22309d1..f72c500 100644 --- a/src/defs.h +++ b/src/defs.h @@ -57,6 +57,8 @@ along with this program. If not, see . #define PATH_MAX 4096 #endif +#define STRMAX 2000 + #define FULLSCREEN SDL_WINDOW_FULLSCREEN_DESKTOP #define DEFAULT_SCREEN_WIDTH MAX(SCREEN_WIDTH, 640) diff --git a/src/engine.c b/src/engine.c index 3bfa12e..a0cc6a2 100644 --- a/src/engine.c +++ b/src/engine.c @@ -134,7 +134,7 @@ void engine_showError(int errorId, const char *name) exit(1); } - char string[255]; + char string[STRMAX]; switch(errorId) { diff --git a/src/event.h b/src/event.h index db1e647..6233809 100644 --- a/src/event.h +++ b/src/event.h @@ -27,7 +27,7 @@ typedef struct Event_ { int time; int face; - char message[255]; + char message[STRMAX]; int entity; int flag; diff --git a/src/gfx.c b/src/gfx.c index 5a5e089..af3ce2f 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -17,12 +17,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +// Fonts not ready yet +#define NOFONT + #include #include #include #include "SDL.h" #include "SDL_image.h" +#ifndef NOFONT +#include "SDL_ttf.h" +#include "utf8proc.h" +#endif #include "defs.h" #include "structs.h" @@ -43,6 +50,10 @@ SDL_Surface *gfx_shopSprites[SHOP_S_MAX]; TextObject gfx_textSprites[TS_MAX]; SDL_Surface *gfx_messageBox; +#ifndef NOFONT +TTF_Font *gfx_unicodeFont; +#endif + void gfx_init() { screen_bufferHead = malloc(sizeof(*screen_bufferHead)); @@ -72,6 +83,15 @@ void gfx_init() gfx_messageBox = NULL; screen = NULL; + +#ifndef NOFONT + gfx_unicodeFont = TTF_OpenFont("data/DroidSansFallbackFull.ttf", 14); + if (gfx_unicodeFont == NULL) + { + printf("ERROR: TTF_OpenFont: %s\n", TTF_GetError()); + exit(1); + } +#endif } SDL_Surface *gfx_setTransparent(SDL_Surface *sprite) @@ -197,6 +217,125 @@ int gfx_renderString(const char *in, int x, int y, int fontColor, int wrap, SDL_ return gfx_renderStringBase(in, x, y, fontColor, wrap, dest); } +#ifdef NOFONT +int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest) +{ + return gfx_renderString(in, x, y, fontColor, wrap, dest); +} +#else +int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest) +{ + SDL_Surface *textSurf; + SDL_Color color; + int w, h; + utf8proc_int32_t charList[STRMAX]; + utf8proc_int32_t buf; + int nCharList; + int breakPoints[STRMAX]; + int nBreakPoints; + char newStr[STRMAX]; + char testStr[STRMAX]; + int state; + int errorcode; + int i, j; + int offset; + + color.r = fontColor & 0xff0000; + color.g = fontColor & 0x00ff00; + color.b = fontColor & 0x0000ff; + + if (gfx_unicodeFont != NULL) + { + if (TTF_SizeUTF8(gfx_unicodeFont, in, &w, &h) < 0) + { + engine_error(TTF_GetError()); + } + + if (w > dest->w) + { + nCharList = 0; + i = 0; + while (i < STRMAX) + { + i += utf8proc_iterate(&in[i], -1, &buf); + if (buf < 0) + { + printf("WARNING: Unicode string \"%s\" contains invalid characters!", in); + break; + } + else + { + charList[nCharList] = buf; + nCharList++; + if (buf == '\0') + { + break; + } + } + } + + state = 0; + nBreakPoints = 0; + for (i = 0; i < nCharList - 1; i++) + { + if (utf8proc_grapheme_break_stateful(charList[i], charList[i + 1], &state)) + { + breakPoints[nBreakPoints] = i; + nBreakPoints++; + } + } + + newStr = strcpy(in); + + while (w > dest->w) + { + for (i = nBreakPoints - 1; i >= 0; i--) + { + testStr = ""; + for (j = 0; j < nCharList - 1; j++) + { + utf8proc_encode_char(charList[j], &testStr[j + offset]); + if (j == breakPoints[i]) + { + break; + } + } + if (TTF_SizeUTF8(gfx_unicodeFont, testStr, &w, &h) < 0) + { + engine_error(TTF_GetError()); + } + if (w <= dest->w) + { + offset = 0; + for (j = 0; j < nCharList - 1; j++) + { + utf8proc_encode_char(charList[j], &newStr[j + offset]); + if (j == breakPoints[i]) + { + offset++; + newStr[j + offset] = '\n'; + } + } + break; + } + } + + if (TTF_SizeUTF8(gfx_unicodeFont, newStr, &w, &h) < 0) + { + 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) +{ + gfx_renderString(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest); +} +#endif + /* * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! @@ -491,6 +630,14 @@ void gfx_free() SDL_FreeSurface(gfx_messageBox); gfx_messageBox = NULL; } + +#ifndef NOFONT + if (gfx_unicodeFont != NULL) + { + TTF_CloseFont(gfx_unicodeFont); + gfx_unicodeFont = NULL; + } +#endif } void gfx_scaleBackground() diff --git a/src/mission.c b/src/mission.c index 4254136..e0e9afe 100644 --- a/src/mission.c +++ b/src/mission.c @@ -794,7 +794,7 @@ Missions 11 and 23 to be exact! static int mission_revealObjectives() { int allDone = 1; - char string[255] = ""; + char string[STRMAX] = ""; for (int i = 0 ; i < 3 ; i++) { diff --git a/src/save.c b/src/save.c index c4679c2..08cb04e 100644 --- a/src/save.c +++ b/src/save.c @@ -47,7 +47,7 @@ int save_initSlots() { char fileName[PATH_MAX]; int system; - char stationedName[255]; + char stationedName[STRMAX]; int imagePos = 0; Game tempGame; struct stat fileInfo; diff --git a/src/shop.c b/src/shop.c index 32a2bc0..bfc9489 100644 --- a/src/shop.c +++ b/src/shop.c @@ -39,7 +39,7 @@ typedef struct ShopItem_ { int x, y; int price; char name[50]; - char description[255]; + char description[STRMAX]; int image; } ShopItem; diff --git a/src/structs.h b/src/structs.h index 3434515..60d0fe5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -81,7 +81,7 @@ typedef struct TextObject_ { int life; float x, y; int fontColor; - char text[255]; + char text[STRMAX]; } TextObject; diff --git a/src/title.c b/src/title.c index 6efd48f..4bcc122 100644 --- a/src/title.c +++ b/src/title.c @@ -594,7 +594,7 @@ void title_showCredits() int yPos = 0; int yPos2 = screen->h; - char text[255]; + char text[STRMAX]; int i; TextObject *credit;