之前有做过 ascii 和汉字库的字体点阵在lcd上显示的例子,都是按照指定大小的字库的点阵来显示的,所以一但选定了字体文件后,就固定了大小,不可变化,当然也可以存放各种 大小的字体文件,但这样的话就需要很多的空间,这种方法显然不好使,所以就引入了失量字体,关于字体的特点就不啰嗦了。可以去网上搜到很多说明。下面我们一步一步的来做实验测试了解失量字体的用法,先在PC机上测试,然后再移植到开发板上用lcd显示。

  一、首先我们要去获得失量字体的源码和一些文档,https://www.freetype.org/freetype2/docs/documentation.html 这里就是官网。然后按照他的文档来简单了解一下,同时还提供了一个C例子,分析例子,修改后可以先在PC机上测试。

  二、得到源码后,解压配置安装。列出步骤和命令。注意这是在PC机上运行的命令如果要在开发板上运行,要用交叉编译 还有配置也有不同

    ./configure    配置

    make      编译

    sudo make install  安装

  三、把源码例子拿过来编译

    gcc -o example example.c -I /usr/local/include/freetype2/ -lfreetype -lm

    /* -I /usr/local/include/freetype2/ 指定头文件目录       -lfreetype 指定库类型        -lm 指定数学库 */

    /* 这是大i                                                                     这是小L                               小L */

    如果没加会出错,不信可以先不加试一试然后一个一个加试下,这是方法,为什么我也不知道

    ./example ./simsun.ttc abc    执行就会打印出字体文件在终端上,但是看不到,因为源码里的设置太大了,要改小一些才可以

    在执行时需要一个字体文件,可以从C:\Windows\Fonts里找一个复制过去

    下面贴出一段在PC上显示代码 用FreeType官方例子稍改就可以了。

  1. /* example1.c */
  2. /* */
  3. /* This small program shows how to print a rotated string with the */
  4. /* FreeType 2 library. */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <math.h>
  9.  
  10. #include <ft2build.h>
  11. #include FT_FREETYPE_H
  12.  
  13. /* 这里修改 原来是680 480 太大 */
  14. #define WIDTH 80
  15. #define HEIGHT 80
  16.  
  17. /* origin is the upper left corner */
  18. unsigned char image[HEIGHT][WIDTH];
  19.  
  20. /* Replace this function with something useful. */
  21.  
  22. void
  23. draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y)
  24. {
  25. FT_Int i, j, p, q;
  26. FT_Int x_max = x + bitmap->width;
  27. FT_Int y_max = y + bitmap->rows;
  28.  
  29. /* for simplicity, we assume that `bitmap->pixel_mode' */
  30. /* is `FT_PIXEL_MODE_GRAY' (i.e., not a bitmap font) */
  31.  
  32. for ( i = x, p = 0; i < x_max; i++, p++ )
  33. {
  34. for ( j = y, q = 0; j < y_max; j++, q++ )
  35. {
  36. if ( i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT )
  37. continue;
  38.  
  39. image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  40. }
  41. }
  42. }
  43.  
  44. void show_image( void )
  45. {
  46. int i, j;
  47.  
  48. for ( i = 0; i < HEIGHT; i++ )
  49. {
  50. for ( j = 0; j < WIDTH; j++ )
  51. putchar( image[i][j] == 0 ? ' '
  52. : image[i][j] < 128 ? '+'
  53. : '*' );
  54. putchar( '\n' );
  55. }
  56. }
  57.  
  58. int
  59. main( int argc, char** argv )
  60. {
  61. FT_Library library;
  62. FT_Face face;
  63.  
  64. FT_GlyphSlot slot;
  65. FT_Matrix matrix; /* transformation matrix */
  66. FT_Vector pen; /* untransformed origin */
  67. FT_Error error;
  68.  
  69. char* filename;
  70. char* text;
  71.  
  72. double angle;
  73. int target_height;
  74. int n, num_chars;
  75.  
  76. if ( argc != 3 )
  77. {
  78. fprintf ( stderr, "usage: %s font sample-text\n", argv[0] );
  79. exit( 1 );
  80. }
  81.  
  82. filename = argv[1]; /* first argument */
  83. text = argv[2]; /* second argument */
  84. num_chars = strlen( text );
  85. /* 角度设为0不旋转 */
  86. angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
  87. target_height = HEIGHT;
  88.  
  89. error = FT_Init_FreeType( &library ); /* initialize library */
  90. /* error handling omitted */
  91.  
  92. error = FT_New_Face( library, filename, 0, &face );/* create face object */
  93. /* error handling omitted */
  94. #if 0
  95. /* use 50pt at 100dpi */
  96. error = FT_Set_Char_Size( face, 50 * 64, 0,
  97. 100, 0 ); /* set character size */
  98. /* error handling omitted */
  99. #else
  100. error = FT_Set_Pixel_Sizes(
  101. face, /* handle to face object */
  102. 0, /* pixel_width */
  103. 16 ); /* pixel_height */
  104. #endif
  105. /* cmap selection omitted; */
  106. /* for simplicity we assume that the font contains a Unicode cmap */
  107.  
  108. slot = face->glyph;
  109.  
  110. /* set up matrix */
  111. matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
  112. matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
  113. matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
  114. matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
  115.  
  116. /* the pen position in 26.6 cartesian space coordinates; */
  117. /* start at (300,200) relative to the upper left corner */
  118. /* 这里也要改 因为上面改了 */
  119. pen.x = 0 * 64;
  120. pen.y = ( target_height - 40 ) * 64;
  121.  
  122. for ( n = 0; n < num_chars; n++ )
  123. {
  124. /* set transformation */
  125. FT_Set_Transform( face, &matrix, &pen );
  126.  
  127. /* load glyph image into the slot (erase previous one) */
  128. error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );
  129. if ( error )
  130. continue; /* ignore errors */
  131.  
  132. /* now, draw to our target surface (convert position) */
  133. draw_bitmap( &slot->bitmap,
  134. slot->bitmap_left,
  135. target_height - slot->bitmap_top );
  136.  
  137. /* increment pen position */
  138. pen.x += slot->advance.x;
  139. pen.y += slot->advance.y;
  140. }
  141.  
  142. show_image();
  143.  
  144. FT_Done_Face ( face );
  145. FT_Done_FreeType( library );
  146.  
  147. return 0;
  148. }
  149.  
  150. /* EOF */

  上面显示了英文字符,通过执行程序时传进去的 abc 如果我们想显示中文怎么办呢,我们在源码里先定义一个字符串,再显示字符串 这里有一个地方要注意,字符串要以宽字符的方式定义保存,不能以 char *str = "矢量字体"; 这样的方式定义,因为中文是用二个字节保存的 英文是一个字节,如果一个字符串里又有中文又有英文就不好处理了。因此又引入了“宽字符” 宽字符怎么用,老办法 搜。wchar_t *str = L"矢量字体"; 这样定义 同时还有一个头文件要包含进去 #include <wchar.h> ,下面列出一个例子,同样是在上面的基础上改的。

  在这个例子里会出现编译时 提示无法转换字符集 error:converting to execution character set: Invalid or incomplete multibyte or wide character

  在指定字符输入输出字符集编译 gcc  -finput-charset=GBK -fexec-charset=UTF-8 -o example example.c -I /usr/local/include/freetype2/ -lfreetype -lm

这里列出源码

  1. /* example1.c */
  2. /* */
  3. /* This small program shows how to print a rotated string with the */
  4. /* FreeType 2 library. */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include <wchar.h>
  10.  
  11. #include <ft2build.h>
  12. #include FT_FREETYPE_H
  13.  
  14. /* 这里修改 原来是680 480 太大 */
  15. #define WIDTH 100
  16. #define HEIGHT 100
  17.  
  18. /* origin is the upper left corner */
  19. unsigned char image[HEIGHT][WIDTH];
  20.  
  21. /* Replace this function with something useful. */
  22.  
  23. void
  24. draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y)
  25. {
  26. FT_Int i, j, p, q;
  27. FT_Int x_max = x + bitmap->width;
  28. FT_Int y_max = y + bitmap->rows;
  29.  
  30. /* for simplicity, we assume that `bitmap->pixel_mode' */
  31. /* is `FT_PIXEL_MODE_GRAY' (i.e., not a bitmap font) */
  32.  
  33. for ( i = x, p = 0; i < x_max; i++, p++ )
  34. {
  35. for ( j = y, q = 0; j < y_max; j++, q++ )
  36. {
  37. if ( i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT )
  38. continue;
  39.  
  40. image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  41. }
  42. }
  43. }
  44.  
  45. void show_image( void )
  46. {
  47. int i, j;
  48.  
  49. for ( i = 0; i < HEIGHT; i++ )
  50. {
  51. for ( j = 0; j < WIDTH; j++ )
  52. putchar( image[i][j] == 0 ? ' '
  53. : image[i][j] < 128 ? '+'
  54. : '*' );
  55. putchar( '\n' );
  56. }
  57. }
  58.  
  59. int
  60. main( int argc, char** argv )
  61. {
  62. FT_Library library;
  63. FT_Face face;
  64.  
  65. FT_GlyphSlot slot;
  66. FT_Matrix matrix; /* transformation matrix */
  67. FT_Vector pen; /* untransformed origin */
  68. FT_Error error;
  69.  
  70. char* filename;
  71. char* text;
  72.  
  73. double angle;
  74. int target_height;
  75. int n, num_chars;
  76.  
  77. wchar_t *chinese_str = L"矢量字体";
  78.  
  79. /* 把参数改为2个 */
  80. if ( argc != 2 )
  81. {
  82. fprintf ( stderr, "usage: %s font \n", argv[0] );
  83. exit( 1 );
  84. }
  85. /* 注释掉这两行 */
  86. filename = argv[1]; /* first argument */
  87. // text = argv[2]; /* second argument */
  88. // num_chars = strlen( text );
  89. /* 角度设为0不旋转 */
  90. angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
  91. target_height = HEIGHT;
  92.  
  93. error = FT_Init_FreeType( &library ); /* initialize library */
  94. /* error handling omitted */
  95.  
  96. error = FT_New_Face( library, filename, 0, &face );/* create face object */
  97. /* error handling omitted */
  98. #if 0
  99. /* use 50pt at 100dpi */
  100. error = FT_Set_Char_Size( face, 50 * 64, 0,
  101. 100, 0 ); /* set character size */
  102. /* error handling omitted */
  103. #else
  104. /* 直接用这个函数设字像素大小 */
  105. error = FT_Set_Pixel_Sizes(
  106. face, /* handle to face object */
  107. 0, /* pixel_width */
  108. 24 ); /* pixel_height */
  109. #endif
  110. /* cmap selection omitted; */
  111. /* for simplicity we assume that the font contains a Unicode cmap */
  112.  
  113. slot = face->glyph;
  114.  
  115. /* set up matrix */
  116. matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
  117. matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
  118. matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
  119. matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
  120.  
  121. /* the pen position in 26.6 cartesian space coordinates; */
  122. /* start at (300,200) relative to the upper left corner */
  123. /* 这里也要改 因为上面改了 */
  124. pen.x = 10 * 64;
  125. pen.y = ( target_height - 40 ) * 64;
  126. /* man wcslen man strlen 去找到用法 得到字符串长度 */
  127. for ( n = 0; n < wcslen(chinese_str); n++ )
  128. {
  129. /* set transformation */
  130. FT_Set_Transform( face, &matrix, &pen );
  131.  
  132. /* load glyph image into the slot (erase previous one) */
  133. /* 直接显示字符串不使用传入参数 */
  134. error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
  135. if ( error )
  136. continue; /* ignore errors */
  137.  
  138. /* now, draw to our target surface (convert position) */
  139. draw_bitmap( &slot->bitmap,
  140. slot->bitmap_left,
  141. target_height - slot->bitmap_top );
  142.  
  143. /* increment pen position */
  144. pen.x += slot->advance.x;
  145. pen.y += slot->advance.y;
  146. }
  147.  
  148. show_image();
  149.  
  150. FT_Done_Face ( face );
  151. FT_Done_FreeType( library );
  152.  
  153. return 0;
  154. }
  155.  
  156. /* EOF */

通过上面的测试,下面总结一下freetype字体的用法,和一些注意事项。参考官方文档。后面会慢慢增加对FreeType的测试代码。

上面的代码都是在PC机上运行的,现在我们来移植到ARM开发板上去,首先要进行交叉编译,试一下一大堆错误,我们连freetype都没有编译配置,下面先来编译

1:解压 tar xjf freetype-2.9.1.tar.bz2  然后进入目录

2:配置 ./configure --host=arm-linux  指定为交叉编译用于ARM平台

3:编译 make

4:安装 make DESTDIR=$PWD/tmp install 先安装到当前目录下的tmp目录里,然后把 lib include里的东西拷贝到我们编译器工具链里 如果直接make 会安装到PC机根目录下

  cd tmp/usr/local/include/

  sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include -rf

  cd tmp/usr/local/lib/

  sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib -d -rf

5:编译应用程序 arm-linux-gcc example example.c 出现一大堆错误

  5.1:sudo mv freetype2/freetype .   编译时找头文件目录多了一个freetype2 我们把下面的都移上来。还是不行,那就指定头文件目录 指定动态库 指定字符集再编译

    arm-linux-gcc -finput-charset=GBK -o freetype freetype.c -I /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/freetype -lfreetype

    编译成功后 可执行程序freetype 字体文件simsun.ttc 拷贝到根文件系统目录里去  动态库tmp/usr/local/lib/ 拷贝到文件系统根目录lib/目录下

    然后就可以执行,且可以在终端打印出字体了。

下一步,修改应用程序源码,让其在lcd上显示,我们之前有做过在Lcd上显示英文和中文字体,那些显示函数是可以用的,这里我们修改的就是把在终端输出改成在lcd上显示

下面列出源码。

  修改后 编译还是出错  error: failure to convert GBK to UTF-8 用amn gcc 找一下 charset 看一个gcc里怎么转换 看到这里

  -fexec-charset=charset
    Set the execution character set, used for string and character constants. The default is UTF-8. charset can be any encoding supported by the system's "iconv" library
    routine.

  我们看一下 iconv --help 怎么用

  Input/Output format specification:
  -f, --from-code=NAME encoding of original text
  -t, --to-code=NAME encoding for output

  我们用执行一下看看

  iconv -f GBK -t UTF-8 freetype.c

  可以看到在处理asicc字体文件时有个别字符他无法识别,我们去掉这些字符就可以了 源码经测试可通过,完全显示在lcd上,可以修改参数,换字体 换大小,换角度都可以修改测试,最关键的地方就是 坐标 freetype是基于“笛卡尔”坐标,我们用的是“lcd”坐标 。

  1. /* example1.c */
  2. /* */
  3. /* This small program shows how to print a rotated string with the */
  4. /* FreeType 2 library. */
  5.  
  6. #include <sys/mman.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include <stdio.h>
  11. #include <linux/fb.h>
  12. #include <fcntl.h>
  13. #include <string.h>
  14.  
  15. #include <math.h>
  16. #include <wchar.h>
  17.  
  18. #include <ft2build.h>
  19. #include FT_FREETYPE_H
  20.  
  21. static int fd_fb;
  22. static struct fb_var_screeninfo var; /* 定义一个可变信息结构体 用于保存获得的可变信息 */
  23. static struct fb_fix_screeninfo fix; /* 定义一个固定信息结构体 用于保存获得的固定信息 */
  24. static int screen_size; /* 定义一个变量 表示 framebuffer 进行内存映射 */
  25. static unsigned char *fbmem; /* 定认一个指针变量 用于保存内存映射后的地址 */
  26.  
  27. static int fd_hzk;
  28. static struct stat hzk_stat; /* 定义一个结构体用于保存统计信息 */
  29. static unsigned char *hzkmem; /* 定义一个指针变量 用于保存央存映射的地址 */
  30.  
  31. static unsigned int line_width;
  32. static unsigned int pixel_whdth;
  33.  
  34. static unsigned char *str = "谢";
  35.  
  36. /* 描点函数 根据 x,y,值 确定对应framebuffer的位置
  37. * 然后依次的在对应的framebuffer上写入颜色值即可
  38. */
  39. void lcd_put_pixel(int x, int y, unsigned int color)
  40. {
  41. unsigned char *pen = fbmem + y*line_width + x*pixel_whdth;
  42.  
  43. *pen = color;
  44. }
  45.  
  46. /* 显示中文 如何显示呢?
  47. * 1: 先得到汉字库的文件 然后可以像打开framebuffe一样打开这个文件
  48. * 2: 打开后就可以去读了,我们也可以把这个文件当成内存一样用 即映射一下
  49. * 3: 然后就可以去里面得到字体点阵数据了,接着和显示字符一样描点即可
  50. * 把文件当成内存去映射先要得到文件大小 可以用 fstat 这个函数来获得大小
  51. * 如何使用这个函数 可以在服务器上输入 man fstat 得到使用说明
  52. * 汉字库的使用方法可以去"度娘"去找,基本上就是下面几个注意的地方
  53. * 1: GBK编码用四个字节表示一个中文 第一个字节表示区码 第二个字节表示位码
  54. * 2: 为了兼容ascii码 编码从a1 开始 例:"中"字 值是 D6 D0 D6=区码 D0=位码
  55. * 3: 所以编码的值是 区码-A1 位码-A1
  56. */
  57. void lcd_put_chinses(int x, int y, unsigned char *str)
  58. {
  59. unsigned int area = str[0] - 0xa1;
  60. unsigned int where = str[1] - 0xa1;
  61. unsigned char *dots = hzkmem + (area * 94 + where) * 32;
  62. unsigned char byte;
  63. int i,j,k;
  64.  
  65. for (i = 0;i < 16;i ++)
  66. {
  67. for (j = 0;j < 2;j ++)
  68. {
  69. byte = dots[i * 2 + j];
  70. for (k = 7;k >=0;k --)
  71. {
  72. if (byte & (1 << k))
  73. {
  74. /* 传入参数的值是lcd要显示的起点坐标 这里每个点的坐标每描一个点要移动一次 */
  75. lcd_put_pixel(x + j * 8 + 7 - k, y + i, 0xffffff); /* 0xffffff 表示白色 */
  76. }
  77. else
  78. {
  79. /* 传入参数的值是lcd要显示的起点坐标 这里每个点的坐标每描一个点要移动一次 */
  80. lcd_put_pixel(x + j * 8 + 7 - k, y + i, 0); /* 0 表示黑色 */
  81. }
  82. }
  83. }
  84. }
  85.  
  86. }
  87.  
  88. void draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y)
  89. {
  90. FT_Int i, j, p, q;
  91. FT_Int x_max = x + bitmap->width;
  92. FT_Int y_max = y + bitmap->rows;
  93.  
  94. /* for simplicity, we assume that `bitmap->pixel_mode' */
  95. /* is `FT_PIXEL_MODE_GRAY' (i.e., not a bitmap font) */
  96.  
  97. for ( i = x, p = 0; i < x_max; i++, p++ )
  98. {
  99. for ( j = y, q = 0; j < y_max; j++, q++ )
  100. {
  101. if ( i < 0 || j < 0 || i >= var.xres|| j >= var.yres )
  102. continue;
  103.  
  104. //image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  105. lcd_put_pixel(i, j, bitmap->buffer[q * bitmap->width + p]);
  106. }
  107. }
  108. }
  109.  
  110. int main(int argc, char **argv)
  111. {
  112.  
  113. FT_Library library;
  114. FT_Face face;
  115.  
  116. FT_GlyphSlot slot;
  117. FT_Matrix matrix; /* transformation matrix */
  118. FT_Vector pen; /* untransformed origin */
  119. FT_Error error;
  120.  
  121. char* filename;
  122. char* text;
  123.  
  124. double angle;
  125. int target_height;
  126. int n, num_chars;
  127.  
  128. wchar_t *chinese_str = L"翻繁敏酩aAbB";
  129.  
  130. fd_fb = open("/dev/fb0", O_RDWR); /* 打开lcd设备 可读可写 */
  131. if (fd_fb < 0)
  132. {
  133. printf("cnt't open /dev/fb0 !\n");
  134. return -1;
  135. }
  136.  
  137. if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &var)) /* 获得可变信息 */
  138. {
  139. /* 正常获得信息的话 ioctl 会返回0 如果返回值不为0时表示出错 */
  140. printf("can't get var! \n");
  141. return -1;
  142. }
  143. if (ioctl(fd_fb,FBIOGET_FSCREENINFO, &fix)) /* 获得固定信息 */
  144. {
  145. /* 正常获得信息的话 ioctl 会返回0 如果返回值不为0时表示出错 */
  146. printf("can't get fix! \n ");
  147. return -1;
  148. }
  149. /* 计算 framebuffer 的大小 用于内存映射单位字节 用x分辩率*y分辩率*每个像素得到总大小这时的单位是bit 除以8 转换成字节 */
  150. screen_size = var.xres * var.yres * var.bits_per_pixel / 8;
  151. /* 内存映射 mmap 怎么用呢,可以在服务器上输入man mmap 得到说明
  152. * void *mmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
  153. * 参数说明:void *addr 设置为0 让内核自动给我们分配地址
  154. * :size_t length 映射内存大小
  155. * :int prot 属性为可读可写
  156. * :int flags 共享 其它进程都可见
  157. * :int fd framebuffer
  158. * :off_t offset 偏移值
  159. */
  160. fbmem = (unsigned char *)mmap(NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
  161. if (fbmem == (unsigned char *)-1)
  162. {
  163. printf("can't mmap!\n");
  164. return -1;
  165. }
  166.  
  167. line_width = var.xres * var.bits_per_pixel / 8;
  168. pixel_whdth = var.bits_per_pixel / 8;
  169.  
  170. /* 打开当前目录下的 HZK16 文件 属性设为只读 */
  171. fd_hzk = open("HZK16", O_RDONLY);
  172. if (fd_hzk < 0)
  173. {
  174. printf("can't open HZK16\n");
  175. return -1;
  176. }
  177. /* 得到这个件的统计信息当然也包含了大小 */
  178. if (fstat(fd_hzk, &hzk_stat))
  179. {
  180. printf("can't get hzk_stat! \n ");
  181. return -1;
  182. }
  183. /* 内存映射 mmap 怎么用呢,可以在服务器上输入man mmap 得到说明
  184. * void *mmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
  185. * 参数说明:void *addr 设置为0 让内核自动给我们分配地址
  186. * :size_t length 映射内存大小
  187. * :int prot 属性为可读可写
  188. * :int flags 共享 其它进程都可见
  189. * :int fd 文件
  190. * :off_t offset 偏移值
  191. */
  192. hzkmem = (unsigned char *)mmap(NULL, hzk_stat.st_size, PROT_READ, MAP_SHARED, fd_hzk, 0);
  193. if (hzkmem == (unsigned char *)-1)
  194. {
  195. printf("can't mmap!\n");
  196. return -1;
  197. }
  198.  
  199. /* 这里先清屏 全部显黑色 */
  200. memset(fbmem, 0, screen_size);
  201.  
  202. filename = argv[1]; /* first argument */
  203. angle = ( 10.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
  204. // target_height = HEIGHT;
  205.  
  206. error = FT_Init_FreeType( &library ); /* initialize library */
  207. /* error handling omitted */
  208.  
  209. error = FT_New_Face( library, filename, 0, &face );/* create face object */
  210. /* error handling omitted */
  211. #if 0
  212. /* use 50pt at 100dpi */
  213. error = FT_Set_Char_Size( face, 50 * 64, 0,
  214. 100, 0 ); /* set character size */
  215. /* error handling omitted */
  216. #else
  217. /* 直接用这个函数设字像素大小 */
  218. error = FT_Set_Pixel_Sizes(
  219. face, /* handle to face object */
  220. 0, /* pixel_width */
  221. 48 ); /* pixel_height */
  222. #endif
  223. /* cmap selection omitted; */
  224. /* for simplicity we assume that the font contains a Unicode cmap */
  225.  
  226. slot = face->glyph;
  227.  
  228. /* set up matrix */
  229. matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
  230. matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
  231. matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
  232. matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
  233.  
  234. /* the pen position in 26.6 cartesian space coordinates; */
  235. /* start at (300,200) relative to the upper left corner */
  236. /* 这里也要改 因为上面改了 */
  237. // pen.x = (var.xres/2 + 24) * 64;
  238. pen.x = (0 + 24) * 64;
  239. pen.y = (var.yres / 2 - 16) * 64;
  240. /* man wcslen man strlen 去找到用法 得到字符串长度 */
  241. for ( n = 0; n < wcslen(chinese_str); n++ )
  242. {
  243. /* set transformation */
  244. FT_Set_Transform( face, &matrix, &pen );
  245.  
  246. /* load glyph image into the slot (erase previous one) */
  247. /* 直接显示字符串不使用传入参数 */
  248. error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
  249. if ( error )
  250. continue; /* ignore errors */
  251.  
  252. /* now, draw to our target surface (convert position) */
  253. draw_bitmap( &slot->bitmap,
  254. slot->bitmap_left,
  255. var.yres - slot->bitmap_top );
  256.  
  257. /* increment pen position */
  258. pen.x += slot->advance.x;
  259. pen.y += slot->advance.y;
  260. }
  261.  
  262. // show_image();
  263.  
  264. /* 在lcd上显示ascii字符 即然是显示,肯定要有位置 在那显示先定在中间 */
  265. // lcd_put_ascii(var.xres / 2, var.yres / 2, 'F');
  266. /* 在lcd上显示中文 即然是显示,肯定要有位置 在那显示 */
  267. lcd_put_chinses(var.xres / 2 + 8, var.yres / 2, str);
  268.  
  269. FT_Done_Face ( face );
  270. FT_Done_FreeType( library );
  271.  
  272. return 0;
  273. }

FreeType 矢量字体 测试移植(1)的更多相关文章

  1. 使用FreeType实现矢量字体的粗体、斜体、描边、阴影效果

    前言: Freetype是一个跨平台.开源的字体渲染器,网上很多文章介绍,本人就不啰嗦了.本文重点在于实现文章标题所属的各种效果,不是Freetype的基本使用方法介绍文档,所以对于Freetype不 ...

  2. WPF自定义控件与样式(1)-矢量字体图标(iconfont)

    一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...

  3. UWP 矢量字体图标(iconfont)使用

    本文使用 阿里巴巴开源字体: 选择矢量字体图标: 查看或编辑 Unicode编码 或字体名称 下载到本地,添加到uwp项目 代码中写法 Text:Unicode编码 FontFamily:文件路径#字 ...

  4. UI图标不用愁:矢量字体图标Font-Awesome

    Font-Awesome,这个项目主要是css3的一个应用,准确的说是一段css,这里的把很多图标的东西做到了font文件里面,然后通过引用外部font文件的方式,来展现图标. Font Awesom ...

  5. windows矢量字体点阵数据的提取(转)

    源:windows矢量字体点阵数据的提取 问题参考:windows api 获取字库点阵的问题 1.提取原理 在windows系统当中提取矢量字体的字模有很多方法,下面介绍一种利用GetGlyphOu ...

  6. WPF使用矢量字体图标(阿里巴巴iconfont)

    原文:WPF使用矢量字体图标(阿里巴巴iconfont) 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/lwwl12/article/details/78 ...

  7. wpf 使用矢量字体 fontawesome

    第一步:首先下载矢量字体 :http://www.fontawesome.com.cn/ 第二步:在将fontawesome-webfont.ttf 文件引用到项目 设置fontawesome-web ...

  8. WPF矢量字体图标(iconfont)

    原文:WPF矢量字体图标(iconfont) 转载:点击打开链接 步骤: 一.下载添加iconfont文件 二.添加到资源文件夹,并设置不复制,且为资源文件 三.增加FIcon.xaml文件 < ...

  9. 如何应用Font Awesome矢量字体图标

    Font Awesome 是一套专门为 Twitter Boostrap 设计的图标字体库.这套图标字体集几乎囊括了网页中可能用到的所有图标,除了包括 Twitter Boostrap 的默认图标外, ...

  10. Font Awesome 4.0.3 提供了369个网页常用的矢量字体图标

    Font Awesome 为您提供了一套可缩放的字体矢量图标,可以快速自定义图标的大小,颜色,阴影,这些都可以通过CSS来实现,无需任何的JS代码哦. 一,主要特点如下: 1,一个字体,369个图标 ...

随机推荐

  1. IPC,进程间通信

    信号机制 也叫软中断,软件层次上对中断的模拟 kill -9 加进程号可以终止进程 linux下执行kill -l可以看到 这里面居然没有32 33 直接从31到34 所以一共是62个信号 1) SI ...

  2. mybatis原理探究

    jdbc数据库运行流程: JDBC有哪三种statement接口: Statement 1.Statement接口提供了执行语句和获取结果的基本方法: 2.Statement继承自Wrapper:3. ...

  3. C# 使用多线程的几种方式

    1.Thread 详细介绍:https://www.cnblogs.com/cheng8/p/16147918.html 使用Thread类通过ThreadStart(无参数)或Parameteriz ...

  4. android手机无线调试

    1.手机与电脑先通过usb链接2.adb devices查看是否链接成功(链接成功会显示设备列表)3.adb tcpip 5555(0-65535之间取值,默认5555输进去)5:断开数据线,查看手机 ...

  5. NAT的转换

    NAT的转换 拓扑图 Sever0的IP地址:192.168.0.1/24 网关:192.168.0.254 PC0的IP地址:192.168.0.100/24 PC1的IP地址:192.168.0. ...

  6. linux搭建FastDFS文件服务器,安装nginx

    本文主要介绍在linux服务器如何搭建FastDFS文件服务器.大概分为9个步骤,由于内容较为繁琐.下面带你入坑! 首先简单介绍一下FastDFS是淘宝资深架构师余庆老师主导开源的一个分布式文件系统, ...

  7. 如何在centos7.6操作系统下安装mysql数据库

    1.从mysql官网上下载自己合适mysql版本,进入mysl官网https://dev.mysql.com/downloads/mysql/5.6.html#downloads,依次点击: 2.下载 ...

  8. Python 的入门学习之 Day4~6 ——from”夜曲编程“

    Day 4 time: 2021.8.1. 打卡第四天.今天起得很早(7点多一些),很棒,而梳头发更快些就更好了.我也算渐渐养成了晨间学习的习惯吧,一起床就心心念念着Python课程,这让我感觉到了生 ...

  9. <小李飞刀>系列 随笔

    1.多情剑客无情剑 古龙的作品在电视上只看过电影版的陆小凤传奇,对古龙的作品也没有过系统的了解,初读时听到了李寻欢的名字,突然感觉可惜.觉得如此早就读到这种级别的小说有些暴殄天物,不过也算是以白纸状态 ...

  10. Arduino开发ESP8266——安装与配置ESP8266开发板

    一.安装Arduino 1.下载安装包:点击打开 2.安装:直接点击下一步直至安装完成.如下图所示: 二.下载ESP8266开发板库: 在这面填写ESP8266开发板地址:http://arduino ...