Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45165
  • 博文数量: 14
  • 博客积分: 1485
  • 博客等级: 上尉
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-13 15:44
文章分类

全部博文(14)

文章存档

2012年(1)

2011年(2)

2010年(3)

2009年(8)

我的朋友

分类: C/C++

2011-02-10 16:50:27

BOOL DrawText(HDC hDC, LPSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
{
 int i, j;
 int x, y;
 int nUnderLineHei;
 BOOL bRet;
 PFT2FONT pFont;
 
 if((NULL == hDC) || (NULL == hDC->hFont) || (NULL == lpString) || ('\0' == lpString) || (NULL == lpRect))
  return FALSE;
 pFont = (PFT2FONT)hDC->hFont;
 bRet = FreeType2_GetFontData(pFont, lpString);
 if(bRet)
 {
  if((pFont->nRealWid > 0) && (pFont->nRealHei > 0))
  {
   int nDy;
   COLORREF clrD;
   BYTE dr, dg, db, mr, mg, mb;
   BYTE sr = fb_r(hDC->clrPen);
   BYTE sg = fb_g(hDC->clrPen);
   BYTE sb = fb_b(hDC->clrPen);
   x = lpRect->left;
   y = lpRect->top;
   nUnderLineHei = 0;
   
   if(pFont->bUnderline)
    nUnderLineHei = pFont->nRealHei / 10;
   
   switch(uFormat & 0xf0)
   {
    case DT_RIGHT:
     x += lpRect->right - pFont->nRealWid;
     break;
    case DT_HCENTER: 
     x = (lpRect->left + lpRect->right - pFont->nRealWid) / 2;
     break;
   }
   nDy = pFont->bUnderline ? (nUnderLineHei + 1) : 0;
   switch(uFormat & 0x0f)
   {
    case DT_VCENTER:
     y = (lpRect->top + lpRect->bottom - (pFont->nRealHei  + nDy)) / 2;
     break;
    case DT_BOTTOM:
     y += lpRect->bottom - (pFont->nRealHei + nDy);
     break;
   }
   
   if(x <= lpRect->left)
    x = lpRect->left;
    
   if(y <= lpRect->top)
    y = lpRect->top;
 
   RequestPaint();
   for(i=0; inRealHei; i++)
   {
    for(j=0; jnRealWid; j++)
    {
     if((x+j < lpRect->right) && (y+i < lpRect->bottom))
     {
      if(*(pFont->pucData + i*pFont->nRealWid + j) != 0xff)
      {       
       clrD = xgui_getpixel(x+j, y+i);
       
       mr = fb_r(clrD);
       mg = fb_g(clrD);
       mb = fb_b(clrD);
       if(!*(pFont->pucData + i*pFont->nRealWid + j))
       {
        dr = sr;
        dg = sg;
        db = sb;
       }
       
       else
       {
        dr = (*(pFont->pucData + i*pFont->nRealWid + j)*(mr - sr) >> 8) + sr;
        dg = (*(pFont->pucData + i*pFont->nRealWid + j)*(mg - sg) >> 8) + sg;
        db = (*(pFont->pucData + i*pFont->nRealWid + j)*(mb - sb) >> 8) + sb;
       }
       
       xgui_setpixel(hDC, x+j, y+i, fb_rgb(dr, dg, db));
      }
     }
    }
   }
   if(pFont->bUnderline)
   {
    y += pFont->nRealHei + 1;
    
    for(i=0; i    {
     for(j=0; jnRealWid; j++)
     {
      if((x+j < lpRect->right) && (y+i < lpRect->bottom))
       xgui_setpixel(hDC, x+j, y+i, hDC->clrPen);
     }
    }
   }
   
   CompletePaint();
  } 
 }
 return TRUE;
}
阅读(657) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~