数码相框——矢量字体原理(5)
来源:互联网 发布:php聚享游快乐赚源码 编辑:程序博客网 时间:2024/06/10 17:13
/* example1.c *//* *//* This small program shows how to print a rotated string with the *//* FreeType 2 library. */#include <stdio.h>#include <string.h>#include <math.h>#include <wchar.h>#include <ft2build.h>#include <string.h>#include FT_FREETYPE_H #include FT_GLYPH_H#define WIDTH 80#define HEIGHT 80/* 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;//printf("x =%d,y =%d\n",x,y); 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; for ( i = 0; i < HEIGHT; i++ ) { printf("%d",i); for ( j = 0; j < WIDTH; j++ ) putchar( image[i][j] == 0 ? ' ' : image[i][j] < 128 ? '+' : '*' ); putchar( '\n' ); }}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; FT_BBox bbox; FT_Glyph glyph; char* filename; char* text; double angle; int target_height; int n, num_chars; //unsigned int str[]= {0x8D75,0x521B,0x007A};wchar_t *chinese_str = L"ÕÔ´´abc";unsigned int *p = (wchar_t *)chinese_str;int i;printf("Unicode:\n");for(i=0;i<wcslen(chinese_str);i++){printf("0x%x\n",p[i]);}printf("\n"); if ( argc != 2 ) { fprintf ( stderr, "usage: %s font sample-text\n", argv[0] ); exit( 1 ); } filename = argv[1]; /* first argument */ //text = argv[2]; /* second argument */ // num_chars = strlen( text ); angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */ target_height = HEIGHT; error = FT_Init_FreeType( &library ); /* initialize library */ /* error handling omitted */ error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */ /* error handling omitted */#if 0 /* use 50pt at 100dpi */ error = FT_Set_Char_Size( face, 50 * 64, 0, 100, 0 ); /* set character size */ /* error handling omitted */#elseFT_Set_Pixel_Sizes(face, 24, 0);#endif 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 = 0 * 64; pen.y = ( target_height - 40 ) * 64; for ( n = 0; n < wcslen(chinese_str); n++ ) { /* set transformation */ FT_Set_Transform( face, &matrix, &pen ); /* load glyph image into the slot (erase previous one) */ error = FT_Load_Char( face, p[n], FT_LOAD_RENDER ); if ( error ) continue; /* ignore errors */ error = FT_Get_Glyph( face->glyph, &glyph ); if(error) {printf("FT_Get_Glyph error\n"); } FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox ); /* now, draw to our target surface (convert position) */ draw_bitmap( &slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top );printf("Unicode:0x%x\n",chinese_str[n]);printf("origin.x/64 = %d, origin.y/64 = %d\n",pen.x/64,pen.y/64);printf("lcd_x = %d,lcd_y = %d ,xMin = %d, xMax = %d,yMin = %d, yMax = %d\n ",slot->bitmap_left,target_height - slot->bitmap_top,bbox.xMin,bbox.xMax,bbox.yMin,bbox.yMax);printf("slot->advance.x/64 = %d",slot->advance.x/64);printf("slot->advance.y/64 = %d\n",slot->advance.y/64); /* 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 */
0 0
- 数码相框——矢量字体原理(5)
- 数码相框——矢量字体原理(6)
- 数码相框——矢量字体原理(4)
- 数码相框——矢量字体原理(3)
- 数码相框——矢量字体原理(1)
- 数码相框——矢量字体原理(6)
- 数码相框——矢量字体原理(7)
- 数码相框——矢量字体原理(2)
- linux应用项目(一)数码相框(2)数码相框之freetype实现矢量字体的显示
- 2.3.1freetype理论介绍、矢量字体原理
- 数码相框——显示图片(缩放功能)
- 点阵字体(也叫位图字体或光栅字体)、矢量字体
- 矢量字体和像素字体
- 关于矢量字体
- 矢量字体字形分布图
- 数码相框
- 数码相框笔记
- 数码相框项目
- iOS通过ASIHTTPRequest提交JSON数据
- C++ STL迭代器
- 广州大学锐捷认证协议安全性研究
- 使用Perfmon和PAL工具查看Server性能--日志的性能分析(PAL)
- flash swf 文件宽高修改
- 数码相框——矢量字体原理(5)
- LIRS缓存替换算法
- JSP 分页(一)
- android 系统回调onSizeChange, onMeasure, onLayout调用时机
- 【OpenCV接口翻译】OpenCV 2.4+ C++ 行人检测
- 《高效学习OpenGL》 之 控制二次方程对象的属性 gluQuadricDrawStyle(),gluQuadricOrientation(),gluQuadricNormals(),gluQu()
- android 拉伸图片 android:layout_gravity="center" android:gravity="center" 实现水平竖直居中
- 设计一个iOS应用的本地缓存机制
- 春城无处不飞花, 寒食东风御柳斜, 日暮汉宫传蜡烛, 轻烟散入五侯家。 这首诗,题名《寒食》,唐代一个叫韩翃的学子所作,拿做行卷投给翰林院大学士李白,因李白的归隐,一直尘封在翰林院的樟...