From d5143b5f824e3bf1525ff49ebc9c91bf6b3b18cd Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 13 Nov 2008 20:20:47 +0000 Subject: [PATCH] Implemented font listing under linux in a quite hacky way. The directory list returned by XGetFontPath is not really usable, there are some path with appended :unscaled for non-ttf fonts, so i needed to add some null-pointer check to for_each_file after the opendir to avoid a crash. I think most of my ttf fonts gets listed, but at a quick glance i find some duplicates and the list is not alphabetically sorted. That would be a great improvement (sort and remove duplicates). Also renamed Mask to Mask_table because XLib.h already defines some var called Mask. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@337 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- Makefile | 4 ++-- boutons.c | 2 +- files.c | 1 + global.h | 2 +- graph.c | 2 +- init.c | 8 ++++---- texte.c | 36 +++++++++++++++++++++++++++++------- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7a0b5a3f..1d477719 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ else OBJDIR = obj/haiku else - # Linux specific + # Linux specific DELCOMMAND = rm -rf MKDIR = mkdir -p ifdef WIN32CROSS @@ -103,7 +103,7 @@ ifeq ($(NOTTF),1) TTFLABEL = -nottf else TTFCOPT = - TTFLOPT = -L/usr/local/lib -lSDL_ttf + TTFLOPT = -L/usr/local/lib -lSDL_ttf -lX11 TTFLIBS = libfreetype-6.dll SDL_ttf.dll TTFLABEL = endif diff --git a/boutons.c b/boutons.c index 7c970a29..de96a690 100644 --- a/boutons.c +++ b/boutons.c @@ -669,7 +669,7 @@ void Bouton_Mask_Mode(void) void Bouton_Mask_Menu(void) { - Menu_Tag_couleurs("Mask",Mask,&Mask_Mode,1, "MASK"); + Menu_Tag_couleurs("Mask",Mask_table,&Mask_Mode,1, "MASK"); } diff --git a/files.c b/files.c index 7016959e..040228eb 100644 --- a/files.c +++ b/files.c @@ -688,6 +688,7 @@ void for_each_file(const char * Nom_repertoire, void Callback(const char *)) int Position_nom_fichier; strcpy(Nom_fichier_complet, Nom_repertoire); Repertoire_Courant=opendir(Nom_repertoire); + if(Repertoire_Courant == NULL) return; // Répertoire invalide ... strcat(Nom_fichier_complet, SEPARATEUR_CHEMIN); Position_nom_fichier = strlen(Nom_fichier_complet); while ((Enreg=readdir(Repertoire_Courant))) diff --git a/global.h b/global.h index 831fb69f..d069633f 100644 --- a/global.h +++ b/global.h @@ -452,7 +452,7 @@ GLOBAL short Tiling_Decalage_Y; // D // Mode Mask GLOBAL byte Mask_Mode; // Le mode Masque est enclenché -GLOBAL byte Mask[256]; // Tableau des couleurs constituant le masque +GLOBAL byte Mask_table[256]; // Tableau des couleurs constituant le masque // Mode loupe: diff --git a/graph.c b/graph.c index 93ae9990..6755c697 100644 --- a/graph.c +++ b/graph.c @@ -1165,7 +1165,7 @@ void Afficher_pixel(word X,word Y,byte Couleur) { if ( ( (!Trame_Mode) || (Effet_Trame(X,Y)) ) && (!((Stencil_Mode) && (Stencil[Lit_pixel_dans_ecran_courant(X,Y)]))) - && (!((Mask_Mode) && (Mask[Lit_pixel_dans_ecran_brouillon(X,Y)]))) ) + && (!((Mask_Mode) && (Mask_table[Lit_pixel_dans_ecran_brouillon(X,Y)]))) ) { Couleur=Fonction_effet(X,Y,Couleur); Pixel_dans_ecran_courant(X,Y,Couleur); diff --git a/init.c b/init.c index a96256f7..33f61745 100644 --- a/init.c +++ b/init.c @@ -1734,7 +1734,7 @@ int Charger_CFG(int Tout_charger) case CHUNK_MASQUE: // Masque if (Tout_charger) { - if (!read_bytes(Handle, Mask, 256)) + if (!read_bytes(Handle, Mask_table, 256)) goto Erreur_lecture_config; } else @@ -1957,11 +1957,11 @@ int Sauver_CFG(void) // Sauvegarde des informations du Masque Chunk.Numero=CHUNK_MASQUE; - Chunk.Taille=sizeof(Mask); + Chunk.Taille=sizeof(Mask_table); if (!write_byte(Handle, Chunk.Numero) || !write_word_le(Handle, Chunk.Taille) ) goto Erreur_sauvegarde_config; - if (!write_bytes(Handle, Mask,256)) + if (!write_bytes(Handle, Mask_table,256)) goto Erreur_sauvegarde_config; // Sauvegarde des informations du Stencil @@ -2108,7 +2108,7 @@ void Config_par_defaut(void) // Masque for (Indice=0; Indice<256; Indice++) - Mask[Indice]=0; + Mask_table[Indice]=0; // Stencil for (Indice=0; Indice<256; Indice++) diff --git a/texte.c b/texte.c index c5b1157a..ee0ff043 100644 --- a/texte.c +++ b/texte.c @@ -30,9 +30,13 @@ // TrueType #ifndef NOTTF #ifdef __macosx__ -#include + #include #else -#include + #include +#endif + +#ifdef __linux__ + #include #endif #endif #include @@ -110,6 +114,7 @@ void Ajout_fonte(const char *Nom) } + // Trouve le nom d'une fonte par son numéro char * Nom_fonte(int Indice) { @@ -120,6 +125,8 @@ char * Nom_fonte(int Indice) Fonte = Fonte->Suivante; return Fonte->Nom; } + + // Trouve le libellé d'affichage d'une fonte par son numéro char * Libelle_fonte(int Indice) { @@ -148,6 +155,8 @@ char * Libelle_fonte(int Indice) Libelle[Indice]=Nom_fonte[Indice]; return Libelle; } + + // Vérifie si une fonte donnée est TrueType int TrueType_fonte(int Indice) { @@ -183,13 +192,24 @@ void Initialisation_Texte(void) strcat(Nom_repertoire, "fonts"); for_each_file(Nom_repertoire, Ajout_fonte); - // Parcours du répertoire systeme windows "fonts" #ifdef __WIN32__ - #ifndef NOTTF - for_each_file("c:\\windows\\fonts", Ajout_fonte); + // Parcours du répertoire systeme windows "fonts" + #ifndef NOTTF + for_each_file("c:\\windows\\fonts", Ajout_fonte); + #endif + #elif defined(__linux__) + // Récupération de la liste des fonts avec fontconfig + #define USE_XLIB + + #ifdef USE_XLIB + int i,number; + Display* dpy = XOpenDisplay(NULL); + char** font_path_list = XGetFontPath(dpy,&number); + + for(i=0;i