如何在linux系统上获得真实types字符的字形轮廓

如何在linux系统上获得真实types字符的字形轮廓,第1张

概述如何在linux系统上获得真实types字符字形轮廓

我正在寻找一个库,以在linux系统上以真正的字体显示字形轮廓。 我们正在使用Pango和开罗,但不幸我没有find任何东西。 我正在寻找类似于GlyphTypeface.GetGlyphOutline的 .NET

任何帮助或提示表示赞赏!

提前致谢

Haskell,GHC,win32,开罗

用PyCairo直接绘制到根窗口

从SVG文件创buildcairopath

如何在windows上安装节点Jscanvas

在win32中打开,处理和渲染SVG文件(C ++)

如何加快在Opengl窗口与开罗绘图?

赢7 / Python 2.7 32位:OSError:无法加载库pangocairo 1.0:错误0x7e

禁用WebKit中的滚动条(平面框架模式)

graphics对于cairo-renderer位图来说太大了

在windows 8机器上安装Cairo和Canvas

解决方案是使用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 haltedn"; 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 contour int End = 0; //end index of contour short* pContEnd = ol->contours; //pointer to contour end FT_Vector* pPoint = ol->points; //pointer to outline point char* pFlag = ol->Tags; //pointer to flag for(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; } //******************** MAIN ************************ // par1: Fontname,par2:Glyph-Nr,par3: FontSize as FT_F26Dot6 int 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; }

开罗有这种能力。

cairo_glyph_path()将获得字形轮廓并使其成为当前路径,并允许您获取当前路径并对其进行迭代。

总结

以上是内存溢出为你收集整理的如何在linux系统上获得真实types字符的字形轮廓全部内容,希望文章能够帮你解决如何在linux系统上获得真实types字符的字形轮廓所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1286086.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存