我正在寻找类似于.NET下的 GlyphTypeface.GetGlyphOutline的东西
任何帮助或提示表示赞赏!
提前致谢
解决方法 解决方案是使用FreeType,它提供了我需要的功能范围:#include <string>#include <iostream>#include <freetype/ftglyph.h>#include <freetype/freetype.h>//******************* check error code ********************voID Check(FT_Error ErrCode,const char* OKMsg,const char* ErrMsg){ if(ErrCode != 0) {std::cout << ErrMsg << ": " << ErrCode << "\n";std::cout << "program halted\n";exit(1); } else std::cout << OKMsg << "\n"; }//******************** get outline ************************int Getoutline(FT_Glyph glyph,FT_OutlineGlyph* Outg){ int Err = 0; switch ( glyph->format ) { case FT_GLYPH_FORMAT_BITMAP: Err = 1; break; case FT_GLYPH_FORMAT_OUTliNE: *Outg = (FT_OutlineGlyph)glyph; break; default: ; } return Err;}//*********** print outline to console ***************int PrintOutline(FT_OutlineGlyph Outg){int Err = 0;FT_Outline* ol = &Outg->outline;int Start = 0; //start index of contourint End = 0; //end index of contourshort* pContEnd = ol->contours; //pointer to contour endFT_Vector* pPoint = ol->points; //pointer to outline point char* pFlag = ol->Tags; //pointer to flagfor(int c = 0; c < ol->n_contours; c++){ std::cout << "\nContour " << c << ":\n"; End = *pContEnd++; for(int p = Start; p <= End; p++) { char Ch = *pFlag++ + '0'; std::cout << "Point " << p <<": X=" << pPoint->x << " Y="<<pPoint->y << " Flag=" << Ch << "\n"; pPoint++; } Start = End + 1;} return Err;}//*********** get glyph index from command line ************* FT_UInt GetGlyphIndex(int argc,char* argv[],int Nr) {if(argc > Nr){ return atoi(argv[Nr]);}else{ return 36;} } //*********** get Font name from command line ************* voID GetFontname(int argc,int Nr,std::string& Fontname) {if(argc > Nr){ Fontname += argv[Nr]; }else{ Fontname += "FreeMono.ttf";} } //*********** get Font size from command line ************* int GetFontSize(int argc,int Nr) { short FontSize = 50 * 64; if(argc > Nr) FontSize += atoi(argv[Nr]); return FontSize; } //******************** M A I N ************************// par1: Fontname,par2:Glyph-Nr,par3: FontSize as FT_F26Dot6int main(int argc,char* argv[]){ FT_Face face; FT_library library; FT_Error error; error = FT_Init_FreeType( &library ); Check(error,"","error initializing FT lib"); std::string Fontname; Fontname = "/usr/share/Fonts/truetype/freeFont/"; GetFontname(argc,argv,1,Fontname); error = FT_New_Face( library,Fontname.c_str(),&face ); Check(error,"error loading Font"); FT_F26Dot6 Font_size = GetFontSize(argc,3); error = FT_Set_Char_Size( face,Font_size,72,72 ); Check(error,"error setting char size"); FT_UInt glyph_index = GetGlyphIndex(argc,2); FT_Int32 load_flags = FT_LOAD_DEFAulT; error = FT_Load_Glyph( face,glyph_index,load_flags ); Check(error,"error loading glyph"); FT_Glyph glyph; error = FT_Get_Glyph( face->glyph,&glyph ); Check(error,"error getting glyph"); FT_OutlineGlyph Outg; error = Getoutline(glyph,&Outg); Check(error,"error getting outline"); std::cout << "=======================================================\n"; std::cout << "Font: " << Fontname << "\n"; std::cout << "Glyph Index: " << glyph_index << "\n"; std::cout << "=======================================================\n"; error = PrintOutline(Outg); Check(error,"error printing outline"); return 0; }总结
以上是内存溢出为你收集整理的如何在linux系统上获得真实类型字符的字形轮廓全部内容,希望文章能够帮你解决如何在linux系统上获得真实类型字符的字形轮廓所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)