Text: Fonts are scanned in fonts/ and Windows own directory

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@319 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2008-10-31 20:03:58 +00:00
parent bd23cc6f76
commit 3b4149be49
5 changed files with 63 additions and 36 deletions

View File

@ -5740,7 +5740,7 @@ void Bouton_Texte()
static char Chaine[256]=""; static char Chaine[256]="";
static int Taille_police=16; static int Taille_police=16;
static int AntiAlias=0; static int AntiAlias=0;
short Debut_liste=0, Position_curseur=0; // Selecteur de fonte static short Debut_liste=0, Position_curseur=0; // Selecteur de fonte
byte * Nouvelle_Brosse; byte * Nouvelle_Brosse;
int Nouvelle_Largeur; int Nouvelle_Largeur;
@ -5896,7 +5896,7 @@ void Bouton_Texte()
case 11: // OK case 11: // OK
// Rendu texte // Rendu texte
Nouvelle_Brosse = Rendu_Texte(Chaine, Position_curseur, Taille_police, AntiAlias, &Nouvelle_Largeur, &Nouvelle_Hauteur); Nouvelle_Brosse = Rendu_Texte(Chaine, Position_curseur+Debut_liste, Taille_police, AntiAlias, &Nouvelle_Largeur, &Nouvelle_Hauteur);
if (!Nouvelle_Brosse) if (!Nouvelle_Brosse)
{ {
Fermer_fenetre(); Fermer_fenetre();

24
files.c
View File

@ -41,6 +41,7 @@
#include "erreurs.h" #include "erreurs.h"
#include "linux.h" #include "linux.h"
#include "io.h"
#ifdef __linux__ #ifdef __linux__
@ -677,3 +678,26 @@ short Calculer_decalage_click_dans_fileselector(void)
return Decalage_calcule; return Decalage_calcule;
} }
void for_each_file(const char * Nom_repertoire, void Callback(const char *))
{
// Pour scan de répertoire
DIR* Repertoire_Courant; //Répertoire courant
struct dirent* Enreg; // Structure de lecture des éléments
char Nom_fichier_complet[TAILLE_CHEMIN_FICHIER];
int Position_nom_fichier;
strcpy(Nom_fichier_complet, Nom_repertoire);
Repertoire_Courant=opendir(Nom_repertoire);
strcat(Nom_fichier_complet, SEPARATEUR_CHEMIN);
Position_nom_fichier = strlen(Nom_fichier_complet);
while ((Enreg=readdir(Repertoire_Courant)))
{
struct stat Infos_enreg;
strcpy(&Nom_fichier_complet[Position_nom_fichier], Enreg->d_name);
stat(Nom_fichier_complet,&Infos_enreg);
if (S_ISREG(Infos_enreg.st_mode))
{
Callback(Nom_fichier_complet);
}
}
}

View File

@ -53,3 +53,6 @@ void Select_Home (short * Decalage_premier,short * Decalage_select);
short Calculer_decalage_click_dans_fileselector(void); short Calculer_decalage_click_dans_fileselector(void);
char * Nom_formate(char * Nom, int Type); char * Nom_formate(char * Nom, int Type);
// Scans a directory, calls Callback for each file in it,
void for_each_file(const char * Nom_repertoire, void Callback(const char *));

66
texte.c
View File

@ -25,7 +25,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <dirent.h> #include <ctype.h> // tolower()
// TrueType // TrueType
#ifndef NOTTF #ifndef NOTTF
@ -43,6 +43,7 @@
#include "global.h" #include "global.h"
#include "sdlscreen.h" #include "sdlscreen.h"
#include "io.h" #include "io.h"
#include "files.h"
typedef struct T_FONTE typedef struct T_FONTE
{ {
@ -59,15 +60,28 @@ T_FONTE * Liste_fontes_fin;
int Fonte_nombre; int Fonte_nombre;
// Ajout d'une fonte à la liste. // Ajout d'une fonte à la liste.
void Ajout_fonte(char *Chemin, char *Nom, int EstTrueType, int EstImage) void Ajout_fonte(const char *Nom)
{ {
T_FONTE * Fonte = (T_FONTE *)malloc(sizeof(T_FONTE)); T_FONTE * Fonte = (T_FONTE *)malloc(sizeof(T_FONTE));
Fonte->Nom = (char *)malloc(strlen(Chemin)+strlen(Nom)+1); int Taille=strlen(Nom)+1;
strcpy(Fonte->Nom, Chemin); Fonte->Nom = (char *)malloc(Taille);
strcat(Fonte->Nom, Nom); strcpy(Fonte->Nom, Nom);
Fonte->EstTrueType = EstTrueType; // Détermination du type:
Fonte->EstImage = EstImage; // On va faire simple: .TTF c'est TrueType, sinon on tente Bitmap.
if (Taille>=5 &&
Fonte->Nom[Taille-5]=='.' &&
tolower(Fonte->Nom[Taille-4]) == 't' &&
tolower(Fonte->Nom[Taille-3]) == 't' &&
tolower(Fonte->Nom[Taille-2]) == 'f')
{
Fonte->EstTrueType = 1;
Fonte->EstImage = 0;
}
else
{
Fonte->EstTrueType = 0;
Fonte->EstImage = 1;
}
// Gestion Liste // Gestion Liste
Fonte->Suivante = NULL; Fonte->Suivante = NULL;
if (Liste_fontes_debut==NULL) if (Liste_fontes_debut==NULL)
@ -122,11 +136,12 @@ char * Libelle_fonte(int Indice)
// Initialisation à faire une fois au début du programme // Initialisation à faire une fois au début du programme
void Initialisation_Texte(void) void Initialisation_Texte(void)
{ {
/*
// Pour scan de répertoire // Pour scan de répertoire
//DIR* Repertoire_Courant; //Répertoire courant DIR* Repertoire_Courant; //Répertoire courant
//struct dirent* Enreg; // Structure de lecture des éléments struct dirent* Enreg; // Structure de lecture des éléments
//char Nom_repertoire[TAILLE_CHEMIN_FICHIER]; */
char Nom_repertoire[TAILLE_CHEMIN_FICHIER];
#ifndef NOTTF #ifndef NOTTF
// Initialisation de TTF // Initialisation de TTF
TTF_Init(); TTF_Init();
@ -136,30 +151,15 @@ void Initialisation_Texte(void)
Liste_fontes_debut = Liste_fontes_fin = NULL; Liste_fontes_debut = Liste_fontes_fin = NULL;
Fonte_nombre=0; Fonte_nombre=0;
// Parcours du répertoire "fonts" // Parcours du répertoire "fonts"
/*strcpy(Nom_repertoire, Repertoire_du_programme); strcpy(Nom_repertoire, Repertoire_du_programme);
strcat(Nom_repertoire, "fonts"); strcat(Nom_repertoire, "fonts");
Repertoire_Courant=opendir(Nom_repertoire); for_each_file(Nom_repertoire, Ajout_fonte);
strcat(Nom_repertoire, SEPARATEUR_CHEMIN);
while ((Enreg=readdir(Repertoire_Courant)))
{
struct stat Infos_enreg;
stat(Enreg->d_name,&Infos_enreg);
if (S_ISREG(Infos_enreg.st_mode))
{
Ajout_fonte(Repertoire_Courant,Enreg->d_name, 1, 0);
}
}
*/
Ajout_fonte(Repertoire_du_programme,"fonts/Tuffy.ttf", 1, 0); // Parcours du répertoire systeme windows "fonts"
Ajout_fonte(Repertoire_du_programme,"fonts/5pxtinyfont.png", 0, 1);
Ajout_fonte(Repertoire_du_programme,"fonts/colorfont.pcx", 0, 1);
Ajout_fonte(Repertoire_du_programme,"fonts/8pxfont.png", 0, 1);
// Parcours du répertoire systeme windows "fontes"
#ifdef __WIN32__ #ifdef __WIN32__
Ajout_fonte("c:/windows/fonts/","arial.ttf", 1, 0); #ifndef NOTTF
Ajout_fonte("c:/windows/fonts/","cour.ttf", 1, 0); for_each_file("c:\\windows\\fonts", Ajout_fonte);
#endif
#endif #endif
} }

View File

@ -25,7 +25,7 @@ void Initialisation_Texte(void);
// 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.
int Support_TrueType(void); int Support_TrueType(void);
// Ajout d'une fonte à la liste. // Ajout d'une fonte à la liste.
void Ajout_fonte(char *Nom, int EstTrueType, int EstImage); void Ajout_fonte(char *Nom);
// Crée une brosse à partir des paramètres de texte demandés. // Crée une brosse à partir des paramètres de texte demandés.
byte *Rendu_Texte(const char *Chaine, int Numero_fonte, int Taille, int AntiAlias, int *Largeur, int *Hauteur); byte *Rendu_Texte(const char *Chaine, int Numero_fonte, int Taille, int AntiAlias, int *Largeur, int *Hauteur);
// Trouve le libellé d'affichage d'une fonte par son numéro // Trouve le libellé d'affichage d'une fonte par son numéro