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

📄 fonttestdlg.cpp

📁 万能字库生成工具: 将UNICODE
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			m_ctlEdit.SetWindowText((LPCTSTR)tsFont);
		}
	}
	else if((nSel == SOURCE_HAND_EDIT) || (nSel == SOURCE_SELECT_FILE))
	{
		CString strHandSel;
		m_ctlEditSource.GetWindowText(strHandSel);
		int nTempHand = m_nCurHandSel; 
		CString strTemp = strHandSel.Mid(nTempHand, 1);
		m_ctlEdit.SetWindowText(strTemp);
	}

	return true;
}

bool CFontTestDlg::ShowGridInfo()
{
	UpdateData();
	int nHeight = m_nFontHeight;//m_spinHeight.GetPos();
	int nSourceSel = m_ctlSourceFrom.GetCurSel();
	int nOffset = AnalyzeOffset(m_nMemWidth, nHeight, nSourceSel);
	if(nOffset == -1)
	{
		memset(m_byShowBuf, 0x00, sizeof(BYTE)*TRAN_FILE_BUF_LEN);
		m_fontCurve.ShowGridData((BSTR*)m_byShowBuf, m_nMemWidth, nHeight, m_nShowType);
		return false;
	}
	
	PreviewShow(m_nMemWidth, nHeight, nOffset);

	return true;
}

void CFontTestDlg::OnButtonStop() 
{
	int nSel = m_ctlSourceFrom.GetCurSel();
	if(nSel == SOURCE_ALL_CODE)
	{
		m_nAddOrDelete = 0;	
	}
	else if((nSel == SOURCE_HAND_EDIT) ||(nSel == SOURCE_SELECT_FILE))
	{
		m_nCurHandSel --;
		
		if(m_nCurHandSel < 0)
			m_nCurHandSel = m_ctlEditSource.GetWindowTextLength()-1;
	}

	ShowInfo();

	ShowGridInfo();
}

void CFontTestDlg::OnButtonNext() 
{
	int nSel = m_ctlSourceFrom.GetCurSel();
	if(nSel == SOURCE_ALL_CODE)
	{
		m_nAddOrDelete = 1;
	}
	else if((nSel == SOURCE_HAND_EDIT) ||(nSel == SOURCE_SELECT_FILE))
	{
		m_nCurHandSel ++;
//GetWindowTextLength()得到的长度包含结尾符"\0"		 
		if(m_nCurHandSel > (m_ctlEditSource.GetWindowTextLength()-1))
			m_nCurHandSel = 0;
	}

	ShowInfo();

	ShowGridInfo();
}

int CFontTestDlg::AnalyzeOffset(int nMemWidth, int nMemHeight, int nSourceType)
{
	int nDiff = 0;
	if(nSourceType == SOURCE_ALL_CODE)
	{
		CString strUnicode, strBig5, strGB2312, strGBK, strGB18030;
		strUnicode.LoadString(IDS_RES_UNICODE);
		strBig5.LoadString(IDS_RES_BIG5);
		strGB2312.LoadString(IDS_RES_GB2312);
		strGBK.LoadString(IDS_RES_GBK);
		strGB18030.LoadString(IDS_RES_GB18030);
		
		WORD wBeginCode = 0x0000;
		if(m_strCodeSel == strUnicode)
			wBeginCode = (WORD)UNICODE_BEGIN;
		else if(m_strCodeSel == strGB2312)
			wBeginCode = (WORD)GB2312_BEGIN;
		else if(m_strCodeSel == strGBK)
			wBeginCode = (WORD)GBK_BEGIN;
		else if(m_strCodeSel == strGB18030)
			wBeginCode = (WORD)GB18030_BEGIN;
		else if(m_strCodeSel == strBig5)
			wBeginCode = (WORD)BIG5_BEGIN;
		
		bool bTran = GetCharToWORD();
		WORD wTran = MAKEWORD(m_pFont[1], m_pFont[0]);
		nDiff = wTran-wBeginCode;

		int nPrevOffset = 0;
		int nCurOffset = 0;
		int nPrevDiff = 0;
		FONT_DIFF_OFFSET * pDiff = NULL;
		POSITION pos = m_offSetDiffList.GetHeadPosition();
		while(pos)
		{
			pDiff = m_offSetDiffList.GetNext(pos);
			nCurOffset = pDiff->realOffset;
			
			if(nDiff > nCurOffset)
			{
				nPrevOffset = nCurOffset;
				nPrevDiff = pDiff->diffCount;
				continue;
			}
			else if(nDiff == nCurOffset)
			{
				return -1;;
			}
			else if((nDiff > nPrevOffset) && (nDiff < nCurOffset))
			{
				nDiff -= nPrevDiff;
				break;
			}
		}
		if(nDiff > m_nMaxOffset)
		{
			nDiff -= nPrevDiff;
		}
	}
	else if((nSourceType = SOURCE_HAND_EDIT) || (nSourceType == SOURCE_SELECT_FILE))
	{
		nDiff = m_nCurHandSel;
	}


	return (nDiff*nMemWidth*nMemHeight/8);
}

bool CFontTestDlg::PreviewShow(int nMemWidth, int nMemHeight, int nOffset)
{
	CString strLibraryFile;
	GetDlgItem(IDC_EDIT_FONT_LIBRARY_URL) ->GetWindowText(strLibraryFile);
	
	int nLen = strLibraryFile.GetLength();
	if(nLen == 0)
		return false;

	CFile fl;
	CFileException p;
	BOOL bOpen = fl.Open((LPCTSTR)strLibraryFile, CFile::modeRead, &p);
	if(!bOpen)
		return false;
	memset(m_byShowBuf, 0x00, TRAN_FILE_BUF_LEN * sizeof(BYTE));
	fl.Seek(nOffset, CFile::begin);
	fl.Read(m_byShowBuf, (nMemWidth*nMemWidth)/8);
	fl.Close();

	m_fontCurve.SetGridHoriNum(nMemWidth);
	m_fontCurve.SetGridVerNum(nMemWidth);
	
	m_fontCurve.ShowGridData((BSTR*)m_byShowBuf, nMemWidth, nMemHeight, m_nShowType); 

	return false;
}

bool CFontTestDlg::FreeResource()
{
	m_nMaxOffset = 0;

	POSITION pos = m_offSetDiffList.GetHeadPosition();
	while(pos)
	{
		FONT_DIFF_OFFSET * pDiff = m_offSetDiffList.GetNext(pos);
		delete pDiff;
	}
	m_offSetDiffList.RemoveAll();

	return true;
}

void CFontTestDlg::OnCancel() 
{
	delete [] m_pFont;

	if(m_fontHandle != NULL)
	{
		CloseHandle(m_fontHandle);
	}
	
	FreeResource();

	CDialog::OnCancel();
}

bool CFontTestDlg::GetCharToWORD(bool bInitBegin)
{
	if(bInitBegin)
	{
		UpdateData();
		LPCTSTR lpLeft = (LPCTSTR)m_strBeginCode;
		TCHAR * pLeft = _tcsupr((TCHAR *)lpLeft);
		char chFir = LOBYTE(pLeft[0]);
		char chSec = LOBYTE(pLeft[1]);
		BYTE byFir = isdigit(chFir) ? (chFir - 0x30) : (chFir - 0x37);
		BYTE bySec = isdigit(chSec) ? (chSec - 0x30) : (chSec - 0x37);
		m_pFont[0] = byFir << 4 | bySec;
		
		chFir = LOBYTE(pLeft[2]);
		chSec = LOBYTE(pLeft[3]);
		byFir = isdigit(chFir) ? (chFir - 0x30) : (chFir - 0x37);
		bySec = isdigit(chSec) ? (chSec - 0x30) : (chSec - 0x37);
		m_pFont[1] = byFir << 4 | bySec;
	}

	return true;
}

void CFontTestDlg::OnButtonApply() 
{
	 bool bBegin = true; 
	 GetCharToWORD(bBegin);

	 m_nAddOrDelete = -1;
	 ShowInfo();

	 ShowGridInfo();
}

void CFontTestDlg::OnSelchangeComboCodeType() 
{
	m_ctlCode.SetWindowText(_T(""));
	m_ctlEdit.SetWindowText(_T(""));

	int nSel = m_ctlCombox.GetCurSel();
	m_strCodeSel.Empty();
	m_ctlCombox.GetLBText(nSel, m_strCodeSel);

	CString strUnicode, strBig5, strGB2312, strGBK, strGB18030;
	strUnicode.LoadString(IDS_RES_UNICODE);
	strBig5.LoadString(IDS_RES_BIG5);
	strGB2312.LoadString(IDS_RES_GB2312);
	strGBK.LoadString(IDS_RES_GBK);
	strGB18030.LoadString(IDS_RES_GB18030);

	if(m_strCodeSel == strGB2312)
	{
		m_pFont[0] = HIBYTE((WORD)GB2312_BEGIN);
		m_pFont[1] = LOBYTE((WORD)GB2312_BEGIN);
	}
	else if(m_strCodeSel == strGBK)
	{
		m_pFont[0] = HIBYTE((WORD)GBK_BEGIN);
		m_pFont[1] = LOBYTE((WORD)GBK_BEGIN);
	}
	else if(m_strCodeSel == strGB18030)
	{
		m_pFont[0] = HIBYTE((WORD)GB18030_BEGIN);
		m_pFont[1] = LOBYTE((WORD)GB18030_BEGIN);
	}
	else if(m_strCodeSel == strBig5)
	{
		m_pFont[0] = HIBYTE((WORD)BIG5_BEGIN);
		m_pFont[1] = LOBYTE((WORD)GB18030_BEGIN);
	}
	else if(m_strCodeSel == strUnicode)
	{
		m_pFont[0] = HIBYTE((WORD)UNICODE_BEGIN);
		m_pFont[1] =LOBYTE((WORD)UNICODE_BEGIN);
	}

	TCHAR szTemp[4] = {0};
	CString str;
	str.Empty();
	for(int i = 0; i < 2; i++)
	{
		_stprintf(szTemp, _T("%02X"), m_pFont[i]);
		str += szTemp;
	}
	m_strBeginCode = str;
	UpdateData(FALSE);
				
	m_ctlCode.SetWindowText(str);

	if(m_strCodeSel != strUnicode)
	{
		TCHAR tsFont[TEST_CODE_LENGTH] = {0};
		MultiByteToWideChar(CP_ACP,0,(char*)m_pFont,2,tsFont,1);
		m_ctlEdit.SetWindowText((LPCTSTR)tsFont);
	}
}

/*
注意:
	1. 以统一的标准(客户坐标或者屏幕坐标)来进行显示;
		在本函数中统一是先使用屏幕坐标,然后将其转换成客户坐标进行操作,因为MoveWindow()
		是使用的是客户坐标;
*/
void CFontTestDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	CRect rect, wndRect;
	int nSize = 0;
	int nHeight = 0; 
	int nWidth = 0;
	CWnd * pPreview = (CWnd *)GetDlgItem(IDC_STATIC_PREVIEW);
	if(pPreview != NULL)
	{
		pPreview ->GetWindowRect(rect);
		ScreenToClient(rect);
	}

	CRect dlgRect;
	GetWindowRect(dlgRect);
	ScreenToClient(dlgRect);

	switch(nType)
	{
	case SIZE_MAXIMIZED:
		break;

	case SIZE_RESTORED:
		if(m_nPrevCX != 0)
		{
			nWidth = dlgRect.Width() - m_nPrevCX;
			rect.right += nWidth;
			nHeight = dlgRect.Height() - m_nPrevCY;;
			rect.bottom += nHeight;
			
			pPreview ->MoveWindow(rect, TRUE);
		}
		break;

	default:
		break;
	}

	m_nPrevCX = dlgRect.Width();
	m_nPrevCY = dlgRect.Height();
}

void CFontTestDlg::OnChangeEditFontWidth() 
{
	UpdateData();
	m_nFontHeight = m_nFontWidth;//m_spinWidth.GetPos(); 
	UpdateData(FALSE);
}

void CFontTestDlg::OnChangeEditFontHeight() 
{
	UpdateData();
	m_nFontWidth = m_nFontHeight;//m_spinWidth.GetPos(); 
	UpdateData(FALSE);
}

bool CFontTestDlg::GetFontSize(FONT_SHOW_SIZE &fontShow)
{
	int nColorUnit = 0;
	int nSel = m_ctlFontColor.GetCurSel();
	if(nSel == 0)
		nColorUnit = COLOR_BIT_1;
	else if(nSel == 1)
		nColorUnit = COLOR_BIT_8;
	else if(nSel == 2)
		nColorUnit = COLOR_BIT_16;
	else if(nSel == 3)
		nColorUnit = COLOR_BIT_24;

	UpdateData();
	int nFontWidth = m_nFontHeight;//m_spinHeight.GetPos();
	if(nFontWidth <= 8)
		m_nMemWidth = 8;
	else if(nFontWidth <= 16)
		m_nMemWidth = 16;
	else if(nFontWidth <= 32)
		m_nMemWidth = 32;

	fontShow.colorUnit = nColorUnit;
	fontShow.fontSize = CSize(nFontWidth, nFontWidth);
	fontShow.memSize = CSize(m_nMemWidth, nFontWidth);

	return true;
}

/////////////////////////////////////////////////////////////////////////////
//Thread Operation
////////////////////////////////////////////////////////////////////////////
/*
问题:
	1. 在窗口进程中可以显示,在工作线程中却不能显示;
	   改多线程为单线程;
*/
void CFontTestDlg::OnCreateFont() 
{
	/*if(m_fontHandle != NULL)
		CloseHandle(m_fontHandle);
	
	m_fontHandle = CreateThread(NULL, 
			0,
			(LPTHREAD_START_ROUTINE)CreateFont_Proc,
			this,
			0,
			&m_dwThreadID);*/
	int nSel = m_ctlSourceFrom.GetCurSel();
	bool bCreate = CreateFontLibrary(nSel);
	if(!bCreate)
	{
		CString strTip, strTitle;
		strTip.LoadString(IDS_CREATE_LIBRARY_FAIL);
		strTitle.LoadString(IDS_TITLE);
		MessageBox(strTip, strTitle, MB_OK | MB_ICONWARNING);

⌨️ 快捷键说明

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