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

📄 gridpic.cpp

📁 字模转换工具
💻 CPP
字号:
// GridPic.cpp : implementation file
//

#include "stdafx.h"
#include "hanzi.h"
#include "GridPic.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGridPic

CGridPic::CGridPic():m_rect(0,0,0,0)
{
	for(int i=0;i<WIDTH*HEIGHT/8;i++)
		m_mask[i]=0;
	m_clorbak=RGB(255,255,255);
	m_clordot=RGB(0,0,0);
	m_bgrid=0;
	m_align=0;
	

}

CGridPic::~CGridPic()
{
}


BEGIN_MESSAGE_MAP(CGridPic, CStatic)
	//{{AFX_MSG_MAP(CGridPic)
	ON_WM_PAINT()
	ON_WM_MBUTTONDBLCLK()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGridPic message handlers

void CGridPic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect rt=m_rect,wrt;
	GetClientRect(&wrt);
	if(m_rect.IsRectEmpty())
	{
	 m_rect=wrt;
	}

	int xstep,ystep;
	xstep=rt.Width()/WIDTH;
	ystep=rt.Height()/HEIGHT;
	dc.PatBlt(0,0,wrt.Width(),wrt.Height(),PATCOPY);
    dc.FillSolidRect(0,0,rt.Width(),rt.Height(),m_clorbak);
	int i,j,k;
	int hth=ystep*HEIGHT,wth=xstep*WIDTH;
	if(m_bgrid)
	{
		for(i=0,k=0;k<WIDTH&&i<rt.Width();k++,i+=xstep)
		{
			dc.MoveTo(i,0);
			dc.LineTo(i,hth);
			if(k==WIDTH/2)
			{
				dc.MoveTo(i-xstep/2,xstep/2);
			    dc.LineTo(i+xstep/2,xstep/2);
			}

		}
		
		for(i=0,k=0;k<HEIGHT&&i<rt.Height();k++,i+=ystep)
		{
			dc.MoveTo(0,i);
			dc.LineTo(wth,i);
			if(k==HEIGHT/2)
			{
				dc.MoveTo(ystep/2,i-ystep/2);
			    dc.LineTo(ystep/2,i+ystep/2);
			}
		}
		dc.MoveTo(wth,0);
		dc.LineTo(wth,hth);
		dc.MoveTo(0,hth);
		dc.LineTo(wth,hth);
	}
	// SetDot(1,0);
	unsigned char bv,bv1;
   	if(m_align) //v
	{

	 for(i=0;i<WIDTH;i++)
		for(j=0;j<HEIGHT/8;j++)
		{
			bv=m_mask[i*HEIGHT/8+j];
			if(bv==0)continue;
			for(k=0;k<8;k++)
			{
				bv1=bv<<k;
				if(bv1&0x80)
				{
					drawxy(&dc,i,j*8+k);
				}
			}
		}
	}
	else  //h
	{
	 for(i=0;i<HEIGHT;i++)
		for(j=0;j<WIDTH/8;j++)
		{
			bv=m_mask[i*WIDTH/8+j];
			if(bv==0)continue;
			for(k=0;k<8;k++)
			{
				bv1=bv<<k;
				if(bv1&0x80)
				{
					drawxy(&dc,j*8+k,i);
				}
			}
		}
	}
		// Do not call CStatic::OnPaint() for painting messages
}

void CGridPic::OnMButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rt;
	GetClientRect(&rt);
	SetWindowPos(NULL,0,0,rt.Width()*2,rt.Height()*2,SWP_NOMOVE);
	//CStatic::OnMButtonDblClk(nFlags, point);
}

void CGridPic::drawxy(CDC* pdc,int x, int y)
{
    CRect rt=m_rect;
	
	int xstep,ystep;
	xstep=rt.Width()/WIDTH;
	ystep=rt.Height()/HEIGHT;
	pdc->FillSolidRect(x*xstep,y*ystep,xstep,ystep,m_clordot);
	
}

void CGridPic::SetDot(int x, int y)
{
 unsigned char bd,bv=0x80;
 bd=y/8;
 bv>>=(y%8);
 m_mask[x*2+bd]|=bv;
}
unsigned char Hextobyte(char * pstr)
{
char ct1,ct2; 

if(strlen(pstr)<2)
{
	ct1=0;
	ct2=*pstr;
}
else if(strlen(pstr)>2)
{
    pstr++;
	ct1=*pstr++;
	ct2=*pstr;
}
else 
{
	ct1=*pstr++;
    ct2=*pstr;
}
 char vt;
 if(ct1>=48&&ct1<=57)
 {
	 vt=(ct1-48)*16;
 }
 else
 {
	 vt=(ct1-55)*16;
 }
 
 if(ct2>=48&&ct2<=57)
 {
	 vt+=(ct2-48);
 }
 else
 {
	 vt+=(ct2-55);
 }
 return vt;

}
BOOL CGridPic::FillMask(CString strValue)
{
	if(strValue.IsEmpty())
		return FALSE;
	ClrMask();

	strValue.MakeUpper();
	CString strOne;
	unsigned char ione=0;
	int i=0,spos=0,epos=0,nlen=strValue.GetLength();
	while((epos=strValue.Find("\r\xa0",spos))!=-1)
	{
		strValue.Delete(epos,2);
		spos=epos+2;
	}
    epos=spos=0;
	if(strValue.Find("H",0)==-1)
	{
		while(i<(HEIGHT*WIDTH/8) && (epos=strValue.Find(",",spos))!=-1)
		{  
			strOne=strValue.Mid(spos,epos-spos);
			strOne.TrimLeft();
			spos=epos+1;
			ione=Hextobyte(strOne.GetBuffer(0));
			m_mask[i++]=ione;
			// MessageBox(strOne);
		}
	}
	else
	{
		while(i<(HEIGHT*WIDTH/8) && (epos=strValue.Find("H",spos))!=-1)
		{  
			strOne=strValue.Mid(spos,epos-spos);
			strOne.TrimLeft();
			spos=epos+2;
			ione=Hextobyte(strOne.GetBuffer(0));
			m_mask[i++]=ione;
			// MessageBox(strOne);
		}
	}
	return TRUE;
}

void CGridPic::ClrMask()
{
 for(int i=0;i<HEIGHT*WIDTH/8;i++)
	 m_mask[i]=0;
}

void CGridPic::SetGrid(int value)
{
  m_bgrid=value;
}

void CGridPic::SetAlign(int value)
{
 if(m_align==value)return;
 m_align=value;
 HtoV();
}

//DEL void CGridPic::SetRectV(CRect rt)
//DEL {
//DEL   m_rect=rt;
//DEL }

//DEL void CGridPic::AddRectV(int actions)
//DEL {
//DEL 	int pt1=m_rect.right,pt2=m_rect.bottom;
//DEL 	CRect rt;
//DEL 	GetClientRect(&rt);
//DEL 	
//DEL 	if(actions==1)
//DEL 	{
//DEL 		pt1+=16;
//DEL 		pt2+=16;
//DEL 		if((pt1-m_rect.left)>rt.Width())
//DEL 			pt1=m_rect.left+rt.Width();
//DEL 		if((pt2-m_rect.top)>rt.Height())
//DEL 			pt2=m_rect.top+rt.Height();
//DEL 		m_rect.SetRect(m_rect.left,m_rect.top,pt1,pt2);
//DEL 	}
//DEL 	else
//DEL 	{
//DEL 		pt1-=16;
//DEL 		pt2-=16;
//DEL 		if((pt1-m_rect.left)<0)
//DEL 			pt1=m_rect.left+rt.Width();
//DEL 		if((pt2-m_rect.top)<0)
//DEL 			pt2=m_rect.top+rt.Height();
//DEL 		m_rect.SetRect(m_rect.left,m_rect.top,pt1,pt2);
//DEL 	}
//DEL 	 
//DEL }

void CGridPic::DeltaRect(BOOL ack)
{
 
	int pt1=m_rect.right,pt2=m_rect.bottom;
 	CRect rt;
 	GetClientRect(&rt);
 	
 	if(ack)
 	{
 		pt1+=16;
 		pt2+=16;
 		if((pt1-m_rect.left)>rt.Width())
 			pt1=m_rect.left+rt.Width();
 		if((pt2-m_rect.top)>rt.Height())
 			pt2=m_rect.top+rt.Height();
 		m_rect.SetRect(m_rect.left,m_rect.top,pt1,pt2);
 	}
 	else
 	{
 		pt1-=16;
 		pt2-=16;
 		if((pt1-m_rect.left)<16)
 			pt1+=16;
 		if((pt2-m_rect.top)<16)
 			pt2+=16;
 		m_rect.SetRect(m_rect.left,m_rect.top,pt1,pt2);
 	}
}

int CGridPic::GetWidth()
{
  return WIDTH;
}

int CGridPic::GetHeight()
{
  return HEIGHT;
}

unsigned char* CGridPic::GetMask()
{
 return m_mask;
}

void CGridPic::HtoV()
{
  unsigned char temp[HEIGHT*WIDTH/8];
  
  int i,j,k;
  for(i=0;i<HEIGHT*WIDTH/8;i++)
	  temp[i]=0;
for(j=0;j<HEIGHT;j++)
 for(i=0;i<WIDTH/8;i++)
	 {
		 unsigned char bv1, bv=m_mask[j*2+i];
		 for(k=0;k<8;k++)
		 {
			 bv1=bv<<k;
			 if(bv1&0x80)
			 {
				 bv1=(0x80)>>(j%8);
				 temp[(i*8+k)*2+j/8]|=bv1;
			 }
		 }
	 }
	 
   
for(i=0;i<HEIGHT*WIDTH/8;i++)
	  *(m_mask+i)=temp[i];
  
}

void CGridPic::VtoH()
{
 unsigned char temp[HEIGHT*WIDTH/8];
  
  int i,j,k;
  for(i=0;i<HEIGHT*WIDTH/8;i++)
	  temp[i]=0;
for(j=0;j<HEIGHT;j++)
 for(i=0;i<WIDTH/8;i++)
	 {
		 unsigned char bv1, bv=m_mask[j*2+i];
		 for(k=0;k<8;k++)
		 {
			 bv1=bv<<k;
			 if(bv1&0x80)
			 {
				 bv1=(0x80)>>(j%8);
				 temp[(i*8+k)*2+j/8]|=bv1;
			 }
		 }
	 }
	 
   
for(i=0;i<HEIGHT*WIDTH/8;i++)
	  *(m_mask+i)=temp[i];
}

BOOL CGridPic::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	 
	return CStatic::OnEraseBkgnd(pDC);
}

void CGridPic::SetBak(const COLORREF &cor)
{
 m_clordot=cor;
}

void CGridPic::SetFore(const COLORREF &cor)
{
  m_clorbak=cor;
}

⌨️ 快捷键说明

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