显示多行文字

两行文字左边对齐

简单使用两个循环显示两行字体

根据上一行字体的宽度来进行下一行左边的计算

  1. #include <sys/mman.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. #include <linux/fb.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include <wchar.h>
  11. #include <ft2build.h>
  12. #include <stdlib.h>
  13. #include FT_FREETYPE_H
  14. #include FT_GLYPH_H
  15.  
  16. #include <linux/font.h>
  17.  
  18. int fd_fb;
  19. struct fb_var_screeninfo var; /* Current var */
  20. struct fb_fix_screeninfo fix; /* Current fix */
  21. int screen_size; //空间大小
  22. unsigned char *fb_mem; //framebaffer空间地址
  23. unsigned int line_width;
  24. unsigned int pixel_width;
  25.  
  26. void lcd_put_pixel(int x, int y, unsigned int color)
  27. {
  28. unsigned char *pen_8 = fb_mem + y * line_width + x * pixel_width; //当前像素对应内存位置
  29. unsigned short *pen_16;
  30. unsigned int *pen_32;
  31.  
  32. unsigned int red, blue, green;
  33.  
  34. pen_16 = (unsigned short *)pen_8;
  35. pen_32 = (unsigned int *)pen_8;
  36.  
  37. switch(var.bits_per_pixel)
  38. {
  39. case 8:
  40. {
  41. *pen_8 = color; //对应调色板颜色
  42.  
  43. break;
  44. }
  45. case 16:
  46. {
  47. /* 5*6*5 */
  48. red = (color >> 16) & 0xff;
  49. green = (color >> 8) & 0xff;
  50. blue = (color >> 0) & 0xff;
  51.  
  52. color = ((red >> 3 ) << 11) | ((green >> 2) << 5) | ( blue >> 3);
  53.  
  54. /* 颜色数据为高位 */
  55. *pen_16 = color;
  56.  
  57. break;
  58. }
  59. case 32:
  60. {
  61. *pen_32 = color;
  62. break;
  63. }
  64.  
  65. }
  66.  
  67. }
  68.  
  69. void draw_bitmap( FT_Bitmap* bitmap,
  70. FT_Int x,
  71. FT_Int y)
  72. {
  73. FT_Int i, j, p, q;
  74. FT_Int x_max = x + bitmap->width;
  75. FT_Int y_max = y + bitmap->rows;
  76.  
  77. printf("x = %d, y = %d\n", x, y);
  78.  
  79. for ( i = x, p = 0; i < x_max; i++, p++ )
  80. {
  81. for ( j = y, q = 0; j < y_max; j++, q++ )
  82. {
  83. if ( i < 0 || j < 0 ||
  84. i >= var.xres || j >= var.yres )
  85. continue;
  86.  
  87. // image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  88.  
  89. lcd_put_pixel(i, j, bitmap->buffer[q * bitmap->width + p]);
  90. }
  91. }
  92. }
  93.  
  94. int main(int argc, char **argv)
  95. {
  96. wchar_t * str1 = L"陈志朋gif";
  97. wchar_t * str2 = L"hello the world";
  98. FT_BBox bbox;
  99. FT_Glyph glyph;
  100.  
  101. FT_Library library;
  102. FT_Face face;
  103. FT_Vector pen; /* untransformed origin */
  104. FT_GlyphSlot slot;
  105. FT_Matrix matrix; /* transformation matrix */
  106.  
  107. int error;
  108. double angle;
  109. int i;
  110. int line_box_ymin = 10000;
  111. int line_box_ymax = 0;
  112.  
  113. if(argc != 2)
  114. {
  115. printf("Usage : %s <font_file> <angle>\n",argv[0]);
  116. return -1;
  117. }
  118.  
  119. fd_fb = open("/dev/fb0",O_RDWR);
  120. if(fd_fb < 0)
  121. {
  122. printf("can't open /dev/fb0 \n");
  123. return -1;
  124. }
  125. if(ioctl(fd_fb, FBIOGET_VSCREENINFO, &var))
  126. {
  127. printf("can't get var \n");
  128. return -1;
  129. }
  130. if(ioctl(fd_fb, FBIOGET_FSCREENINFO, &fix))
  131. {
  132. printf("can't get fix \n");
  133. return -1;
  134. }
  135. screen_size = var.xres * var.yres * var.bits_per_pixel / 8; //单位字节
  136. line_width = var.xres * var.bits_per_pixel / 8;
  137. pixel_width = var.bits_per_pixel / 8;
  138.  
  139. fb_mem = (unsigned char *)mmap(NULL, screen_size, \
  140. PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
  141. if(fb_mem == (unsigned char *) -1)
  142. {
  143. printf("can't mmap \n");
  144. return -1;
  145. }
  146. memset(fb_mem, 0, screen_size);
  147.  
  148. /* 显示矢量文字 */
  149.  
  150. error = FT_Init_FreeType( &library ); /* initialize library */
  151. /* error handling omitted */
  152.  
  153. error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
  154. /* error handling omitted */
  155.  
  156. slot = face->glyph;
  157.  
  158. FT_Set_Pixel_Sizes(face, 24, 0);
  159.  
  160. /*确定坐标
  161. *lcd_x = 0
  162. *lcd_y = 24
  163. *笛卡尔坐标
  164. *x = lcd_x = 0
  165. *y = var.yres - 24
  166. */
  167.  
  168. pen.x = ( 0 ) * 64;
  169. pen.y = ( var.yres - 24 ) * 64;
  170.  
  171. for(i = 0; i < wcslen(str1); i++)
  172. {
  173.  
  174. /* set transformation */
  175. FT_Set_Transform( face,0, &pen );
  176.  
  177. /* load glyph image into the slot (erase previous one) */
  178.  
  179. error = FT_Load_Char( face, str1[i], FT_LOAD_RENDER );
  180. if ( error )
  181. {
  182. printf("FT_Load_Char error\n");
  183. return -1;
  184. }
  185.  
  186. error = FT_Get_Glyph( face->glyph, &glyph );
  187. if (error)
  188. {
  189. printf("FT_Get_Glyph error!\n");
  190. return -1;
  191. }
  192.  
  193. FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox );
  194.  
  195. if(line_box_ymin > bbox.yMin)
  196. line_box_ymin = bbox.yMin;
  197. if(line_box_ymax < bbox.yMax)
  198. line_box_ymax = bbox.yMax;
  199.  
  200. /* now, draw to our target surface (convert position) */
  201. draw_bitmap( &slot->bitmap,
  202. slot->bitmap_left,
  203. var.yres - slot->bitmap_top );
  204. pen.x += slot->advance.x;
  205.  
  206. }
  207.  
  208. /*确定坐标
  209. *lcd_x = 0
  210. *lcd_y = 24
  211. *笛卡尔坐标
  212. *x = lcd_x = 0
  213. *y = var.yres - 24
  214. */
  215.  
  216. pen.x = ( 0 ) * 64;
  217. pen.y = ( var.yres - (line_box_ymax - line_box_ymin + 24) ) * 64;
  218.  
  219. for(i = 0; i < wcslen(str2); i++)
  220. {
  221.  
  222. /* set transformation */
  223. FT_Set_Transform( face,0, &pen );
  224.  
  225. /* load glyph image into the slot (erase previous one) */
  226.  
  227. error = FT_Load_Char( face, str2[i], FT_LOAD_RENDER );
  228. if ( error )
  229. {
  230. printf("FT_Load_Char error\n");
  231. return -1;
  232. }
  233.  
  234. error = FT_Get_Glyph( face->glyph, &glyph );
  235. if (error)
  236. {
  237. printf("FT_Get_Glyph error!\n");
  238. return -1;
  239. }
  240.  
  241. FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox );
  242.  
  243. if(line_box_ymin > bbox.yMin)
  244. line_box_ymin = bbox.yMin;
  245. if(line_box_ymax < bbox.yMax)
  246. line_box_ymax = bbox.yMax;
  247.  
  248. /* now, draw to our target surface (convert position) */
  249. draw_bitmap( &slot->bitmap,
  250. slot->bitmap_left,
  251. var.yres - slot->bitmap_top );
  252. pen.x += slot->advance.x;
  253.  
  254. }
  255. }

使用freetpye中的函数实现一行文字居中

4.6 高级文本渲染:变换 + 居中 + 字距调整
现在我们将修改我们的代码,以便可以容易地变换已渲染的字符串,例如旋转它。我们将以实行少许小
改进开始:
4.6.1 打包然后平移字形
我们先把与一个字形图像相关的信息打包到一个结构体,而不是并行的数组。因此我们定义下面的结构
体类型:
typedef struct TGlyph_
{
FT_UInt index; /* 字形索引 */
FT_Vector pos; /* 基线上面的字形原点 */
FT_Glyph image; /* 字形图像 */
} TGlyph, *PGlyph;
我们在装载每一个字形图像过程中,在把它装载它在基线所在位置后便直接平移它。我们将看到,这有若干
好处。我们的字形序列装载其因而变成:
FT_GlyphSlot slot = face->glyph; /* 一个小捷径 */
FT_UInt glyph_index;
FT_Bool use_kerning;
FT_UInt previous;
int pen_x, pen_y, n;
TGlyph glyphs[MAX_GLYPHS]; /* 字形表 */
PGlyph glyph; /* 表中的当前字形*/
FT_UInt num_glyphs;
... 初始化库 ...
... 创建 face 对象 ...
... 设置字符尺寸 ...
pen_x = 0; /* 以 (0,0) 开始 */
pen_y = 0;
num_glyphs = 0;
use_kerning = FT_HAS_KERNING( face );
previous = 0;
glyph = glyphs;
for ( n = 0; n < num_chars; n++ )
{
glyph->index = FT_Get_Char_Index( face, text[n] );
if ( use_kerning && previous && glyph->index )
{
FT_Vector delta;
FT_Get_Kerning( face, previous, glyph->index,
FT_KERNING_MODE_DEFAULT, &delta );
pen_x += delta.x >> 6;
}
/* 保存当前笔位置 */
glyph->pos.x = pen_x;
glyph->pos.y = pen_y;
error = FT_Load_Glyph(face,glyph_index,FT_LOAD_DEFAULT);
if ( error ) continue;
error = FT_Get_Glyph( face->glyph, &glyph->image );
if ( error ) continue;
/* 现在平移字形图像 */
FT_Glyph_Transform( glyph->image, 0, &glyph->pos );
pen_x += slot->advance.x >> 6;
previous = glyph->index;
/* 增加字形的数量 */
glyph++;
}
/* 计算已装载的字形的数量 */
num_glyphs = glyph - glyphs;
注意,这个时候平移字形有若干好处。第一是当我们计算字符串的边界框时不需要平移字形 bbox。代码将会
变成这样:
void compute_string_bbox( FT_BBox *abbox )
{
FT_BBox bbox;
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000;
for ( n = 0; n < num_glyphs; n++ )
{
FT_BBox glyph_bbox;
FT_Glyph_Get_CBox( glyphs[n], &glyph_bbox );
if (glyph_bbox.xMin < bbox.xMin)
bbox.xMin = glyph_bbox.xMin;
if (glyph_bbox.yMin < bbox.yMin)
bbox.yMin = glyph_bbox.yMin;
if (glyph_bbox.xMax > bbox.xMax)
bbox.xMax = glyph_bbox.xMax;
if (glyph_bbox.yMax > bbox.yMax)
bbox.yMax = glyph_bbox.yMax;
}
if ( bbox.xMin > bbox.xMax )
{
bbox.xMin = 0;
bbox.yMin = 0;
bbox.xMax = 0;
bbox.yMax = 0;
}
*abbox = bbox;
}
更详细描述: compute_string_bbox 函数现在可以计算一个已转换的字形字符串的边界框。例如,我们可以做
如下的事情:
FT_BBox bbox;
FT_Matrix matrix;
FT_Vector delta;
... 装载字形序列 ...
... 设置 "matrix" 和 "delta" ...
/* 变换字形 */
for ( n = 0; n < num_glyphs; n++ )
FT_Glyph_Transform( glyphs[n].image, &matrix, &delta );
/* 计算已变换字形的边界框 */
compute_string_bbox( &bbox );

  1. #include <sys/mman.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. #include <linux/fb.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <math.h>
  10. #include <wchar.h>
  11. #include <ft2build.h>
  12. #include <stdlib.h>
  13. #include FT_FREETYPE_H
  14. #include FT_GLYPH_H
  15. #include <linux/font.h>
  16.  
  17. #define MAX_GLYPHS 100
  18.  
  19. typedef struct TGlyph_
  20. {
  21. FT_UInt index; /* ???? */
  22. FT_Vector pos; /* ????????? */
  23. FT_Glyph image; /* ???? */
  24. } TGlyph, *PGlyph;
  25.  
  26. int fd_fb;
  27. struct fb_var_screeninfo var; /* Current var */
  28. struct fb_fix_screeninfo fix; /* Current fix */
  29. int screen_size; //空间大小
  30. unsigned char *fb_mem; //framebaffer空间地址
  31. unsigned int line_width;
  32. unsigned int pixel_width;
  33.  
  34. void lcd_put_pixel(int x, int y, unsigned int color)
  35. {
  36. unsigned char *pen_8 = fb_mem + y * line_width + x * pixel_width; //当前像素对应内存位置
  37. unsigned short *pen_16;
  38. unsigned int *pen_32;
  39.  
  40. unsigned int red, blue, green;
  41.  
  42. pen_16 = (unsigned short *)pen_8;
  43. pen_32 = (unsigned int *)pen_8;
  44.  
  45. switch(var.bits_per_pixel)
  46. {
  47. case 8:
  48. {
  49. *pen_8 = color; //对应调色板颜色
  50.  
  51. break;
  52. }
  53. case 16:
  54. {
  55. /* 5*6*5 */
  56. red = (color >> 16) & 0xff;
  57. green = (color >> 8) & 0xff;
  58. blue = (color >> 0) & 0xff;
  59.  
  60. color = ((red >> 3 ) << 11) | ((green >> 2) << 5) | ( blue >> 3);
  61.  
  62. /* 颜色数据为高位 */
  63. *pen_16 = color;
  64.  
  65. break;
  66. }
  67. case 32:
  68. {
  69. *pen_32 = color;
  70. break;
  71. }
  72.  
  73. }
  74.  
  75. }
  76.  
  77. void draw_bitmap( FT_Bitmap* bitmap,
  78. FT_Int x,
  79. FT_Int y)
  80. {
  81. FT_Int i, j, p, q;
  82. FT_Int x_max = x + bitmap->width;
  83. FT_Int y_max = y + bitmap->rows;
  84.  
  85. printf("x = %d, y = %d\n", x, y);
  86.  
  87. for ( i = x, p = 0; i < x_max; i++, p++ )
  88. {
  89. for ( j = y, q = 0; j < y_max; j++, q++ )
  90. {
  91. if ( i < 0 || j < 0 ||
  92. i >= var.xres || j >= var.yres )
  93. continue;
  94.  
  95. // image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  96.  
  97. lcd_put_pixel(i, j, bitmap->buffer[q * bitmap->width + p]);
  98. }
  99. }
  100. }
  101.  
  102. int Get_Glphs_Frm_Wstr(FT_Face face, wchar_t * wstr, TGlyph glyphs[])
  103. {
  104. PGlyph glyph = glyphs;
  105. FT_GlyphSlot slot = face->glyph;
  106. int n;
  107. int pen_x =0;
  108. int pen_y = 0;
  109. int error;
  110.  
  111. for(n = 0; n < wcslen(wstr); n++ )
  112. {
  113. glyph->index = FT_Get_Char_Index( face, wstr[n] );
  114. /* 保存当前笔位置 */
  115. glyph->pos.x = pen_x;
  116. glyph->pos.y = pen_y;
  117. /* load 是把glyph 加载到face->glyph */
  118. error = FT_Load_Glyph(face, glyph->index, FT_LOAD_DEFAULT);
  119. if ( error )
  120. continue;
  121.  
  122. error = FT_Get_Glyph( face->glyph, &glyph->image );
  123. if ( error )
  124. continue;
  125.  
  126. /* 现在平移字形图像 */
  127. /* 使得glyph->image里面有位置信息 */
  128. FT_Glyph_Transform( glyph->image, 0, &glyph->pos );
  129.  
  130. pen_x += slot->advance.x; /* 1 / 64 piont */
  131.  
  132. /* 增加字形的数量 */
  133. glyph++;
  134.  
  135. }
  136. /* 计算已装载的字形的数量 */
  137.  
  138. return (glyph - glyphs);
  139.  
  140. }
  141.  
  142. void compute_string_bbox( TGlyph glyphs[], FT_UInt num_glyphs, FT_BBox *abbox )
  143. {
  144. FT_BBox bbox;
  145. int n;
  146.  
  147. bbox.xMin = bbox.yMin = 32000;
  148. bbox.xMax = bbox.yMax = -32000;
  149.  
  150. for ( n = 0; n < num_glyphs; n++ )
  151. {
  152. FT_BBox glyph_bbox;
  153. FT_Glyph_Get_CBox( glyphs[n].image, FT_GLYPH_BBOX_TRUNCATE, &glyph_bbox );
  154. if (glyph_bbox.xMin < bbox.xMin)
  155. bbox.xMin = glyph_bbox.xMin;
  156. if (glyph_bbox.yMin < bbox.yMin)
  157. bbox.yMin = glyph_bbox.yMin;
  158. if (glyph_bbox.xMax > bbox.xMax)
  159. bbox.xMax = glyph_bbox.xMax;
  160. if (glyph_bbox.yMax > bbox.yMax)
  161. bbox.yMax = glyph_bbox.yMax;
  162. }
  163. *abbox = bbox;
  164. }
  165.  
  166. void Draw_Glyphs(TGlyph glyphs[], FT_UInt num_glyphs, FT_Vector pen)
  167. {
  168. int n;
  169. int error;
  170.  
  171. for ( n = 0; n < num_glyphs; n++ )
  172. {
  173. FT_Glyph_Transform( glyphs[n].image, 0, &pen );
  174. error = FT_Glyph_To_Bitmap(&glyphs[n].image, FT_RENDER_MODE_NORMAL, 0, 1 ); /* 没有附加的平移*//* 销毁 "image" 指向的副本 */
  175. if ( !error )
  176. {
  177. FT_BitmapGlyph bit = (FT_BitmapGlyph)glyphs[n].image;
  178. draw_bitmap( &bit->bitmap, bit->left, var.yres - bit->top);
  179. FT_Done_Glyph( glyphs[n].image );
  180. }
  181.  
  182. }
  183. }
  184.  
  185. int main(int argc, char **argv)
  186. {
  187. wchar_t * str1 = L"陈志朋gif";
  188. wchar_t * str2 = L"hello the world";
  189. FT_BBox bbox;
  190. FT_Glyph glyph;
  191.  
  192. FT_Library library;
  193. FT_Face face;
  194. FT_Vector pen; /* untransformed origin */
  195. FT_GlyphSlot slot;
  196. FT_Matrix matrix; /* transformation matrix */
  197.  
  198. TGlyph glyphs[MAX_GLYPHS]; /* ??? */
  199. FT_UInt num_glyphs;
  200.  
  201. int error;
  202. double angle;
  203. int i;
  204. int line_box_ymin = 10000;
  205. int line_box_ymax = 0;
  206.  
  207. int line_box_width;
  208. int line_box_hight;
  209.  
  210. if(argc != 2)
  211. {
  212. printf("Usage : %s <font_file> <angle>\n",argv[0]);
  213. return -1;
  214. }
  215.  
  216. fd_fb = open("/dev/fb0",O_RDWR);
  217. if(fd_fb < 0)
  218. {
  219. printf("can't open /dev/fb0 \n");
  220. return -1;
  221. }
  222. if(ioctl(fd_fb, FBIOGET_VSCREENINFO, &var))
  223. {
  224. printf("can't get var \n");
  225. return -1;
  226. }
  227. if(ioctl(fd_fb, FBIOGET_FSCREENINFO, &fix))
  228. {
  229. printf("can't get fix \n");
  230. return -1;
  231. }
  232.  
  233. screen_size = var.xres * var.yres * var.bits_per_pixel / 8; //单位字节
  234. line_width = var.xres * var.bits_per_pixel / 8;
  235. pixel_width = var.bits_per_pixel / 8;
  236.  
  237. fb_mem = (unsigned char *)mmap(NULL, screen_size, \
  238. PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
  239. if(fb_mem == (unsigned char *) -1)
  240. {
  241. printf("can't mmap \n");
  242. return -1;
  243. }
  244. memset(fb_mem, 0, screen_size);
  245.  
  246. /* 显示矢量文字 */
  247.  
  248. error = FT_Init_FreeType( &library ); /* initialize library */
  249. /* error handling omitted */
  250.  
  251. error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
  252. /* error handling omitted */
  253.  
  254. slot = face->glyph;
  255.  
  256. FT_Set_Pixel_Sizes(face, 24, 0);
  257.  
  258. num_glyphs = Get_Glphs_Frm_Wstr(face, str1, glyphs);
  259. compute_string_bbox(glyphs, num_glyphs, &bbox);
  260.  
  261. line_box_width = bbox.xMax - bbox.xMin;
  262. line_box_hight = bbox.yMax - bbox.yMin;
  263.  
  264. pen.x = (var.xres - line_box_width) / 2 * 64;
  265. pen.y = (var.yres - line_box_hight) / 2 * 64;
  266.  
  267. Draw_Glyphs(glyphs, num_glyphs, pen);
  268.  
  269. num_glyphs = Get_Glphs_Frm_Wstr(face, str2, glyphs);
  270. compute_string_bbox(glyphs, num_glyphs, &bbox);
  271.  
  272. line_box_width = bbox.xMax - bbox.xMin;
  273. line_box_hight = bbox.yMax - bbox.yMin;
  274.  
  275. pen.x = (var.xres - line_box_width) / 2 * 64;
  276. pen.y = pen.y - 24 * 64;
  277.  
  278. Draw_Glyphs(glyphs, num_glyphs, pen);
  279.  
  280. }

中心双行输出

4.6.2 渲染一个已变换的字形序列
无论如何,如果我们想重用字形来以不同的角度或变换方式绘制字符串,直接变换序列中的字形都不是
一个好主意。更好的方法是在字形被渲染前执行放射变换,如下面的代码所示:
FT_Vector start;
FT_Matrix transform;
/* 获取原始字形序列的 bbox */
compute_string_bbox( &string_bbox );
/* 计算整数象素表示的字符串尺度 */
string_width = (string_bbox.xMax - string_bbox.xMin) / 64;
string_height = (string_bbox.yMax - string_bbox.yMin) / 64;
/* 设置 26.6 笛卡儿空间表示的笔起始位置 */
start.x = ( ( my_target_width - string_width ) / 2 ) * 64;
start.y = ( ( my_target_height - string_height ) / 2 ) * 64;
/* 设置变换(旋转) */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
for ( n = 0; n < num_glyphs; n++ )
{
FT_Glyph image;
FT_Vector pen;
FT_BBox bbox;
/* 创建原始字形的副本 */
error = FT_Glyph_Copy( glyphs[n].image, &image );
if ( error ) continue;
/* 变换副本(这将平移它到正确的位置) */
FT_Glyph_Transform( image, &matrix, &start );
/* 检查边界框;如果已变换的字形图像不在*/
/* 我们的目标表面中,我们可以避免渲染它 */
FT_Glyph_Get_CBox( image, ft_glyph_bbox_pixels, &bbox );
if ( bbox.xMax <= 0 || bbox.xMin >= my_target_width ||
bbox.yMax <= 0 || bbox.yMin >= my_target_height )
continue;
/* 把字形图像转换为位图(销毁字形的副本!) */
error = FT_Glyph_To_Bitmap(
&image,
FT_RENDER_MODE_NORMAL,
0, /* 没有附加的平移*/
1 ); /* 销毁 "image" 指向的副本 */
if ( !error )
{
FT_BitmapGlyph bit = (FT_BitmapGlyph)image;
my_draw_bitmap( bitmap->bitmap,
bitmap->left,
my_target_height - bitmap->top );
FT_Done_Glyph( image );
}
}
这份代码相对于原始版本有少许改变:
z 我们没改变原始的字形图像,而是变换该字形图像的拷贝。
z 我们执行“剪取”操作以处理渲染和绘制的字形不在我们的目标表面(surface)的情况。
z 当调用 FT_Glyhp_To_Bitmap 时,我们总是销毁字形图像的拷贝,这是为了销毁已变换的图像。注意,即
使当这个函数返回错误码,该图像依然会被销毁(这就是为什么 FT_Done_Glyph 只在复合语句中被调用
的原因)。
z 平移字形序列到起始笔位置集成到 FT_Glyph_Transform 函数,而不是 FT_Glyph_To_Bitmap 函数。
可以多次调用这个函数以渲染字符串到不同角度的,或者甚至改变计算 start 的方法以移动它到另外的地
方。无论如何,要注意通常的实现会使用一个字形缓冲以减少内存消耗。据个例子,让我们假定我们的字符

文件浏览器及数码相框 -2.3.2-freetype_arm-2的更多相关文章

  1. 文件浏览器及数码相框 -2.3.2-freetype_arm-1

    交叉编译:tar xjf freetype-2.4.10.tar.bz2 ./configure --host=arm-linuxmakemake DESTDIR=$PWD/tmp install f ...

  2. 文件浏览器及数码相框 -2.3.1freetype_pc

    例子 #include <stdio.h> #include <string.h> #include <math.h> #include <ft2build. ...

  3. 下载apk文件浏览器会直接打开并显示乱码的问题

    今天同事反映他的apk文件在自己的老项目中下载有问题:下载apk文件浏览器会直接打开并显示乱码,在别的项目中就没有问题. 后分析response的content-type发现,老项目的类型是text/ ...

  4. Win 10 文件浏览器无法打开

    今天遇到个很奇怪的问题,文件浏览器File Explorer无法正常显示,点击打开后任务栏上已经显示打开了,但是屏幕上却看不到任何窗口,开始以为机子中了恶意的木马,然后就疯狂的查毒,然而并没有解决问题 ...

  5. Mac下DIY文件浏览器

    2015-07-14 15:07:53 Mac下的finder不能浏览Linux文件目录, 一些优秀的资源管理器是收费的..... 于是想到了既然Mac的本质是类Unix, 而在windows下查看L ...

  6. 比nerdtree更好的文件浏览器:vimfiler

    通过:VimFilerExplorer来打开一个文件浏览器 h:收起 t:展开 -:close 回车:进入或展开 空格:收起

  7. 【转】显示Ubuntu文件浏览器的地址栏--不错

    原文网址:http://www.blogbus.com/anythingok-logs/144447448.html Ubuntu默认使用nautilus作为其可视化的文件浏览器,其默认值不显示地址栏 ...

  8. 【Java】 实现一个简单文件浏览器(1)

    学习Java的Swing的时候写的一个超简单文件浏览器 效果如图: 项目结构: 这里面主要用了两个控件,JTree和JTable 下面先说下左侧的文件树如何实现: 首先是FileTree类,继承于JT ...

  9. SharePoint 2013 解惑 无法打开文件浏览器

    你有时候会看到这东西谈出来,当你想像管理文件一样,管理SharePoint上资源的时候 意思是说,不能打开文件浏览器,请加入你的站点到信任站点,这个有两个问题,一个是IE设置,一个是WebClient ...

随机推荐

  1. laravel 开启sql查询日志

    \DB::enableQueryLog(); dd(\DB::getQueryLog());

  2. 20160805_CentOS6_控制台切换

    1. Ctrl + Alt + F1~F6 Ctrl + Alt + F1 是 图形界面(如果装了的话),后面的是 控制台界面 2. 3.

  3. html5常用API之Full Screen

    所谓Full Screen API,就是全屏API,在html5中,该API允许开发者以编程方式将Web应用程序全屏运行,使Web应用程序更像本地应用程序.这款API十分简单有用,是html5初学者必 ...

  4. 犯过错误的C语言问题

    1 memcpy函数: 函数原型:void *memcpy(void *dest, void *src, unsigned int count); 函数源码: void *memcpy1(void * ...

  5. er6855的工作经验

    1 VIEWS里面的关系要搞清楚 里面的内容类型要理清 不要相信别人做好的事情 不要相信看到的结果 2 git rm -rf之后需要git commit提交到.git文件中正式生效 不然可能就是中间打 ...

  6. HTTP Content-Type的作用

    在用java的 AsyncHttpClient与服务器通信时,忘记设置了 Content-Type的值,开始以为没有问题,使用默认的值就行 后面出现了问题.查资料发现,Content-Type是用在M ...

  7. linux笔记:用户配置文件

    用户信息文件:/etc/passwd功能:存放用户基本信息每一行代表一个用户. 第一字段:用户名称第二字段:密码标志(只是一个密码的占位符,表示该用户有密码,不存放真正的密码)第三字段:UID(用户I ...

  8. WANL标准组织介绍-02

    无线电管理委员会 FCC ETSI IEEE Wi-Fi IETF WAPI 国家无线电管理委员会认证 国家无线电管理委员会认证(State Radio Regulatory Commission o ...

  9. 为MySQL选择合适的备份方式

    数据库的备份是极其重要的事情.如果没有备份,遇到下列情况就会抓狂: UPDATE or DELETE whitout where… table was DROPPed accidentally… IN ...

  10. Hadoop-env.sh[翻译]

    说明: 某天 ,把hadoop-env.sh的注释看了看 , 感觉受益匪浅,于是想要写一篇告诉大家,文档是最靠谱的,鉴于我的水平有限,只能翻译大概,切勿吐槽,提建议请留言 摘要: 1.这个文件中只有J ...