免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2357 | 回复: 0
打印 上一主题 下一主题

使用FreeType库显示汉字 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-25 20:04 |只看该作者 |倒序浏览

                                                                一段使用FreeType库显示汉字的代码
               
               
               
               
                static DS32 ShowChar(DU16 code, int x, int y, DU32 color,DU8 alignFlag)
{
        DS32 osdwidth,osdheight;
        DU8 xSize,ySize;
        int i=0, j, xx = x;
        FT_Glyph glyph;
        FT_Error error;
        FT_BitmapGlyph        bitmap_glyph ;
        FT_Bitmap bitmap;               
        osdwidth = D_OSD_GetWidth();
        osdheight = D_OSD_GetHeight();
        D_Font_Set_Pix_Sizes(                        
                        Pixs[fontCurIndex], /* pixel width */
                        Pixs[fontCurIndex] ); /* pixel height */
        FT_Load_Glyph(pFTFace, FT_Get_Char_Index(pFTFace,code), FT_LOAD_DEFAULT);//0x5B8B
        error = FT_Get_Glyph(pFTFace->glyph, &glyph);
        if(!error)
        {
                FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
                bitmap_glyph = (FT_BitmapGlyph)glyph;
                bitmap = bitmap_glyph->bitmap;
                xSize = bitmap.width;
                ySize = bitmap.rows;
                if(alignFlag == Center)
                        y += (fontStr.fontCurHeight - ySize) >>1;
                else if(alignFlag == Bottom)
                        y += ((fontStr.fontCurHeight + fontStr.fontCurWidth)>>1) - ySize;
                for(; iySize; ++i)
                {
                        for(j=0; jxSize; ++j)
                        {
                                if (bitmap.buffer[i*xSize+j] && xx >= 0 && xx  osdwidth && y >= 0 && yosdheight)
                             D_OSD_DrawPixel(xx,y,color);
                                xx++;
                        }
                        xx = x;
                        y++;
                       
                }
                 FT_Done_Glyph(glyph);
                glyph = NULL;
        }
        if((code & 0xFF00) != 0){
                return fontStr.fontCurWidth;
        }
        else {
                if(xSize == 0) {
                        if(code != 0x20)
                                return 0;               
                }
               
                return CharPixelLen;
        }
}
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12258/showart_585978.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP