⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sysfont16.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 2 页
字号:
      0x82,
      0x82,
      0x82,
      0x82,
      0x82,
      0x82,
      0xfe,
      0x00 };

   if( IS_CHINESE( lpText ) )
   {
       lpMask->bmWidth = CHINESE_WIDTH;
       lpMask->bmHeight = FONT_HEIGHT;
       lpMask->bmWidthBytes = 2;
       lpMask->bmBits = (BYTE FAR*)chineseMask;
       return 2;
   }
   else
   {
       lpMask->bmWidth = ENGLISH_WIDTH;
       lpMask->bmHeight = FONT_HEIGHT;
       lpMask->bmWidthBytes = 1;
       lpMask->bmBits = englishMask;
       return 1;
   }
#else
   //字模
   extern const unsigned char eng16Mask[];
   if( IS_CHINESE( lpText ) )
   {	//汉字
       lpMask->bmWidth = 16;
       lpMask->bmHeight = 16;
       lpMask->bmWidthBytes = 2;
       lpMask->bmBits = (LPBYTE)_GetChineseMask( _GET_CHINESE( lpText ) );
       return 2;
   }
   else
   {	//ascii
       lpMask->bmWidth = 8;
       lpMask->bmHeight = 16;
       lpMask->bmWidthBytes = 1;
       lpMask->bmBits = (LPBYTE)(eng16Mask+_GET_ENGLISH( lpText )*16);//_ptrInRomEFont+ _GET_ENGLISH( lpText )*16;
       return 1;
   }
#endif
}

// *****************************************************************
// 声明:static int SYSFont16_TextWidth( HANDLE handle, const BYTE FAR* lpText, int len )
// 参数:
//	IN handle - 由 SYSFont16_CreateFont 返回的逻辑字体对象句柄
//	IN lpText - 文本指针
//	IN len - 需要统计的文本长度
// 返回值:
//	文本的象素长度
// 功能描述:
//	得到文本的象素长度,如果文本长度(len)中间包含换行字符,则统计到换行字符位置为止。
// 引用: 
//	驱动程序接口函数
// *****************************************************************

static int SYSFont16_TextWidth( HANDLE handle, LPCBYTE lpText, int len )
{
   int  w = 0;

   if( lpText )
   {
       while( !IS_TEXT_MARK( *lpText ) && *lpText && len )
       {	//换行 或 已到限制宽度
           if( IS_CHINESE( lpText ) )
           {	//汉字
               w += SYSFont16_WordWidth( handle, _GET_CHINESE( lpText ) );
               lpText += 2;
               if( len > 0 )
                   len -= 2;
           }
           else
           {	//ascii 
               w += SYSFont16_WordWidth( handle, _GET_ENGLISH( lpText ) );
               lpText += 1;
               if( len > 0 )
                   len--;
           }
       }
   }
   return w;

}

// *****************************************************************
// 声明:static int SYSFont16_TextHeight( HANDLE handle, const BYTE FAR* lpText, int aLineWidth )
// 参数:
//	IN handle - 由 SYSFont16_CreateFont 返回的逻辑字体对象句柄
//	IN lpText - 文本指针
//	IN aLineWidth - 需要统计的象素最大宽度,如果为0,则没有宽度限制
// 返回值:
//	文本的象素高度
// 功能描述:
//	得到文本的象素高度,如果文本象素长度 大于等于aLineWidth则增加字体高度;
//	如果文本中间包含换行字符,则增加字体高度。
//	如果aLineWidth为0,则没有宽度限制,以换行字符确定下一行
// 引用: 
//	驱动程序接口函数
// *****************************************************************
static int SYSFont16_TextHeight( HANDLE handle, LPCBYTE lpText, int aLineWidth )
{
    int h = 0, w = 0;

    if( lpText )
    {
        h = FONT_HEIGHT;	//默认高度
        do  {
            if( IS_CHINESE( lpText ) )
            {	//汉字
                if( aLineWidth > 0 && w + CHINESE_WIDTH >= aLineWidth )
                {	//超过宽度
                    h += FONT_HEIGHT;
                    w = 0;
                }
                else
                    w += CHINESE_WIDTH;
				//汉字字符字节数为2 ,下一个字符
                lpText += 2;	
            }
            else
            {  //ascii字符 english font
                if( (aLineWidth > 0 && w + ENGLISH_WIDTH >= aLineWidth) ||
                    IS_TEXT_MARK( *lpText ) )
                {	//超过宽度 或 有换行字符
                    h += FONT_HEIGHT;
                    w = 0;
                }
                else
                    w += ENGLISH_WIDTH;
                lpText++;
            }
        }while( *lpText );
    }
    return h;
}

// *****************************************************************
// 声明:const BYTE FAR* SYSFont16_NextWord( HANDLE handle, const BYTE FAR* lpText )
// 参数:
//	IN handle - 由 SYSFont16_CreateFont 返回的逻辑字体对象句柄
//	IN lpText - 文本指针
// 返回值:
//	文本的下一个字符地址指针
// 功能描述:
//	得到文本的下一个字符地址指针
// 引用: 
//	驱动程序接口函数
// *****************************************************************
static LPCBYTE SYSFont16_NextWord( HANDLE handle, LPCBYTE lpText )
{
    return IS_CHINESE( lpText ) ? (lpText + 2) : (lpText + 1);
}

// *****************************************************************
// 声明:int SYSFont16_WordLength( HANDLE handle, const BYTE FAR* lpText )
// 参数:
//	IN handle - 由 SYSFont16_CreateFont 返回的逻辑字体对象句柄
//	IN lpText - 文本指针
// 返回值:
//	文本中以字符为单位的数量
// 功能描述:
//	得到文本中以字符为单位的数量
// 引用: 
//	驱动程序接口函数
// *****************************************************************
int SYSFont16_WordLength( HANDLE handle, LPCBYTE lpText )
{
     int l = 0;
     if( lpText )
     {
         while( *lpText )
         {
             if( IS_CHINESE( lpText ) )
			 {
                 lpText += 2;
				 //l+= 2;
			 }
             else
                 lpText++;//l++;
             //lpText++;
			 l++;
         }
     }
     return l;
}

// *****************************************************************
// 声明:static LPCBYTE _GetChineseMask( WORD aWord )
// 参数:
//	IN aWord - 汉字代码
// 返回值:
//	该字符的字模
// 功能描述:
//	得到汉字字模
// 引用: 
//	驱动程序接口函数
// *****************************************************************

static LPCBYTE _GetChineseMask( WORD aWord )
{
    const static BYTE undefMask[32] = {
        0x00,0x00,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x40,0x02,
        0x00,0x00
    };

#ifdef EML_DOS
    long offset;
    BYTE hi = (BYTE)(aWord >> 8);
    BYTE lo = (BYTE)aWord;

    offset = ( ( (long)hi - 0xa1L )*94L + (long)lo - 0xa1L ) << 5;  // * 32
/*
    if( _ptrInXMSFont )
    {
        XMSSeek( _ptrInXMSFont, Offset, XMS_BEG );
        XMSRead( _ptrInXMSFont, Mask, 16, 1 );
    }
    else if( _ptrInFileFont )
    {
        fseek( _ptrInFileFont, Offset, SEEK_SET );
        fread( Mask, 32, 1, _ptrInFileFont );
    }
*/
    return (BYTE FAR*)undefMask;

#else
	//包含汉字字模的数组
    extern const unsigned char hzk16Mask[];

    long offset;
    BYTE hi = (BYTE)(aWord >> 8);
    BYTE lo = (BYTE)aWord;
	//得到相对偏移
    offset = ( ( (long)hi - 0xa1L )*94L + (long)lo - 0xa1L ) << 5;  // * 32
	if( offset <= 267616 - 32 )
		return (LPCBYTE)(hzk16Mask+offset);	
	else
		return undefMask;	//未定义
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -