[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] Need help to compile application
From: |
Vinayak SWARUP |
Subject: |
[ft] Need help to compile application |
Date: |
Mon, 9 May 2011 20:57:28 +0800 |
Hi,
I am trying to use Freetype 2 library to develop a simple application that
converts UTF-8 text to bitmaps. On the mailing list I came across an example
that takes ASCII characters as input and returns bitmap glymhs on the console.
As I am a new user of Freetype 2 library I am facing difficulty in compiling
the application code. I have moved the application code given below in a file
example.c. I have been able to successfully install the freetype 2 on my Linux
machine. What should be my command to compile the application example.c using
gcc or make on a linux console? Please help.
////////////////////////////////////////////////////////////////////////////
///
// Include files
//
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
////////////////////////////////////////////////////////////////////////////
///
// main
//
int main(int argc, char* argv[]){
FT_Library library; // handle to library
FT_Face face; // handle to face object
FT_Error nError;
unsigned nGlyphIndex;
bool bAntialias(false);
nError = FT_Init_FreeType(&library);
if(nError == 0){
nError = FT_New_Face(library, "courier.ttf", 0, &face);
if(nError == FT_Err_Unknown_File_Format){
//.... the font file could be opened and read, but it
//.... appears that its font format is unsupported
}
else if(nError){
//.... another error code means that the font file could not
//.... be opened, read or simply that it is broken..
}
else{
nError = FT_Set_Pixel_Sizes(face, 64, 64);
if(nError == 0){
nGlyphIndex = FT_Get_Char_Index(face, (FT_ULong)'a');
if(nGlyphIndex){
FT_Vector origin = { 0, 0 };
FT_BitmapGlyph pBitmapglyph;
nError = FT_Get_Glyph_Bitmap(face, nGlyphIndex,
FT_LOAD_DEFAULT, bAntialias ? 128 : 0, &origin, &pBitmapglyph);
if(nError == 0){
printf("Char height: %d, Char width: %d.\n",
pBitmapglyph->bitmap.rows, pBitmapglyph->bitmap.width);
for(int y(0); y<pBitmapglyph->bitmap.rows; y++){
for(int x(0); x<pBitmapglyph->bitmap.width; x++){
char c =
((char*)pBitmapglyph->bitmap.buffer)[y*pBitmapglyph->bitmap.pitch+x];
if(c == 127)
printf("M");
else if(c > 110)
printf("W");
else if(c > 90)
printf("8");
else if(c > 70)
printf("5");
else if(c > 50)
printf("[");
else if(c > 30)
printf("+");
else if(c > 10)
printf("-");
else
printf(" ");
}
printf("\n");
}
printf("\n");
pBitmapglyph->bitmap.rows;
pBitmapglyph->bitmap.width;
pBitmapglyph->bitmap.pitch;
pBitmapglyph->bitmap.buffer;
pBitmapglyph->bitmap.num_grays;
pBitmapglyph->bitmap.pixel_mode;
pBitmapglyph->bitmap.palette_mode;
pBitmapglyph->bitmap.palette;
FT_Done_Glyph((FT_Glyph)pBitmapglyph);
}
}
}
FT_Done_Face(face);
}
FT_Done_FreeType(library);
}
//Shutdown
printf("Press any key.\n");
getchar();
return 0;
}
Thanks & Regards,
Vinayak
- [ft] Need help to compile application,
Vinayak SWARUP <=