zoukankan      html  css  js  c++  java
  • FreeType的使用

    在嵌入式环境中显示字体,如果采用点阵的方式,要先取得汉字的点阵表示形式,然后根据点阵中每一位是否为1来决定是否对屏幕上相应的像素赋值;如果采用矢量字体的话,例如使用freetype库来显示TrueType类型的字体时,其大致的过程如下:
    1.初始化库

    1 FT_Library library;
    2 FT_Face face;
    3
     FT_Error error = FT_Init_FreeType( &library ); 


    2. 加载相应的字体文件

    error = FT_New_Face( library, "/usr/share/fonts/truetype/arial.ttf"0&face );


    3. 设置字体的大小  

    1 error = FT_Set_Char_Size(face, /* handle to face object */  
    2   0/* char_width in 1/64th of points */
    3   16*64/* char_height in 1/64th of points */
    4   300/* horizontal device resolution */
    5   300 ); /* vertical device resolution */
    6 
    7   error = FT_Set_Pixel_Sizes(face, /* handle to face object */
    8   0/* pixel_width */
    9   16 ); /* pixel_height */


    4. 加载字符的glyph

    1 glyph_index = FT_Get_Char_Index( face, charcode );
    2 
    3 error = FT_Load_Glyph(face, /* handle to face object */
    4   glyph_index, /* glyph index */
    5   load_flags ); /* load flags, see below */
    6 
    7 error = FT_Render_Glyph( face->glyph, /* glyph slot */
    8   render_mode ); /* render mode */


    5. 字体变换(旋转和缩放)

    1 error = FT_Set_Transform( face, /* target face object */
    2   &matrix, /* pointer to 2x2 matrix */
    3   &delta ); /* pointer to 2d vector */


    6. 把字符显示出来

    1 draw_bitmap( &slot->bitmap, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top );



    Wangkeke 2011-09-07 10:47 发表评论
  • 相关阅读:
    基于RSA securID的Radius二次验证java实现(PAP验证方式)
    一些指令 & 一些知识 (Linux Spring log4j...)
    RSA, ACS5.X 集成配置
    Python中的动态属性与描述符
    设计模式(一):单例模式
    JavaWeb
    动态规划_背包问题
    动态规划_最长上升子序列
    MySQL复习
    动态规划_数字三角形
  • 原文地址:https://www.cnblogs.com/cokecoffe/p/2537134.html
Copyright © 2011-2022 走看看