ttfcompiler : Create image from a font.

ttfcompiler : Create image from a font.

SDL_ttf

See version :

Dépendances (dans l'archive) :
arial.ttf

Download :

#include <stdio.h>
#include <stdlib.h>
#include <sdl/sdl_ttf.h>  // dans votre répertoire SDL

#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdlmain.lib")
#pragma comment(lib,"sdl_ttf.lib")  // dans votre répertore lib (ou sdl_ttf.a)

// n'oubliez pas de mettre la dll sdl_ttf.dll dans votre répertoire !!

void assemblage(int taille,TTF_Font* font,SDL_Color color,SDL_Surface** sortie)
{
    int hauteur;
    int depart=32;
    int nb=224;
    int backline=16;
    char s[2];
    SDL_Surface* temp;
    SDL_Rect Rdst;
    int i;
    s[1]='\0';
    temp = TTF_RenderText_Solid(font,"F",color); // juste pour avoir la hauteur
    hauteur=temp->h;
    SDL_FreeSurface(temp);
    *sortie = SDL_CreateRGBSurface(SDL_SWSURFACE, backline*taille, (nb/backline)*hauteur, 32, 0, 0, 0, 0);
    for(i=depart;i<depart+nb;i++)
    {
        s[0]=(char)i;
        temp=TTF_RenderText_Solid(font,s,color);
        Rdst.x = ((i-depart)%16)*taille+(taille-temp->w)/2;
        Rdst.y = ((i-depart)/16)*hauteur;
        SDL_BlitSurface(temp,NULL,*sortie,&Rdst);
        SDL_FreeSurface(temp);
    }

}

int GetAll(char fichier[500],int* ptaille,int* pitalique,SDL_Color* pcolor)
{
    int tempcolor;
    printf("Bienvenue sur TTF_Compiler\n");
    printf("entrez nom (avec chemin) de la police a compiler\n");
    scanf("%s",fichier);
    printf("Entrez taille\n");
    scanf("%d",ptaille);
    printf("italique ? (1 ou 0)\n");
    scanf("%d",pitalique);
    printf("couleur R (0..255)\n");
    scanf("%d",&tempcolor);
    pcolor->r = tempcolor;
    printf("couleur G (0..255)\n");
    scanf("%d",&tempcolor);
    pcolor->g = tempcolor;
    printf("couleur B (0..255)\n");
    scanf("%d",&tempcolor);
    pcolor->b = tempcolor;
    return 0;
}

int main(int argc,char** argv)
{
    int italique;
    char fichier[500];
    int taille;
    int flag=0;
    TTF_Font* font;
    SDL_Color color;
    SDL_Surface* sortie;
    GetAll(fichier,&taille,&italique,&color);
    SDL_Init(0);
    TTF_Init();
    font = TTF_OpenFont(fichier,taille);
    if (!font)
    {
        printf("Font non trouvee.\n");
        return -1;
    }
    color.r=color.g=color.b=255;
    if (font==NULL)
    {
        printf("font introuvable\n");
        system("pause");
        TTF_Quit();
        return -1;
    }
    if (italique)
        flag|=TTF_STYLE_ITALIC; 
    TTF_SetFontStyle(font,flag);
    assemblage(taille,font,color,&sortie);
    SDL_SaveBMP(sortie,"out.bmp");
    printf("Fini !! (voir out.bmp)\n");
    TTF_Quit();
    return 0;
}




Explanations

	No explanations yet.