Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1104342
  • 博文数量: 121
  • 博客积分: 8910
  • 博客等级: 上将
  • 技术积分: 2915
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-18 09:36
文章分类

全部博文(121)

文章存档

2011年(3)

2010年(100)

2008年(18)

分类: BSD

2008-04-25 20:04:14

一段使用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(; i<ySize; ++i)
                {
                        for(j=0; j<xSize; ++j)
                        {
                                if (bitmap.buffer[i*xSize+j] && xx >= 0 && xx < osdwidth && y >= 0 && y<osdheight)
                             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;
        }

}

阅读(8280) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~