📄 binfilefactory_font.cpp
字号:
}
}
return TRUE;
}
//xe
BOOL CBinFileFactory::ReadFontInfo( FILE * pFile, BOOL bBuildInfo /* = FALSE */ )
{
_ASSERTE( pFile != NULL );
CMMIRes &mmires = g_theApp.m_MMIRes;
MMI_RESOURCE_T &res = mmires.m_Resource;
MMI_RES_DATA_T &FontData = res.mmi_data_table[MMI_RT_FONT];
FONT_MAP &fontMap = mmires.m_mapFont;
CDirFileInfo * pInfo = g_theApp.m_pFontInfo;
FONTEX_MAP &fontExMap= mmires.m_mapFontEx;
int nOldLangNum = g_theApp.m_nOldUsedLangNum;
int nLangNum = g_theApp.m_nUsedLangNum;
const BOOL bBigEdn = res.ToolUsedInfo.bBigEndian;
CConverter conv;
if( bBigEdn )
{
FontData.uCount = conv.ConvEdn_INT(FontData.uCount);
FontData.uSize = conv.ConvEdn_INT(FontData.uSize);
}
int nCount = FontData.uCount;
if( nCount == 0 )
return TRUE;
///////////////////////////////////////////////////////////////////////////////
#define READ_FILE(des, st, num, file) \
if( fread(des, st, num, file) != num ) \
{ \
_ASSERTE(0); \
_tcscpy(m_szErrMsg, _T("Read file(Font Info) error!")); \
return FALSE; \
}
#define SEEK_FILE(pfile, st) \
if( fseek(pfile,st, SEEK_CUR) != 0 ) \
{ _ASSERTE(0); return FALSE; }
///////////////////////////////////////////////////////////////////////////////
CStringArray arrID;
pInfo->CalcAllLeafID( arrID );
int i = 0;
_ASSERTE( 0 == fontMap.GetCount() );
CUIntArray arrFlag;
arrFlag.SetSize(nCount);
PGUI_FONT_INFO_T pFontInfo = NULL;
LPBYTE pData = NULL;
int nSize = 0;
for( i = 0; i < nCount; ++i )
{
pFontInfo = new GUI_FONT_INFO_T;
if( NULL == pFontInfo )
return FALSE;
arrFlag[i] = FALSE;
READ_FILE( pFontInfo, sizeof(GUI_FONT_INFO_T), 1, pFile );
if( bBigEdn )
{
pFontInfo->pascii_ptr = (uint8 *)conv.ConvEdn_INT((DWORD)pFontInfo->pascii_ptr);
pFontInfo->nascii_db_size = conv.ConvEdn_INT(pFontInfo->nascii_db_size);
pFontInfo->gb_database_ptr = (uint8 *)conv.ConvEdn_INT((DWORD)pFontInfo->gb_database_ptr);
pFontInfo->ngb_db_size = conv.ConvEdn_INT(pFontInfo->ngb_db_size);
}
if( pFontInfo->pascii_ptr == pFontInfo->gb_database_ptr )
{
arrFlag[i] = TRUE;
}
//if( bBuildInfo )
//{
//CDirFileNode * pRoot = (CDirFileNode *)pInfo->GetRoot();
//CDirFileNode * pNode = (CDirFileNode *)pInfo->MallocNode();
//if( NULL == pNode )
// return FALSE;
//_tcscpy(pNode->szID, GetFontType(pFontInfo->type));
//_tcscpy(pNode->szName, pNode->szID);
//fontMap.SetAt(arrID[i], pFontInfo );
//arrID.Add(pNode->szID);
//pInfo->AddChild(pRoot, pNode);
//}
//else
//{
fontMap.SetAt( arrID[i], pFontInfo );
//}
}
int nAlign = 0;
for( i = 0; i < nCount; ++i )
{
VERIFY( fontMap.Lookup(arrID[i], pFontInfo) );
pFontInfo->pascii_ptr = new BYTE[pFontInfo->nascii_db_size];
if( pFontInfo->pascii_ptr == NULL )
return FALSE;
READ_FILE( pFontInfo->pascii_ptr, pFontInfo->nascii_db_size, 1, pFile );
nAlign = Addr4ByteAlign(pFontInfo->nascii_db_size);
fseek(pFile, nAlign - pFontInfo->nascii_db_size, SEEK_CUR);
}
for( i = 0; i < nCount; ++i )
{
VERIFY( fontMap.Lookup(arrID[i], pFontInfo) );
if( arrFlag[i] )
{
pFontInfo->gb_database_ptr = pFontInfo->pascii_ptr;
pFontInfo->ngb_db_size = pFontInfo->nascii_db_size;
}
else
{
pFontInfo->gb_database_ptr = new BYTE[pFontInfo->ngb_db_size];
if( pFontInfo->gb_database_ptr == NULL )
return FALSE;
READ_FILE( pFontInfo->gb_database_ptr, pFontInfo->ngb_db_size, 1, pFile );
nAlign = Addr4ByteAlign(pFontInfo->ngb_db_size);
fseek(pFile, nAlign - pFontInfo->ngb_db_size, SEEK_CUR);
}
}
PGUI_FONT_INFO_EX_T pFontInfoEx = NULL;//x
PGUI_FONT_DB_T pDBT=NULL;
for( i = 0; i < nCount; i++)
{
pFontInfoEx = (PGUI_FONT_INFO_EX_T)new GUI_FONT_INFO_EX_T;
if(pFontInfoEx == NULL)
return FALSE;
memset(pFontInfoEx,0,sizeof(GUI_FONT_INFO_EX_T));
VERIFY( fontMap.Lookup(arrID[i], pFontInfo) );
pFontInfoEx->type = pFontInfo->type;
if( bBuildInfo )
{
CDirFileNode * pRoot = (CDirFileNode *)pInfo->GetRoot();
CDirFileNode * pNode = (CDirFileNode *)pInfo->MallocNode();
if( NULL == pNode )
return FALSE;
_tcscpy(pNode->szID, arrID.GetAt(i));
_tcscpy(pNode->szName, pNode->szID);
fontExMap.SetAt(pNode->szID, pFontInfoEx );
//arrID.Add(pNode->szID);
pInfo->AddChild(pRoot, pNode);
}
else
fontExMap.SetAt( arrID[i], pFontInfoEx );
}
for( i = 0; i < nCount; i++)
{
VERIFY( fontMap.Lookup(arrID[i], pFontInfo) );
VERIFY( fontExMap.Lookup(arrID[i], pFontInfoEx) );
pDBT = (PGUI_FONT_DB_T)new GUI_FONT_DB_T[MAX_FONT_NUM];
pDBT[0].db_size = pFontInfo->nascii_db_size;
pDBT[0].pdb = (uint8 *) new uint8[pDBT[0].db_size];
memcpy(pDBT[0].pdb,pFontInfo->pascii_ptr,pDBT[0].db_size);
if( pFontInfo->pascii_ptr == pFontInfo->gb_database_ptr )
{
pDBT[1].db_size = pDBT[0].db_size;
pDBT[1].pdb = pDBT[0].pdb;
}
else
{
pDBT[1].db_size = pFontInfo->ngb_db_size;
pDBT[1].pdb = (uint8 *) new uint8[pDBT[1].db_size];
memcpy(pDBT[1].pdb,pFontInfo->gb_database_ptr,pDBT[1].db_size);
}
pFontInfoEx->pDbtt = (uint8*) pDBT;
}
for(int j = 0;j<nCount;j++)
{
VERIFY( fontExMap.Lookup(arrID[j], pFontInfoEx) );
pDBT = (PGUI_FONT_DB_T)(pFontInfoEx->pDbtt);
for( i = 2;i<nLangNum;i++)
{
pDBT[i].db_size = pDBT[0].db_size;
pDBT[i].pdb = pDBT[0].pdb;
}
}
return TRUE;
}
//x
BOOL CBinFileFactory::ReadFontInfoEx( FILE * pFile, BOOL bBuildInfo /* = FALSE */ )
{
_ASSERTE( pFile != NULL );
CMMIRes &mmires = g_theApp.m_MMIRes;
MMI_RESOURCE_T &res = mmires.m_Resource;
MMI_RES_DATA_T &FontData = res.mmi_data_table[MMI_RT_FONT];
FONTEX_MAP &fontExMap = mmires.m_mapFontEx;
CDirFileInfo * pInfo = g_theApp.m_pFontInfo;
int nOldLangNum = g_theApp.m_nOldUsedLangNum;
int nLangNum = g_theApp.m_nUsedLangNum;
const BOOL bBigEdn = res.ToolUsedInfo.bBigEndian;
CConverter conv;
if( bBigEdn )
{
FontData.uCount = conv.ConvEdn_INT(FontData.uCount);
FontData.uSize = conv.ConvEdn_INT(FontData.uSize);
}
int nCount = FontData.uCount;
if( nCount == 0 )
return TRUE;
///////////////////////////////////////////////////////////////////////////////
#define READ_FILE(des, st, num, file) \
if( fread(des, st, num, file) != num ) \
{ \
_ASSERTE(0); \
_tcscpy(m_szErrMsg, _T("Read file(Font Info) error!")); \
return FALSE; \
}
#define SEEK_FILE(pfile, st) \
if( fseek(pfile,st, SEEK_CUR) != 0 ) \
{ _ASSERTE(0); return FALSE; }
///////////////////////////////////////////////////////////////////////////////
CStringArray arrID;
pInfo->CalcAllLeafID( arrID );
int i = 0,j=0;
_ASSERTE( 0 == fontExMap.GetCount() );
CUIntArray arrFlag;
arrFlag.SetSize(nCount);
PGUI_FONT_INFO_EX_T pFontInfo = NULL;
LPBYTE pData = NULL;
int nSize = 0;
for( i = 0; i < nCount; ++i )
{
pFontInfo = new GUI_FONT_INFO_EX_T;
if( NULL == pFontInfo )
return FALSE;
READ_FILE( pFontInfo, sizeof(GUI_FONT_INFO_EX_T), 1, pFile );
if( bBigEdn )
{
pFontInfo->pDbtt = (uint8 *)conv.ConvEdn_INT((DWORD)(pFontInfo->pDbtt));
pFontInfo->type = conv.ConvEdn_INT(pFontInfo->type);
}
if( bBuildInfo )
{
CDirFileNode * pRoot = (CDirFileNode *)pInfo->GetRoot();
CDirFileNode * pNode = (CDirFileNode *)pInfo->MallocNode();
if( NULL == pNode )
return FALSE;
_tcscpy(pNode->szID, arrID.GetAt(i));
_tcscpy(pNode->szName, pNode->szID);
fontExMap.SetAt(pNode->szID, pFontInfo );
arrID.Add(pNode->szID);
pInfo->AddChild(pRoot, pNode);
}
else
{
fontExMap.SetAt( arrID[i], pFontInfo );
}
}
uint8 * pdb = NULL;
uint32 * pdb0 = (uint32 *)new uint32[nCount];
if(pdb0 == NULL)
return FALSE;
memset(pdb0,0,sizeof(uint32)*nCount);
for(i=0;i<nCount;i++)
{
VERIFY( fontExMap.Lookup(arrID[i], pFontInfo) );
pFontInfo->pDbtt = (uint8 *) new GUI_FONT_DB_T[MAX_FONT_NUM];
if(pFontInfo->pDbtt == NULL)
return FALSE;
memset(pFontInfo->pDbtt,0,sizeof(GUI_FONT_DB_T)*MAX_FONT_NUM);
READ_FILE( pFontInfo->pDbtt, sizeof(GUI_FONT_DB_T)*nOldLangNum, 1, pFile );
pdb0[i] =(uint32)(((PGUI_FONT_DB_T)(pFontInfo->pDbtt))->pdb);
if( bBigEdn )
{
for( j = 0; j < nOldLangNum; j++)
{
((PGUI_FONT_DB_T)(pFontInfo->pDbtt))[j].db_size =
conv.ConvEdn_INT(((PGUI_FONT_DB_T)(pFontInfo->pDbtt))[j].db_size);
}
}
}
PGUI_FONT_DB_T pDbt = NULL,pDbt0 = NULL;
int nAlign = 0;
for( j = 0; j < nOldLangNum; j++)
{
for( i = 0; i < nCount; ++i )
{
VERIFY( fontExMap.Lookup(arrID[i], pFontInfo) );
pDbt = (PGUI_FONT_DB_T)(pFontInfo->pDbtt);
if(j!=0 && pDbt[j].pdb == (uint8 *)pdb0[i] )
{
pDbt[j].pdb = pDbt[0].pdb;
pDbt[j].db_size = pDbt[0].db_size;
}
else
{
pDbt[j].pdb = (uint8 *)new BYTE[pDbt[j].db_size];
if( pDbt->pdb == NULL )
return FALSE;
READ_FILE( pDbt[j].pdb, pDbt[j].db_size, 1, pFile );
nAlign = Addr4ByteAlign(pDbt[j].db_size);
fseek(pFile, nAlign - pDbt[j].db_size, SEEK_CUR);
}
}
}
if(nLangNum>nOldLangNum)
{
for( i = nOldLangNum ; i<nLangNum;i++)
{
for(j = 0; j< nCount;j++)
{
VERIFY( fontExMap.Lookup(arrID[j], pFontInfo) );
pDbt = pDbt0 = (PGUI_FONT_DB_T)(pFontInfo->pDbtt);
pDbt += i;
pDbt->pdb = pDbt0->pdb;
pDbt->db_size = pDbt0->db_size;
}
}
}
return TRUE;
}
//xe
CString CBinFileFactory::GetFontType(int nType)
{
CString strType = _T("");
switch( nType )
{
case SONG_FONT_8:
strType = _T("SONG_FONT_8");
break;
case SONG_FONT_10:
strType = _T("SONG_FONT_10");
break;
case SONG_FONT_12:
strType = _T("SONG_FONT_12");
break;
case SONG_FONT_14:
strType = _T("SONG_FONT_14");
break;
case SONG_FONT_16:
strType = _T("SONG_FONT_16");
break;
case ASC_ME_FONT_38:
strType = _T("ASC_ME_FONT_38");
break;
case ARI_NARROW_FONT_29:
strType = _T("ARI_NARROW_FONT_29");
break;
default:
_ASSERTE( 0 );
break;
}
return strType;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -