例子

#include <stdio.h>
#include <string.h>
#include <math.h> #include <ft2build.h>
#include FT_FREETYPE_H #define WIDTH 80
#define HEIGHT 80 /* origin is the upper left corner */
unsigned char image[HEIGHT][WIDTH]; /* Replace this function with something useful. */ void
draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows; for ( i = x, p = ; i < x_max; i++, p++ )
{
for ( j = y, q = ; j < y_max; j++, q++ )
{
if ( i < || j < ||
i >= WIDTH || j >= HEIGHT )
continue; image[j][i] |= bitmap->buffer[q * bitmap->width + p];
}
}
} void
show_image( void )
{
int i, j; for ( i = ; i < HEIGHT; i++ )
{
for ( j = ; j < WIDTH; j++ )
putchar( image[i][j] == ? ' '
: image[i][j] < ? '+'
: '*' );
putchar( '\n' );
}
} int
main( int argc,
char** argv )
{
FT_Library library;
FT_Face face; FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error; char* filename;
char* text; double angle;
int target_height;
int n, num_chars; if ( argc != )
{
fprintf ( stderr, "usage: %s font sample-text\n", argv[] );
exit( );
} filename = argv[]; /* first argument */
text = argv[]; /* second argument */
num_chars = strlen( text );
angle = ( 0.0 / ) * 3.14159 * ; /* use 25 degrees */
target_height = HEIGHT; error = FT_Init_FreeType( &library ); /* initialize library */
/* error handling omitted */ error = FT_New_Face( library, argv[], , &face ); /* create face object */
/* error handling omitted */ #if 0
/* use 50pt at 100dpi */
error = FT_Set_Char_Size( face, * , ,
, ); /* set character size */ /* pixels = 50 /72 * 100 = 69 个像素点*/
#else
FT_Set_Pixel_Sizes(face, , );
#endif
/* error handling omitted */ slot = face->glyph; /* set up matrix */
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 ); /* the pen position in 26.6 cartesian space coordinates; */
/* start at (0,40) relative to the upper left corner */
pen.x = * ;
pen.y = ( target_height - ) * ; for ( n = ; n < num_chars; n++ )
{
/* set transformation */
FT_Set_Transform( face, &matrix, &pen ); /* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */ /* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top ); /* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
} show_image(); FT_Done_Face ( face );
FT_Done_FreeType( library ); return ;
}

1.编译free_type

配置  ./configure

编译   make

安装 sudo make install

gcc -o example1 example1.c

error: freetype/config/ftheader.h: No such file or directory
example1.c:12:10: error: #include expects "FILENAME" or <FILENAME>

指定头文件目录编译

gcc -o example1 example1.c  -I /usr/local/include/freetype2

报错缺库

example1.c:(.text+0x1ea): undefined reference to `FT_Init_FreeType'
example1.c:(.text+0x216): undefined reference to `FT_New_Face'
example1.c:(.text+0x236): undefined reference to `FT_Set_Pixel_Sizes'
example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'
example1.c:(.text+0x360): undefined reference to `FT_Set_Transform'
example1.c:(.text+0x386): undefined reference to `FT_Load_Char'
example1.c:(.text+0x409): undefined reference to `FT_Done_Face'
example1.c:(.text+0x415): undefined reference to `FT_Done_FreeType'

example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'

指定库编译freetype    gcc -o example1 example1.c  -I /usr/local/include/freetype2 –lfreetype

缺数学类定义

example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'

加-lm为加数学类库意思   gcc -o example1 example1.c  -I /usr/local/include/freetype2 -lfreetype  -lm

执行exampe1  用宋体文件    显示abcfg

./example1   ./simsun.ttc  abcfg

陈志朋uicode码为  48 96 D7 5F 67 0B

int chinese_str[] = {0x9648,0x5fd7,0x670b};

for ( n = ; n < ; n++ )
{
/* set transformation */
FT_Set_Transform( face, &matrix, &pen ); /* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */ /* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top ); /* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}

./example1   ./simsun.ttc   abc

无法直接使用“abc陈志朋a”

使用宽字符

添加头文件include<wchar.h>

#include <wchar.h>

wchar_t * chinese_str = L"陈志朋~陈";
  unsigned int *p = (wchar_t *)chinese_str;

int i = 0;

printf("uicode: \n");
  for( i = 0; i < wcslen(chinese_str); i++)
  {
    printf("0x%x " , p[i]);
  }

printf("\n");
  return 0;

85:27: error: converting to execution character set: Invalid or incomplete multibyte or wide character

代码格式为asii应转化为uicode码

gcc -finput-charset=GBK -fexec-charset=UTF-8 -o example1 example1.c  -I /usr/local/include/freetype2 -lfreetype  -lm

结果

uicode:
0x9648 0x5fd7 0x670b 0x7e 0x9648

打印出位置大小参数

添加头文件#include FT_GLYPH_H

FT_BBox bbox;
FT_Glyph glyph; // 将FT_GlyphSlot glyph转化为 FT_Glyph glyph;
error = FT_Get_Glyph( face->glyph, &glyph );
if(error)
{
printf("FT_Get_Glyph error \n");
}
/*从glyph中获取bbox*/
FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox );
//汉字uicode码
printf("uicode: %x\n", chinese_str[n]);
//汉字位置原点
printf("origin.x /64 = %d , origin.y /64 = %d ", pen.x/, pen.y/);
//最小最大X,Y
printf("x_min = %d ,x_max = %d, y_min = %d, y_max = %d \n", bbox.xMin, bbox.xMax, bbox.yMin, bbox.yMax);
//X,Y偏移值
printf("slot.advance.x/64 = %d, slot.advance.y/64 = %d \n", slot->advance.x/, slot->advance.y/);

结果

uicode: 9648
origin.x /64 = 0 , origin.y /64 = 40 x_min = 2 ,x_max = 23, y_min = 37, y_max = 60
slot.advance.x/64 = 24, slot.advance.y/64 = 0
uicode: 5fd7
origin.x /64 = 24 , origin.y /64 = 40 x_min = 25 ,x_max = 47, y_min = 38, y_max = 60
slot.advance.x/64 = 24, slot.advance.y/64 = 0
uicode: 670b
origin.x /64 = 48 , origin.y /64 = 40 x_min = 48 ,x_max = 70, y_min = 37, y_max = 59
slot.advance.x/64 = 24, slot.advance.y/64 = 0
uicode: 7e
origin.x /64 = 72 , origin.y /64 = 40 x_min = 73 ,x_max = 84, y_min = 55, y_max = 60
slot.advance.x/64 = 12, slot.advance.y/64 = 0
uicode: 9648
origin.x /64 = 84 , origin.y /64 = 40 x_min = 86 ,x_max = 107, y_min = 37, y_max = 60
slot.advance.x/64 = 24, slot.advance.y/64 = 0

文件浏览器及数码相框 -2.3.1freetype_pc的更多相关文章

  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.2-freetype_arm-2

    显示多行文字 两行文字左边对齐 简单使用两个循环显示两行字体 根据上一行字体的宽度来进行下一行左边的计算 #include <sys/mman.h> #include <sys/ty ...

  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. Forbidden You don't have permission to access / on this server. You don't have permission to access /phpmyadmin/ on this server. 解决办法

    Forbidden  You don't have permission to access / on this server.   解决办法 打开 httpd.conf 文件, 将 #   onli ...

  2. (四)主控板改IP,升级app,boot,mac

    给主控板升级boot要在boot界面进行,进入boot后,要先查看boot下ip和掩码是否和电脑ip(severip)在一个网段,不在的话要使用setenv命令设置ip地址和掩码.之后再输入upboo ...

  3. HBase分享会议笔记

    今天参加了一个关于HBase的分享,有一些内容是之前的知识的补充. 之前关于Hadoop家族,包括HBase的内容,可以参考:http://www.cnblogs.com/charlesblc/p/6 ...

  4. ACM比赛经验

    这篇博客是转别人的,觉得很好,希望能在以后的现场赛中用上:ACM比赛经验 推荐此篇文章打印,与模板放在一起. 1. 比赛中评测会有些慢,偶尔还会碰到隔10分钟以上才返回结果的情况,这段时间不能等结果, ...

  5. angularJS中ng-if的用法

    <!DOCTYPE html> <html ng-app> <head> <meta charset="utf-8"> <ti ...

  6. Scroller 实现的弹性回弹的LinearLayout

    由于公司业务发展,多app需求很少,被调到java后台开发接口三个月了,还要我继续做 java,最近有点想换工作,不得不重新看看基础知识了. 晚上看到了滑动的实现方式,平滑滑package com.e ...

  7. java 集合2(迭代器)

    迭代器方法:(把迭代器想象成抓娃娃机的爪子) hasNext()     问是否有元素可遍历,如果有元素可以遍历,返回true,否则返回false 工作原理:这一个迭代的过程是这样的,获取到迭代器时候 ...

  8. redis订阅发布

    一.简介 Pub/Sub 从字面上理解就是发布(Publish)与订阅(Subscribe),在Redis中,你可以设定对某一个key值进行消息发布及消息订阅,当一个key值上进行了消息发布后,所有订 ...

  9. quartz定时任务框架的使用

    quartz定时任务时间设置 这些星号由左到右按顺序代表 :     *    *     *     *    *     *   *                                 ...

  10. 20145218 《Java程序设计》第05次实验报告

    北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验名称:Java网络编程及安全 一.实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使 ...