Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15530578
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: C/C++

2007-09-07 10:40:58

//*********************************************************************************************************************
//【 版      权 】Copyright (c) 2007-2008 http://gliethttp.cublog.cn
//
//【 文 件 版 本 】v1.x
//
//【 文 件 名 称 】GFontHZK.c
//
//【 创 建 日 期 】2007-09-03  于2007-09-11做过修改
//
//【 功 能 描 述 】μC/GUI-v3.90a内核汉化--中英文混合显示
//*********************************************************************************************************************
#include "GUI.h"
#include "GUIType.h"
#include "GUI_Protected.h"
extern unsigned char FHZK12ASCII[];
#define GUI_FHZK12ASCII_BASE    (void*)FHZK12ASCII
#define GUI_FHZK12_BASE            (void*)0x10070000
//---------------------------------------------------
//HZK12EN
const GUI_FONT_MONO GUI_FHZK12_EN = {
 GUI_FHZK12ASCII_BASE,
 0,
 0,
 0x20,                        /* FirstChar */
 0xff,                        /* LastChar */
 6,                            /* XSize */
 7,                            /* XDist */
 1                            /* BytesPerLine */
};
/*static*/ GUI_FONT GUI_FHZK12E = {
  GUI_FONTTYPE_MONO
  ,12                        /* height of font */
  ,13                        /* space of font y */
  ,1                        /* magnification x */
  ,1                        /* magnification y */
  ,{&GUI_FHZK12_EN}/*pMono*/
};
//合成公式,将显示第3区的unicode字母gliethttp
//sprintf(tmp,"%c",i+count);
//tmp[0] = 0xa3;
//tmp[1] = 0xa1+i+count;
//tmp[2] = 0;
//GUI_DispString(tmp);
//---------------------------------------------------
//HZK12CH
const GUI_FONT_MONO GUI_FHZK12_CH = {
 GUI_FHZK12_BASE,
 0,
 0,
 0xa1a1,                    /* FirstChar */
 0xfefe,                    /* LastChar */
 12,                        /* XSize */
 13,                        /* XDist */
 2                          /* BytesPerLine */
};
/*static*/ GUI_FONT GUI_FHZK12C = {
  GUI_FONTTYPE_MONO
  ,12                       /* height of font */
  ,13                       /* space of font y */
  ,1                        /* magnification x */
  ,1                        /* magnification y */
  ,{&GUI_FHZK12_CH}/*pMono*/
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++
extern unsigned char FHZK16ASCII[];
#define GUI_FHZK16ASCII_BASE    (void*)FHZK16ASCII
#define GUI_FHZK16_BASE            (void*)0x10070000
//---------------------------------------------------
//HZK16EN
const GUI_FONT_MONO GUI_FHZK16_EN = {
 GUI_FHZK16ASCII_BASE,
 0,
 0,
 0x20,                        /* FirstChar */
 0xff,                        /* LastChar */
 8,                           /* XSize */
 9,                           /* XDist */
 1                            /* BytesPerLine */
};
/*static*/ GUI_FONT GUI_FHZK16E = {
  GUI_FONTTYPE_MONO
  ,16                        /* height of font */
  ,17                        /* space of font y */
  ,1                         /* magnification x */
  ,1                         /* magnification y */
  ,{&GUI_FHZK16_EN}/*pMono*/
};
//合成公式,将显示第3区的unicode字母gliethttp
//sprintf(tmp,"%c",i+count);
//tmp[0] = 0xa3;
//tmp[1] = 0xa1+i+count;
//tmp[2] = 0;
//GUI_DispString(tmp);
//---------------------------------------------------
//HZK16CH
const GUI_FONT_MONO GUI_FHZK16_CH = {
 GUI_FHZK16_BASE,
 0,
 0,
 0xa1a1,                    /* FirstChar */
 0xfefe,                    /* LastChar */
 16,                        /* XSize */
 17,                        /* XDist */
 2                          /* BytesPerLine */
};
/*static*/ GUI_FONT GUI_FHZK16C = {
  GUI_FONTTYPE_MONO
  ,16                        /* height of font */
  ,17                        /* space of font y */
  ,1                         /* magnification x */
  ,1                         /* magnification y */
  ,{&GUI_FHZK16_CH}/*pMono*/
};
//将以下属性变量封装在该.c文件中,若需引用使用方法函数[gliethttp]
GUI_FONT *FHZK_CH        = &GUI_FHZK12C;
GUI_FONT *FHZK_Ascii    = &GUI_FHZK12E;//&GUI_Font6x8;
static const GUI_FONT *FHZK_Pre;
//---------------------------
void GUI_CHAscii(void)//(GUI_FONT *CHAscii)
{
    if(FHZK_Ascii)
    {
        //GUI_LOCK();GUI_DispSring在最外层已经加了GUI_LOCK()保护
        GUI_Context.pAFont = FHZK_Ascii;
        //GUI_UNLOCK();
        //GUI_SetFont(FHZK_Ascii);//GUI_SetFont()函数只是用来登记ascii码
    }
}
void GUI_CHSetAscii(GUI_FONT *CHAscii)
{
    if(CHAscii)FHZK_Ascii = CHAscii;
}
//---------------------------
void GUI_CHS(void)//(GUI_FONT *CH)
{
    if(FHZK_CH)
    {
        //GUI_LOCK();GUI_DispSring在最外层已经加了GUI_LOCK()保护
        if(FHZK_Pre == 0)FHZK_Pre = GUI_Context.pAFont;
        GUI_Context.pAFont = FHZK_CH;
        //GUI_SetFont(FHZK_CH);//GUI_SetFont()函数只是用来登记ascii码
        //GUI_UNLOCK();
    }
}
//---------------------------
void GUI_CHO(void)
{
    if(FHZK_Pre)
    {
        //GUI_LOCK();GUI_DispSring在最外层已经加了GUI_LOCK()保护
        GUI_Context.pAFont = FHZK_Pre;
        //GUI_UNLOCK();
        //GUI_SetFont(FHZK_Pre);//GUI_SetFont()函数只是用来登记ascii码
        FHZK_Pre = 0;
    };
}
void GUI_CH(GUI_FONT *CH)
{
    if(CH)FHZK_CH = CH;
}
//---------------------------
int User_GUIMONO_GetCharDistX(U16P Char)
{const GUI_FONT_MONO * pMono;
 int result;
     if((Char & 0x8080) == 0)
    {
        pMono = FHZK_Ascii->p.pMono;
    }else pMono = FHZK_CH->p.pMono;
    result = pMono->XDist*GUI_Context.pAFont->XMag;
  return result;
}
//---------------------------
U16P Set2FHZK(U16 Char)
{
    if((Char & 0x8080) == 0)
    {
        GUI_CHAscii();
        //将ascii码转换成HZK中对应的码值
        //合成公式,将显示第3区的unicode字母gliethttp
        //tmp[0] = 0xa3;
        //tmp[1] = 0xa1+i+count;
        //tmp[2] = 0;
        return Char;
    }else {GUI_CHS();return Char;}
}
//---------------------------
void RetfFHZK(void)
{
    /*if(GUI_GetFont() == FHZK_Ascii)*/GUI_CHS();
}
/*
//以下是对ucguiv3.90a系统文件的修改
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUI_UC_EncodeNone.c->_GetCharCode()
static U16 _GetCharCode(const char GUI_UNI_PTR * s) {
//2007-09-06 gliethttp
    if((s[1] & 0x80) && (s[0] & 0x80))return ((s[1] << 8) | s[0]);
    else return s[0];
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUI_UC_EncodeNone.c->_GetCharSize
static int _GetCharSize(const char GUI_UNI_PTR * s) {
  //汉字占用2个char字符
  if((s[1] & 0x80) && (s[0] & 0x80))return 2;
  return 1;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUICharM.c->GUIMONO_GetCharDistX()
int GUIMONO_GetCharDistX(U16P c) {
//2007-09-06 gliethttp
    return User_GUIMONO_GetCharDistX(c);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUICharLine.c->_DispLine()
static void _DispLine(const char GUI_UNI_PTR *s, int MaxNumChars, const GUI_RECT *pRect) {
  if (GUI_Context.pClipRect_HL) {
    if (GUI_RectsIntersect(GUI_Context.pClipRect_HL, pRect) == 0)
      return;
  }
  #if GUI_COMPILER_SUPPORTS_FP
  if (GUI_Context.pAFont->pafEncode) {
    GUI_Context.pAFont->pafEncode->pfDispLine(s, MaxNumChars);
  } else {
  #else
  {
  #endif
    U16 Char;
    while (--MaxNumChars >= 0) {
      Char = GUI_UC__GetCharCodeInc(&s);
     Char = Set2FHZK(Char);//2007-09-04 gliethttp添加
      GUI_Context.pAFont->pfDispChar(Char);
      if (GUI_pfDispCharStyle) {
        GUI_pfDispCharStyle(Char);
      }
    }
    GUI_CHO();//恢复到之前设置的ascii字体
  }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUICharM.c->GUIMONO_DispChar()
void GUIMONO_DispChar(U16P c) {
  int c0, c1;
  const unsigned char GUI_UNI_PTR * pd;
  int x = GUI_Context.DispPosX;
  int y = GUI_Context.DispPosY;
  // do some checking if drawing is actually necessary ...
  const GUI_FONT_MONO GUI_UNI_PTR * pMono = GUI_Context.pAFont->p.pMono;
  unsigned int FirstChar = pMono->FirstChar;
  // translate character into 2 characters to display : c0,c1
  // Check if regular character first.
  if ((c >= (U16P)FirstChar) &&(c <= (U16P)pMono->LastChar)) {
    pd = pMono->pData;
    if(c > 0xff)
    {U8 *s;
    //2007-09-06 gliethttp
    //汉字区位码索引计算
        s = (U8*)&c;
        c0 = (*s-0xa1)*94 + *(s+1)-0xa1;//小端存储模式
    }else c0 = ((int)c) - FirstChar;
    c1 = -1;
  } else {
    // Check if character is in translation table
    GUI_FONT_TRANSINFO const GUI_UNI_PTR * pti = pMono->pTrans;
    pd = pMono->pTransData;
    if (pti) {
      FirstChar = pti->FirstChar;
      if ((c >= (U16P)FirstChar) && (c <= (U16P)pti->LastChar)) {
        GUI_FONT_TRANSLIST const GUI_UNI_PTR * ptl;
        c -= pti->FirstChar;
        ptl = pti->pList;
        ptl += c;
        c0 = ptl->c0;
        c1 = ptl->c1;
      } else {
        c0 = c1 = -1;
      }
    } else {
      c0 = c1 = -1;
    }
  }
  // Draw first character if it is valid
  if (c0!=-1) {
    int BytesPerChar = GUI_Context.pAFont->YSize*pMono->BytesPerLine;
    GUI_DRAWMODE DrawMode;
    int XSize = pMono->XSize;
    int YSize = GUI_Context.pAFont->YSize;
    // Select the right drawing mode
    DrawMode = GUI_Context.TextMode;
    // call drawing routine
    {
      U8 OldMode = LCD_SetDrawMode(DrawMode);
      LCD_DrawBitmap( x, y,
                         XSize, YSize,
                         GUI_Context.pAFont->XMag, GUI_Context.pAFont->YMag,
                         1, // Bits per Pixel
                         pMono->BytesPerLine,
                         pd + c0* BytesPerChar,
                         &LCD_BKCOLORINDEX
                         );
      if (c1 != -1) {
        LCD_SetDrawMode(DrawMode | LCD_DRAWMODE_TRANS);
        LCD_DrawBitmap( x, y,
                           XSize, YSize,
                           GUI_Context.pAFont->XMag, GUI_Context.pAFont->YMag,
                           1, //Bits per Pixel
                           pMono->BytesPerLine,
                           pd + c1* BytesPerChar,
                           &LCD_BKCOLORINDEX
                           );
      }
      // Fill empty pixel lines
      if (GUI_Context.pAFont->YDist > GUI_Context.pAFont->YSize) {
        if (DrawMode != LCD_DRAWMODE_TRANS) {
          LCD_SetDrawMode(DrawMode ^ LCD_DRAWMODE_REV); //Reverse so we can fill with BkColor
          LCD_FillRect(x,
                       y + GUI_Context.pAFont->YSize * GUI_Context.pAFont->YDist,
                       x + XSize * GUI_Context.pAFont->XMag,
                       y + GUI_Context.pAFont->YDist);
        }
      }
      LCD_SetDrawMode(OldMode);
    }
  }
//2007-09-06 gliethttp
  GUI_Context.DispPosX+=pMono->XDist * GUI_Context.pAFont->XMag;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUI_DispString.c->GUI_DispString()函数的回车换行问题\r\n
void GUI_DispString(const char GUI_UNI_PTR *s) {
  int xAdjust, yAdjust, xOrg;
  int FontSizeY;
  if (!s)
    return;
  GUI_LOCK();
  FontSizeY = GUI_GetFontDistY();
  xOrg = GUI_Context.DispPosX;
 // Adjust vertical position
  yAdjust = GUI_GetYAdjust();
  GUI_Context.DispPosY -= yAdjust;
  for (; *s; s++) {
    GUI_RECT r;
    int LineNumChars = GUI__GetLineNumChars(s, 0x7fff);
    int xLineSize = GUI__GetLineDistX(s, LineNumChars);
  // Check if x-position needs to be changed due to h-alignment
    switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
      case GUI_TA_CENTER: xAdjust = xLineSize / 2; break;
      case GUI_TA_RIGHT: xAdjust = xLineSize; break;
      default: xAdjust = 0;
    }
    r.x0 = GUI_Context.DispPosX -= xAdjust;
    r.x1 = r.x0 + xLineSize - 1;
    r.y0 = GUI_Context.DispPosY;
    r.y1 = r.y0 + FontSizeY - 1;
    GUI__DispLine(s, LineNumChars, &r);
    GUI_Context.DispPosY = r.y0;
    s += GUI_UC__NumChars2NumBytes(s, LineNumChars);
    //if ((*s == '\n') || (*s == '\r')) {
    //2007-09-07 gliethttp
    //回车
    if((s[0] == '\r') || (s[1] == '\r')) {
      switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
      case GUI_TA_CENTER:
      case GUI_TA_RIGHT:
        GUI_Context.DispPosX = xOrg;
        break;
      default:
        GUI_Context.DispPosX = GUI_Context.LBorder;
        break;
      }
     // if (*s == '\n')
     //2007-09-07 gliethttp
     //换行
     if((s[0] == '\n') || (s[1] == '\n'))//只出现一个换行
        GUI_Context.DispPosY += FontSizeY;
     if((s[1] == '\r') || (s[1] == '\n'))s += 1;//跳过\r\n组合
    } else {
      GUI_Context.DispPosX = r.x0 + xLineSize;
    }
    if (*s == 0) // end of string (last line) reached
      break;
  }
  GUI_Context.DispPosY += yAdjust;
  GUI_Context.TextAlign &= ~GUI_TA_HORIZONTAL;
  GUI_UNLOCK();
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//修改GUI/Core/GUICharLine.c->GUI__GetLineNumChars()函数的回车换行问题\r\n
int GUI__GetLineNumChars(const char GUI_UNI_PTR *s, int MaxNumChars) {
  int NumChars = 0;
  if (s) {
    #if GUI_COMPILER_SUPPORTS_FP
      if (GUI_Context.pAFont->pafEncode) {
        return GUI_Context.pAFont->pafEncode->pfGetLineLen(s, MaxNumChars);
      }
    #endif
    for (; NumChars < MaxNumChars; NumChars++) {
      U16 Data = GUI_UC__GetCharCodeInc(&s);
      // if ((Data == 0) || (Data == '\n')) {
      // break;
      // }
      //2007-09-07 gliethttp
      if(Data == 0)break;
      if( (Data == '\n') || (Data == '\r') )
      {U16 TData = GUI_UC__GetCharCodeInc(&s);
          if( (TData == '\n') || (TData == '\r') )
          {//正常的\r\n
              //if(TData != Data)break;
              break;
          }
      }
    }
  }
  return NumChars;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
修改GUI/Core/GUI__DispStringInRect.c->GUI__DispStringInRect()函数的回车换行问题\r\n
void GUI__DispStringInRect(const char GUI_UNI_PTR *s, GUI_RECT* pRect, int TextAlign, int MaxNumChars) {
  GUI_RECT r;
  GUI_RECT rLine;
  int y = 0;
  const char GUI_UNI_PTR *sOrg =s;
  int FontYSize;
  int xLine = 0;
  int LineLen;
  int NumCharsRem; // Number of remaining characters
  FontYSize = GUI_GetFontSizeY();
  if (pRect) {
    r = *pRect;
  } else {
    GUI_GetClientRect(&r);
  }
  // handle vertical alignment
  if ((TextAlign & GUI_TA_VERTICAL) == GUI_TA_TOP) {
        y = r.y0;
  } else {
    int NumLines;
    // Count the number of lines
    for (NumCharsRem = MaxNumChars, NumLines = 1; NumCharsRem ;NumLines++) {
      LineLen = GUI__GetLineNumChars(s, NumCharsRem);
      NumCharsRem -= LineLen;
      //2007-09-07 gliethttp
      if( (LineLen == 0) && (NumCharsRem == 1) )
      {//说明\r\n错行了,即\r为当前行所能显示的最后一个字符,这时LineLen = 0;
          LineLen = 1;
      }
      s += GUI_UC__NumChars2NumBytes(s, LineLen);
      if (GUI__HandleEOLine(&s))
        break;
    }
    // Do the vertical alignment
    switch (TextAlign & GUI_TA_VERTICAL) {
     case GUI_TA_BASELINE:
     case GUI_TA_BOTTOM:
     y = r.y1 -NumLines * FontYSize+1;
      break;
     case GUI_TA_VCENTER:
         y = r.y0+(r.y1-r.y0+1 -NumLines * FontYSize) /2;
      break;
     }
  }
  // Output string
  for (NumCharsRem = MaxNumChars, s = sOrg; NumCharsRem;) {
    int xLineSize;
    LineLen = GUI__GetLineNumChars(s, NumCharsRem);
    NumCharsRem -= LineLen;
    xLineSize = GUI__GetLineDistX(s, LineLen);
    switch (TextAlign & GUI_TA_HORIZONTAL) {
    case GUI_TA_HCENTER:
      xLine = r.x0+(r.x1-r.x0-xLineSize)/2; break;
    case GUI_TA_LEFT:
      xLine = r.x0; break;
    case GUI_TA_RIGHT:
      xLine = r.x1 -xLineSize + 1;
    }
    rLine.x0 = GUI_Context.DispPosX = xLine;
    rLine.x1 = rLine.x0 + xLineSize-1;
    rLine.y0 = GUI_Context.DispPosY = y;
    rLine.y1 = y + FontYSize-1;
    GUI__DispLine(s, LineLen, &rLine);
    s += GUI_UC__NumChars2NumBytes(s, LineLen);
    y += GUI_GetFontDistY();
    if (GUI__HandleEOLine(&s))
      break;
  }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
修改GUI/Core/GUI_SetFont.c->GUI_SetFont()
const GUI_FONT GUI_UNI_PTR* GUI_SetFont(const GUI_FONT GUI_UNI_PTR * pNewFont) {
  const GUI_FONT GUI_UNI_PTR* pOldFont = GUI_Context.pAFont;
  GUI_LOCK();
  if (pNewFont)
  {
      //2007-09-11 gliethttp
      //GUI_SetFont()函数只是用来登记ascii码
      GUI_CHSetAscii(pNewFont);//临时存储ascii显示字体集
      //GUI_Context.pAFont = pNewFont;
  }
  GUI_UNLOCK();
  return pOldFont;
}
//2007-09-11 修改
至此uCGUIv3.90a内核汉化工作全部完成,我们熟悉的中英文混合文本可以正常显示了[gliethttp]
显示中英文混合文本的代码模型:
1.指定中英文混合显示时字体
GUI_SetFont(&GUI_FHZK12E);//选择中英文混合显示时--英文字体
GUI_CH(&GUI_FHZK16C);//选择中英文显示时--中文字体
GUI_DispString("uCGUIv3.90a不错的图形引擎!\r\nGood\r\n让我们共同努力!");
2.使用默认的中文字体
GUI_SetFont(&GUI_Font8_1);//选择中英文混合显示时--英文字体
GUI_DispString("uCGUIv3.90a不错的图形引擎!\r\nGood\r\n让我们共同努力!");
*/

 

文件: μCGUI-v3.90a内核汉化文件__GFontHZK.rar.rar
大小: 4KB
下载: 下载
阅读(3732) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~