博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Free Type 在win32平台下显示中文
阅读量:5161 次
发布时间:2019-06-13

本文共 3907 字,大约阅读时间需要 13 分钟。

/* example1.c                                                      *//*                                                                 *//* This small program shows how to print a rotated string with the *//* FreeType 2 library.                                             */#include 
#include
#include
#include
#include FT_FREETYPE_H#pragma comment(lib, "freetype.lib")#define WIDTH 640#define HEIGHT 480/* origin is the upper left corner */unsigned char image[HEIGHT][WIDTH];/* Replace this function with something useful. */voiddraw_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 = 0; i < x_max; i++, p++) { for (j = y, q = 0; j < y_max; j++, q++) { if (i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT) continue; image[j][i] |= bitmap->buffer[q * bitmap->width + p]; } }}voidshow_image(void){ int i, j; FILE *fp; fopen_s(&fp, "tmp.txt", "w"); for (i = 0; i < HEIGHT; i++) { for (j = 0; j < WIDTH; j++) fputc(image[i][j] == 0 ? ' ' : image[i][j] < 128 ? '+' : '*', fp); putchar('\n'); } fclose(fp);}intmain(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 != 3) { fprintf(stderr, "usage: %s font sample-text\n", argv[0]); exit(1); }*/ filename = "a";// argv[1]; /* first argument */ text = "1"; /* second argument */ num_chars = strlen(text); angle = (25.0 / 360) * 3.14159 * 2; /* use 25 degrees */ target_height = HEIGHT; error = FT_Init_FreeType(&library); /* initialize library */ /* error handling omitted */ if (error) { printf("is error1!"); } error = FT_New_Face(library, "C:/airstrip.ttf", 0, &face); /* create face object */ /* error handling omitted */ if (error) { printf("is error2!"); } /* use 50pt at 100dpi */ error = FT_Set_Char_Size(face, 50 * 64, 0, 100, 0); /* set character size */ /* 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 (300,200) relative to the upper left corner */ pen.x = 300 * 64; pen.y = (target_height - 200) * 64; for (n = 0; 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 0;}/* EOF */

 

posted on
2014-01-18 23:51  阅读(
...) 评论(
...) 收藏

转载于:https://www.cnblogs.com/zhouyongqiang/p/3525639.html

你可能感兴趣的文章
netstat实现原理
查看>>
寻找完美平方数
查看>>
初学反编译-.-
查看>>
防御式编程
查看>>
单线程并发的server端
查看>>
View可以设置tag携带数据
查看>>
individual reading task ---12061183 叶露婷
查看>>
delphi的消息对话框
查看>>
java:Apache Shiro 权限管理
查看>>
38.输出1到最大的N位数[Print 1 to max number of N bits]
查看>>
ZOJ - 2165 Red and Black
查看>>
objective c的注释规范
查看>>
FreeNas安装配置使用
查看>>
机器学习中的F1-score
查看>>
百度编辑器造成无用图片解决方案
查看>>
编译安装php5.5.38
查看>>
常用查找数据结构及算法(Python实现)
查看>>
Scrapy框架-CrawlSpider
查看>>
Django(一)框架简介
查看>>
java.lang.OutOfMemoryError: Java heap space
查看>>