📄 fontodlg.cpp
字号:
// fontoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "fonto.h"
#include "fontoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFontoDlg dialog
CFontoDlg::CFontoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFontoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFontoDlg)
m_sHZCode = _T("程");
m_nWidth = 16;
m_nHeight = 20;
m_sOutputCode = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
mHollowBrush.CreateStockObject(HOLLOW_BRUSH);
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_lfFont.lfWidth=m_nWidth;
m_lfFont.lfHeight=m_nHeight;
m_lfFont.lfEscapement=0;
m_lfFont.lfOrientation=0;
m_lfFont.lfWeight=FW_BOLD;
m_lfFont.lfItalic=0;
m_lfFont.lfUnderline=0;
m_lfFont.lfStrikeOut=0;
m_lfFont.lfCharSet=ANSI_CHARSET;
m_lfFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
m_lfFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
m_lfFont.lfQuality=PROOF_QUALITY;
m_lfFont.lfPitchAndFamily=VARIABLE_PITCH||FF_ROMAN;
strcpy(m_lfFont.lfFaceName,"Times New Roman");
}
void CFontoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFontoDlg)
DDX_Text(pDX, IDC_EDIT_HZ, m_sHZCode);
DDV_MaxChars(pDX, m_sHZCode, 2);
DDX_Text(pDX, IDC_EDIT_Width, m_nWidth);
DDV_MinMaxInt(pDX, m_nWidth, 0, 80);
DDX_Text(pDX, IDC_EDIT_Height, m_nHeight);
DDV_MinMaxInt(pDX, m_nHeight, 0, 80);
DDX_Text(pDX, IDC_EDIT_OUTPUT, m_sOutputCode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFontoDlg, CDialog)
//{{AFX_MSG_MAP(CFontoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_EN_CHANGE(IDC_EDIT_HZ, OnChangeEditHz)
ON_BN_CLICKED(IDC_BUTTON_SELFONT, OnButtonSelfont)
ON_EN_CHANGE(IDC_EDIT_Width, OnChangeEDITWidth)
ON_EN_CHANGE(IDC_EDIT_Height, OnChangeEDITHeight)
ON_BN_CLICKED(IDC_BUTTON_GENALL, OnButtonGenall)
ON_BN_CLICKED(IDC_BUTTON1, OnButton_32x24_all)
ON_BN_CLICKED(IDC_BUTTON2, OnButton_ASC_16x24_all)
ON_BN_CLICKED(IDC_BUTTON3, OnButton_ASC_16x16_All_CCode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFontoDlg message handlers
BOOL CFontoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CFontoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFontoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
/// get item id of FontView Picture and display
CWnd *pWndFontView=GetDlgItem(IDC_STATIC_FONTVIEW);
if(pWndFontView)
{
CPaintDC dc(pWndFontView);
DrawFontView(&dc);
}
CWnd *pWnd_ZoomIn_View=GetDlgItem(IDC_STATIC_ZOOM);
if(pWnd_ZoomIn_View)
{
CPaintDC xdc(pWnd_ZoomIn_View);
DrawFont_ZoomIn(&xdc);
// DrawFontView(&xdc);
}
/// here to set output text for the font in C code
/// top down ,left right
{
int i,j,line_output_bytes_count;
char out_buf[12];
CString output;
for(j=0;j<m_nHeight;j++)
{
int line_dot_count=0;
line_output_bytes_count=0;
for(i=0;i<m_nBytesPerLine;i++)
{
unsigned char bitmap_8_dot=0;
unsigned char mask_8_dot=0x80;
while(mask_8_dot && line_dot_count<m_nActualWidth)
{
if(CharBitmap[j][line_dot_count])
bitmap_8_dot|=mask_8_dot;
mask_8_dot>>=1;
line_dot_count++;
}
wsprintf(out_buf,"0x%02x,",bitmap_8_dot);
output += out_buf;
if(++line_output_bytes_count==20)
{
line_output_bytes_count=0;
output += "\r\n";
}
}
output += "\r\n";
}
SetDlgItemText(IDC_EDIT_OUTPUT,output);
}
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFontoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int CFontoDlg::DrawFontView(CDC *pDC)
{
m_lfFont.lfWidth=m_nWidth;
m_lfFont.lfHeight=m_nHeight;
CFont font;
font.CreateFontIndirect(&m_lfFont);
CFont *old_font=pDC->SelectObject(&font);
COLORREF col_black=0x00000000;
COLORREF col_WHITE=0x00ffffff;
COLORREF bkColor=pDC->GetBkColor();
pDC->SetBkColor(col_WHITE);
COLORREF forColor=pDC->SetTextColor(col_black);
pDC->TextOut(0,0,m_sHZCode);
pDC->SetBkColor(bkColor);
pDC->SetTextColor(forColor);
pDC->SelectObject(old_font);
int w;
if(m_sHZCode.GetLength()>1)
w=m_nWidth<<1;
else
w=m_nWidth;
for(int i=0;i<m_nHeight;i++)
{
POINT xy;
xy.y=i;
for(int j=0;j<w;j++)
{
xy.x=j;
COLORREF pix_col;
pix_col=pDC->GetPixel(xy);
if(pix_col==0x00)
{
CharBitmap[i][j]=1;
}
else
{
CharBitmap[i][j]=0;
}
}
}
m_nActualWidth=w;
m_nBytesPerLine=(w+7)/8;
return 1;
}
int CFontoDlg::DrawFont_ZoomIn(CDC *pDC)
{
POINT xy;
int w;
if(m_sHZCode.GetLength()>1)
w=m_nWidth<<1;
else
w=m_nWidth;
pDC->SetBkMode(TRANSPARENT);
for(int j=0;j<=w;j++)
{
xy.x=j*5;
xy.y=0;
pDC->MoveTo(xy);
xy.y=m_nHeight*5;
pDC->LineTo(xy);
}
for(int i=0;i<=m_nHeight;i++)
{
xy.y=i*5;
xy.x=0;
pDC->MoveTo(xy);
xy.x=w*5;
pDC->LineTo(xy);
}
COLORREF pix_col;
pix_col=0x000000ff;
for(j=0;j<m_nHeight;j++)
{
for(i=0;i<w;i++)
{
if(CharBitmap[j][i])
{
for(int m=0;m<4;m++)
for(int n=0;n<4;n++)
{
xy.x=i*5+1+n;
xy.y=j*5+1+m;
// now fill the rect of (i,j)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -