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

📄 fontmng.c.bak

📁 好记星的控件,包括button,list,对文件操作
💻 BAK
📖 第 1 页 / 共 4 页
字号:
			INT i;
			for(i = 0;i < (INT)uBytes;i++)
			{
				*lpDotArray++ = ~*lpDotArray;
			}
		}
	}
	
    return TRUE;
}

/********************************************************************
 Function:  to judge if the code is composed char
 Input:     wCode: char code
 Output:    TRUE: yes
            FALSE: no
 Notes:
 Update:
          Date         Name         Description
      ============ ============ ===================================
	  2007-04-09   Liang Ruhui  modify
********************************************************************/
BOOL FontIsComposeFont(UINT32 wCode)
{
	UINT8 byCodeL 	= (UINT8)(wCode&0xff);  
	UINT8 byCodeH 	= (UINT8)(wCode>>8);
	
	if(byCodeH >= (COMPOSE_FONT_START_CODE>>8)   && byCodeH <= (COMPOSE_FONT_END_CODE>>8)	&&
	   byCodeL >= (COMPOSE_FONT_START_CODE&0xff) && byCodeL <= (COMPOSE_FONT_END_CODE&0xff))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

/********************************************************************\
 Function:  get char width
 Input:     wFontLibID: fontlib id
            char - the character 
 Output:    the character width
 Notes:     output is FALSE shows fontlib id not exist or not a character
	 Date         Name         Description
	============ ============ ===================================
	2007-04-09   Liang Ruhui  Modified
\********************************************************************/
UINT16 FontGetAsciiWidth(UINT16 wFontLibID, UINT8 ch)
{
	UINT16  wRet = 0;
    
    if((ch <= 0x7F) && (ch >= 0x20) && (wFontLibID < FONT_TOTAL))       //ch不是ASCii码
	{	
		INT index = wFontLibID*FONTLIBNUM;
		wRet = aPrjFontLib[index].uFontWidth;
	}
	return wRet;
}

/********************************************************************\
Function:  	get string size
Input:     	fontlibID:      font id
			width/height:	return string size
			lpString:		long pointer to the string
Output:    	TRUE:  success
			FALSE: some fonts not exist
Notes:		//正常情况:返回的宽是所有字符宽之和 高等于行高
Update:
Date         Name       VERSION Description
============ ==========  ======= ===========================
2007-4-09    Liang Ruhui v1.1    create
\********************************************************************/
BOOL _FontGetStringRect(UINT16 wFontLibID,UINT16 *width, UINT16 *height, UINT8 *lpString)
{
//	UINT16  wFontWidth;
    UINT16 	wCode;
    UINT8	*pStr;
	INT     index;
    
    if(width == NULL || height == NULL) 
    	return FALSE;
    	
	*width = 0;
	*height = 0;

    if(IS_ID(lpString))
        ResGetString(GET_ID(lpString), &pStr); // get string address
    else
        pStr = lpString;
	
	if(pStr == NULL || pStr[0] == 0)
		return FALSE;
		
//	wFontWidth  = aPrjFontLib[wFontLibID*FONTLIBNUM+1].uFontWidth;
	*width		= 0;
	*height  	= aPrjFontLib[wFontLibID*FONTLIBNUM].uFontHeight;
	
    while( *pStr != 0)
    {
		index = FontGetCharCodeWidth(pStr);

        if(index == 1)   //ASCii
        {
            (*width) += aPrjFontLib[wFontLibID*FONTLIBNUM+ASCII].uFontWidth/*(wFontWidth>>1)*/;
			pStr++;
        }
        else if(index == 2)                      //双字节字符
        {
            wCode = (pStr[0]<<8)+pStr[1];
			
			if(FontIsComposeFont(wCode))    //组合字
			{
				(*width) += 0;
			}
            else if(IsSmallFont(wCode) == TRUE)       //半角自造字
			{
            	(*width) += aPrjFontLib[wFontLibID*FONTLIBNUM+LARDIN].uFontWidth/*(wFontWidth>>1)*/;
			}
            else
            {
            	(*width) += aPrjFontLib[wFontLibID*FONTLIBNUM+GBK1].uFontWidth/*wFontWidth*/;
            }

            pStr += 2;
        }
		else
		{
			(*width) += aPrjFontLib[wFontLibID*FONTLIBNUM+FOURFONT].uFontWidth;
			pStr += 4;
		}
/*
		else if()                                 //四字节字
		{
		}
*/
    }
    return TRUE;
}

/********************************************************************\
 Function:  get string width
 Input:     wFontLibID: fontlib id
            lpString - long pointer to the string
 Output:    the string width
 Notes:     output is FALSE shows fontlib id not exist
 Update:
          Date         Name         Description
      ============ ============ ===================================
	  2007-04-09   Liang Ruhui  Modified
\********************************************************************/
UINT16 FontGetStringWidth(UINT16 wFontLibID, UINT8 *lpString)
{
    UINT16 	wWidth, wHeight;
	BOOL    bRet;

	bRet = _FontGetStringRect(wFontLibID,&wWidth,&wHeight,lpString);
    if(bRet)
	{
		return wWidth;
	}
	else
	{
		return 0;
	}
}

/********************************************************************\
 Function:  get char number which can be set in the area
 Input:     wFontLibID: fontlib id
            width/height: 
            in: the area; out: the fact area
            lpString: long pointer to the string
 Output:    number of the char
 Notes:		//函数会对用户输入的宽和高进行修正
			//修正结果是宽是所有字符宽之和 高等于行高
 Update:
          Date         Name         Description
      ============ ============ ===================================
	  2007-04-09   Liang Ruhui  Modify
\********************************************************************/
UINT16 FontGetRectCharNum(UINT16 wFontLibID, UINT16 *wWidth, UINT16 *wHeight, UINT8 *lpString)
{
    UINT8  *p1, *p2;
    UINT16 wFontHeight,wTempWidth1,wTempWidth2;
    FontLibInfo *pTemp;
	INT    index;
    
    if(wFontLibID >= FONT_TOTAL || !wWidth || !wHeight)
    	return 0;	//参数检查

	pTemp 		= (FontLibInfo*)&aPrjFontLib[wFontLibID*FONTLIBNUM];
	wFontHeight = pTemp[0].uFontHeight; 
	
	if(((*wWidth) < (wFontHeight>>1)) || ((*wHeight) < wFontHeight))
		return 0;

    if (IS_ID(lpString) == TRUE)
        ResGetString(GET_ID(lpString), &p1); // get string address
    else
        p1 = lpString;

    if(p1 == NULL || p1[0] == 0)
        return 0;

    wTempWidth1 = *wWidth;
    
    p2 = p1;
    do
    {
		index = FontGetCharCodeWidth(p1);
        //calculate the width of code
        if (index == 1)                                  //单字节字符
        {
            wTempWidth2 = pTemp[ASCII].uFontWidth/*wFontHeight>>1*/;
        }
        else if(index == 2)                             //双字节字符
        {
			UINT16 wTempNum = ((*p1)<<8) + *(p1+1);

			if(!IsSmallFont(wTempNum))                   //全角
			{
				wTempWidth2 = pTemp[GBK1].uFontWidth/*wFontHeight*/;
			}
			else                                         //半角自造字
			{
				if(FontIsComposeFont(wTempNum) == TRUE)  //组合字不占宽度
					wTempWidth2 = 0;	
				else
					wTempWidth2 = pTemp[LARDIN].uFontWidth/*wFontHeight>>1*/;
			}
        }
        else                                             //四字节字符
		{
            wTempWidth2 = pTemp[FOURFONT].uFontWidth;
		}
        
        if( wTempWidth1 >= wTempWidth2)
		{
            wTempWidth1 -= wTempWidth2;
		}
		else
		{
			break;
		}

		p1 += index;
//		if(*p1 >= 0x80)p1 += 2;
//		else p1++;
    }while(*p1 != 0);

	*wWidth  -= wTempWidth1;	//减掉多余的不足一字符的宽度
	*wHeight = wFontHeight;
	
    return (UINT16)((UINT32)p1 - (UINT32)p2);
}

/********************************************************************\
Function:  	get string size
Input:     	fontlibID:      font id
			width/height:	return string size

⌨️ 快捷键说明

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