hominem_te_esse avatar hominem_te_esse committed 4e607b0

* fix for theme font handling (when switching back to the default theme, the language font wasn't re-applyied)
* font code factorization

Comments (0)

Files changed (10)

 #define FNT_ERROR (-1)
 
 /** Initializes the font subsystem */
-void fntInit(void);
+void fntInit();
 
 /** Terminates the font subsystem */
-void fntEnd(void);
-
-/** Loads a font
-  * @param buffer The memory buffer containing the font
-  * @param bufferSize Size of the buffer
-  * @param takeover Set to nonzero
-  * @return font slot id (negative value means error happened) */
-int fntLoad(void* buffer, int bufferSize, int takeover);
+void fntEnd();
 
 /** Loads a font from a file path
   * @param path The path to the font file
   * @return font slot id (negative value means error happened) */
 int fntLoadFile(char* path);
 
-/** Replaces the given font slot with the defined font */
-void fntReplace(int id, void* buffer, int bufferSize, int takeover, int asDefault);
-
-/** Reloads the default font into the given font slot */
-void fntSetDefault(int id);
+/** Reloads the default font */
+void fntLoadDefault(char* path);
 
 /** Releases a font slot */
 void fntRelease(int id);
 void fntSetAspectRatio(float aw, float ah);
 
 /** Renders a text with specified window dimensions */
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour);
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour);
 
 /** replaces spaces with newlines so that the text fits into the specified width.
   * @note A destrutive operation - modifies the given string!
   */
-void fntFitString(int font, unsigned char *string, size_t width);
+void fntFitString(int id, unsigned char *string, size_t width);
 
 /** Calculates the width of the given text string
 * We can't use the height for alignment, as the horizontal center would depends of the contained text itself */
-int fntCalcDimensions(int font, const unsigned char* str);
+int fntCalcDimensions(int id, const unsigned char* str);
 
 #endif

lng/lang_Italian.lng

-# translation by 0NullChAr0
-Italian
-               WELCOME TO OPEN PS2 LOADER. MAIN CODE BASED ON SOURCE CODE OF HD PROJECT <http://psx-scene.com> ADAPTATION TO USB ADVANCE FORMAT AND INITIAL GUI BY IFCARO <http://ps2dev.ifcaro.net> MOST OF LOADER CORE IS MADE BY JIMMIKAELKAEL. ALL THE GUI IMPROVEMENTS ARE MADE BY VOLCA. THANKS FOR USING OUR PROGRAM ^^
-Open PS2 Loader %s
-Salva cambiamenti
-O Indietro
-Configura Network
-<nessun valore>
-Impostazioni salvate...
-Errore scrittura impostazioni!
-Esci
-Impostazioni
-Giochi USB
-Giochi HDD
-Giochi Network
-Applicazioni
-Tema
-Lingua
-Errore avvio Network: %d
-Attivato
-Disattivato
-OK
-Impostazioni Gioco
-Rimuovi tutte le impostazioni
-Tutte le impostazioni del gioco sono state rimosse
-Scorrimento
-Lento
-Medio
-Veloce
-Menu Predefinito
-Carica dal disco
-Per favore attendere
-Errore caricamento ID del Gioco
-Ordinamento Automatico
-Errore caricamento file linguaggio
-Disabilita Colori di Debug
-Nessun controller rilevato, attendere...
-Abilita Cover Art
-Schermo ampio
-Spegni
-Caricamento Configurazioni
-Salvataggio Configurazioni
-Avvia Periferica
-Avviamento periferica USB
-Avviamento periferica HDD
-Avviamento periferica ETH
-Avviamento Applicazioni
-Automatico
-Manuale
-Avvia HDL Server
-Avviamento HDL Server...
-Caricamento HDL Server... [O] Per Fermare
-Premi [X] per fermare HDL...
-Scaricamento HDL Server...
-Esci per
-Colore dello Sfondo
-Colore del Testo
-IP
-Maschera
-Ingresso
-Porta
-Titolo
-Utente
-Parola d'ordine
-<non impostato>
-X Accetta
-L'oggetto sara' cancellato definitivamente, continuare?
-Rinomina
-Cancella
-Avvia
-Impostazioni Schermo
-Abilita operazioni di Elimina e Rinomina
-Controlla frammentazione Gioco USB
-Ricorda ultimo gioco Avviato
-Errore, il gioco e' frammentato
-Errore, impossibile avviare l'oggetto
-Testa
-Lasciare vuoto per Autorizzazioni GUEST
-Carica Nucleo Alternativo
-Metodo lettura data alternativo
-Sgancia chiamate Sistema
-PSS Disabilitati
-Disabilita DVD-DL
-Disabilita IGR
-Riduci buffer cdvdfsv
-Nascondi modulo dev9
-Combo IGR alternato
-Cambiare le dimensioni della VMC
-Creare
-Modifica
-Annulla
-Resetta
-Usa generico
-Configura VMC
-Nome
-Dimensione
-Stato
-Progresso
-File VMC esiste
-File VMC invalido, la dimensione non e' corretta
-File VMC deve essere creato
-Errore con il File VMC, continuare con MC fisica ?
-Aggiornamento automatico
-Informazioni
-Sviluppatori
+# translation by 0NullChAr0
+Italian
+               WELCOME TO OPEN PS2 LOADER. MAIN CODE BASED ON SOURCE CODE OF HD PROJECT <http://psx-scene.com> ADAPTATION TO USB ADVANCE FORMAT AND INITIAL GUI BY IFCARO <http://ps2dev.ifcaro.net> MOST OF LOADER CORE IS MADE BY JIMMIKAELKAEL. ALL THE GUI IMPROVEMENTS ARE MADE BY VOLCA. THANKS FOR USING OUR PROGRAM ^^
+Open PS2 Loader %s
+Salva cambiamenti
+Indietro
+Configura Network
+<nessun valore>
+Impostazioni salvate...
+Errore scrittura impostazioni!
+Esci
+Impostazioni
+Giochi USB
+Giochi HDD
+Giochi Network
+Applicazioni
+Tema
+Lingua
+Avvio Network Errore: %d
+Attivato
+Disattivato
+Ok
+Impostazioni Gioco
+Rimuovi tutte le impostazioni
+Tutte le impostazioni del gioco sono state rimosse
+Scorrimento
+Lento
+Medio
+Veloce
+Menu Predefinito
+Carica dal disco
+Per favore attendere
+Errore caricamento ID del Gioco
+Ordinamento Automatico
+Errore caricamento file linguaggio
+Disabilita Colori di Debug
+Nessun controller rilevato, attendere...
+Abilita Cover Art
+Schermo ampio
+Spegni
+Caricamento Configurazioni
+Salvataggio Configurazioni
+Avvia Periferica
+Avviamento periferica USB
+Avviamento periferica HDD
+Avviamento periferica ETH
+Avviamento Applicazioni
+Automatico
+Manuale
+Avvia HDL Server
+Avviamento HDL Server...
+Caricamento HDL Server... [O] Per Fermare
+Premi [X] per fermare HDL...
+Scaricamento HDL Server...
+Esci per
+Colore dello Sfondo
+Colore del Testo
+IP
+Maschera
+Ingresso
+Porta
+Titolo
+Utente
+Parola d'ordine
+<non impostato>
+Accetta
+L'oggetto sarà cancellato definitivamente, continuare ?
+Rinomina
+Cancella
+Avvia
+Impostazioni Schermo
+Abilita operazioni di Elimina e Rinomina
+Controlla frammentazione Gioco USB
+Ricorda ultimo gioco Avviato
+Errore, il gioco è frammentato
+Errore, impossibile avviare l'oggetto
+Testa
+Lasciare vuoto per Autorizzazioni GUEST
+Carica Nucleo Alternativo
+Metodo lettura data Alternativo
+Sgancia chiamate Sistema
+PSS Disabilitati
+Disabilita DVD-DL
+Disabilita IGR
+Non utilizzato
+Nascondi modulo dev9
+Combo IGR Alternato
+Cambia le dimensioni della VMC
+Creare
+Modifica
+Annulla
+Resetta
+Usa generico
+Configura VMC
+Nome
+Dimensione
+Stato
+Progresso
+File VMC esistente
+File VMC invalido, la dimensione non è corretta
+File VMC ancora da creare
+Errore con il File VMC %s, continuare con MC fisica (slot %d) ?
+Aggiornamento automatico
+Informazioni
+Sviluppatori
+Ritardo USB
+Prefisso Percorso USB
+Lasciare vuoto per uscire al Browser
+Valore in minuti, 0 per disabilitare spin down
+Spin down HDD automatico
+Modo Video
+Colore Dialogo
+Colore Selezionato
+Mostra pagina info
+Info
+ELF Personalizzato
+Colore Selezione
+Riconnetti
+Lasciare vuoto per la lista condivisioni
+Prefisso Percorso ETH
+Backspace
+Spazio
+Invio
+Modo
+VMC Slot 1
+VMC Slot 2
+ID Gioco
+Modo DMA
+V-Sync
+Modo 1
+Modo 2
+Modo 3
+Modo 4
+Modo 5
+Modo 6
+Modo 7
+Modo 8
+Modo 9
+Cronometro Chiamata
+Applica un ritardo alle funzioni CDVD (0 è Predefinito)
 		rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
 
 		//Text
-		fntRenderString(FNT_DEFAULT, 50, 120, ALIGN_NONE, 0, 0, text, gTheme->textColor);
+		fntRenderString(gTheme->fonts[0], 50, 120, ALIGN_NONE, 0, 0, text, gTheme->textColor);
 		
 		// separating line for simpler orientation
 		rmDrawLine(25, 138, 615, 138, gColWhite);
 				c[0] = keyb[i + j * KEYB_WIDTH];
 
 				x = 50 + i * 31;
-				w = fntRenderString(FNT_DEFAULT, x, 170 + 3 * UI_SPACING_H * j, ALIGN_NONE, 0, 0, c, gTheme->uiTextColor) - x;
+				w = fntRenderString(gTheme->fonts[0], x, 170 + 3 * UI_SPACING_H * j, ALIGN_NONE, 0, 0, c, gTheme->uiTextColor) - x;
 				if ((i + j * KEYB_WIDTH) == selchar)
 					diaDrawBoundingBox(x, 170 + 3 * UI_SPACING_H * j, w, UI_SPACING_H, 0);
 			}
 				rmDrawPixmap(cmdicons[i], 436, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, cmdicons[i]->Width, cmdicons[i]->Height, SCALING_RATIO, gDefaultCol);
 			
 			x = 477;
-			w = fntRenderString(FNT_DEFAULT, x, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, 0, 0, commands[i], gTheme->uiTextColor) - x;
+			w = fntRenderString(gTheme->fonts[0], x, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, 0, 0, commands[i], gTheme->uiTextColor) - x;
 			if (i == selcommand)
 				diaDrawBoundingBox(x, 170 + 3 * UI_SPACING_H * i, w, UI_SPACING_H, 0);
 		}
 		rmDrawRect(0, 0,  screenWidth, screenHeight, gColDarker);
 		
 		// "Color selection"
-		fntRenderString(FNT_DEFAULT, 50, 50, ALIGN_NONE, 0, 0, _l(_STR_COLOR_SELECTION), GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
+		fntRenderString(gTheme->fonts[0], 50, 50, ALIGN_NONE, 0, 0, _l(_STR_COLOR_SELECTION), GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
 
 		// 3 bars representing the colors...
 		size_t co;
 	
 	char* text = _l(text_id);
 	
-	x = screenWidth - fntCalcDimensions(FNT_DEFAULT, text) - 10;
+	x = screenWidth - fntCalcDimensions(gTheme->fonts[0], text) - 10;
 	y = gTheme->usedHeight - 40;
 	
 	// render hint on the lower side of the screen.
 	rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
-	fntRenderString(FNT_DEFAULT, x + 5, y + 5, ALIGN_NONE, 0, 0, text, gTheme->textColor);
+	fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, text, gTheme->textColor);
 }
 
 /// renders an ui item (either selected or not)
 			// width is text length in pixels...
 			const char *txt = diaGetLocalisedText(item->label.text, item->label.stringId);
 			if(txt && strlen(txt))
-				*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
+				*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
 			else
-				*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
+				*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
 
 			break;
 		}
 
 		case UI_OK: {
 			const char *txt = _l(_STR_OK);
-			*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
+			*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
 			break;
 		}
 
 			char tmp[10];
 
 			snprintf(tmp, 10, "%d", item->intvalue.current);
-			*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, tmp, txtcol) - x;
+			*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, tmp, txtcol) - x;
 			break;
 		}
 
 		case UI_STRING: {
 			if(strlen(item->stringvalue.text))
-				*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, item->stringvalue.text, txtcol) - x;
+				*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, item->stringvalue.text, txtcol) - x;
 			else
-				*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
+				*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
 			break;
 		}
 
 				stars[i] = '*';
 
 			stars[i] = '\0';
-			*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, stars, txtcol) - x;
+			*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, stars, txtcol) - x;
 			break;
 		}
 
 		case UI_BOOL: {
 			const char *txtval = _l((item->intvalue.current) ? _STR_ON : _STR_OFF);
-			*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txtval, txtcol) - x;
+			*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txtval, txtcol) - x;
 			break;
 		}
 
 			if (!tv)
 				tv = _l(_STR_NO_ITEMS);
 
-			*w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, tv, txtcol) - x;
+			*w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, tv, txtcol) - x;
 			break;
 		}
 
 // freetype vars
 static FT_Library font_library;
 
-static int gCharHeight;
+static int gCharHeight = 16;
 
 static s32 gFontSemaId;
 static ee_sema_t gFontSema;
 	/// Nonzero if font is used
 	int isValid;
 
-	/// Nonzero for custom fonts
-	int isDefault;
-
 	/// Texture atlases (default to NULL)
 	atlas_t *atlases[ATLAS_MAX];
 	
 
 #define GLYPH_PAGE_OK(font,page) ((pageid <= font->cacheMaxPageID) && (font->glyphCache[page]))
 
+static void fntCacheFlushPage(fnt_glyph_cache_entry_t *page) {
+	int i;
+
+	for (i = 0; i < GLYPH_CACHE_PAGE_SIZE; ++i, ++page) {
+		page->isValid = 0;
+		// we're not doing any atlasFree or such - atlas has to be rebuild
+		page->allocation = NULL;
+		page->atlas = NULL;
+	}
+}
+
+static void fntCacheFlush(font_t *font) {
+	// Release all the glyphs from the cache
+	int i;
+	for (i = 0; i <= font->cacheMaxPageID; ++i) {
+		if (font->glyphCache[i]) {
+			fntCacheFlushPage(font->glyphCache[i]);
+			free(font->glyphCache[i]);
+			font->glyphCache[i] = NULL;
+		}
+	}
+
+	free(font->glyphCache);
+	font->glyphCache = NULL;
+	font->cacheMaxPageID = -1;
+
+	// free all atlasses too, they're invalid now anyway
+	int aid;
+	for(aid = 0; aid < ATLAS_MAX; ++aid) {
+		atlasFree(font->atlases[aid]);
+		font->atlases[aid] = NULL;
+	}
+}
+
 static int fntPrepareGlyphCachePage(font_t *font, int pageid) {
 	if (pageid > font->cacheMaxPageID) {
 		fnt_glyph_cache_entry_t **np = realloc(font->glyphCache, (pageid + 1) * sizeof(fnt_glyph_cache_entry_t *));
 	return 1;
 }
 
-static void fntResetFontDef(font_t *fnt) {
-	fnt->glyphCache = NULL;
-	fnt->cacheMaxPageID = -1;
-	fnt->isValid = 0;
-	fnt->isDefault = 0;
-	
-	int aid;
-	for(aid = 0; aid < ATLAS_MAX; ++aid)
-		fnt->atlases[aid] = NULL;
-		
-	fnt->dataPtr = NULL;
-}
-
 static void fntPrepareCLUT() {
 	fontClut.PSM = GS_PSM_T8;
 	fontClut.ClutPSM = GS_PSM_CT32;
 	fontClut.Clut = memalign(128, 256 * 4);
 	fontClut.VramClut = 0;
-	
+
 	// generate the clut table
 	size_t i;
 	u32 *clut = fontClut.Clut;
 	for (i = 0; i < 256; ++i) {
 		u8 alpha =  i > 0x080 ? 0x080 : i;
-		
+
 		*clut = alpha << 24 | i << 16 | i << 8 | i;
-		clut++; 
+		clut++;
 	}
 }
 
 	fontClut.Clut = NULL;
 }
 
-void fntInit(void) {
+static void fntInitSlot(font_t *font) {
+	font->face = NULL;
+	font->glyphCache = NULL;
+	font->cacheMaxPageID = -1;
+	font->dataPtr = NULL;
+	font->isValid = 0;
+
+	int aid = 0;
+	for(; aid < ATLAS_MAX; ++aid)
+		font->atlases[aid] = NULL;
+}
+
+static void fntDeleteSlot(font_t *font) {
+	// free the glyph cache, atlases, unload the font
+	fntCacheFlush(font);
+
+	FT_Done_Face(font->face);
+	font->face = NULL;
+
+	if (font->dataPtr) {
+		free(font->dataPtr);
+		font->dataPtr = NULL;
+	}
+
+	font->isValid = 0;
+}
+
+void fntRelease(int id) {
+	if (id > FNT_DEFAULT && id < FNT_MAX_COUNT)
+		fntDeleteSlot(&fonts[id]);
+}
+
+static int fntLoadSlot(font_t *font, char* path) {
+	void* buffer = NULL;
+	int bufferSize = -1;
+
+	fntInitSlot(font);
+
+	if (path) {
+		buffer = readFile(path, -1, &bufferSize);
+		if (!buffer) {
+			LOG("FNTSYS Font file loading failed: %s\n", path);
+			return FNT_ERROR;
+		}
+		font->dataPtr = buffer;
+	} else {
+		buffer = &freesansfont_raw;
+		bufferSize = size_freesansfont_raw;
+	}
+
+	// load the font via memory handle
+	int error = FT_New_Memory_Face(font_library, (FT_Byte*) buffer, bufferSize, 0, &font->face);
+	if (error) {
+		LOG("FNTSYS Freetype font loading failed with %x!\n", error);
+		fntDeleteSlot(font);
+		return FNT_ERROR;
+	}
+
+	error = FT_Set_Char_Size(font->face, 0, gCharHeight * 16, 300, 300);
+	/*error = FT_Set_Pixel_Sizes( face, 0, // pixel_width gCharHeight ); // pixel_height */
+	if (error) {
+		LOG("FNTSYS Freetype error setting font pixel size with %x!\n", error);
+		fntDeleteSlot(font);
+		return FNT_ERROR;
+	}
+
+	font->isValid = 1;
+	return 0;
+}
+
+void fntInit() {
 	LOG("FNTSYS Init\n");
 	int error = FT_Init_FreeType(&font_library);
-
 	if (error) {
 		// just report over the ps2link
 		LOG("FNTSYS Freetype init failed with %x!\n", error);
 	gFontSema.option = 0;
 	gFontSemaId = CreateSema(&gFontSema);
 
-	int i;
-	for (i = 0; i < FNT_MAX_COUNT; ++i)
-		fntResetFontDef(&fonts[i]);
+	int i = 0;
+	for (; i < FNT_MAX_COUNT; ++i)
+		fntInitSlot(&fonts[i]);
 
-	// load the default font (will be id=0)
-	fntLoad(NULL, -1, 0);
+	fntLoadDefault(NULL);
 }
 
-static void fntCacheFlushPage(fnt_glyph_cache_entry_t *page) {
-	int i;
-
-	for (i = 0; i < GLYPH_CACHE_PAGE_SIZE; ++i, ++page) {
-		page->isValid = 0;
-		// we're not doing any atlasFree or such - atlas has to be rebuild
-		page->allocation = NULL;
-		page->atlas = NULL;
-	}
-}
-
-static void fntCacheFlush(font_t *fnt) {
-	int i;
-
-	// Release all the glyphs from the cache
-	for (i = 0; i <= fnt->cacheMaxPageID; ++i) {
-		if (fnt->glyphCache[i]) {
-			fntCacheFlushPage(fnt->glyphCache[i]);
-			free(fnt->glyphCache[i]);
-			fnt->glyphCache[i] = NULL;
-		}
-	}
-
-	free(fnt->glyphCache);
-	fnt->glyphCache = NULL;
-	fnt->cacheMaxPageID = -1;
-	
-	// free all atlasses too, they're invalid now anyway
-	int aid;
-	for(aid = 0; aid < ATLAS_MAX; ++aid) {
-		atlasFree(fnt->atlases[aid]);
-		fnt->atlases[aid] = NULL;
-	}
-}
-
-static int fntNewFont() {
-	int i;
-	for (i = 0; i < FNT_MAX_COUNT; ++i) {
-		if (fonts[i].isValid == 0) {
-			fntResetFontDef(&fonts[i]);
-			return i;
+int fntLoadFile(char* path) {
+	font_t *font;
+	int i = 1;
+	for (; i < FNT_MAX_COUNT; i++) {
+		font = &fonts[i];
+		if (!font->isValid) {
+			if (fntLoadSlot(font, path) != FNT_ERROR)
+				return i;
+			break;
 		}
 	}
 
 	return FNT_ERROR;
 }
 
-void fntDeleteFont(font_t *font) {
-	// skip already deleted fonts
-	if (!font->isValid)
-		return;
+void fntLoadDefault(char* path) {
+	font_t newFont, oldFont;
 
-	// free the glyph cache, atlases, unload the font
-	fntCacheFlush(font);
+	if (fntLoadSlot(&newFont, path) != FNT_ERROR) {
+		// copy over the new font definition
+		// we have to lock this phase, as the old font may still be used
+		// Note: No check for concurrency is done here, which is kinda funky!
+		WaitSema(gFontSemaId);
+		memcpy(&oldFont, &fonts[FNT_DEFAULT], sizeof(font_t));
+		memcpy(&fonts[FNT_DEFAULT], &newFont, sizeof(font_t));
+		SignalSema(gFontSemaId);
 
-	FT_Done_Face(font->face);
-
-	if (font->dataPtr) {
-		free(font->dataPtr);
-		font->dataPtr = NULL;
+		// delete the old font
+		fntDeleteSlot(&oldFont);
 	}
-
-	font->isValid = 0;
 }
 
-int fntLoadSlot(font_t *fnt, void* buffer, int bufferSize) {
-	if (!buffer) {
-		buffer = &freesansfont_raw;
-		bufferSize = size_freesansfont_raw;
-		fnt->isDefault = 1;
-	}
-
-	// load the font via memory handle
-	int error = FT_New_Memory_Face(font_library, (FT_Byte*) buffer, bufferSize, 0, &fnt->face);
-
-	if (error) {
-		// just report over the ps2link
-		LOG("FNTSYS Freetype font loading failed with %x!\n", error);
-		// SleepThread();
-		return -1;
-	}
-
-	gCharHeight = 16;
-
-	error = FT_Set_Char_Size(fnt->face, 0, gCharHeight * 16, 300, 300);
-	/*error = FT_Set_Pixel_Sizes( face,
-	 0, // pixel_width
-	 gCharHeight ); // pixel_height*/
-
-	if (error) {
-		// just report over the ps2link
-		LOG("FNTSYS Freetype error setting font pixel size with %x!\n", error);
-		// SleepThread();
-		return -1;
-	}
-
-	fnt->isValid = 1;
-	return 0;
-}
-
-int fntLoad(void* buffer, int bufferSize, int takeover) {
-	// we need a new slot in the font array
-	int fontID = fntNewFont();
-
-	if (fontID == FNT_ERROR)
-		return FNT_ERROR;
-
-	font_t *fnt = &fonts[fontID];
-
-	if (fntLoadSlot(fnt, buffer, bufferSize) == FNT_ERROR)
-		return FNT_ERROR;
-
-	if (takeover)
-		fnt->dataPtr = buffer;
-
-	return fontID;
-}
-
-int fntLoadFile(char* path) {
-	LOG("FNTSYS LoadFile: %s\n", path);
-	// load the buffer with font
-	int size = -1;
-	void* customFont = readFile(path, -1, &size);
-
-	if (!customFont)
-		return FNT_ERROR;
-
-	int fontID = fntLoad(customFont, size, 1);
-
-	return fontID;
-}
-
-void fntRelease(int id) {
-	if (id < FNT_MAX_COUNT)
-		fntDeleteFont(&fonts[id]);
-}
-
-/** Terminates the font rendering system */
-void fntEnd(void) {
+void fntEnd() {
 	LOG("FNTSYS End\n");
 	// release all the fonts
 	int id;
 	for (id = 0; id < FNT_MAX_COUNT; ++id)
-		fntDeleteFont(&fonts[id]);
+		fntDeleteSlot(&fonts[id]);
 
 	// deinit freetype system
 	FT_Done_FreeType(font_library);
 	return atl;
 }
 
-static int fntGlyphAtlasPlace(font_t *fnt, fnt_glyph_cache_entry_t* glyph) {
-	FT_GlyphSlot slot = fnt->face->glyph;
+static int fntGlyphAtlasPlace(font_t *font, fnt_glyph_cache_entry_t* glyph) {
+	FT_GlyphSlot slot = font->face->glyph;
 	
  	//LOG("FNTSYS GlyphAtlasPlace: Placing the glyph... %d x %d\n", slot->bitmap.width, slot->bitmap.rows);
 	
 		return 1;
 	}
 	
-	int aid;
-	
-	for (aid = 0; aid < ATLAS_MAX; ++aid) {
+	int aid = 0;
+	for (; aid < ATLAS_MAX; aid++) {
 		//LOG("FNTSYS Placing aid %d...\n", aid);
-		atlas_t **atl = &fnt->atlases[aid];
+		atlas_t **atl = &font->atlases[aid];
 		if (!*atl) { // atlas slot not yet used
 			//LOG("FNTSYS aid %d is new...\n", aid);
 			*atl = fntNewAtlas();
 		}
 		
-		glyph->allocation = 
-			atlasPlace(*atl, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.buffer);
-			
+		glyph->allocation =	atlasPlace(*atl, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.buffer);
 		if (glyph->allocation) {
 			//LOG("FNTSYS Found placement\n", aid);
 			glyph->atlas = *atl;
 }
 
 /** Internal method. Makes sure the bitmap data for particular character are pre-rendered to the glyph cache */
-static fnt_glyph_cache_entry_t* fntCacheGlyph(font_t *fnt, uint32_t gid) {
+static fnt_glyph_cache_entry_t* fntCacheGlyph(font_t *font, uint32_t gid) {
 	// calc page id and in-page index from glyph id
 	int pageid = gid / GLYPH_CACHE_PAGE_SIZE;
 	int idx = gid % GLYPH_CACHE_PAGE_SIZE;
 
 	// do not call on every char of every font rendering call
-	if (!GLYPH_PAGE_OK(fnt,pageid))
-		if (!fntPrepareGlyphCachePage(fnt, pageid)) // failed to prepare the page...
+	if (!GLYPH_PAGE_OK(font, pageid))
+		if (!fntPrepareGlyphCachePage(font, pageid)) // failed to prepare the page...
 			return NULL;
 
-	fnt_glyph_cache_entry_t *page = fnt->glyphCache[pageid];
-
+	fnt_glyph_cache_entry_t *page = font->glyphCache[pageid];
 	/* Should never happen. 
 	if (!page) // safeguard
 		return NULL;
 	*/
 
 	fnt_glyph_cache_entry_t* glyph = &page[idx];
-
 	if (glyph->isValid)
 		return glyph;
 
 	// not cached but valid. Cache
-	if (!fnt->face) {
+	if (!font->face) {
 		LOG("FNTSYS Face is NULL!\n");
 	}
 
-	int error = FT_Load_Char(fnt->face, gid, FT_LOAD_RENDER);
-
+	int error = FT_Load_Char(font->face, gid, FT_LOAD_RENDER);
 	if (error) {
 		LOG("FNTSYS Error loading glyph - %d\n", error);
 		return NULL;
 	}
 
 	// find atlas placement for the glyph
-	if  (!fntGlyphAtlasPlace(fnt, glyph))
+	if  (!fntGlyphAtlasPlace(font, glyph))
 		return NULL;
 
-	FT_GlyphSlot slot = fnt->face->glyph;
+	FT_GlyphSlot slot = font->face->glyph;
 	glyph->width = slot->bitmap.width;
 	glyph->height = slot->bitmap.rows;
 	glyph->shx = slot->advance.x;
 
 void fntSetAspectRatio(float aw, float ah) {
 	// flush cache - it will be invalid after the setting
-	int i;
-
-	for (i = 0; i < FNT_MAX_COUNT; ++i) {
+	int i = 0;
+	for (; i < FNT_MAX_COUNT; i++) {
 		if (fonts[i].isValid)
 			fntCacheFlush(&fonts[i]);
 	}
 
-	// set new aspect ratio (Is this correct, I wonder?)
-	// TODO: error = FT_Set_Char_Size(face, 0, gCharHeight*64, ah*300, aw*300);
+	// TODO: set new aspect ratio (Is this correct, I wonder?)
+	// error = FT_Set_Char_Size(face, 0, gCharHeight*64, ah*300, aw*300);
 }
 
 static void fntRenderGlyph(fnt_glyph_cache_entry_t* glyph, int pen_x, int pen_y) {
 		 *
 		 * 2. GS_SETREG_TEX0 for every quad - why? gsKit should only set texture if demanded
 		 *    We should prepare a special fnt render method that would step over most of the
-		 *    performance problems under - begining with rmSetupQuad and continuing into gsKit
-		 *    - this method would handle the preparetion of the quads and GS upload itself,
+		 *    performance problems under - beginning with rmSetupQuad and continuing into gsKit
+		 *    - this method would handle the preparation of the quads and GS upload itself,
 		 *    without the use of prim_quad_texture and rmSetupQuad...
 		 *
 		 * 3. We should use clut to keep the memory allocations sane - we're linear in the 32bit buffers
 }
 
 #ifndef __RTL
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
 	// wait for font lock to unlock
 	WaitSema(gFontSemaId);
-	font_t *fnt = &fonts[font];
+	font_t *font = &fonts[id];
 	SignalSema(gFontSemaId);
 
 	if (aligned) {
 		if (width) {
-			x -= min(fntCalcDimensions(font, string), width) >> 1;
+			x -= min(fntCalcDimensions(id, string), width) >> 1;
 		} else {
-			x -= fntCalcDimensions(font, string) >> 1;
+			x -= fntCalcDimensions(id, string) >> 1;
 		}
 		y -= MENU_ITEM_HEIGHT >> 1;
 	}
 	int xmax = x + width;
 	int ymax = y + height;
 
-	use_kerning = FT_HAS_KERNING(fnt->face);
+	use_kerning = FT_HAS_KERNING(font->face);
 	state = UTF8_ACCEPT;
 	previous = 0;
 
 		if (utf8Decode(&state, &codepoint, *string)) // accumulate the codepoint value
 			continue;
 
-		glyph = fntCacheGlyph(fnt, codepoint);
+		glyph = fntCacheGlyph(font, codepoint);
 		if (!glyph)
 			continue;
 
 		// kerning
 		if (use_kerning && previous) {
-			glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+			glyph_index = FT_Get_Char_Index(font->face, codepoint);
 			if (glyph_index) {
-				FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+				FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
 				pen_x += delta.x >> 6;
 			}
 			previous = glyph_index;
 }
 
 #else
-static void fntRenderSubRTL(font_t *fnt, const unsigned char* startRTL, const unsigned char* string, fnt_glyph_cache_entry_t* glyph, int x, int y) {
+static void fntRenderSubRTL(font_t *font, const unsigned char* startRTL, const unsigned char* string, fnt_glyph_cache_entry_t* glyph, int x, int y) {
 	if (glyph) {
 		x -= glyph->shx >> 6;
 		fntRenderGlyph(glyph, x, y);
 		if (utf8Decode(&state, &codepoint, *startRTL))
 			continue;
 
-		glyph = fntCacheGlyph(fnt, codepoint);
+		glyph = fntCacheGlyph(font, codepoint);
 		if (!glyph)
 			continue;
 
 		if (use_kerning && previous) {
-			glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+			glyph_index = FT_Get_Char_Index(font->face, codepoint);
 			if (glyph_index) {
-				FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+				FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
 				x -= delta.x >> 6;
 			}
 			previous = glyph_index;
 	}
 }
 
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
 	// wait for font lock to unlock
 	WaitSema(gFontSemaId);
-	font_t *fnt = &fonts[font];
+	font_t *font = &fonts[id];
 	SignalSema(gFontSemaId);
 
 	if (aligned) {
 		if (width) {
-			x -= min(fntCalcDimensions(font, string), width) >> 1;
+			x -= min(fntCalcDimensions(id, string), width) >> 1;
 		} else {
-			x -= fntCalcDimensions(font, string) >> 1;
+			x -= fntCalcDimensions(id, string) >> 1;
 		}
 		y -= MENU_ITEM_HEIGHT >> 1;
 	}
 	/*int xmax = x + width;
 	int ymax = y + height;*/
 
-	use_kerning = FT_HAS_KERNING(fnt->face);
+	use_kerning = FT_HAS_KERNING(font->face);
 	state = UTF8_ACCEPT;
 	previous = 0;
 
 		if (utf8Decode(&state, &codepoint, *string)) // accumulate the codepoint value
 			continue;
 
-		glyph = fntCacheGlyph(fnt, codepoint);
+		glyph = fntCacheGlyph(font, codepoint);
 		if (!glyph)
 			continue;
 
 		// kerning
 		delta_x = 0;
 		if (use_kerning && previous) {
-			glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+			glyph_index = FT_Get_Char_Index(font->face, codepoint);
 			if (glyph_index) {
-				FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+				FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
 				delta_x = delta.x >> 6;
 			}
 			previous = glyph_index;
 			if (inRTL) { // render RTL
 				inRTL = 0;
 				pen_x = pen_xRTL;
-				fntRenderSubRTL(fnt, startRTL, string, glyphRTL, pen_xRTL, y);
+				fntRenderSubRTL(font, startRTL, string, glyphRTL, pen_xRTL, y);
 			}
 		}
 
 
 	if (inRTL) {
 		pen_x = pen_xRTL;
-		fntRenderSubRTL(fnt, startRTL, string, glyphRTL, pen_xRTL, y);
+		fntRenderSubRTL(font, startRTL, string, glyphRTL, pen_xRTL, y);
 	}
 
 	return pen_x;
 }
 #endif
 
-void fntFitString(int font, unsigned char *string, size_t width) {
+void fntFitString(int id, unsigned char *string, size_t width) {
 	size_t cw = 0;
 	unsigned char *str = string;
-	size_t spacewidth = fntCalcDimensions(font, " ");
+	size_t spacewidth = fntCalcDimensions(id, " ");
 	unsigned char *psp = NULL;
 	
 	while (*str) {
 		// Calc the font's width...
 		// NOTE: The word was terminated, so we're seeing a single word
 		// on that position
-		size_t ww = fntCalcDimensions(font, str);
+		size_t ww = fntCalcDimensions(id, str);
 		
 		if (cw + ww > width) {
 			if (psp) {
 	}
 }
 
-int fntCalcDimensions(int font, const unsigned char* str) {
+int fntCalcDimensions(int id, const unsigned char* str) {
 	int w = 0;
 
 	WaitSema(gFontSemaId);
-	font_t *fnt = &fonts[font];
+	font_t *font = &fonts[id];
 	SignalSema(gFontSemaId);
 
 	uint32_t codepoint;
 	uint32_t state = UTF8_ACCEPT;
-	FT_Bool use_kerning = FT_HAS_KERNING(fnt->face);
+	FT_Bool use_kerning = FT_HAS_KERNING(font->face);
 	FT_UInt glyph_index, previous = 0;
 	FT_Vector delta;
 
 
 		// Could just as well only get the glyph dimensions
 		// but it is probable the glyphs will be needed anyway
-		fnt_glyph_cache_entry_t* glyph = fntCacheGlyph(fnt, codepoint);
+		fnt_glyph_cache_entry_t* glyph = fntCacheGlyph(font, codepoint);
 		if (!glyph)
 			continue;
 
 		// kerning
 		if (use_kerning && previous) {
-			glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+			glyph_index = FT_Get_Char_Index(font->face, codepoint);
 			if (glyph_index) {
-				FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+				FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
 				w += delta.x >> 6;
 			}
 			previous = glyph_index;
 
 	return w;
 }
-
-void fntReplace(int id, void* buffer, int bufferSize, int takeover, int asDefault) {
-	font_t *fnt = &fonts[id];
-
-	font_t ndefault, old;
-	fntResetFontDef(&ndefault);
-	fntLoadSlot(&ndefault, buffer, bufferSize);
-	ndefault.isDefault = asDefault;
-
-	// copy over the new font definition
-	// we have to lock this phase, as the old font may still be used
-	WaitSema(gFontSemaId);
-	memcpy(&old, fnt, sizeof(font_t));
-	memcpy(fnt, &ndefault, sizeof(font_t));
-
-	if (takeover)
-		fnt->dataPtr = buffer;
-
-	SignalSema(gFontSemaId);
-
-	// delete the old font
-	fntDeleteFont(&old);
-}
-
-void fntSetDefault(int id) {
-	font_t *fnt = &fonts[id];
-
-	// already default
-	if (fnt->isDefault)
-		return;
-
-	font_t ndefault, old;
-	fntResetFontDef(&ndefault);
-	fntLoadSlot(&ndefault, NULL, -1);
-
-	// copy over the new font definition
-	// we have to lock this phase, as the old font may still be used
-	// Note: No check for concurrency is done here, which is kinda funky!
-	WaitSema(gFontSemaId);
-	memcpy(&old, fnt, sizeof(font_t));
-	memcpy(fnt, &ndefault, sizeof(font_t));
-	SignalSema(gFontSemaId);
-
-	// delete the old font
-	fntDeleteFont(&old);
-}
 	else
 		snprintf(fps, 20, "%3d ms ----- FPS", time_render);
 
-	fntRenderString(FNT_DEFAULT, screenWidth - 90, 30, ALIGN_CENTER, 0, 0, fps, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
+	fntRenderString(gTheme->fonts[0], screenWidth - 90, 30, ALIGN_CENTER, 0, 0, fps, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
 #endif
 }
 
 		rmDrawLine(50, 75, screenWidth - 50, 75, gColWhite);
 		rmDrawLine(50, 410, screenWidth - 50, 410, gColWhite);
 
-		fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, text, gTheme->textColor);
-		guiDrawIconAndText(CIRCLE_ICON, _STR_O_BACK, FNT_DEFAULT, 500, 417, gTheme->selTextColor);
+		fntRenderString(gTheme->fonts[0], screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, text, gTheme->textColor);
+		guiDrawIconAndText(CIRCLE_ICON, _STR_O_BACK, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
 		if (addAccept)
-			guiDrawIconAndText(CROSS_ICON, _STR_X_ACCEPT, FNT_DEFAULT, 70, 417, gTheme->selTextColor);
+			guiDrawIconAndText(CROSS_ICON, _STR_X_ACCEPT, gTheme->fonts[0], 70, 417, gTheme->selTextColor);
 
 		guiEndFrame();
 	}
 
 	rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
 
-	fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, message, gTheme->textColor);
+	fntRenderString(gTheme->fonts[0], screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, message, gTheme->textColor);
 
 	guiDrawOverlays();
 
 			strId++;
 		}
 
-		int size = -1;
 		char path[255];
 		snprintf(path, 255, "%s/font_%s.ttf", gBaseMCDir, name);
-		
 		LOG("LANG Custom font path: %s\n", path);
-		
-		void* customFont = readFile(path, -1, &size);
-		if (customFont)
-			fntReplace(FNT_DEFAULT, customFont, size, 1, 1);  // consider fonts loaded through language as default, so they won't be reset-ed when changing themes
-		else
-			fntSetDefault(FNT_DEFAULT);
+		fntLoadDefault(path);
 
 		return 1;
 	}
 	int cp = 0; // current position
 	for (it = mainMenu; it; it = it->next, cp++) {
 		// render, advance
-		fntRenderString(gTheme->itemsList->font, 320, y, ALIGN_CENTER, 0, 0, submenuItemGetText(&it->item), (cp == sitem) ? gTheme->selTextColor : gTheme->textColor);
+		fntRenderString(gTheme->fonts[0], 320, y, ALIGN_CENTER, 0, 0, submenuItemGetText(&it->item), (cp == sitem) ? gTheme->selTextColor : gTheme->textColor);
 		y += spacing;
 	}
 }
 	else
 		elem->color = color;
 
+	elem->font = font;
 	snprintf(elemProp, 64, "%s_font", name);
-	if (configGetInt(themeConfig, elemProp, &intValue))
-		font = intValue;
-	if (font >= 0 && font < THM_MAX_FONTS)
-		elem->font = theme->fonts[font];
-	else
-		elem->font = FNT_DEFAULT;
+	if (configGetInt(themeConfig, elemProp, &intValue)) {
+		if (intValue > 0 && intValue < THM_MAX_FONTS)
+			elem->font = theme->fonts[intValue];
+	}
 
 	return elem;
 }
 	// 1. check we have a valid Background elements
 	if ( !theme->mainElems.first || (theme->mainElems.first->type != TYPE_BACKGROUND) ) {
 		LOG("THEMES No valid background found for main, add default BG_ART\n");
-		theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+		theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
 		if (themePath)
 			initBackground(themePath, themeConfig, theme, backgroundElem, "bg", "BG", 1, "background");
 		else
 	if (theme->infoElems.first) {
 		if (theme->infoElems.first->type != TYPE_BACKGROUND) {
 			LOG("THEMES No valid background found for info, add default BG_ART\n");
-			theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+			theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
 			if (themePath)
 				initBackground(themePath, themeConfig, theme, backgroundElem, "bg", "BG", 1, "background");
 			else
 		}
 	} else {
 		LOG("THEMES No itemsList found, adding a default one\n");
-		theme->itemsList = initBasic(themePath, themeConfig, theme, "il", TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+		theme->itemsList = initBasic(themePath, themeConfig, theme, "il", TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 		initItemsList(themePath, themeConfig, theme, theme->itemsList, "il", NULL);
 		theme->itemsList->next = theme->mainElems.first->next; // Position the itemsList as second element (right after the Background)
 		theme->mainElems.first->next = theme->itemsList;
 		configGetStr(themeConfig, elemProp, &type);
 		if (type) {
 			if (!strcmp(elementsType[TYPE_ATTRIBUTE_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				initAttributeText(themePath, themeConfig, theme, elem, name, NULL);
 			} else if (!strcmp(elementsType[TYPE_STATIC_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				initStaticText(themePath, themeConfig, theme, elem, name, NULL);
 			} else if (!strcmp(elementsType[TYPE_ATTRIBUTE_IMAGE], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				initAttributeImage(themePath, themeConfig, theme, elem, name);
 			} else if (!strcmp(elementsType[TYPE_GAME_IMAGE], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				initGameImage(themePath, themeConfig, theme, elem, name, NULL, 1, NULL, NULL);
 			} else if (!strcmp(elementsType[TYPE_STATIC_IMAGE], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				initStaticImage(themePath, themeConfig, theme, elem, name, NULL);
 			} else if (!strcmp(elementsType[TYPE_BACKGROUND], type)) {
 				if (!elems->first) { // Background elem can only be the first one
-					elem = initBasic(themePath, themeConfig, theme, name, TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+					elem = initBasic(themePath, themeConfig, theme, name, TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
 					initBackground(themePath, themeConfig, theme, elem, name, NULL, 1, NULL);
 				}
 			} else if (!strcmp(elementsType[TYPE_MENU_ICON], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_ICON, 40, 40, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_ICON, 40, 40, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				elem->drawElem = &drawMenuIcon;
 			} else if (!strcmp(elementsType[TYPE_MENU_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_TEXT, screenWidth >> 1, 20, ALIGN_CENTER, 200, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_TEXT, screenWidth >> 1, 20, ALIGN_CENTER, 200, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				elem->drawElem = &drawMenuText;
 			} else if (!strcmp(elementsType[TYPE_ITEMS_LIST], type)) {
 				if (!theme->itemsList) {
-					elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+					elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 					initItemsList(themePath, themeConfig, theme, elem, name, NULL);
 					theme->itemsList = elem;
 				}
 			} else if (!strcmp(elementsType[TYPE_ITEM_ICON], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 80, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 80, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				initGameImage(themePath, themeConfig, theme, elem, name, "ICO", 20, NULL, NULL);
 			} else if (!strcmp(elementsType[TYPE_ITEM_COVER], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 520, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 520, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 				initGameImage(themePath, themeConfig, theme, elem, name, "COV", 10, NULL, NULL);
 			} else if (!strcmp(elementsType[TYPE_ITEM_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEM_TEXT, 520, 370, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEM_TEXT, 520, 370, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				elem->drawElem = &drawItemText;
 			} else if (!strcmp(elementsType[TYPE_HINT_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				elem->drawElem = &drawHintText;
 			} else if (!strcmp(elementsType[TYPE_INFO_HINT_TEXT], type)) {
-				elem = initBasic(themePath, themeConfig, theme, name, TYPE_INFO_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+				elem = initBasic(themePath, themeConfig, theme, name, TYPE_INFO_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
 				elem->drawElem = &drawInfoHintText;
 			} else if (!strcmp(elementsType[TYPE_LOADING_ICON], type)) {
 				if (!theme->loadingIcon)
-					theme->loadingIcon = initBasic(themePath, themeConfig, theme, name, TYPE_LOADING_ICON, -40, -60, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+					theme->loadingIcon = initBasic(themePath, themeConfig, theme, name, TYPE_LOADING_ICON, -40, -60, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
 			}
 
 			if (elem) {
 		}
 
 		// free fonts
-		for (id = 0; id < THM_MAX_FONTS; ++id) {
-			int fntid = theme->fonts[id];
-
-			if (fntid != FNT_DEFAULT)
-				fntRelease(fntid);
-		}
+		for (id = 0; id < THM_MAX_FONTS; ++id)
+			fntRelease(theme->fonts[id]);
 
 		free(theme);
 		theme = NULL;
 
 static void thmLoadFonts(config_set_t* themeConfig, const char* themePath, theme_t* theme) {
     int fntID; // theme side font id, not the fntSys handle
-	for (fntID = -1; fntID < THM_MAX_FONTS; ++fntID) {
+	for (fntID = 0; fntID < THM_MAX_FONTS; ++fntID) {
 		// does the font by the key exist?
 		char fntKey[16];
 
-		// -1 is a placeholder for default font...
-		if (fntID >= 0) {
-			// Default font handle...
-			theme->fonts[fntID] = FNT_DEFAULT;
+		if (fntID == 0) {
+			snprintf(fntKey, 16, "default_font");
+			theme->fonts[0] = FNT_DEFAULT;
+		} else {
 			snprintf(fntKey, 16, "font%d", fntID);
-		} else {
-			snprintf(fntKey, 16, "default_font");
+			theme->fonts[fntID] = theme->fonts[0];
 		}
 
+		char fullPath[128];
 		char *fntFile;
-		int cfgKeyOK = configGetStr(themeConfig, fntKey, &fntFile);
-		if (!cfgKeyOK && (fntID >= 0))
-			continue;
-
-		char fullPath[128];
-
-		if (fntID < 0) {
-			// replace the default font
-			if (cfgKeyOK) {
-				snprintf(fullPath, 128, "%s%s", themePath, fntFile);
-
-				int size = -1;
-				void* customFont = readFile(fullPath, -1, &size);
-
-				if (customFont)
-					fntReplace(FNT_DEFAULT, customFont, size, 1, 0);
-			} else {
-				// TODO reload the language font file
-				fntSetDefault(FNT_DEFAULT);
-			}
-		} else {
+		if (configGetStr(themeConfig, fntKey, &fntFile)) {
 			snprintf(fullPath, 128, "%s%s", themePath, fntFile);
 			int fntHandle = fntLoadFile(fullPath);
 
 			// Do we have a valid font? Assign the font handle to the theme font slot
 			if (fntHandle != FNT_ERROR)
 				theme->fonts[fntID] = fntHandle;
-		};
-	};
+		}
+	}
 }
 
 static void thmLoad(char* themePath) {
 		addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_ITEM_TEXT], "_");
 		addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_HINT_TEXT], "_");
 		addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_LOADING_ICON], "_");
-
-		// reset the default font to be sure
-		fntSetDefault(FNT_DEFAULT);
 	} else {
 		char path[255];
 		snprintf(path, 255, "%sconf_theme.cfg", themePath);
Add a comment to this file

thirdparty/font_Hungarian.ttf

Binary file modified.

Add a comment to this file

thirdparty/font_Italian.ttf

Binary file added.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.