📄 guisysfont.c
字号:
/* $id: guiSysfont.c V1.0 2001/11/1 */
/***************************************************************************
* This source code has been made available to you by EPSON on an AS-IS
* basis. Anyone receiving this source is licensed under EPSON
* copyrights to use it in any way he or she deems fit, including
* copying it, modifying it, compiling it, and redistributing it either
* with or without modifications.
*
* Any person who transfers this source code or any derivative work
* must include the EPSON copyright notice, this paragraph, and the
* preceding two paragraphs in the transferred software.
*
* COPYRIGHT EPSON CORPORATION 2001
* LICENSED MATERIAL - PROGRAM PROPERTY OF EPSON
**************************************************************************/
/***************************************************************************
* FILE: guiSysfont.c
* MODULE: FONT
*
* PURPOSE: Load, create and handle system font and system charset.
*
*
* AUTHOR(S): ZhaoJZ
* GROUP: GUI Group
* DATE CREATED: 2001/11/1
* REFERENCE DOCUMENT ID:
* MODIFICATIONS:
* Date userName Description
* 2001/11/1 ZhaoJZ Create this file
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "sysGUI.h"
//#include "guiTotal.h"
#include "guiFont.h"
#include "guiSysfont.h"
#include "guiCharset.h"
#include "guiDevfont.h"
#include "guiFontname.h"
#include "guiRawbitmap.h"
T_GUI_LogFont tFNT_SysLogFont;
T_MODULE T_WORD nr_fonts;
T_MODULE T_FNT_RBFInfo *SysRBFInfos = NULL; /*Init for E0C33 */
T_MODULE T_GUI_DevFont *SysDevFonts = NULL; /*Init for E0C33 */
T_EXTERN T_BYTE font_12[];
T_EXTERN T_BYTE font_16[];
#ifdef _GB_SUPPORT
#ifdef _gb12x12
T_EXTERN T_BYTE gb[];
#endif
#ifdef _gb16x16
T_EXTERN T_BYTE gb16[];
#endif
#endif
#ifdef _BIG5_SUPPORT
#ifdef _big12x12
T_EXTERN T_BYTE big5[];
#endif
#ifdef _big16x16
T_EXTERN T_BYTE big16[];
#endif
#endif
#ifdef _SJIS_SUPPORT
#ifdef _SJIS12x12
T_EXTERN const unsigned char sjis[6879][24];
#endif
// #ifdef _SJIS16x16
// big16,
// #endif
#endif
/* the character set table */
T_MODULE T_BYTE *fontlib[] =
{
font_12,
font_16,
#ifdef _GB_SUPPORT
#ifdef _gb12x12
gb,
#endif
#ifdef _gb16x16
gb16,
#endif
#endif
#ifdef _BIG5_SUPPORT
#ifdef _big12x12
big5,
#endif
#ifdef _big16x16
big16,
#endif
#endif
#ifdef _SJIS_SUPPORT
#ifdef _SJIS12x12
(T_UBYTE *)sjis,
#endif
// #ifdef _SJIS16x16
// big16,
// #endif
#endif
};
/* supported fonts by GUI */
T_MODULE T_BYTE *systemfont[] =
{
"rbf-song-rrncnn-6-12-ISO8859-1",
"rbf-song-rrncnn-8-16-ISO8859-1",
#ifdef _GB_SUPPORT
#ifdef _gb12x12
"rbf-song-rrncnn-12-12-GB2312.1980-0",
#endif
#ifdef _gb16x16
"rbf-song-rrncnn-16-16-GB2312.1980-0",
#endif
#endif
#ifdef _BIG5_SUPPORT
#ifdef _big12x12
"rbf-ming-rrncnn-12-12-BIG5",
#endif
#ifdef _big16x16
"rbf-ming-rrncnn-16-16-BIG5",
#endif
#endif
#ifdef _SJIS_SUPPORT
#ifdef _SJIS12x12
"rbf-japan-rrncnn-12-12-sjis",
#endif
// #ifdef _SJIS16x16
// "rbf-ming-rrncnn-16-16-BIG5",
// #endif
#endif
};
/******************************************************************
* FUNCTION: fnFNT_InitSysFont
*
* PURPOSE:
* Initialize syslogfont
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value: T_BOOL -----if Initialization is TRUE, else FALSE.
* Reentrant : No
*****************************************************************/
T_BOOL fnFNT_InitSysFont(T_VOID)
{
T_WORD i;
//LEN_DEVFONT_NAME is defined as 79
T_BYTE font_name[LEN_DEVFONT_NAME + 1];
T_WORD size;
//The types of fonts
nr_fonts = sizeof(fontlib)/sizeof(T_UBYTE *);
//Structure fontlib is defined in guiSysfont.c
//SysRBFInfos is point of T_FNT_RBFInfo
SysRBFInfos = malloc (sizeof(T_FNT_RBFInfo) * nr_fonts);
SysDevFonts = malloc (sizeof(T_GUI_DevFont) * nr_fonts);
if(SysRBFInfos == NULL || SysDevFonts == NULL)
{
return FALSE;
}
for(i = 0; i < nr_fonts; i++)
{
memset(SysRBFInfos+i,0,sizeof(T_FNT_RBFInfo));
memset(SysDevFonts+i,0,sizeof(T_GUI_DevFont));
}
// init SysRBFInfos and SysDevFonts
for(i = 0; i < nr_fonts; i++)
{
//LEN_FONT_NAME is defined as 15
T_BYTE charset[LEN_FONT_NAME + 1];
strcpy(font_name, systemfont[i]);
if(!fontGetCharsetFromName(font_name, charset))
goto error_load;
if((SysRBFInfos[i].charset_ops=fnFNT_GetCharsetOps (charset))==NULL)
goto error_load;
if((SysRBFInfos[i].width = fontGetWidthFromName (font_name)) == -1)
goto error_load;
if((SysRBFInfos[i].height = fontGetHeightFromName (font_name)) == -1)
goto error_load;
SysRBFInfos[i].nr_chars = SysRBFInfos[i].charset_ops->nr_chars;
//The pointer of font lib
SysRBFInfos[i].font = fontlib[i];
//The number of bytes in fontlib
size = ((SysRBFInfos[i].width + 7) >> 3) * SysRBFInfos[i].height * SysRBFInfos[i].nr_chars;
SysRBFInfos[i].font_size = size;
strncpy(SysDevFonts[i].name, font_name, LEN_DEVFONT_NAME);
SysDevFonts[i].name[LEN_DEVFONT_NAME] = '\0';
SysDevFonts[i].font_ops = &raw_bitmap_font_ops;
SysDevFonts[i].charset_ops = SysRBFInfos[i].charset_ops;
//Member data points to SysRBFInfos[i].
SysDevFonts[i].data = SysRBFInfos + i;
}
/* add the single byte device fonts */
for (i = 0; i < 2; i++)
{
AddSBDevFont(&SysDevFonts[i]);
}
/* add the double bytes device fonts */
for (i = 2; i < nr_fonts; i++)
{
AddMBDevFont(&SysDevFonts[i]);
}
/* Initilize tFNT_SysLogFont */
strcpy(tFNT_SysLogFont.type, "rbf");
strcpy(tFNT_SysLogFont.family, "system");
strcpy(tFNT_SysLogFont.charset, "system"); /*2.22 modified */
tFNT_SysLogFont.style = 0;
tFNT_SysLogFont.size = SysRBFInfos[0].height;
tFNT_SysLogFont.sbc_devfont = SysDevFonts;
if(nr_fonts > 2)
tFNT_SysLogFont.mbc_devfont = &SysDevFonts[2];
else
tFNT_SysLogFont.mbc_devfont = NULL;
return TRUE;
/********************* error *******************/
error_load:
free (SysRBFInfos);
free (SysDevFonts);
SysRBFInfos = NULL;
SysDevFonts = NULL;
return FALSE;
}
/******************************************************************
* FUNCTION: fnFNT_TermSysFont
*
* PURPOSE:
* Terminate syslogfont
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value:
* Reentrant : No
*****************************************************************/
T_VOID fnFNT_TermSysFont(T_VOID)
{
free (SysRBFInfos);
free (SysDevFonts);
SysRBFInfos = NULL;
SysDevFonts = NULL;
}
/**************************** API: System Font Info *************************/
/* added by zjz 2001.12.11 */
/******************************************************************
* FUNCTION: fnGUI_SetSysType
*
* PURPOSE:
* set the Syslogfont's type
*
* PARAMETERS
* Input: T_BYTE --- font's type(such as rbf,or vbf)
* Output:
* InOut:
* Return value: T_BOOL---if success then TRUE,or else FALSE
* Reentrant : No
*****************************************************************/
T_BOOL fnGUI_SetSysType(T_CONST T_UBYTE* type)
{
T_WORD i;
T_UBYTE name[LEN_FONT_NAME + 1];
for(i = 0; i < LEN_FONT_NAME + 1; i++)
{
if(type[i] == '\0')
break;
name[i] = toupper(type[i]);
}
name[i] = '\0';
/* set the various bitmap font */
if(strstr(name, "VBF") )
{
tFNT_SysLogFont.sbc_devfont = tFNT_SysLogFont.sbc_devfont->sbc_next->sbc_next;
return TRUE;
}
/* set the raw bitmap font */
else if(strstr(name, "RBF") )
{
tFNT_SysLogFont.sbc_devfont = SysDevFonts;
return TRUE;
}
else
return FALSE;
}
/******************************************************************
* FUNCTION: fnGUI_GetSysCharset
*
* PURPOSE:
* get the name of system's charset
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value: T_BYTE* --- the name of charset
* Reentrant : No
*****************************************************************/
T_CONST T_BYTE *fnGUI_GetSysCharset(T_VOID)
{
if(tFNT_SysLogFont.mbc_devfont == NULL)
return fnGUI_SBC_DEVFONT_INFO(tFNT_SysLogFont)->charset_ops->name;
else
return fnGUI_MBC_DEVFONT_INFO(tFNT_SysLogFont)->charset_ops->name;
}
/******************************************************************
* FUNCTION: fnGUI_DoesSupportCharset
*
* PURPOSE:
* Judge that syslogfont support the charset
*
* PARAMETERS
* Input: T_BYTE --- the charset's name
* Output:
* InOut:
* Return value: T_BOOL --- if support is TRUE, or FALSE.
* Reentrant : No
*****************************************************************/
T_BOOL fnGUI_DoesSupportCharset(T_CONST T_BYTE * charset)
{
T_WORD i;
for(i = 0; i < nr_fonts; i++)
{
if((SysRBFInfos[i].charset_ops->is_this_charset)(charset) == 0)
return TRUE;
}
return FALSE;
}
/******************************************************************
* FUNCTION: fnGUI_SetSysCharset
*
* PURPOSE:
* Set the syslogfont's charset
*
* PARAMETERS
* Input: T_BYTE --- the charset's name
* Output:
* InOut:
* Return value: T_BOOL --- if setup is TRUE, or FALSE.
* Reentrant : No
*****************************************************************/T_BOOL fnGUI_SetSysCharset(T_CONST T_BYTE* charset)
{
T_WORD n;
for(n = 0; n < nr_fonts; n++)
{
if((SysRBFInfos[n].charset_ops->is_this_charset)(charset) == TRUE)
break;
}
if(n == nr_fonts)
return FALSE;
tFNT_SysLogFont.sbc_devfont = &SysDevFonts[0];
/* change the double bytes device font of the tFNT_SysLogFont */
if(n == 0)
tFNT_SysLogFont.mbc_devfont = NULL;
else
tFNT_SysLogFont.mbc_devfont = &SysDevFonts[n];
return TRUE;
}
/******************************************************************
* FUNCTION: fnGUI_GetSysCharWidth
*
* PURPOSE:
* get the width of English character
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value: T_WORD --- the char's width.
* Reentrant : No
*****************************************************************/
T_WORD fnGUI_GetSysCharWidth(T_VOID)
{
return SysRBFInfos[0].width;
}
/******************************************************************
* FUNCTION: fnGUI_GetSysCCharWidth
*
* PURPOSE:
* get the width of Chinese character
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value: T_WORD --- the char's width.
* Reentrant : No
*****************************************************************/
T_WORD fnGUI_GetSysCCharWidth(T_VOID)
{
#if defined(_GB_SUPPORT) | defined(_BIG5_SUPPORT)
return SysRBFInfos[2].width;
#endif
return SysRBFInfos[0].width;
}
/******************************************************************
* FUNCTION: fnGUI_GetSysCharHeight
*
* PURPOSE:
* get the height of character
*
* PARAMETERS
* Input:
* Output:
* InOut:
* Return value: T_WORD --- the char's height.
* Reentrant : No
*****************************************************************/
T_WORD fnGUI_GetSysCharHeight(T_VOID)
{
return SysRBFInfos[0].height;
}
#define TEXT_TABSIZE 8
#define DEF_TABSTOPS GUI_TEXT_TABSIZE
/******************************************************************
* FUNCTION: fnGUI_GetSysTabbedTextExtent
*
* PURPOSE:
* get the size of the string with controlling characters
*
* PARAMETERS
* Input: T_BYTE --- the string
* Output: T_GUI_EXTENT --- the space occupied by the control characters
* InOut:
* Return value:
* Reentrant : No
*****************************************************************/
T_VOID fnGUI_GetSysTabbedTextExtent(T_CONST T_BYTE *spText, T_GUI_Extent* pSize)
{
T_WORD x = 0;
T_WORD y = 0;
pSize->cx = 0;
pSize->cy = 0;
for(; *spText; spText++)
{
switch(*spText)
{
case '\a': /* badly implemented */
break;
case '\b':
x -= fnGUI_GetSysCharWidth();
if(x < 0)
x = 0;
break;
case '\n':
y += fnGUI_GetSysCharHeight();
if(y > pSize->cy)
pSize->cy = y;
break;
case '\r':
x = 0;
break;
case '\t':
x += (TEXT_TABSIZE - (x / fnGUI_GetSysCharWidth()) % TEXT_TABSIZE)
*fnGUI_GetSysCharWidth();
if(x > pSize->cx)
pSize->cx = x;
break;
case '\v':
y += fnGUI_GetSysCharHeight();
if(y > pSize->cy)
pSize->cy = y;
break;
default:
if( ((T_UBYTE)(*spText) & 0x80)
&& ((T_UBYTE)(*(spText + 1)) & 0x80))
{
spText++;
x += fnGUI_GetSysCCharWidth();
if(x > pSize->cx)
pSize->cx = x;
}
else
{
x += fnGUI_GetSysCharWidth();
if(x > pSize->cx)
pSize->cx = x;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -