// FreetyprTest.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include "ft2build.h" #include FT_FREETYPE_H using namespace std; char m_arrnMappingTable[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 16,17,18,19,20,21,22,23,24,25,26,27,28,29, 30,31,32,33,34,35,36,37,38,39,40,41,42,43, 44,45,46,47,48,49,50,51,52,53,54,55,56,57, 58,59,60,61,62,63,64,65,66,67,68,69,70,71, 72,73,74,75,76,77,78,79,80,81,82,83,84,85, 86,87,88,89,90,91,92,93,94 }; struct FT_FaceRec_; struct FT_LibraryRec_; int main() { char fontdata[732160] = { '\0' }; FILE * fptr = fopen(".\\stbc39h.ttf", "rb"); if (fptr == NULL) { printf("Cannot open file \n"); exit(0); } // Read contents from file int len = 0; char c = fgetc(fptr); fseek(fptr, 0, SEEK_END); unsigned int uiSize = ftell(fptr) + 1; fseek(fptr, 0, SEEK_SET); size_t read = fread(fontdata, sizeof(char), uiSize, fptr); fclose(fptr); FT_Library m_ftlbLibrary; struct FT_FaceRec_ * m_ftfcFace; int nError = FT_Init_FreeType(&m_ftlbLibrary); if (nError) { cout << "ERROR - Failed to initialize FreeType library." << endl; cout << "\tError code: " << nError << endl; return false; } nError = FT_New_Memory_Face(m_ftlbLibrary, (unsigned char *)fontdata, uiSize, 0, &m_ftfcFace); nError = FT_Set_Char_Size( m_ftfcFace, /* handle to face object */ 0, /* char_width in 1/64th of points */ 16 * 64, /* char_height in 1/64th of points */ 300, /* horizontal device resolution */ 300); /* vertical device resolution */ int nChar; int nGlyphIndex; bool bGlyphIndexFound = false; for (int i = 16; i < 36; i++) { nChar = m_arrnMappingTable[i]; nGlyphIndex = FT_Get_Char_Index(m_ftfcFace, nChar); if (!nGlyphIndex) { continue; } nError = FT_Load_Glyph(m_ftfcFace, /* handle to face object */ nGlyphIndex, /* glyph index */ FT_LOAD_DEFAULT); /* load flags, see below */ if (nError) { continue; } nError = FT_Render_Glyph(m_ftfcFace->glyph, /* glyph slot */ ft_render_mode_mono); /* render mode */ if (nError) { continue; } } }