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

📄 fontconverterview.cpp

📁 开发UC/GUI用的字体转换工具.
💻 CPP
字号:
// FontConverterView.cpp : implementation of the CFontConverterView class
//

#include "stdafx.h"
#include "FontConverter.h"

#include "FontConverterDoc.h"
#include "FontConverterView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView

IMPLEMENT_DYNCREATE(CFontConverterView, CScrollView)

BEGIN_MESSAGE_MAP(CFontConverterView, CScrollView)
	//{{AFX_MSG_MAP(CFontConverterView)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView construction/destruction

CFontConverterView::CFontConverterView()
{
	// TODO: add construction code here
	CFileException e;
	if( !m_File.Open("Hzk16",CFile::modeRead, &e) )
	{
#ifdef _DEBUG
		afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
	}
}

CFontConverterView::~CFontConverterView()
{
	m_File.Close();
}

BOOL CFontConverterView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView drawing

void CFontConverterView::OnDraw(CDC* pDC)
{
	CFontConverterDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	
	BYTE buf[32];
	int x,y,i,j;

	//unsigned char temp[3] = "啊";

	//	f.Seek(90*20*32,CFile::begin);
	m_File.SeekToBegin();
	j = 1;

	while(m_File.GetPosition()!= m_File.GetLength())
	{
		for(i=1;i<33;i++)
		{
			m_File.Read(buf,32);
			for(y = 0; y < 16; y++)
				for(x = 0; x < 16; x++) 		
					if (buf[y * 2 + x / 8]  & (0x80 >> (x % 8)))					
						pDC->SetPixel(CPoint(x+i*20,y+j*20),RGB(0,0,255));
		}
		j++;
	}
	char str[40];
	sprintf(str,"一共 %d 行",j);
	pDC->TextOut(0,0,str);
}

void CFontConverterView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = 16*20;
	sizeTotal.cy = (m_File.GetLength()/(32*32))*20;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView printing

BOOL CFontConverterView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CFontConverterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CFontConverterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView diagnostics

#ifdef _DEBUG
void CFontConverterView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CFontConverterView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CFontConverterDoc* CFontConverterView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFontConverterDoc)));
	return (CFontConverterDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFontConverterView message handlers

void CFontConverterView::OnFileSave() 
{
	// TODO: Add your command handler code here
	CStdioFile f;
	CFileException e;

	if( !f.Open("HZ16.c",CFile::modeCreate | CFile::modeWrite, &e))
	{
#ifdef _DEBUG
   afxDump << "File could not be opened " << e.m_cause << "\n";
#endif   
	}

	f.SeekToBegin();

//文件头
	f.WriteString(
"/*                    \n\
   Source file: HZ16.c \n\
   Font:        GB2312 \n\
   Width:       16     \n\
   Height:      16     \n\
 */					   \n\
 \n\
 #include \"GUI.H\"    \n\
 \n\
 #ifndef GUI_FLASH     \n\
   #define GUI_FLASH   \n\
 #endif                \n\
 \n\
 extern GUI_FLASH const GUI_FONT GUI_Font_HZ16; \n\
 \n\
 /* Start of unicode area <Basic Latin> */ \n"
 );

	CString str;
//	char nm[5] = "BBD2";
//	str.Format("GUI_FLASH const unsigned char acFont_HZ16_%s[32] = { /* code %s */ \n",	nm,nm);
//	f.WriteString(str);

	BYTE buf[32];

	int x,y;
	int qm,wm;
    //Off = ( (0xd2-0xa1)*94+(0xbb-0xa1) ) * 32;
	//m_File.Seek(Off,CFile::begin);
	qm = 1; wm = 1;
	m_File.SeekToBegin();

	while(qm < 95)
	{
		m_File.Read(buf,32);
		if( qm == 3 )
			str.Format("GUI_FLASH const unsigned char acFont_HZ16_%02x%02x[32] = { /* code %02x%02x */ \n",0x00,wm+0x20,0x00,wm+0x20);
		else
			str.Format("GUI_FLASH const unsigned char acFont_HZ16_%02x%02x[32] = { /* code %02x%02x */ \n",qm+0xa0,wm+0xa0,qm+0xa0,wm+0xa0);
		f.WriteString(str);
		for(y = 0; y < 16; y++)
		{
			f.WriteString("     ");
			for(x = 0; x < 16; x++) 
			{		
				if (buf[y * 2 + x / 8]  & (0x80 >> (x % 8)))
				{
					f.WriteString("X");
				}
				else
				{
					f.WriteString("_");
				}
				if( (x+1) % 8 ==0 )
				{
				  if((y==15)&(x==15))
				  {
					f.WriteString(" ");
				  }
				  else
				  {
                   f.WriteString(",");
				  }
			}
			}
			f.WriteString("\n");
		}
		f.WriteString("}; \n");
		f.WriteString("\n");

		wm++;
		if(wm > 94)
		{
			wm = 1;
			qm++;
		}
	}

	f.WriteString("\n");
	str.Format("GUI_FLASH const GUI_CHARINFO GUI_Font_HZ16_CharInfo[%4d] = { \n",(qm-1)*94);
	f.WriteString(str);
	int q,w;
	q = 1; w = 1;
	str.Format("  {  16,  16,  2, (void GUI_FLASH *)&acFont_HZ16_%02x%02x } /* code %02x%02x */ \n",
								q+0xa0,w+0xa0,q+0xa0,w+0xa0);
	f.WriteString(str);
	w++;
	while(q<qm)
	{
		if( q == 3 )
			str.Format("  ,{  16,  16,  2, (void GUI_FLASH *)&acFont_HZ16_%02x%02x } /* code %02x%02x */ \n",
								0x00,w+0x20,0x00,w+0x20);
		else
			str.Format("  ,{  16,  16,  2, (void GUI_FLASH *)&acFont_HZ16_%02x%02x } /* code %02x%02x */ \n",
								q+0xa0,w+0xa0,q+0xa0,w+0xa0);
		f.WriteString(str);
		w++;
		if( w > 94 )
		{
			w = 1;
			q++;
		}
	}
	f.WriteString("};\n");	

	f.WriteString("\n");
	str.Format("GUI_FLASH const GUI_FONT_PROP GUI_Font_HZ16_Prop%d = {\n",--q);
	f.WriteString(str);
	str.Format("   0x%02x%02x  /* first character */ \n  ,0x%02x%02x /* last character  */ \n",
				   0xa0+q,0xa0+1,0xa0+q,0xa0+94);
	f.WriteString(str);
	str.Format("  ,&GUI_Font_HZ16_CharInfo[%d] /* address of first character */ \n",(q-1)*94);
	f.WriteString(str);
	f.WriteString("   ,NULL \n");
	f.WriteString("}; \n ");

	while(q>1)
	{
		f.WriteString("\n");
		str.Format("GUI_FLASH const GUI_FONT_PROP GUI_Font_HZ16_Prop%d = {\n",--q);
		f.WriteString(str);
		if( q == 3 )
			str.Format("   0x%02x%02x  /* first character */ \n  ,0x%02x%02x  /* last character  */ \n",
						   0x00,0x20+1,0x00,0x20+94);
		else
			str.Format("   0x%02x%02x  /* first character */ \n  ,0x%02x%02x  /* last character  */ \n",
						   0xa0+q,0xa0+1,0xa0+q,0xa0+94);
		f.WriteString(str);
		str.Format("  ,&GUI_Font_HZ16_CharInfo[%d] /* address of first character */ \n",(q-1)*94);
		f.WriteString(str);
		str.Format("   ,(void GUI_FLASH *)&GUI_Font_HZ16_Prop%d \n",q+1);
		f.WriteString(str);
		f.WriteString("}; \n ");
	}
		
	f.WriteString("\n");
	f.WriteString(
"GUI_FLASH const GUI_FONT GUI_Font_HZ16 = {  \n\
  GUI_FONTTYPE_PROP /* type of font    */  \n\
  ,16 /* height of font  */ \n\
  ,16 /* space of font y */ \n\
  ,1 /* magnification x */  \n\
  ,1 /* magnification y */  \n\
  ,(void GUI_FLASH *)&GUI_Font_HZ16_Prop1 \n\
}; \n "
	);


	f.Close();

}

⌨️ 快捷键说明

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