Source code translated to english

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@697 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2009-03-27 16:50:21 +00:00
parent 6b4a8f674e
commit efbc978e6f
68 changed files with 22766 additions and 22766 deletions

286
texte.c
View File

@@ -56,41 +56,41 @@
#include "sdlscreen.h"
#include "io.h"
typedef struct T_FONTE
typedef struct T_Font
{
char * Name;
int EstTrueType;
int EstImage;
int Is_truetype;
int Is_bitmap;
char Label[22];
// Liste chainée simple
struct T_FONTE * Suivante;
struct T_FONTE * Precedente;
} T_FONTE;
struct T_Font * Next;
struct T_Font * Previous;
} T_Font;
// Liste chainée des polices de texte
T_FONTE * Liste_fontes_debut;
int Fonte_nombre;
T_Font * Font_list_start;
int Nb_fonts;
// Inspiré par Allegro
#define EXTID(a,b,c) ((((a)&255)<<16) | (((b)&255)<<8) | (((c)&255)))
#define EXTID4(a,b,c,d) ((((a)&255)<<24) | (((b)&255)<<16) | (((c)&255)<<8) | (((d)&255)))
int Compare_fontes(T_FONTE * Fonte1, T_FONTE * Fonte2)
int Compare_fonts(T_Font * font_1, T_Font * font_2)
{
if (Fonte1->EstImage && !Fonte2->EstImage)
if (font_1->Is_bitmap && !font_2->Is_bitmap)
return -1;
if (Fonte2->EstImage && !Fonte1->EstImage)
if (font_2->Is_bitmap && !font_1->Is_bitmap)
return 1;
return strcmp(Fonte1->Label, Fonte2->Label);
return strcmp(font_1->Label, font_2->Label);
}
// Ajout d'une fonte à la liste.
void Ajout_fonte(const char *name)
void Add_font(const char *name)
{
char * Nom_fonte;
T_FONTE * Fonte;
char * Font_name;
T_Font * Font;
int size=strlen(name)+1;
int Indice;
int index;
// Détermination du type:
@@ -114,7 +114,7 @@ void Ajout_fonte(const char *name)
return;
#endif
Fonte = (T_FONTE *)malloc(sizeof(T_FONTE));
Font = (T_Font *)malloc(sizeof(T_Font));
switch (EXTID(tolower(name[size-4]), tolower(name[size-3]), tolower(name[size-2])))
{
@@ -122,8 +122,8 @@ void Ajout_fonte(const char *name)
case EXTID('f','o','n'):
case EXTID('o','t','f'):
case EXTID('p','f','b'):
Fonte->EstTrueType = 1;
Fonte->EstImage = 0;
Font->Is_truetype = 1;
Font->Is_bitmap = 0;
break;
case EXTID('b','m','p'):
case EXTID('g','i','f'):
@@ -136,153 +136,153 @@ void Ajout_fonte(const char *name)
case EXTID('x','c','f'):
case EXTID('x','p','m'):
case EXTID('.','x','v'):
Fonte->EstTrueType = 0;
Fonte->EstImage = 1;
Font->Is_truetype = 0;
Font->Is_bitmap = 1;
break;
default:
#ifdef __macosx__
if(strcasecmp(&name[size-6], "dfont") == 0)
{
Fonte->EstTrueType = 1;
Fonte->EstImage = 0;
Font->Is_truetype = 1;
Font->Is_bitmap = 0;
}
else
{
free(Fonte);
free(Font);
return;
}
#else
free(Fonte);
free(Font);
return;
#endif
}
Fonte->Name = (char *)malloc(size);
strcpy(Fonte->Name, name);
Font->Name = (char *)malloc(size);
strcpy(Font->Name, name);
// Label
strcpy(Fonte->Label, " ");
if (Fonte->EstTrueType)
Fonte->Label[17]=Fonte->Label[18]='T'; // Logo TT
Nom_fonte=Position_dernier_slash(Fonte->Name);
if (Nom_fonte==NULL)
Nom_fonte=Fonte->Name;
strcpy(Font->Label, " ");
if (Font->Is_truetype)
Font->Label[17]=Font->Label[18]='T'; // Logo TT
Font_name=Find_last_slash(Font->Name);
if (Font_name==NULL)
Font_name=Font->Name;
else
Nom_fonte++;
for (Indice=0; Indice < 17 && Nom_fonte[Indice]!='\0' && Nom_fonte[Indice]!='.'; Indice++)
Fonte->Label[Indice]=Nom_fonte[Indice];
Font_name++;
for (index=0; index < 17 && Font_name[index]!='\0' && Font_name[index]!='.'; index++)
Font->Label[index]=Font_name[index];
// Gestion Liste
Fonte->Suivante = NULL;
Fonte->Precedente = NULL;
if (Liste_fontes_debut==NULL)
Font->Next = NULL;
Font->Previous = NULL;
if (Font_list_start==NULL)
{
// Premiere (liste vide)
Liste_fontes_debut = Fonte;
Fonte_nombre++;
Font_list_start = Font;
Nb_fonts++;
}
else
{
int Compare;
Compare = Compare_fontes(Fonte, Liste_fontes_debut);
if (Compare<=0)
int compare;
compare = Compare_fonts(Font, Font_list_start);
if (compare<=0)
{
if (Compare==0 && !strcmp(Fonte->Name, Liste_fontes_debut->Name))
if (compare==0 && !strcmp(Font->Name, Font_list_start->Name))
{
// Doublon
free(Fonte->Name);
free(Fonte);
free(Font->Name);
free(Font);
return;
}
// Avant la premiere
Fonte->Suivante=Liste_fontes_debut;
Liste_fontes_debut=Fonte;
Fonte_nombre++;
Font->Next=Font_list_start;
Font_list_start=Font;
Nb_fonts++;
}
else
{
T_FONTE *Fonte_cherchee;
Fonte_cherchee=Liste_fontes_debut;
while (Fonte_cherchee->Suivante && (Compare=Compare_fontes(Fonte, Fonte_cherchee->Suivante))>0)
Fonte_cherchee=Fonte_cherchee->Suivante;
// Après Fonte_cherchee
if (Compare==0 && strcmp(Fonte->Name, Fonte_cherchee->Suivante->Name)==0)
T_Font *searched_font;
searched_font=Font_list_start;
while (searched_font->Next && (compare=Compare_fonts(Font, searched_font->Next))>0)
searched_font=searched_font->Next;
// Après searched_font
if (compare==0 && strcmp(Font->Name, searched_font->Next->Name)==0)
{
// Doublon
free(Fonte->Name);
free(Fonte);
free(Font->Name);
free(Font);
return;
}
Fonte->Suivante=Fonte_cherchee->Suivante;
Fonte_cherchee->Suivante=Fonte;
Fonte_nombre++;
Font->Next=searched_font->Next;
searched_font->Next=Font;
Nb_fonts++;
}
}
}
// Trouve le nom d'une fonte par son numéro
char * Nom_fonte(int Indice)
char * Font_name(int index)
{
T_FONTE *Fonte = Liste_fontes_debut;
if (Indice<0 ||Indice>=Fonte_nombre)
T_Font *Font = Font_list_start;
if (index<0 ||index>=Nb_fonts)
return "";
while (Indice--)
Fonte = Fonte->Suivante;
return Fonte->Name;
while (index--)
Font = Font->Next;
return Font->Name;
}
// Trouve le libellé d'affichage d'une fonte par son numéro
// Renvoie un pointeur sur un buffer statique de 20 caracteres.
char * Libelle_fonte(int Indice)
char * Font_label(int index)
{
T_FONTE *Fonte;
T_Font *Font;
static char label[20];
strcpy(label, " ");
// Recherche de la fonte
Fonte = Liste_fontes_debut;
if (Indice<0 ||Indice>=Fonte_nombre)
Font = Font_list_start;
if (index<0 ||index>=Nb_fonts)
return label;
while (Indice--)
Fonte = Fonte->Suivante;
while (index--)
Font = Font->Next;
// Libellé
strcpy(label, Fonte->Label);
strcpy(label, Font->Label);
return label;
}
// Vérifie si une fonte donnée est TrueType
int TrueType_fonte(int Indice)
int TrueType_font(int index)
{
T_FONTE *Fonte = Liste_fontes_debut;
if (Indice<0 ||Indice>=Fonte_nombre)
T_Font *Font = Font_list_start;
if (index<0 ||index>=Nb_fonts)
return 0;
while (Indice--)
Fonte = Fonte->Suivante;
return Fonte->EstTrueType;
while (index--)
Font = Font->Next;
return Font->Is_truetype;
}
// Initialisation à faire une fois au début du programme
void Initialisation_Texte(void)
void Init_text(void)
{
char Nom_repertoire[TAILLE_CHEMIN_FICHIER];
char directory_name[MAX_PATH_CHARACTERS];
#ifndef NOTTF
// Initialisation de TTF
TTF_Init();
#endif
// Initialisation des fontes
Liste_fontes_debut = NULL;
Fonte_nombre=0;
Font_list_start = NULL;
Nb_fonts=0;
// Parcours du répertoire "fonts"
strcpy(Nom_repertoire, Repertoire_des_donnees);
strcat(Nom_repertoire, "fonts");
for_each_file(Nom_repertoire, Ajout_fonte);
strcpy(directory_name, Repertoire_des_donnees);
strcat(directory_name, "fonts");
For_each_file(directory_name, Add_font);
#ifdef __WIN32__
// Parcours du répertoire systeme windows "fonts"
@@ -291,8 +291,8 @@ void Initialisation_Texte(void)
char * WindowsPath=getenv("windir");
if (WindowsPath)
{
sprintf(Nom_repertoire, "%s\\FONTS", WindowsPath);
for_each_file(Nom_repertoire, Ajout_fonte);
sprintf(directory_name, "%s\\FONTS", WindowsPath);
For_each_file(directory_name, Add_font);
}
}
#endif
@@ -315,7 +315,7 @@ void Initialisation_Texte(void)
font_path_list[2] = home_dir;
for(i=0;i<number;i++)
for_each_file(*(font_path_list+i),Ajout_fonte);
For_each_file(*(font_path_list+i),Add_font);
CFRelease(url);
#endif
@@ -332,7 +332,7 @@ void Initialisation_Texte(void)
XCloseDisplay(dpy);
for(i=0;i<number;i++)
for_each_file(*(font_path_list+i),Ajout_fonte);
For_each_file(*(font_path_list+i),Add_font);
XFreeFontPath(font_path_list);
}
@@ -340,23 +340,23 @@ void Initialisation_Texte(void)
#endif
#elif defined(__amigaos4__)
#ifndef NOTTF
for_each_file( "FONTS:_TrueType", Ajout_fonte );
For_each_file( "FONTS:_TrueType", Add_font );
#endif
#elif defined(__BEOS__) || defined(__HAIKU__)
#ifndef NOTTF
for_each_file("/etc/fonts/ttfonts", Ajout_fonte);
For_each_file("/etc/fonts/ttfonts", Add_font);
#endif
#elif defined(__SKYOS__)
#ifndef NOTTF
for_each_file("/boot/system/fonts", Ajout_fonte);
For_each_file("/boot/system/fonts", Add_font);
#endif
#endif
}
// Informe si texte.c a été compilé avec l'option de support TrueType ou pas.
int Support_TrueType()
int TrueType_is_supported()
{
#ifdef NOTTF
return 0;
@@ -367,21 +367,21 @@ int Support_TrueType()
#ifndef NOTTF
byte *Rendu_Texte_TTF(const char *Chaine, int Numero_fonte, int size, int antialias, int bold, int italic, int *width, int *height)
byte *Render_text_TTF(const char *str, int font_number, int size, int antialias, int bold, int italic, int *width, int *height)
{
TTF_Font *Fonte;
TTF_Font *Font;
SDL_Surface * TexteColore;
SDL_Surface * Texte8Bit;
byte * BrosseRetour;
int Indice;
byte * new_brush;
int index;
int style;
SDL_Color Couleur_Avant;
SDL_Color Couleur_Arriere;
// Chargement de la fonte
Fonte=TTF_OpenFont(Nom_fonte(Numero_fonte), size);
if (!Fonte)
Font=TTF_OpenFont(Font_name(font_number), size);
if (!Font)
{
return NULL;
}
@@ -391,28 +391,28 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Numero_fonte, int size, int antial
style|=TTF_STYLE_ITALIC;
if (bold)
style|=TTF_STYLE_BOLD;
TTF_SetFontStyle(Fonte, style);
TTF_SetFontStyle(Font, style);
// Couleurs
if (antialias)
{
Couleur_Avant = Conversion_couleur_SDL(Fore_color);
Couleur_Arriere = Conversion_couleur_SDL(Back_color);
Couleur_Avant = Color_to_SDL_color(Fore_color);
Couleur_Arriere = Color_to_SDL_color(Back_color);
}
else
{
Couleur_Avant = Conversion_couleur_SDL(CM_Blanc);
Couleur_Arriere = Conversion_couleur_SDL(CM_Noir);
Couleur_Avant = Color_to_SDL_color(MC_White);
Couleur_Arriere = Color_to_SDL_color(MC_Black);
}
// Rendu du texte: crée une surface SDL RGB 24bits
if (antialias)
TexteColore=TTF_RenderText_Shaded(Fonte, Chaine, Couleur_Avant, Couleur_Arriere );
TexteColore=TTF_RenderText_Shaded(Font, str, Couleur_Avant, Couleur_Arriere );
else
TexteColore=TTF_RenderText_Solid(Fonte, Chaine, Couleur_Avant);
TexteColore=TTF_RenderText_Solid(Font, str, Couleur_Avant);
if (!TexteColore)
{
TTF_CloseFont(Fonte);
TTF_CloseFont(Font);
return NULL;
}
@@ -420,108 +420,108 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Numero_fonte, int size, int antial
SDL_FreeSurface(TexteColore);
BrosseRetour=Surface_en_bytefield(Texte8Bit, NULL);
if (!BrosseRetour)
new_brush=Surface_to_bytefield(Texte8Bit, NULL);
if (!new_brush)
{
SDL_FreeSurface(TexteColore);
SDL_FreeSurface(Texte8Bit);
TTF_CloseFont(Fonte);
TTF_CloseFont(Font);
return NULL;
}
if (!antialias)
{
// Mappage des couleurs
for (Indice=0; Indice < Texte8Bit->w * Texte8Bit->h; Indice++)
for (index=0; index < Texte8Bit->w * Texte8Bit->h; index++)
{
if (*(BrosseRetour+Indice) == CM_Noir)
*(BrosseRetour+Indice)=Back_color;
else if (*(BrosseRetour+Indice) == CM_Blanc)
*(BrosseRetour+Indice)=Fore_color;
if (*(new_brush+index) == MC_Black)
*(new_brush+index)=Back_color;
else if (*(new_brush+index) == MC_White)
*(new_brush+index)=Fore_color;
}
}
*width=Texte8Bit->w;
*height=Texte8Bit->h;
SDL_FreeSurface(Texte8Bit);
TTF_CloseFont(Fonte);
return BrosseRetour;
TTF_CloseFont(Font);
return new_brush;
}
#endif
byte *Rendu_Texte_SFont(const char *Chaine, int Numero_fonte, int *width, int *height)
byte *Render_text_SFont(const char *str, int font_number, int *width, int *height)
{
SFont_Font *Fonte;
SFont_Font *Font;
SDL_Surface * TexteColore;
SDL_Surface * Texte8Bit;
SDL_Surface *Surface_fonte;
byte * BrosseRetour;
byte * new_brush;
// Chargement de la fonte
Surface_fonte=IMG_Load(Nom_fonte(Numero_fonte));
Surface_fonte=IMG_Load(Font_name(font_number));
if (!Surface_fonte)
return NULL;
Fonte=SFont_InitFont(Surface_fonte);
if (!Fonte)
Font=SFont_InitFont(Surface_fonte);
if (!Font)
{
return NULL;
}
// Calcul des dimensions
*height=SFont_TextHeight(Fonte);
*width=SFont_TextWidth(Fonte, Chaine);
*height=SFont_TextHeight(Font);
*width=SFont_TextWidth(Font, str);
// Allocation d'une surface SDL
TexteColore=SDL_CreateRGBSurface(SDL_SWSURFACE, *width, *height, 24, 0, 0, 0, 0);
// Rendu du texte
SFont_Write(TexteColore, Fonte, 0, 0, Chaine);
SFont_Write(TexteColore, Font, 0, 0, str);
if (!TexteColore)
{
SFont_FreeFont(Fonte);
SFont_FreeFont(Font);
return NULL;
}
Texte8Bit=SDL_DisplayFormat(TexteColore);
SDL_FreeSurface(TexteColore);
BrosseRetour=Surface_en_bytefield(Texte8Bit, NULL);
if (!BrosseRetour)
new_brush=Surface_to_bytefield(Texte8Bit, NULL);
if (!new_brush)
{
SDL_FreeSurface(TexteColore);
SDL_FreeSurface(Texte8Bit);
SFont_FreeFont(Fonte);
SFont_FreeFont(Font);
return NULL;
}
SDL_FreeSurface(Texte8Bit);
SFont_FreeFont(Fonte);
SFont_FreeFont(Font);
return BrosseRetour;
return new_brush;
}
// Crée une brosse à partir des paramètres de texte demandés.
// Si cela réussit, la fonction place les dimensions dans width et height,
// et retourne l'adresse du bloc d'octets.
byte *Rendu_Texte(const char *Chaine, int Numero_fonte, int size, int antialias, int bold, int italic, int *width, int *height)
byte *Render_text(const char *str, int font_number, int size, int antialias, int bold, int italic, int *width, int *height)
{
T_FONTE *Fonte = Liste_fontes_debut;
int Indice=Numero_fonte;
T_Font *Font = Font_list_start;
int index=font_number;
// Verification type de la fonte
if (Numero_fonte<0 ||Numero_fonte>=Fonte_nombre)
if (font_number<0 ||font_number>=Nb_fonts)
return NULL;
while (Indice--)
Fonte = Fonte->Suivante;
if (Fonte->EstTrueType)
while (index--)
Font = Font->Next;
if (Font->Is_truetype)
{
#ifndef NOTTF
return Rendu_Texte_TTF(Chaine, Numero_fonte, size, antialias, bold, italic, width, height);
return Render_text_TTF(str, font_number, size, antialias, bold, italic, width, height);
#else
return NULL;
#endif
}
else
{
return Rendu_Texte_SFont(Chaine, Numero_fonte, width, height);
return Render_text_SFont(str, font_number, width, height);
}
}