⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gfxfont.c

📁 IBM source for pallas/vulcan/vesta
💻 C
📖 第 1 页 / 共 3 页
字号:
            rtn =  -1;            goto clean_up;        }        if(gfx_lock_surface(fdGfxDev, pFont->hFont, &pFont->infoFont) < 0)        {            fprintf(stderr, "Failed to lock font surface !\n");            gfx_destroy_surface(fdGfxDev, pFont->hScratch);            gfx_destroy_surface(fdGfxDev, pFont->hMonoFont);            gfx_destroy_surface(fdGfxDev, pFont->hFont);            free(cmap);            free(pFont->uWidth);            rtn =  -1;            goto clean_up;        }        if(gfx_lock_surface(fdGfxDev, pFont->hMonoFont, &pFont->infoMono) < 0)        {            fprintf(stderr, "Failed to lock font surface !\n");            gfx_unlock_surface(fdGfxDev, pFont->hFont, &pFont->infoFont);            gfx_destroy_surface(fdGfxDev, pFont->hScratch);            gfx_destroy_surface(fdGfxDev, pFont->hMonoFont);            gfx_destroy_surface(fdGfxDev, pFont->hFont);            free(cmap);            free(pFont->uWidth);            rtn =  -1;            goto clean_up;        }                for(i=0; i<face->num_glyphs; i++)        {            // load glyph            if(xadv[i] == 0 && yadv[i] == 0)  continue;  // unused slots                        rtn = FT_Load_Glyph( face, i, FT_LOAD_DEFAULT );                 if(rtn) continue;                                                                        // extract glyph image                                                     rtn = FT_Get_Glyph( face->glyph, &glyph );                                                                                                     // convert to a bitmap (default render mode + destroy old)                if ( glyph->format != ft_glyph_format_bitmap )                            {                                                                             rtn = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal,                                        0, 1 );                                       if ( rtn ) continue; // glyph unchanged                                      }                                                                                                                                        // access bitmap content by typecasting                            glyph_bitmap = (FT_BitmapGlyph)glyph;                                                                                            // do funny stuff with it, like blitting/drawing                 {                int x,y, real_x, real_y;                unsigned char *pbmp;                if(glyph_bitmap->left > 0)                    real_x = xadv[i] +  glyph_bitmap->left; // + 4;                else                    real_x = xadv[i]; // + 4;                                real_y = yadv[i] + ((face->size->metrics.ascender+0x3f)>>6) - glyph_bitmap->top;                pbmp = glyph_bitmap->bitmap.buffer;                         // printf("glyph %d,  realx = %d  realy = %d  bmp->left = %d bmp->top = %d row = %d  col = %d\n", i, real_x, real_y, glyph_bitmap->left, glyph_bitmap->top, glyph_bitmap->bitmap.rows, glyph_bitmap->bitmap.width);                for(y=0; y<glyph_bitmap->bitmap.rows; y++)                {                    unsigned char *ppix = (unsigned char *)pFont->infoFont.plane[0].pPlane                                     + (y+real_y)*pFont->infoFont.plane[0].uBytePerLine + real_x;                     unsigned char *ppixb = (unsigned char *)pFont->infoMono.plane[0].pPlane                                     + (y+real_y)*pFont->infoMono.plane[0].uBytePerLine;                     for(x=0; x<glyph_bitmap->bitmap.width; x++)                    {                        //printf("%2x ", pbmp[x]);                        ppix[x] = pbmp[x];                        ppixb[(real_x+x)>>3] |= (pbmp[x]&0x80) >> ((real_x+x)&7);                    }                    //printf("\n");                    pbmp +=glyph_bitmap->bitmap.pitch;                 }            }            // discard glyph image (bitmap or not)            FT_Done_Glyph( glyph );                              }        // yehoo, we are here !        rtn = 0;        goto normal_rtn;    }clean_up:    memset(pFont, 0, sizeof(GFX_FONT_INFO_T));normal_rtn:    FT_Done_Face(face);clean_up1:    FT_Done_FreeType(ft_library);    return rtn;}int gfx_free_font(int fdGfxDev, GFX_FONT_INFO_T *pFont){    if(!pFont) return 0;    if(!pFont->uWidth) return 0;    free(pFont->uWidth);    gfx_unlock_surface(fdGfxDev, pFont->hMonoFont, &pFont->infoMono);    gfx_unlock_surface(fdGfxDev, pFont->hFont, &pFont->infoFont);    gfx_destroy_surface(fdGfxDev, pFont->hScratch);    gfx_destroy_surface(fdGfxDev, pFont->hMonoFont);    gfx_destroy_surface(fdGfxDev, pFont->hFont);    memset(pFont, 0, sizeof(GFX_FONT_INFO_T));    return 0;}/******************************************************************************* Function:    gfx_draw_font**** Purpose:     draw a single character of a font into a region buffer**** Returns:      the width of font: if successful**               -1: if an error occurs*****************************************************************************/int __gfx_draw_font_mono(       int fdGfxDev,        int hDes,        unsigned int uPlaneConfig,       GFX_FONT_INFO_T *pFont,        unsigned int uChar,        long X,       long Y,       unsigned int uColor,       unsigned int uBackColor,       unsigned int uFlag    ){    int rtn;    if(uFlag & GFX_DRAW_FONT_BACKGROUND)    {        GFX_PALETTE_T pal[2];        GFX_BITBLT_PARM_T bltparm;        pal[0] = *((GFX_PALETTE_T *)&uBackColor);        pal[1] = *((GFX_PALETTE_T *)&uColor);        gfx_set_surface_palette(fdGfxDev, pFont->hMonoFont, 0, 2, pal);        bltparm.hDesSurface = hDes;        bltparm.uDesX = X;        bltparm.uDesY = Y;        bltparm.uWidth = pFont->uWidth[uChar];        bltparm.uHeight = pFont->uHeight;        bltparm.hSrcSurface = pFont->hMonoFont;        bltparm.uSrcX = pFont->uPosX[uChar];        bltparm.uSrcY = pFont->uPosY[uChar];        bltparm.alphaSelect.storedAlphaSelect =             (uFlag & GFX_DRAW_FONT_WITHALPHA) ? GFX_BLEND_ALPHA_FROM_SOURCE : GFX_DEST_ALPHA_FROM_DESTINATION;        bltparm.alphaSelect.globalAlphaValue = 255;        bltparm.enableGammaCorrection = 0;        rtn = ioctl(fdGfxDev, IOC_GFX_BITBLT, &bltparm);    }    else    // transparent background    {        if(!IS_GFX_SURFACE_CLUT(uPlaneConfig) && IS_OSD_SURFACE_YUV(uPlaneConfig)) // YUV direct color mode        {            // :-( we need to draw every dirty pixel            int x, y, posx, wdx;            unsigned char *ppix;            GFX_FILLBLT_PARM_T   parm;            parm.hDesSurface = hDes;            parm.uHeight = 1;            parm.uFillColor = uColor;            posx = pFont->uPosX[uChar];            wdx = pFont->uWidth[uChar];            for(y=0; y < pFont->uHeight; y++)            {                int scanlth = 0, scanx = -1;                 ppix = (unsigned char *)pFont->infoMono.plane[0].pPlane                                 + (pFont->uPosY[uChar]+y)*pFont->infoMono.plane[0].uBytePerLine;                 parm.uDesY = Y+y;                for(x=0; x<wdx; x++)                {                    if(ppix[(posx+x)>>3] & (0x80 >> ((posx+x)&7)))                    {                        scanlth ++;                        if(scanx < 0) scanx = x;                    }                    else if(scanx >= 0) // fill now                    {                        parm.uDesX = X + scanx;                        parm.uWidth = scanlth;                        if(ioctl(fdGfxDev, IOC_GFX_FILLBLT, &parm)) return -1;                        scanx = -1;                        scanlth = 0;                    }                }                if(scanx >= 0) // fill now                {                        parm.uDesX = X + scanx;                        parm.uWidth = scanlth;                        if(ioctl(fdGfxDev, IOC_GFX_FILLBLT, &parm)) return -1;                        scanx = -1;                        scanlth = 0;                }            }        }        else    // we could use adv_fillblt to draw font        {            GFX_ADV_FILLBLT_PARM_T fparm;            fparm.hDesSurface = hDes;            fparm.uDesX = X;            fparm.uDesY = Y;            fparm.uWidth = pFont->uWidth[uChar];            fparm.uHeight = pFont->uHeight;            fparm.hMaskSurface = pFont->hMonoFont;            fparm.uMaskX = pFont->uPosX[uChar];            fparm.uMaskY = pFont->uPosY[uChar];            fparm.ROP = GFX_ROP_DISABLE;            fparm.transparencyEnable = 1;            fparm.enablePixelBitMask = 0;            fparm.uFillColor = uColor;            rtn = ioctl(fdGfxDev, IOC_GFX_ADV_FILLBLT, &fparm);        }    }    return rtn;}int __gfx_draw_font_antialias(       int fdGfxDev,        int hDes,        unsigned int uPlaneConfig,       GFX_FONT_INFO_T *pFont,        unsigned int uChar,        long X,       long Y,       unsigned int uColor,       unsigned int uBackColor,       unsigned int uFlag    ){    int rtn;    if(IS_GFX_SURFACE_CLUT(uPlaneConfig)#ifdef G2D_AYCBCR        || GET_GFX_SURFACE_DATA_TYPE(uPlaneConfig) == G2D_AYCBCR #endif        )        return __gfx_draw_font_mono(fdGfxDev, hDes, uPlaneConfig, pFont, uChar, X, Y, uColor, uBackColor, uFlag);    // fill the foreground    {        GFX_FILLBLT_PARM_T  fparm;        fparm.hDesSurface = pFont->hScratch;        fparm.uDesX = pFont->uMaxWidth;        fparm.uDesY = 0;        fparm.uWidth = pFont->uWidth[uChar];        fparm.uHeight = pFont->uHeight;        fparm.uFillColor = uColor;        if(ioctl(fdGfxDev, IOC_GFX_FILLBLT, &fparm)) return -1;    }    if(GET_GFX_SURFACE_DATA_TYPE(uPlaneConfig) == G2D_ARGB_8888)    // a special case we could use dest blend    {        // fill the background        if(uFlag & GFX_DRAW_FONT_BACKGROUND)        {            GFX_FILLBLT_PARM_T  fparm;            fparm.hDesSurface = hDes;            fparm.uDesX = X;            fparm.uDesY = Y;            fparm.uWidth = pFont->uWidth[uChar];            fparm.uHeight = pFont->uHeight;            fparm.uFillColor = uBackColor;            if(ioctl(fdGfxDev, IOC_GFX_FILLBLT, &fparm)) return -1;        }                {            GFX_ADV_BLEND_PARM_T   parm;                    parm.hDesSurface = hDes;            parm.uDesX = X;            parm.uDesY = Y;            parm.uWidth = pFont->uWidth[uChar];            parm.uHeight = pFont->uHeight;            parm.hSrcSurface = pFont->hScratch;            parm.uSrcX = pFont->uMaxWidth;            parm.uSrcY = 0;            parm.hAlphaSurface = pFont->hFont;            parm.uAlphaX = pFont->uPosX[uChar];            parm.uAlphaY = pFont->uPosY[uChar];            parm.blendSelect.storedAlphaSelect = (uFlag & GFX_DRAW_FONT_WITHALPHA) ? GFX_DEST_ALPHA_FROM_BLEND : GFX_DEST_ALPHA_FROM_DESTINATION;            parm.blendSelect.blendInputSelect  = GFX_BLEND_ALPHA_FROM_PATTERN;            rtn =  ioctl(fdGfxDev, IOC_GFX_ADV_BLEND, &parm);        }    }    else // we blend at scratch pad and then blt back to dest    {        unsigned int uwidth = IS_GFX_SURFACE_YUV(uPlaneConfig) ? ((pFont->uWidth[uChar]+1)&0xfffffffe) : pFont->uWidth[uChar];        // fill the background scratch        if(uFlag & GFX_DRAW_FONT_BACKGROUND)        {            GFX_FILLBLT_PARM_T  fparm;            fparm.hDesSurface = pFont->hScratch;            fparm.uDesX = 0;            fparm.uDesY = 0;            fparm.uWidth = uwidth;            fparm.uHeight = pFont->uHeight;            fparm.uFillColor = uBackColor;            if(ioctl(fdGfxDev, IOC_GFX_FILLBLT, &fparm)) return -1;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -