fork download
  1. #include <ft2build.h>
  2. #include <stdexcept>
  3. #include FT_FREETYPE_H
  4. #include FT_GLYPH_H
  5. #include <windows.h>
  6. #include <string.h>
  7.  
  8. class FT2_Obj{
  9. FT_Library library;
  10. int size ;
  11. FT_Face face;
  12. public:
  13. void Init(const char * fname, unsigned int h);
  14. void Free();
  15. void DrawAUnicode(wchar_t ch);
  16. };
  17. void FT2_Obj::Init(const char * fname, unsigned int h){
  18. this->size=h;
  19. if (FT_Init_FreeType( &library ))
  20. throw std::runtime_error("FT_Init_FreeType failed");
  21. if (FT_New_Face( library, fname, 0, &face ))
  22. throw std::runtime_error("FT_New_Face failed (there is probably a problem with your font file)");
  23. FT_Set_Char_Size( face,h<< 6, h << 6, 72, 72);
  24. FT_Matrix matrix; /* transformation matrix */
  25. FT_UInt glyph_index;
  26. FT_Vector pen;
  27.  
  28. }
  29. void FT2_Obj::DrawAUnicode(wchar_t ch){
  30. if(FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ))
  31. throw std::runtime_error("FT_Load_Glyph failed");
  32. FT_Glyph glyph;
  33. if(FT_Get_Glyph( face->glyph, &glyph ))
  34. throw std::runtime_error("FT_Get_Glyph failed");
  35. FT_Render_Glyph( face->glyph, FT_RENDER_MODE_MONO );
  36. FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
  37. FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
  38. FT_Bitmap& bitmap=bitmap_glyph->bitmap;
  39. int width = bitmap.width;
  40. int height = bitmap.rows;
  41. wchar_t wstr[256];
  42. wsprintfW(wstr,L"World :%c , width :%d height : %d\n",ch,width , height);
  43. OutputDebugStringW(wstr);
  44. for(int j=0; j < height ; j++){
  45. for(int i=0; i < width; i++){
  46. char tmp[5]={0};
  47. sprintf(tmp,"%2x",bitmap.buffer[i+ bitmap.width*j]);
  48. OutputDebugString(tmp);
  49. }
  50. OutputDebugString("\n");
  51. }
  52. OutputDebugString("\n");
  53. }
  54. void FT2_Obj::Free(){
  55. FT_Done_Face(face);
  56. FT_Done_FreeType(library);
  57. }
  58. int main(int argc, char* argv[]){
  59. FT2_Obj text;
  60. text.Init("msjh.ttc",6);
  61. text.DrawAUnicode(L'王');
  62. text.Free();
  63. return 0;
  64. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
stdout
Standard output is empty