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:
parent
bd23cc6f76
commit
3b4149be49
@ -5740,7 +5740,7 @@ void Bouton_Texte()
|
||||
static char Chaine[256]="";
|
||||
static int Taille_police=16;
|
||||
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;
|
||||
int Nouvelle_Largeur;
|
||||
@ -5896,7 +5896,7 @@ void Bouton_Texte()
|
||||
|
||||
case 11: // OK
|
||||
// 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)
|
||||
{
|
||||
Fermer_fenetre();
|
||||
|
||||
24
files.c
24
files.c
@ -41,6 +41,7 @@
|
||||
|
||||
#include "erreurs.h"
|
||||
#include "linux.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
@ -677,3 +678,26 @@ short Calculer_decalage_click_dans_fileselector(void)
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
files.h
3
files.h
@ -53,3 +53,6 @@ void Select_Home (short * Decalage_premier,short * Decalage_select);
|
||||
short Calculer_decalage_click_dans_fileselector(void);
|
||||
|
||||
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
66
texte.c
@ -25,7 +25,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h> // tolower()
|
||||
|
||||
// TrueType
|
||||
#ifndef NOTTF
|
||||
@ -43,6 +43,7 @@
|
||||
#include "global.h"
|
||||
#include "sdlscreen.h"
|
||||
#include "io.h"
|
||||
#include "files.h"
|
||||
|
||||
typedef struct T_FONTE
|
||||
{
|
||||
@ -59,15 +60,28 @@ T_FONTE * Liste_fontes_fin;
|
||||
int Fonte_nombre;
|
||||
|
||||
// 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));
|
||||
Fonte->Nom = (char *)malloc(strlen(Chemin)+strlen(Nom)+1);
|
||||
strcpy(Fonte->Nom, Chemin);
|
||||
strcat(Fonte->Nom, Nom);
|
||||
Fonte->EstTrueType = EstTrueType;
|
||||
Fonte->EstImage = EstImage;
|
||||
|
||||
int Taille=strlen(Nom)+1;
|
||||
Fonte->Nom = (char *)malloc(Taille);
|
||||
strcpy(Fonte->Nom, Nom);
|
||||
// Détermination du type:
|
||||
// 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
|
||||
Fonte->Suivante = NULL;
|
||||
if (Liste_fontes_debut==NULL)
|
||||
@ -122,11 +136,12 @@ char * Libelle_fonte(int Indice)
|
||||
// Initialisation à faire une fois au début du programme
|
||||
void Initialisation_Texte(void)
|
||||
{
|
||||
/*
|
||||
// Pour scan de répertoire
|
||||
//DIR* Repertoire_Courant; //Répertoire courant
|
||||
//struct dirent* Enreg; // Structure de lecture des éléments
|
||||
//char Nom_repertoire[TAILLE_CHEMIN_FICHIER];
|
||||
|
||||
DIR* Repertoire_Courant; //Répertoire courant
|
||||
struct dirent* Enreg; // Structure de lecture des éléments
|
||||
*/
|
||||
char Nom_repertoire[TAILLE_CHEMIN_FICHIER];
|
||||
#ifndef NOTTF
|
||||
// Initialisation de TTF
|
||||
TTF_Init();
|
||||
@ -136,30 +151,15 @@ void Initialisation_Texte(void)
|
||||
Liste_fontes_debut = Liste_fontes_fin = NULL;
|
||||
Fonte_nombre=0;
|
||||
// Parcours du répertoire "fonts"
|
||||
/*strcpy(Nom_repertoire, Repertoire_du_programme);
|
||||
strcpy(Nom_repertoire, Repertoire_du_programme);
|
||||
strcat(Nom_repertoire, "fonts");
|
||||
Repertoire_Courant=opendir(Nom_repertoire);
|
||||
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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
for_each_file(Nom_repertoire, Ajout_fonte);
|
||||
|
||||
Ajout_fonte(Repertoire_du_programme,"fonts/Tuffy.ttf", 1, 0);
|
||||
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"
|
||||
// Parcours du répertoire systeme windows "fonts"
|
||||
#ifdef __WIN32__
|
||||
Ajout_fonte("c:/windows/fonts/","arial.ttf", 1, 0);
|
||||
Ajout_fonte("c:/windows/fonts/","cour.ttf", 1, 0);
|
||||
#ifndef NOTTF
|
||||
for_each_file("c:\\windows\\fonts", Ajout_fonte);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
2
texte.h
2
texte.h
@ -25,7 +25,7 @@ void Initialisation_Texte(void);
|
||||
// Informe si texte.c a été compilé avec l'option de support TrueType ou pas.
|
||||
int Support_TrueType(void);
|
||||
// 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.
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user