emwin 汉字显示方法
本帖最后由 sea_star 于 2013-8-9 18:11 编辑这几天想做个MP3播放器,用到了中文,搞了一天,增加俩个文件,放在库文件目录下,字库是我从文件加载的,现在共享。
/*
*********************************************************************************************************
* uC/GUI V3.98
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
* µC/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File : GUI_UC_EncodeNone.c
Purpose : Encoding routines for non unicode systems (default)
---------------------------END-OF-HEADER------------------------------
*/
#include "GUI_Private.h"
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _GetCharCode
*
* Purpose:
* Return the UNICODE character code of the current character.
*/
static U16 _GetCharCode(const char GUI_UNI_PTR * s) {
if((*s) > 0xA0)
return *(const U16 GUI_UNI_PTR *)s;
return *(const U8 GUI_UNI_PTR *)s;
}
/*********************************************************************
*
* _GetCharSize
*
* Purpose:
* Return the number of bytes of the current character.
*/
static int _GetCharSize(const char GUI_UNI_PTR * s) {
GUI_USE_PARA(s);
if((*s) > 0xA0) return 2;
return 1;
}
/*********************************************************************
*
* _CalcSizeOfChar
*
* Purpose:
* Return the number of bytes needed for the given character.
*/
static int _CalcSizeOfChar(U16 Char) {
GUI_USE_PARA(Char);
if(Char > 0xA0A0) return 2;
return 1;
}
/*********************************************************************
*
* _Encode
*
* Purpose:
* Encode character into 1/2/3 bytes.
*/
static int _Encode(char *s, U16 Char) {
if(Char > 0xA0A0)
{
*((U16 *)s) = (U16)(Char);
return 2;
}
*s = (U8)(Char);
return 1;
}
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _API_Table
*/
const GUI_UC_ENC_APILIST GUI_UC_None = {
_GetCharCode, /*return character code as U16 */
_GetCharSize, /*return size of character: 1 */
_CalcSizeOfChar,/*return size of character: 1 */
_Encode /*Encode character */
};
//const GUI_UC_ENC_APILIST GUI__API_TableNone = {
//_GetCharCode, /*return character code as U16 */
//_GetCharSize, /*return size of character: 1 */
//_CalcSizeOfChar,/*return size of character: 1 */
//_Encode /*Encode character */
//};
/*********************************************************************
*
* Exported code
*
**********************************************************************
*/
/*********************************************************************
*
* GUI_UC_SetEncodeNone
*/
// void GUI_UC_SetEncodeNone(void) {
// #if GUI_SUPPORT_UNICODE
// GUI_LOCK();
// GUI_Context.pUC_API = &GUI_UC_None;
// GUI_UNLOCK();
// #endif
// }
/*************************** End of file ****************************/
#include <stddef.h> /* needed for definition of NULL */
#include "GUI_Private.h"
#include <string.h>
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
//×ÖÄ£Êý¾ÝµÄÔÝ´æÊý×é,ÒÔµ¥¸ö×ÖÄ£µÄ×î´ó×Ö½ÚÊýΪÉ趨ֵ
#define BYTES_PER_FONT 128
static U8 GUI_FontDataBuf;
extern unsigned char *_Hzk_16;
extern unsigned char *_Asc_16;
//´ÓÍⲿ´æ´¢Æ÷È¡µÃ×ÖÄ£Êý¾Ý
static void GUI_GetDataFromMemory(const GUI_FONT_PROP GUI_UNI_PTR *pProp, U16P c)
{
U16 BytesPerFont;
U32 oft;
char *font = (char *)pProp->paCharInfo->pData;
BytesPerFont = GUI_pContext->pAFont->YSize * pProp->paCharInfo->BytesPerLine; //ÿ¸ö×ÖÄ£µÄÊý¾Ý×Ö½ÚÊý
if (BytesPerFont > BYTES_PER_FONT){BytesPerFont = BYTES_PER_FONT;}
if (c < 0x80) //Ó¢ÎÄ×Ö·ûµØÖ·Æ«ÒÆËã·¨
{
oft = c * BytesPerFont;
}
else
{
oft = ((((c >> 8) - 0xA1)) + ((c & 0xFF) - 0xA1) * 94l) * BytesPerFont; //ÖÐÎÄ×Ö·ûµØÖ·Æ«ÒÆËã·¨°üÀ¨·ûºÅ
}
if (font == 'a')
{
memcpy(GUI_FontDataBuf, _Asc_16 + oft, BytesPerFont);
}
else
memcpy(GUI_FontDataBuf, _Hzk_16 + oft, BytesPerFont);
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* GUIPROP_DispChar
*
* Purpose:
* This is the routine that displays a character. It is used by all
* other routines which display characters as a subroutine.
*/
void GUIPROP_X_DispChar(U16P c)
{
int BytesPerLine;
GUI_DRAWMODE DrawMode = GUI_pContext->TextMode;
const GUI_FONT_PROP GUI_UNI_PTR *pProp = GUI_pContext->pAFont->p.pProp;
//ËÑË÷¶¨Î»×Ö¿âÊý¾ÝÐÅÏ¢
for (; pProp; pProp = pProp->pNext)
{
if ((c >= pProp->First) && (c <= pProp->Last))
{
break;
}
}
if (pProp)
{
GUI_DRAWMODE OldDrawMode;
const GUI_CHARINFO GUI_UNI_PTR * pCharInfo = pProp->paCharInfo;
GUI_GetDataFromMemory(pProp, c);//È¡³ö×ÖÄ£Êý¾Ý
BytesPerLine = pCharInfo->BytesPerLine;
OldDrawMode= LCD_SetDrawMode(DrawMode);
LCD_DrawBitmap(GUI_pContext->DispPosX, GUI_pContext->DispPosY,
pCharInfo->XSize, GUI_pContext->pAFont->YSize,
GUI_pContext->pAFont->XMag, GUI_pContext->pAFont->YMag,
1, /* Bits per Pixel */
BytesPerLine,
&GUI_FontDataBuf,
&LCD_BKCOLORINDEX
);
/* Fill empty pixel lines */
if (GUI_pContext->pAFont->YDist > GUI_pContext->pAFont->YSize)
{
int YMag = GUI_pContext->pAFont->YMag;
int YDist = GUI_pContext->pAFont->YDist * YMag;
int YSize = GUI_pContext->pAFont->YSize * YMag;
if (DrawMode != LCD_DRAWMODE_TRANS)
{
LCD_COLOR OldColor = GUI_GetColor();
GUI_SetColor(GUI_GetBkColor());
LCD_FillRect(GUI_pContext->DispPosX, GUI_pContext->DispPosY + YSize,
GUI_pContext->DispPosX + pCharInfo->XSize,
GUI_pContext->DispPosY + YDist);
GUI_SetColor(OldColor);
}
}
LCD_SetDrawMode(OldDrawMode); /* Restore draw mode */
// if (!GUI_MoveRTL)
GUI_pContext->DispPosX += pCharInfo->XDist * GUI_pContext->pAFont->XMag;
}
}
/*********************************************************************
*
* GUIPROP_GetCharDistX
*/
int GUIPROP_X_GetCharDistX(U16P c)
{
const GUI_FONT_PROP GUI_UNI_PTR * pProp = GUI_pContext->pAFont->p.pProp;
for (; pProp; pProp = pProp->pNext)
{
if ((c >= pProp->First) && (c <= pProp->Last))break;
}
return (pProp) ? (pProp->paCharInfo)->XSize * GUI_pContext->pAFont->XMag : 0;
}
GUI_CONST_STORAGE GUI_CHARINFO GUI_FontHZ16_CharInfo =
{
{8, 8,1, (void *)"a"},
{16,16,2, (void *)"b"},
};
GUI_CONST_STORAGE GUI_FONT_PROP GUI_FontHZ16_PropHZ = {
0xA1A1,
0xFFFF,
&GUI_FontHZ16_CharInfo,
(void *)0,
};
GUI_CONST_STORAGEGUI_FONT_PROP GUI_FontHZ16_PropASC = {
0x0000,
0x007F,
&GUI_FontHZ16_CharInfo,
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropHZ,
};
GUI_CONST_STORAGEGUI_FONT GUI_FontHZ16 =
{
GUI_FONTTYPE_PROP_USER,
16,
16,
1,
1,
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropASC
};
GUI_CONST_STORAGEGUI_FONT GUI_FontHZ16x2 =
{
GUI_FONTTYPE_PROP_USER,
16,
16,
2,
2,
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropASC
};
在 gui_type.h 加
/*PROP_USER: chian */
#define GUI_FONTTYPE_PROP_USER \
GUIPROP_X_DispChar, \
GUIPROP_X_GetCharDistX, \
GUIMONO_GetFontInfo, \
GUIMONO_IsInFont, \
(GUI_GETCHARINFO *)0, \
(tGUI_ENC_APIList*)0
在 gui.h 加
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ12;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16x2; 楼主开源{:lol:} 不知道这种方法能否用在 EMWIN 5.20上,能否详细点 我就是在emwin5.20上用的 mark……
顶一个… 楼主无私奉献,{:lol:},学习了!顶! 请问楼主,你这个是emWin,还是uCGUI3.98的版本?或者说你这种方法也能够在emWin下面实现吗? 先mark,回去试试 收藏了,以后研究下,想弄这个很久了. mark一下1准备用 看了一下,这个不是在UCGUI3.xx时候的移植办法么,都说emWin只有库,没有源码,要修改源码,谁知试了试真的能用。。。
今天尝试了一下,真的可以用,哎,只怪自己以前没有去尝试,感谢楼主让我勇敢的去尝试
测试STemWin5.20,字库放到SD卡里面,显示效果如下:
lz的播放器效果真赞 伤心病狂的MARK. 今天没白包宿,终于找到一个能使得例子了,万分感谢楼主的奉献 强烈的MARK一下 强烈的的感谢楼主啊 字库会不会太占FLASH? 很好 大部分系统都会在界面上用到中文 谢谢楼主分享 恩,现在显示汉字大体方法。这2天看了看。
1、外置字库,然后GBK 或者GB2312 之类的 解码 如楼主所说
2、分散加载内部flash
3、自制字库,utf8 转码之类的
由于自己半路出家。像楼主所用的那几个 文件,能否简单的解释下,说说下出处。现在是能用。但是不知道具体实现。很头疼··· 感谢楼主的分享。 记号,多谢楼主分享 能上传一个工程文件吗 {:lol:}{:lol:}{:lol:}{:lol:}{:lol:}{:lol:} 不错 点个赞 LZ,你说的“放在库文件目录下”,是指的字库文件么?字库文件如何生成? 先学习下 ok,可用 兄弟,今天弄外部汉字显示弄了好几个小时!还是没搞出来!查了几个小时的原因,最终定位到这个地方
int GUIPROP_X_GetCharDistX(U16P c)
void GUIPROP_X_DispChar(U16P c)
这两个函数,按照代码里面,应该是读取一个汉字对应的内码。c就是这个汉字对应的内码。但是,我的程序里面每次读到的都是汉字的双字节内码的单独的一个字节。
第一次读第一字节,第二次读第二字节。GUI_UC_ENCODENONE.c这个文件里面,最后的那个函数又无法实现。不能实现这个函数,就没办法一次使用这个文件里面的读2汉字的方法。
我看你的代码里面直接把他注释掉了。那你是怎么样做到可以正确识别汉字的内码的呢?
请问如果用stm32f10x的资源,能使用emwin吗?
谢谢! 准备什么时候玩下emwin,看似很炫的样子。 收藏 emWin可以用官方配的软件把电脑系统的字库生成专用的XBF字库的,可以存在TF卡中,也可以存在SPI FLASH中,那个的显示效果灰常好,硬件资源足可以圆滑字体,但是圆滑字体我没试过。 谢谢楼主分享 好东西收藏先!! 用得到.感谢楼主. 参考下楼主的方法, 回去也试下. 用得到.感谢楼主. 楼主可以分享一下gbk的字符集么
页:
[1]