📄 gfxfont.c
字号:
else // get the dest to scratch backgrond { GFX_BITBLT_PARM_T bparm; bparm.hDesSurface = pFont->hScratch; bparm.uDesX = 0; bparm.uDesY = 0; bparm.uWidth = uwidth; bparm.uHeight = pFont->uHeight; bparm.hSrcSurface = hDes; bparm.uSrcX = X; bparm.uSrcY = Y;#if defined(G2D_RGB_565) && defined(G2D_YCBCR) // pallas only if(GET_GFX_SURFACE_DATA_TYPE(uPlaneConfig) == G2D_RGB_565 || GET_GFX_SURFACE_DATA_TYPE(uPlaneConfig) == G2D_YCBCR ) { bparm.alphaSelect.storedAlphaSelect = GFX_DEST_ALPHA_FROM_GIVEN; bparm.alphaSelect.globalAlphaValue = 255; } else #endif bparm.alphaSelect.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; if(ioctl(fdGfxDev, IOC_GFX_BITBLT, &bparm)) return -1; } // blend on scratch pad { GFX_ADV_BLEND_PARM_T parm; parm.hDesSurface = pFont->hScratch; parm.uDesX = 0; parm.uDesY = 0; 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; if(ioctl(fdGfxDev, IOC_GFX_ADV_BLEND, &parm)) return -1; } // blt scratch back to dest { GFX_BITBLT_PARM_T bparm; bparm.hDesSurface = hDes; bparm.uDesX = X; bparm.uDesY = Y; bparm.uWidth = uwidth; bparm.uHeight = pFont->uHeight; bparm.hSrcSurface = pFont->hScratch; bparm.uSrcX = 0; bparm.uSrcY = 0; bparm.alphaSelect.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; rtn = ioctl(fdGfxDev, IOC_GFX_BITBLT, &bparm); } } return rtn;}// return font width in pixelsint gfx_draw_font( int fdGfxDev, int hDes, GFX_FONT_INFO_T *pFont, unsigned int uChar, long X, long Y, unsigned int uColor, unsigned int uBackColor, unsigned int uFlag ){ GFX_SURFACE_INFO_T sInfo; int rtn; if(!pFont || !pFont->uWidth) return -1; if(uChar > pFont->uMaxChar || uChar < pFont->uMinChar) return -1; // out of range uChar -= pFont->uMinChar; if(!pFont->uWidth[uChar]) // zero width or not encoded { return(0); } sInfo.hSurface = hDes; // try to get some information regarding the surface rtn = ioctl(fdGfxDev, IOC_GFX_GET_SURFACE_INFO, &sInfo); if( rtn < 0) { return rtn; } if((uFlag & GFX_DRAW_FONT_ANTIALIAS)) { rtn = __gfx_draw_font_antialias(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, X, Y, uColor, uBackColor, uFlag); } else // no anti-aliasing, we may choose to use either bit_blt, adv_fill_blt or draw pixel using fill_blt { rtn = __gfx_draw_font_mono(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, X, Y, uColor, uBackColor, uFlag); } if( rtn || ioctl(fdGfxDev, IOC_GFX_WAIT_FOR_COMPLETE, GFX_DRAW_TIMEOUT)) return -1; return pFont->uWidth[uChar];}/******************************************************************************* Function: gfx_draw_ascii_string**** Purpose: draw a string of ascii characters into a region buffer**** Returns: width of string : if successful** -1: if an error occurs*****************************************************************************/int gfx_draw_ascii_string( int fdGfxDev, int hDes, GFX_FONT_INFO_T *pFont, const char *szStr, long X, long Y, unsigned int uColor, unsigned int uBackColor, unsigned int uFlag ){ GFX_SURFACE_INFO_T sInfo; int rtn; int xadv; if(!pFont || !pFont->uWidth || pFont->uMinChar >= 256 || !szStr) return -1; sInfo.hSurface = hDes; // try to get some information regarding the surface rtn = ioctl(fdGfxDev, IOC_GFX_GET_SURFACE_INFO, &sInfo); if( rtn < 0) { return rtn; } xadv = 0; while(*szStr) { unsigned int uChar = (unsigned int)*szStr; if(uChar >= pFont->uMinChar || uChar <= pFont->uMaxChar) { uChar -= pFont->uMinChar; if(pFont->uWidth[uChar]) // zero width or not encoded { if((uFlag & GFX_DRAW_FONT_ANTIALIAS)) { rtn = __gfx_draw_font_antialias(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, X+xadv, Y, uColor, uBackColor, uFlag); } else // no anti-aliasing, we may choose to use either bit_blt, adv_fill_blt or draw pixel using fill_blt { rtn = __gfx_draw_font_mono(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, X+xadv, Y, uColor, uBackColor, uFlag); } if(rtn) break; xadv += pFont->uWidth[uChar]; } } szStr ++; } if(rtn || ioctl(fdGfxDev, IOC_GFX_WAIT_FOR_COMPLETE, GFX_DRAW_TIMEOUT)) return -1; return xadv;}/******************************************************************************* Function: gfx_draw_ascii_string_rect**** Purpose: draw a string of ascii characters into a rect of region buffer** with line wrap !!!**** Returns: num of char written : if successful** -1: if an error occurs*****************************************************************************/int gfx_draw_ascii_string_rect( int fdGfxDev, int hDes, GFX_FONT_INFO_T *pFont, const char *szStr, long X1, long Y1, long X2, long Y2, int char_space, int line_space, unsigned int uColor, unsigned int uBackColor, unsigned int uFlag ){ GFX_SURFACE_INFO_T sInfo; int rtn, c; int xadv, yadv; if(!pFont || !pFont->uWidth || pFont->uMinChar >= 256 || !szStr) return -1; /* return an error if part of the font is outside the region */ if ((X1 > X2 ) || (Y1 > Y2) ) { return(-1); } sInfo.hSurface = hDes; // try to get some information regarding the surface rtn = ioctl(fdGfxDev, IOC_GFX_GET_SURFACE_INFO, &sInfo); if( rtn < 0) { return rtn; } xadv = X1; yadv = Y1; c = 0; while(*szStr) { unsigned int uChar = (unsigned int)*szStr; if(uChar >= pFont->uMinChar || uChar <= pFont->uMaxChar) { uChar -= pFont->uMinChar; if(pFont->uWidth[uChar]) // zero width or not encoded { if(xadv + pFont->uWidth[uChar] + char_space > X2) { if(X1 + pFont->uWidth[uChar] + char_space > X2) break; // that's all xadv = X1; yadv += pFont->uHeight + line_space; } if(yadv + pFont->uHeight + line_space > Y2) break; // that's all if((uFlag & GFX_DRAW_FONT_ANTIALIAS)) { rtn = __gfx_draw_font_antialias(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, xadv, yadv, uColor, uBackColor, uFlag); } else // no anti-aliasing, we may choose to use either bit_blt, adv_fill_blt or draw pixel using fill_blt { rtn = __gfx_draw_font_mono(fdGfxDev, hDes, sInfo.uPlaneConfig, pFont, uChar, xadv, yadv, uColor, uBackColor, uFlag); } if(rtn) break; xadv += pFont->uWidth[uChar] + char_space; c++; } } szStr ++; } if(rtn || ioctl(fdGfxDev, IOC_GFX_WAIT_FOR_COMPLETE, GFX_DRAW_TIMEOUT)) return -1; return c;}/******************************************************************************* Function: gfx_get_ascii_string_length**** Returns: width of string in pixels: if successful** -1: if an error occurs*****************************************************************************/int gfx_get_ascii_string_length( GFX_FONT_INFO_T *pFont, const char *szStr ){ int rtn; if(!pFont || !pFont->uWidth || pFont->uMinChar >= 256 ) return -1; if(!szStr) return 0; rtn = 0; while(*szStr) { unsigned int uChar = (unsigned int)*szStr; if(uChar >= pFont->uMinChar || uChar <= pFont->uMaxChar) { uChar -= pFont->uMinChar; rtn += (int)pFont->uWidth[uChar]; } szStr ++; } return(rtn);}/******************************************************************************* Function: gfx_get_ascii_string_height**** Purpose: determine the height of a font in pixels**** Returns: height of sting in pixels: if successful** -1: if an error occurs*****************************************************************************/int gfx_get_ascii_string_height( GFX_FONT_INFO_T *pFont, const char *szStr ){ if(!pFont || !pFont->uWidth || pFont->uMinChar >= 256) return -1; return (int)pFont->uHeight;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -