Browse Source

allow language file specify whether using isofont

Pal Lockheart 6 years ago
parent
commit
cb61e5738b
4 changed files with 99 additions and 36 deletions
  1. 15 5
      font.c
  2. 6 6
      main.c
  3. 51 25
      text.c
  4. 27 0
      text.h

+ 15 - 5
font.c

@@ -41,6 +41,15 @@ static uint8_t reverseBits(uint8_t x) {
     return y;
 }
 
+static void PAL_LoadISOFont(void)
+{
+    for (int i = 0; i < 0x80; i++)
+    {
+        int j=-1;while(j++<16)unicode_font[i][j]=reverseBits(iso_font[i*15+j]);
+        unicode_font[i][15] = 0;
+    }
+}
+
 static void PAL_LoadEmbeddedFont(void)
 {
 	FILE *fp;
@@ -134,11 +143,7 @@ static void PAL_LoadEmbeddedFont(void)
 
 	fclose(fp);
 
-	for (i = 0; i < 0x80; i++)
-	{
-		int j=-1;while(j++<16)unicode_font[i][j]=reverseBits(iso_font[i*15+j]);
-		unicode_font[i][15] = 0;
-	}
+	PAL_LoadISOFont();
 	_font_height = 15;
 }
 
@@ -258,6 +263,11 @@ PAL_InitFont(
 		PAL_LoadEmbeddedFont();
 	}
 
+	if (g_TextLib.fUseISOFont)
+	{
+		PAL_LoadISOFont();
+	}
+
 	if (cfg->pszFontFile)
 	{
 		PAL_LoadUserFont(cfg->pszFontFile);

+ 6 - 6
main.c

@@ -79,12 +79,6 @@ PAL_Init(
 
    VIDEO_SetWindowTitle("Loading...");
 
-   e = PAL_InitFont(&gConfig);
-   if (e != 0)
-   {
-      TerminateOnError("Could not load fonts: %d.\n", e);
-   }
-
    e = PAL_InitUI();
    if (e != 0)
    {
@@ -97,6 +91,12 @@ PAL_Init(
       TerminateOnError("Could not initialize text subsystem: %d.\n", e);
    }
 
+   e = PAL_InitFont(&gConfig);
+   if (e != 0)
+   {
+      TerminateOnError("Could not load fonts: %d.\n", e);
+   }
+
    PAL_InitInput();
    PAL_InitResources();
    AUDIO_OpenDevice();

+ 51 - 25
text.c

@@ -58,31 +58,7 @@ static LPWSTR gc_rgszSDLPalWords[CP_MAX][SDLPAL_EXTRA_WORD_COUNT] = {
 
 LPWSTR g_rcCredits[12];
 
-typedef struct tagTEXTLIB
-{
-   LPWSTR         *lpWordBuf;
-   LPWSTR         *lpMsgBuf;
-   int           **lpIndexBuf;
-
-   int             nWords;
-   int             nMsgs;
-   int             nIndices;
-
-   int             nCurrentDialogLine;
-   BYTE            bCurrentFontColor;
-   PAL_POS         posIcon;
-   PAL_POS         posDialogTitle;
-   PAL_POS         posDialogText;
-   BYTE            bDialogPosition;
-   BYTE            bIcon;
-   int             iDelayTime;
-   BOOL            fUserSkip;
-   BOOL            fPlayingRNG;
-
-   BYTE            bufDialogIcons[282];
-} TEXTLIB, *LPTEXTLIB;
-
-static TEXTLIB         g_TextLib;
+TEXTLIB         g_TextLib;
 
 PAL_FORCE_INLINE int
 PAL_ParseLine(
@@ -199,6 +175,7 @@ PAL_ReadMessageFile(
 	enum _message_state
 	{
 		ST_OUTSIDE,
+		ST_SETTING,
 		ST_DIALOG,
 		ST_WORD,
 		ST_CREDIT,
@@ -240,6 +217,10 @@ PAL_ReadMessageFile(
 						item->count = 0; item->next = NULL; cur_val = NULL;
 						if (idx_cnt < item->index) idx_cnt = item->index;
 					}
+					else if (strncmp(buffer, "[BEGIN SETTING]", 15) == 0 && !witem)
+					{
+						state = ST_SETTING;
+					}
 					else if (strncmp(buffer, "[BEGIN WORDS]", 13) == 0 && !witem)
 					{
 						state = ST_WORD;
@@ -323,6 +304,51 @@ PAL_ReadMessageFile(
 					}
 				}
 				break;
+			case ST_SETTING:
+				//
+				// Check if to end setting list
+				//
+				if (strncmp(buffer, "[END SETTING]", 13) == 0)
+				{
+					// End setting list
+					state = ST_OUTSIDE;
+				}
+				else
+				{
+					char *line = buffer;
+					while (*buffer && iswspace(*buffer)) line++;
+					//
+					// Skip comments starting with '#'
+					//
+					if (*line && *line != '#')
+					{
+						//
+						// Split the index and value
+						//
+						LPSTR val = strchr(line, '=');
+						if (val)
+						{
+							char index[80];
+							*val = '\0';
+
+							//
+							// Remove the trailing spaces
+							//
+							LPSTR end = line + strlen(line);
+							if (end > line && end[-1] == '\n') *(--end) = 0;
+							if (FALSE) while (end > line && iswspace(end[-1])) *(--end) = 0;
+
+							//
+							// Parse the index and pass out value
+							//
+							if (sscanf(line, "%s", index) == 1 && strncasecmp(index, "UseISOFont", 10) == 0 )
+							{
+								g_TextLib.fUseISOFont = atoi(val + 1) == 1;
+							}
+						}
+					}
+				}
+				break;
 			case ST_CREDIT:
 				//
 				// Check if to end credit list

+ 27 - 0
text.h

@@ -35,6 +35,33 @@ typedef enum tagDIALOGPOSITION
 
 PAL_C_LINKAGE_BEGIN
 
+typedef struct tagTEXTLIB
+{
+    LPWSTR         *lpWordBuf;
+    LPWSTR         *lpMsgBuf;
+    int           **lpIndexBuf;
+    BOOL            fUseISOFont;
+
+    int             nWords;
+    int             nMsgs;
+    int             nIndices;
+
+    int             nCurrentDialogLine;
+    BYTE            bCurrentFontColor;
+    PAL_POS         posIcon;
+    PAL_POS         posDialogTitle;
+    PAL_POS         posDialogText;
+    BYTE            bDialogPosition;
+    BYTE            bIcon;
+    int             iDelayTime;
+    BOOL            fUserSkip;
+    BOOL            fPlayingRNG;
+
+    BYTE            bufDialogIcons[282];
+} TEXTLIB, *LPTEXTLIB;
+
+extern TEXTLIB         g_TextLib;
+
 extern LPWSTR g_rcCredits[12];
 
 INT