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
This commit is contained in:
Adrien Destugues 2008-11-13 20:20:47 +00:00
parent 038303721c
commit d5143b5f82
7 changed files with 39 additions and 16 deletions

View File

@ -71,7 +71,7 @@ else
OBJDIR = obj/haiku OBJDIR = obj/haiku
else else
# Linux specific # Linux specific
DELCOMMAND = rm -rf DELCOMMAND = rm -rf
MKDIR = mkdir -p MKDIR = mkdir -p
ifdef WIN32CROSS ifdef WIN32CROSS
@ -103,7 +103,7 @@ ifeq ($(NOTTF),1)
TTFLABEL = -nottf TTFLABEL = -nottf
else else
TTFCOPT = TTFCOPT =
TTFLOPT = -L/usr/local/lib -lSDL_ttf TTFLOPT = -L/usr/local/lib -lSDL_ttf -lX11
TTFLIBS = libfreetype-6.dll SDL_ttf.dll TTFLIBS = libfreetype-6.dll SDL_ttf.dll
TTFLABEL = TTFLABEL =
endif endif

View File

@ -669,7 +669,7 @@ void Bouton_Mask_Mode(void)
void Bouton_Mask_Menu(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");
} }

View File

@ -688,6 +688,7 @@ void for_each_file(const char * Nom_repertoire, void Callback(const char *))
int Position_nom_fichier; int Position_nom_fichier;
strcpy(Nom_fichier_complet, Nom_repertoire); strcpy(Nom_fichier_complet, Nom_repertoire);
Repertoire_Courant=opendir(Nom_repertoire); Repertoire_Courant=opendir(Nom_repertoire);
if(Repertoire_Courant == NULL) return; // Répertoire invalide ...
strcat(Nom_fichier_complet, SEPARATEUR_CHEMIN); strcat(Nom_fichier_complet, SEPARATEUR_CHEMIN);
Position_nom_fichier = strlen(Nom_fichier_complet); Position_nom_fichier = strlen(Nom_fichier_complet);
while ((Enreg=readdir(Repertoire_Courant))) while ((Enreg=readdir(Repertoire_Courant)))

View File

@ -452,7 +452,7 @@ GLOBAL short Tiling_Decalage_Y; // D
// Mode Mask // Mode Mask
GLOBAL byte Mask_Mode; // Le mode Masque est enclenché 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: // Mode loupe:

View File

@ -1165,7 +1165,7 @@ void Afficher_pixel(word X,word Y,byte Couleur)
{ {
if ( ( (!Trame_Mode) || (Effet_Trame(X,Y)) ) if ( ( (!Trame_Mode) || (Effet_Trame(X,Y)) )
&& (!((Stencil_Mode) && (Stencil[Lit_pixel_dans_ecran_courant(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); Couleur=Fonction_effet(X,Y,Couleur);
Pixel_dans_ecran_courant(X,Y,Couleur); Pixel_dans_ecran_courant(X,Y,Couleur);

8
init.c
View File

@ -1734,7 +1734,7 @@ int Charger_CFG(int Tout_charger)
case CHUNK_MASQUE: // Masque case CHUNK_MASQUE: // Masque
if (Tout_charger) if (Tout_charger)
{ {
if (!read_bytes(Handle, Mask, 256)) if (!read_bytes(Handle, Mask_table, 256))
goto Erreur_lecture_config; goto Erreur_lecture_config;
} }
else else
@ -1957,11 +1957,11 @@ int Sauver_CFG(void)
// Sauvegarde des informations du Masque // Sauvegarde des informations du Masque
Chunk.Numero=CHUNK_MASQUE; Chunk.Numero=CHUNK_MASQUE;
Chunk.Taille=sizeof(Mask); Chunk.Taille=sizeof(Mask_table);
if (!write_byte(Handle, Chunk.Numero) || if (!write_byte(Handle, Chunk.Numero) ||
!write_word_le(Handle, Chunk.Taille) ) !write_word_le(Handle, Chunk.Taille) )
goto Erreur_sauvegarde_config; goto Erreur_sauvegarde_config;
if (!write_bytes(Handle, Mask,256)) if (!write_bytes(Handle, Mask_table,256))
goto Erreur_sauvegarde_config; goto Erreur_sauvegarde_config;
// Sauvegarde des informations du Stencil // Sauvegarde des informations du Stencil
@ -2108,7 +2108,7 @@ void Config_par_defaut(void)
// Masque // Masque
for (Indice=0; Indice<256; Indice++) for (Indice=0; Indice<256; Indice++)
Mask[Indice]=0; Mask_table[Indice]=0;
// Stencil // Stencil
for (Indice=0; Indice<256; Indice++) for (Indice=0; Indice<256; Indice++)

36
texte.c
View File

@ -30,9 +30,13 @@
// TrueType // TrueType
#ifndef NOTTF #ifndef NOTTF
#ifdef __macosx__ #ifdef __macosx__
#include <SDL_ttf/SDL_ttf.h> #include <SDL_ttf/SDL_ttf.h>
#else #else
#include <SDL/SDL_ttf.h> #include <SDL/SDL_ttf.h>
#endif
#ifdef __linux__
#include <X11/Xlib.h>
#endif #endif
#endif #endif
#include <SDL/SDL_image.h> #include <SDL/SDL_image.h>
@ -110,6 +114,7 @@ void Ajout_fonte(const char *Nom)
} }
// Trouve le nom d'une fonte par son numéro // Trouve le nom d'une fonte par son numéro
char * Nom_fonte(int Indice) char * Nom_fonte(int Indice)
{ {
@ -120,6 +125,8 @@ char * Nom_fonte(int Indice)
Fonte = Fonte->Suivante; Fonte = Fonte->Suivante;
return Fonte->Nom; return Fonte->Nom;
} }
// Trouve le libellé d'affichage d'une fonte par son numéro // Trouve le libellé d'affichage d'une fonte par son numéro
char * Libelle_fonte(int Indice) char * Libelle_fonte(int Indice)
{ {
@ -148,6 +155,8 @@ char * Libelle_fonte(int Indice)
Libelle[Indice]=Nom_fonte[Indice]; Libelle[Indice]=Nom_fonte[Indice];
return Libelle; return Libelle;
} }
// Vérifie si une fonte donnée est TrueType // Vérifie si une fonte donnée est TrueType
int TrueType_fonte(int Indice) int TrueType_fonte(int Indice)
{ {
@ -183,13 +192,24 @@ void Initialisation_Texte(void)
strcat(Nom_repertoire, "fonts"); strcat(Nom_repertoire, "fonts");
for_each_file(Nom_repertoire, Ajout_fonte); for_each_file(Nom_repertoire, Ajout_fonte);
// Parcours du répertoire systeme windows "fonts"
#ifdef __WIN32__ #ifdef __WIN32__
#ifndef NOTTF // Parcours du répertoire systeme windows "fonts"
for_each_file("c:\\windows\\fonts", Ajout_fonte); #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<number;i++)
for_each_file(*(font_path_list+i),Ajout_fonte);
#endif
#endif #endif
#endif
} }
// Informe si texte.c a été compilé avec l'option de support TrueType ou pas. // Informe si texte.c a été compilé avec l'option de support TrueType ou pas.
@ -276,6 +296,7 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Numero_fonte, int Taille, int Anti
} }
#endif #endif
byte *Rendu_Texte_SFont(const char *Chaine, int Numero_fonte, int *Largeur, int *Hauteur) byte *Rendu_Texte_SFont(const char *Chaine, int Numero_fonte, int *Largeur, int *Hauteur)
{ {
SFont_Font *Fonte; SFont_Font *Fonte;
@ -324,6 +345,7 @@ byte *Rendu_Texte_SFont(const char *Chaine, int Numero_fonte, int *Largeur, int
return BrosseRetour; return BrosseRetour;
} }
// Crée une brosse à partir des paramètres de texte demandés. // Crée une brosse à partir des paramètres de texte demandés.
// Si cela réussit, la fonction place les dimensions dans Largeur et Hauteur, // Si cela réussit, la fonction place les dimensions dans Largeur et Hauteur,
// et retourne l'adresse du bloc d'octets. // et retourne l'adresse du bloc d'octets.