记录每天学习的内容

freetype2 使用

下载源代码在linux下编译 make   make install

https://blog.csdn.net/bryce_xiao/article/details/70787810    pkg-config使用方法

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

以下代码保存为 test_freetype.c

//

#include <ft2build.h>

#include FT_FREETYPE_H

FT_Library library;
FT_Face face;
#define slot face->glyph
int error;
FT_UInt  glyph_index;

int pen_x = 0;
int pen_y = 0;

void DisplayByte(unsigned char value)
{
    int i;
    for(i=0; i<8; i++)
    {
        if(value & 0x80)
        {
            printf("0");
        }
        else
        {
            printf(" ");
        }
        value = (value << 1);
    }
}
void my_draw_bitmap( FT_Bitmap * pBitmap, int x, int y)
{
    int row, i;
    printf("x = %d, y = %d\n", x, y);
    printf("pBitmap rows=%d, width=%d, pitch=%d, pixel_mode=%d\n", 
        pBitmap->rows, pBitmap->width, pBitmap->pitch, pBitmap->pixel_mode);
    for(row=0; row<pBitmap->rows; row++)
    {
        for(i=0; i<pBitmap->pitch; i++)
        {
            DisplayByte(pBitmap->buffer[row*pBitmap->pitch+i]);
        }
        printf("\n");
            
    }
    
}

int main(void)
{
    //FT_GlyphSlot  slot = face->glyph;  /* a small shortcut */
    error = FT_Init_FreeType( &library);
    if( error )
    {
        printf("FT_Init_FreeType error = %d\n", error);
        return -1;
    }
    
    error = FT_New_Face(library, "OpenSans-Regular.ttf", 0, &face);

if ( error == FT_Err_Unknown_File_Format )
    {
        printf("FT_Err_Unknown_File_Format\n");
        return -2;
    }
    else if ( error )
    {
        printf("FT_New_Face error = %d\n", error);
        return -3;
    }
    
    error = FT_Set_Pixel_Sizes(
          face,   /* handle to face object */
          0,      /* pixel_width           */
          16 );   /* pixel_height          */
          
    if ( error )
    {
        printf("FT_Set_Pixel_Sizes error = %d\n", error);
        return -4;
    }
    
    /* retrieve glyph index from character code */
    glyph_index = FT_Get_Char_Index( face, '!' );

/* load glyph image into the slot (erase previous one) */
    error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
    if ( error )
    {
        printf("FT_Load_Glyph error = %d\n", error);
        return -5;
    }
    
    error = FT_Render_Glyph( face->glyph,   /* glyph slot  */
                         FT_RENDER_MODE_MONO ); /* render mode FT_RENDER_MODE_MONO FT_RENDER_MODE_NORMAL */
    /* now, draw to our target surface */
    my_draw_bitmap( &face->glyph->bitmap,
                  pen_x+face->glyph->bitmap_left, pen_y+face->glyph->bitmap_top);

/* increment pen position */
    pen_x += face->glyph->advance.x >> 6;
    pen_y += face->glyph->advance.y >> 6; /* not useful for now */    
    printf("pen_x = %d, pen_y = %d\n", pen_x, pen_y);

}

///

freetype2 使用相关推荐

  1. OpenGL学习笔记--字体库freetype2、FTGL

    freetype2 FreeType库是一个完全免费(开源)的.高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件,包括TrueType, OpenType, Type1, CID, ...

  2. FreeType2使用总结

    一.FreeType2简介 1. 是一个免费.开源.可移植且高质量的字体引擎: 2. 支持多种字体格式文件,并提供了统一的访问接口: 3. 支持单色位图.反走样位图渲染,这使字体显示质量达到Mac的水 ...

  3. Ubuntu下mingw和aarch64交叉编译x264/x265/openssl/freetype2的ffmpeg

    1.ffmpeg下载 前往ffmpeg官网下载地址下载需要的最新ffmpeg发布版本 2.ffmpeg编译选项说明 在ffmpeg官网中有对ffmpeg编译选项的部分说明内容如下: --enable- ...

  4. FLTK Debian 安装中make报错 X11 libraries No package ‘xft‘ found No package ‘freetype2‘ found

    Q:Configure could not find required X11 libraries A:sudo aptitude install libx11-dev Q: to the PKG_C ...

  5. linux调节字体大小加粗,支持任意大小字体freetype2显示(linux frambuffer)版

    #include #include #include #include #include "gb2312.h" #include "freetype2.h" s ...

  6. freetype2 下载编译以及测试代码

    源码: https://sourceforge.net/projects/freetype/files/freetype2 下载解压后,进入源码目录执行cmake-gui,界面中配置源码目录与编译目录 ...

  7. [电子书]项目储备二:用FreeType2绘制矢量字体、多行文字

    [电子书]项目储备二:用FreeType2绘制矢量字体.多行文字 0 矢量字体 VS 点阵字体 1 FreeType2的介绍与基本使用 2 在LCD显示一个矢量字体,且可旋转 3 在LCD任意位置显示 ...

  8. linux上freetype2安装编译和使用

    目前正在做linux上的opengl开发,是做视频图像处理的,需要叠加一下文字动画和特效.用opengl的做法是先生成文字贴图然后用opengl渲染在视频帧上就可以了,所以关键是要获得文字的图片,网上 ...

  9. FreeType2中文手册

    前言:最近有个项目需要将中文英文泰文可以进行osd叠加到照片上.泰文处理转换成Unicode编码之前的博客已经详细介绍了,目前准备使用freetype矢量字体进行显示.在网上找到一个大佬的一篇文章写的 ...

最新文章

  1. android的init过程分析
  2. mysql 图形化工具
  3. 指针-指向函数指针数组的指针
  4. java ee的小程序_Java EE调度程序
  5. 查询优化器内核剖析第四篇:从一个实例看执行计划
  6. JAVA核心技术卷2:高级特征(原书第8版)
  7. python目前有多少库文件_必学Python库 你知道多少?
  8. [转贴]关于项目管理的一点体会
  9. python开发mbus程序_一种PMBus总线电源模块的控制与实现
  10. kodi没有声音_如何使用Yatse用声音(及更多)控制Kodi
  11. 数据结构(计算机存储、组织数据方式)
  12. python中sys模块下载_怎样进行python sys模块安装及使用
  13. 一周信创舆情观察(2.14~2.20)
  14. 用手机把纸质文件扫描成pdf的方法分享,不能错过哦。
  15. ab压力测试结果-简要说明
  16. 解决Unable to open debugger port错误
  17. 案例直播 | Pulsar Summit Asia 2022:Day 1 - 分论坛 1:腾讯、华为、有道、vivo、科大讯飞...
  18. 数组中的slice()方法和splice()
  19. [转]python各模块的学习
  20. 麦块我的世界怎么用java_我的世界从进入游戏到多人游戏 生存要点 Java下载一套龙教程【含麦块使用教程】...

热门文章

  1. 广州IATF16949认证_广州IATF16949咨询_8.3.3.3特殊特性
  2. 将英文版《深入理解计算机系统》与大家分享!
  3. 网络学习day04_子网划分
  4. 第十章 SQL命令 CREATE PROCEDURE(一)
  5. 矿物追踪mod_技术处于危险之中,我们可以依靠矿物原料多长时间
  6. twitter验证_社交网络身份验证:Twitter和Facebook
  7. c语言a++与++a的区别
  8. halcon 圆点标定板相关算法说明及使用方法
  9. 从惠普“质量门”到洋品牌的习惯性傲慢
  10. 高职计算机基础教案,高职计算机基础教案(3--6周).doc