- n_contours: 2
- n_points: 48
- flags: 0
- Contour 0: 32
- Contour 1: 47
- 0 : 805 0 1
- 1 : 801 135 1
- 2 : 719 54 0
- 3 : 550 -18 0
- 4 : 457 -18 1
- 5 : 371 -18 0
- 6 : 249 26 0
- 7 : 170 103 0
- 8 : 133 207 0
- 9 : 133 268 1
- 10 : 133 419 0
- 11 : 358 590 0
- 12 : 578 590 1
- 13 : 786 590 1
- 14 : 786 678 1
- 15 : 786 767 0
- 16 : 672 874 0
- 17 : 555 874 1
- 18 : 470 874 0
- 19 : 305 836 0
- 20 : 217 801 1
- 21 : 217 958 1
- 22 : 250 970 0
- 23 : 331 993 0
- 24 : 421 1011 0
- 25 : 519 1022 0
- 26 : 569 1022 1
- 27 : 660 1022 0
- 28 : 806 982 0
- 29 : 907 900 0
- 30 : 961 776 0
- 31 : 961 692 1
- 32 : 961 0 1
- 33 : 786 457 1
- 34 : 565 457 1
- 35 : 500 457 0
- 36 : 406 431 0
- 37 : 346 383 0
- 38 : 317 316 0
- 39 : 317 274 1
- 40 : 317 245 0
- 41 : 335 192 0
- 42 : 375 151 0
- 43 : 439 127 0
- 44 : 485 127 1
- 45 : 545 127 0
- 46 : 700 200 0
- 47 : 786 279 1
2楼:坐标解读、完善输出
2楼:带错误判断的示例代码
3楼:
- #include <stdio.h>
- #include <string.h>
- #include <ft2build.h>
- #include <freetype/ftoutln.h>
- #include FT_FREETYPE_H
- FT_Library library;
- FT_Face face;
- FT_GlyphSlot slot;
- FT_Error error;
- FT_Outline outline;
- void ftinit(void)
- {
- char* filename;
- filename = "C:/windows/fonts/consola.ttf";
- FT_Init_FreeType( &library ); //初始化库实例(句柄)
- FT_New_Face( library, filename, 0, &face ); //初始化face对象,设置字体
- }
- void LoadGlyph(FT_ULong symbol)
- {
- //获取符号对应的索引,可以是unicode编码值(如果该字体支持)
- FT_UInt index = FT_Get_Char_Index(face, symbol);
- //装载字符
- FT_Load_Glyph(face,
- index,
- FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
- //装载字符到face后,可以从字形槽获取点阵信息,也可以获取轮廓信息
- slot = face->glyph; //字形槽
- outline = slot->outline; //轮廓对象
- }
- int
- main( int argc, char** argv )
- {
- ftinit();
- LoadGlyph( 'a' );
- printf("n_contours: %d \n n_points: %d \n flags: %d\n",
- outline.n_contours, //轮廓曲线的数量
- outline.n_points, //坐标点数量
- outline.flags //暂时不确定含义
- );
- for (int i=0; i<outline.n_contours; i++ )
- {
- printf("Contour %d: %d\n", i, outline.contours[i]);
- }
- printf("\n");
- for (int i = 0; i<outline.n_points ; i++)
- {
- printf("%2d : %4d %4d %d\n",
- i,
- outline.points[i].x,
- outline.points[i].y,
- outline.tags[i]
- );
- }
- FT_Done_Face ( face );
- FT_Done_FreeType( library );
- return 0;
- }
单纯的提取,没有错误判断
编译参考(其中-lpng -lz不是必须的)
gcc -std=c11 Simple_Outline.c -o Simple_Outline ^
-ID:/lib/freetype-2.7/include ^
-LD:/lib/freetype-2.7/objs/.libs ^
-lfreetype -lpng -lz
输出结果
这些坐标画出来是这样子的:
左边是点绘,右边是线绘(没有划分),绿色是初始点,橙色是末尾点。正确解读请移步二楼