#include #include //using namespace std; #include #include "ft2build.h" #include FT_FREETYPE_H #include FT_LIST_H #include "freetype/internal/internal.h" #include FT_INTERNAL_TRUETYPE_TYPES_H #include FT_TRUETYPE_TAGS_H #include "freetype/winfnt.h" #include FT_INTERNAL_SFNT_H #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_SFNT_H #include FT_TRUETYPE_TABLES_H #include FT_TRUETYPE_IDS_H #include FT_SFNT_NAMES_H #include FT_TRUETYPE_TABLES_H struct FT_FaceRec_; #include bool GetTable(SFNT_Interface * pSfntInterface, TT_Face TTFace, TT_TableRec & tableDirEntry, FT_Byte *& puchTable, FT_ULong & ftuSize) { if (pSfntInterface->load_any( TTFace, tableDirEntry.Tag, 0, puchTable, &ftuSize)) { return false; } //std::cout << "size is: " << ftuSize << std::endl; puchTable = new FT_Byte[ftuSize]; if (pSfntInterface->load_any( TTFace, tableDirEntry.Tag, 0, puchTable, &ftuSize)) { delete [] puchTable; puchTable = 0; return false; } return true; } int main(int argc, char** argv) { FT_Library library; struct FT_FaceRec_ * m_ftfcFace; //FT_Face face; int error = FT_Init_FreeType(&library); if (error) { std::cout << "an error occurred during library initialization" << std::endl; } char* m_FontBuffer; unsigned int m_FontBufferLen = 100000; FILE * pFile = fopen("Arial.ttf", "rb"); fseek(pFile, 0, SEEK_END); unsigned int uiSize = ftell(pFile) + 1; fseek(pFile, 0, SEEK_SET); if (uiSize >= m_FontBufferLen) { m_FontBufferLen = uiSize; } m_FontBuffer = new char[m_FontBufferLen]; memset(m_FontBuffer, 0, m_FontBufferLen); fread(m_FontBuffer, 1, uiSize, pFile); fclose(pFile); error = FT_New_Memory_Face(library, (u_char *)m_FontBuffer, uiSize, 0, &m_ftfcFace); if (error == FT_Err_Unknown_File_Format) { std::cout << "the font file could be opened and read, but it appears\ that its font format is unsupported" << std::endl; } else if (error) { std::cout << "another error code means that the font file could not\ ... be opened or read, or that it is broken" << std::endl; } std::cout << "module_name: " << m_ftfcFace->driver->root.clazz->module_name << " Address " << m_ftfcFace->driver->root.clazz << std::endl; TT_Face TTFace = (TT_Face) m_ftfcFace; std::cout << "No of tables" <num_tables << std::endl; int nTempCount =TTFace->num_tables; TT_TableRec tableDirectory; FT_Byte * puchTable = 0; FT_Byte * m_puchHhea; FT_ULong ftuSize = 0; SFNT_Interface * pSfntInterface; pSfntInterface = (SFNT_Interface*)FT_Get_Module_Interface(library, "sfnt" ); for (int i = 0; i < nTempCount; i++) { tableDirectory = TTFace->dir_tables[i]; ftuSize = 0; if (!GetTable(pSfntInterface, TTFace, tableDirectory, puchTable, ftuSize)) { continue; } if (tableDirectory.Tag == TTAG_hhea) { std::cout<<"found header table" << std::endl; m_puchHhea = puchTable; } } TT_HoriHeader * m_pHoriHeader; m_pHoriHeader = (TT_HoriHeader *)m_puchHhea; if(m_pHoriHeader) { std::cout << "Version is : " << m_pHoriHeader->Version << std::endl; } }