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

📄 childview.cpp

📁 Sunplus DVD 字体文件查看修改工具,只针对Font_ori.c文件!使用方便,可以编译成支持Unicode的软件!
💻 CPP
📖 第 1 页 / 共 3 页
字号:

#ifdef ALECK_USE_CHINESE
	sShow.Append(_T("(4).正在装入数组字体位数据....\n"));
#else
	sShow.Append(_T("(4).Loading array and font data....\n"));
#endif
	winShow.SetDlgItemText(IDC_STATIC,sShow);

	//------------------------------------------------------------------------------
	//	装入数据,对应到名称数组
	//------------------------------------------------------------------------------
	iLevel = 0;
	idItem = -1;

	fseek(fpin,0L,SEEK_SET);
	while(!feof(fpin))
	{
		//	查找单词
		cWord = FindWord(fpin);
		
		//	查找括号,当前级别.
		if(cWord.Compare(_T("{")) == 0)	
		{	
			iLevel ++;
			continue;
		}
		else if(cWord.Compare(_T("}")) == 0)
		{
			iLevel --;
			continue;
		}

		switch(iLoad)
		{
		case LOAD_STEP_DONE:
			
			//	查找数据项,在两个表格中查询
			if(iLevel == 0)
			{
				for(i = 0; i< MAX_FONT_TABLE; i++)
				{
					//	查找单词是否包含
					idItem = FindItem(sFnt[i],cWord);
#ifdef ALECK_DEBUG
					if(idItem > 0)
					{
						TRACE(_T("Font[%d]=[%s]\n"),idItem,cWord);
					}
#endif
					//	数据还没有满就添加
					if( idItem >= 0 && idItem < MAX_CHAR_NUM )
					{
						idFont = i;
						iLoad = LOAD_STEP_DATA0;
						break;
					}
					else if(idItem > 0)
					{
#ifdef ALECK_DEBUG
						TRACE(_T("FontArray[%d][%d]=[%s]\n"),i,idItem,cWord);
#endif
					}
				}
			}
			break;
		
			//--------------------------------------------------------------
			//	查找数据宽度
			//--------------------------------------------------------------
		case LOAD_STEP_DATA0:
			if(iLevel == 1)
			{
				if(IsHexData(cWord))
				{
					d[0] = StringToInt(cWord);
					iLoad = LOAD_STEP_DATA1;
#ifdef ALECK_DEBUG
					TRACE(_T("数据[0]:%x,"),d[0]);
#endif
				}
			}
			break;
			
			//--------------------------------------------------------------
			//	查找数据高度
			//--------------------------------------------------------------
		case LOAD_STEP_DATA1:
			if(iLevel == 1)
			{
				if(IsHexData(cWord))
				{
					d[1] = StringToInt(cWord);
					iLoad = LOAD_STEP_DATA2;
#ifdef ALECK_DEBUG
					TRACE(_T("数据[1]:%x,"),d[1]);
#endif
				}
			}
			break;

			//--------------------------------------------------------------
			//	查找行字节数
			//--------------------------------------------------------------
		case LOAD_STEP_DATA2:
			if(iLevel == 1)
			{
				if(IsHexData(cWord))
				{
					d[2] = StringToInt(cWord);
#ifdef ALECK_DEBUG
					TRACE(_T("数据[2]:%x,"),d[2]);
#endif
					//	计算空间大小
					iSize = (d[0] * d[1] + 7) / 8 + 3;
#ifdef ALECK_DEBUG
					TRACE(_T("大小:{%d},"),iSize + 3);
#endif
					//	检查数据指针是否有效,有效就要释放,否则会泄漏哦!
					if(arr_tbl[idFont][idItem] != NULL)
					{
						free(arr_tbl[idFont][idItem]);
						arr_tbl[idFont][idItem] = NULL;
					}

					//	进入无效模式
					iLoad = LOAD_STEP_DONE;

					//	分配数据空间
					if(iSize > 3 && iSize <= (MAX_MALLOC_SIZE))
					{
						arr_tbl[idFont][idItem] = (BYTE *)malloc(iSize);
						
						if(arr_tbl[idFont][idItem] != NULL)
						{
							//	拷贝数据
							arr_tbl[idFont][idItem][0] = d[0];
							arr_tbl[idFont][idItem][1] = d[1];
							arr_tbl[idFont][idItem][2] = d[2];
							
							//	下一个数据存储的位置.
							idData = 3;

							//	进入读入分配数据装入模式
							iLoad = LOAD_STEP_READ;
						}
					}
					else
					{
#ifdef ALECK_DEBUG
						if(iSize <= 3)
						{
							TRACE(_T("分配空间太小[%d]错误!\n"),iSize);
						}
						else
						{
							TRACE(_T("分配空间太大[%d]错误!\n"),iSize);
						}
#endif				
					}
				}
			}
			break;

			//--------------------------------------------------------------
			//	开始读数据.
			//--------------------------------------------------------------
		case LOAD_STEP_READ:

			if(IsHexData(cWord) && (iLevel == 1) && (idData < iSize))
			{
				//	添加数据
				arr_tbl[idFont][idItem][idData ++ ] = StringToInt(cWord);
			}
			else
			{
				//	级别改变或者累计满,或者无效数据就表示完成.
#ifdef ALECK_DEBUG
				static int i;
				TRACE(_T("{\n"));

				for(i = 0;i < iSize; i++)
				{
					TRACE(_T("%02x,"),arr_tbl[idFont][idItem][i]);
					if(i % 16 == 2)
					{
						TRACE(_T("\n"));
					}
				}

				TRACE(_T("}\n"));
#endif
				iLoad = LOAD_STEP_DONE;
			}
			break;
		}
	}

	fclose(fpin);

	winShow.GetDlgItemText(IDC_STATIC,sShow);

#ifdef ALECK_USE_CHINESE
	sShow.Append(_T("(5).数据转载完毕...装入完成!\n"));
#else
	sShow.Append(_T("(5).Data converting done...and All steps done!\n"));
#endif
	winShow.SetDlgItemText(IDC_STATIC,sShow);

	//	默认显示第一个表格
	p_fnt = (BYTE **)(&arr_tbl[id_fnt = 0][0]);

	this->Invalidate(TRUE);

	this->EndWaitCursor();

	//	删除临时文件
	DeleteFile(TEMP_FILE_NAME);

	//	隐藏提示窗
	winShow.ShowWindow(SW_HIDE);
	winShow.DestroyWindow();

	//	检查菜单
	this->OnFont1();

	//	修改标题
	this->GetParentFrame()->SetWindowText
		(CString(_T("TFont V 1.00 (R) - Font File [")) + m_SavePathName + CString(_T("]")));
}

//================================================================================
//=		创建窗口
//================================================================================
BOOL CChildView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	//	装入配置文件数据
	this->m_data.LoadFromProfile();

	if(this->m_data.m_iSizeW >= 8 && this->m_data.m_iSizeW <= 100)
		p_Grid_W = this->m_data.m_iSizeW;

	if(this->m_data.m_iSizeH >= 8 && this->m_data.m_iSizeH <= 100)
		p_Grid_H = this->m_data.m_iSizeH;

	//	添加滚动条
	dwStyle |= WS_HSCROLL| WS_VSCROLL;
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

//================================================================================
//=		终结窗口
//================================================================================
BOOL CChildView::DestroyWindow() 
{
	return CWnd ::DestroyWindow();
}

//================================================================================
//=		纵向滚动
//================================================================================
void CChildView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	static UINT OldPos = 0;
	static UINT nOffset = 0;

	TRACE("nSBCode=%d,nPos=%d\n",nSBCode,nPos);

	if(nSBCode == 5 )
	{
		this->SetScrollPos(1,nPos);
		this->m_MapY = m_spc - (nPos * (p_Grid_H * m_row + m_spc * 2) / MAX_SCROLL_POS);
		if( OldPos != nPos)
		{
			OldPos = nPos;
		}
	}
	else if(nSBCode == 8 )
	{
		nPos = this->GetScrollPos(1);
		this->m_MapY = m_spc - (nPos * (p_Grid_H * m_row + m_spc * 2) / MAX_SCROLL_POS);
	}
	else if( nSBCode == 1||nSBCode == 3)
	{
		nPos = this->GetScrollPos(1);
		nOffset = 1;
		if (nPos < MAX_SCROLL_POS)
		{
			this->SetScrollPos(1, nPos + nOffset);
			this->m_MapY = m_spc - (nPos * (p_Grid_H * m_row + m_spc * 2) / MAX_SCROLL_POS);		
		}
	}
	else if(nSBCode == 0 || nSBCode == 2)
	{
		nPos = this->GetScrollPos(1);
		nOffset = 1;
		if (nPos > 0)
		{
			this->SetScrollPos(1, nPos - nOffset);
			this->m_MapY = m_spc - (nPos * (p_Grid_H * m_row + m_spc * 2) / MAX_SCROLL_POS);
		}
	}
	
	this->Invalidate(0);

	CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}

//================================================================================
//=		横向滚动
//================================================================================
void CChildView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	static UINT OldPos = 0;
	static UINT nOffset = 0;

	TRACE("nSBCode=%d,nPos=%d\n",nSBCode,nPos);

	if(nSBCode == 5)
	{
		this->SetScrollPos(0,nPos);
		this->m_MapX = m_spc - (nPos * (p_Grid_W * m_col + m_spc * 2) / MAX_SCROLL_POS);
		
		if( OldPos != nPos)
		{
			OldPos = nPos;
		}
	}
	else if(nSBCode == 8 )
	{
		nPos = this->GetScrollPos(0);
		this->m_MapX = m_spc - (nPos * (p_Grid_W * m_col + m_spc * 2) / MAX_SCROLL_POS);
	}
	else if( nSBCode == 1||nSBCode == 3)
	{
		nPos = this->GetScrollPos(0);
		nOffset = 1;

		if (nPos < MAX_SCROLL_POS)
		{	
			this->SetScrollPos(0, nPos + nOffset);
			this->m_MapX = m_spc - (nPos * (p_Grid_W * m_col + m_spc * 2) / MAX_SCROLL_POS);
		}
	}
	else if(nSBCode == 0 || nSBCode == 2)
	{
		nPos = this->GetScrollPos(0);
		nOffset = 1;

		if (nPos > 0)
		{
			this->SetScrollPos(0, nPos - nOffset);
			this->m_MapX = m_spc - (nPos * (p_Grid_W * m_col + m_spc * 2) / MAX_SCROLL_POS);
		}
	}
	
	this->Invalidate(0);

	CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
}

//================================================================================
//=		终结窗口处理
//================================================================================
void CChildView::OnDestroy()
{
	CWnd::OnDestroy();
	
	int i,j;
	for(i = 0 ; i < MAX_FONT_TABLE; i++)
	{
		for(j = 0;j < MAX_CHAR_NUM; j++)
		{
			if(arr_tbl[i][j] != NULL)
			{
				free(arr_tbl[i][j]);
			}
			arr_tbl[i][j] = NULL;
		}
	}
}

//================================================================================
//=		修改窗口大小
//================================================================================
void CChildView::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	UINT win_w;
	UINT win_h;
	
	//	滚动条信息
	SCROLLINFO sif;

	//	窗口区域
	RECT r;

	//	取得区域
	this->GetClientRect(&r);
	win_w = r.right- r.left;
	win_h = r.bottom - r.top ;

	if(this->m_data.m_bAutoSize)
	{
		this->m_MapX = m_spc;
		this->m_MapY = m_spc;

		p_Grid_W = (cx - m_spc * 2) / m_col;
		p_Grid_H = (cy - m_spc * 2) / m_row;
	}

	//	窗口宽度
	if(win_w > 0 )
	{
		if( win_w < p_Grid_W * m_col + m_spc * 2)
		{
			this->EnableScrollBar(0,ESB_ENABLE_BOTH);
			this->GetScrollInfo(0,&sif);	
			sif.nPage = MAX_SCROLL_POS * win_w / (p_Grid_W * m_col + m_spc * 2);

			this->SetScrollInfo(0,&sif);

			if(this->m_MapX > m_spc)
			{
				this->m_MapX = m_spc;
				this->SetScrollPos(0,0);
			}
		}
		else
		{
			this->m_MapX = (win_w -  (p_Grid_W * m_col)) / 2;
			this->SetScrollPos(0,0);
			this->EnableScrollBar(0,ESB_DISABLE_BOTH);
		}
	}

	//	窗口高度
	if(win_h > 0 )
	{
		if(win_h < p_Grid_H * m_row + m_spc * 2)
		{
			this->EnableScrollBar(1,ESB_ENABLE_BOTH);
			this->GetScrollInfo(1,&sif);
			sif.nPage = MAX_SCROLL_POS * win_h / (p_Grid_H * m_row + m_spc * 2);
			this->SetScrollInfo(1,&sif);

			if(this->m_MapY > m_spc)
			{
				this->m_MapY = m_spc;
				this->SetScrollPos(1,0);
			}
		}
		else
		{
			this->m_MapY = (win_h - (p_Grid_H * m_row)) / 2;
			this->SetScrollPos(1,0);
			this->EnableScrollBar(1,ESB_DISABLE_BOTH);
		}
	}
	this->Invalidate(TRUE);
}

//================================================================================
//=		移动鼠标
//================================================================================
void CChildView::OnMouseMove(UINT nFlags, CPoint point)
{
	//	调用基类
	CWnd::OnMouseMove(nFlags, point);
}

//================================================================================
//=		保存到文件
//================================================================================
BYTE DoSaveToFile(CString &FileName)
{
	FILE *fp;
	int i,j,k;

	//	打开文件准备写入
	fp = _tfopen(FileName,_T("w+"));

	//	打开无效就退出
	if(!fp)
		return 0;

	//	写入文件头信息
	fprintf(fp,"//===========================================================================\n");
	fprintf(fp,"//= \n");
	fprintf(fp,"//= Name:   Sunplus Font Tools 1.01 (R)\n");
	fprintf(fp,"//= \n");
	fprintf(fp,"//= Date:	2006-10-1\n");
	fprintf(fp,"//= \n");
	fprintf(fp,"//= Writer: Aleck.Shi\n");
	fprintf(fp,"//= \n");
	fprintf(fp,"//= Notes:	(You can change/make font files so ease!)\n");
	fprintf(fp,"//= \n");
	fprintf(fp,"//===========================================================================\n\n");
	fprintf(fp,"typedef unsigned char BYTE;\n\n");

	//	先填写一个空的字符,然后,无效字符全部填写这个字符.

	fprintf(fp,"const BYTE encoding_tbx_space [] =\n"
				"{\n"
				"\t0x08,0x18,0x02,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"\t0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\n"
				"};\n\n");

	//	写入字体表格
	for(i = 0; i < MAX_FONT_TABLE; i ++)
	{
		if(sFnt[i].GetCount() > 0)
		{
			for(j = 0; j < MAX_CHAR_NUM; j++)
			{
				//	如果有数据就保存数据,没有就要写入空白
				if(arr_tbl[i][j])
				{
					fprintf(fp,"const BYTE encoding_tb%d_%04x [] =\n{\n\t",i,j);

					for(k = 0; k < (arr_tbl[i][j][0] * arr_tbl[i][j][1] + 7)/ 8 + 3; k ++)
					{
						fprintf(fp,"0X%02X,",arr_tbl[i][j][k]);

						//	每八个就换行,开始三个就换行
						if(k % 8 - 2 == 0)
							fprintf(fp,"\n\t");
					}
					fprintf(fp,"\n};\n\n");
				}
			}

			//	构建表格.
			if(i == 0)
				fprintf(fp,"const BYTE *const fn_table700[]=\n{\n");
			else 
				fprintf(fp,"const BYTE *const fn_table700_%d[]=\n{\n",i+1);

			for(j = 0; j< MAX_CHAR_NUM; j++)
			{
				//	有效就填写名称,否则填写空格!
				if(arr_tbl[i][j])
				{
					fprintf(fp,"/*0x%02x*/\nencoding_tb%d_%04x,\n",j,i,j);
				}
				else
				{
					fprintf(fp,"/*0x%02x*/\nencoding_tbx_space,\n",j,i);
				}
			}
			fprintf(fp,"\n};\n");
		}
	}
	
	//	写入结尾信息
	fprintf(fp,"//===========================================================================\n");
	fprintf(fp,"//= End of file .                                                            \n");
	fprintf(fp,"//===========================================================================\n");

	//	关闭文件
	fclose(fp);

	//	写入成功就返回 1,否则返回 0
	return 1;
}

//================================================================================
//=		显示字体属性(可以编辑修改)
//================================================================================
void CChildView::OnLButtonDblClk(UINT nFlags, CPoint point)
{

⌨️ 快捷键说明

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