添加LCD字库生成工具
This commit is contained in:
parent
698d233af9
commit
db6c5104f5
|
@ -12,6 +12,7 @@
|
|||
#include "DlgTwain.h"
|
||||
#include "DlgOptJson.h"
|
||||
#include "DlgManualUSB.h"
|
||||
#include "DlgZk.h"
|
||||
|
||||
|
||||
// CDlgMain 对话框
|
||||
|
@ -95,6 +96,10 @@ BOOL CDlgMain::OnInitDialog()
|
|||
page->Create(CDlgManualUSB::IDD, this);
|
||||
insert_page(page, L"USB");
|
||||
|
||||
page = new CDlgZk(this);
|
||||
page->Create(CDlgZk::IDD, this);
|
||||
insert_page(page, L"LCD字库");
|
||||
|
||||
tab_.SetCurSel(2);
|
||||
OnTcnSelchangeTab1(NULL, &lret);
|
||||
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
// DlgInput.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "hgjson.h"
|
||||
#include "DlgZk.h"
|
||||
#include "afxdialogex.h"
|
||||
#include "DlgRange.h"
|
||||
#include "DlgCondition.h"
|
||||
#include "opt_ui/DlgPage.h" // for local_trans
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// known name ...
|
||||
namespace hz_2_py
|
||||
{
|
||||
std::string getLetter(std::string strText, bool head_only = false);
|
||||
};
|
||||
namespace util
|
||||
{
|
||||
std::wstring a2u(const char* a, bool from_utf8 = false);
|
||||
std::string u2a(const wchar_t* u, bool to_utf8 = false);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgZk dialog
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDlgZk, CDialogEx)
|
||||
|
||||
CDlgZk::CDlgZk(CWnd* pParent /*=NULL*/)
|
||||
: CDialogEx(CDlgZk::IDD, pParent)
|
||||
{
|
||||
}
|
||||
|
||||
CDlgZk::~CDlgZk()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::wstring CDlgZk::get_item_text(UINT id)
|
||||
{
|
||||
int l = GetDlgItem(id)->GetWindowTextLengthW();
|
||||
wchar_t* buf = new wchar_t[l + 4];
|
||||
|
||||
l = GetDlgItem(id)->GetWindowTextW(buf, l + 2);
|
||||
buf[l] = 0;
|
||||
|
||||
std::wstring ret(buf);
|
||||
|
||||
delete[] buf;
|
||||
|
||||
return std::move(ret);
|
||||
}
|
||||
|
||||
void CDlgZk::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_COMBO_FONT, font_);
|
||||
DDX_Control(pDX, IDC_COMBO_SIZE, size_);
|
||||
DDX_Control(pDX, IDC_COMBO_SIZE2, o_size_);
|
||||
}
|
||||
BOOL CDlgZk::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
// Set the icon for this dialog. The framework does this automatically
|
||||
// when the application's main window is not a dialog
|
||||
font_.SetCurSel(0);
|
||||
size_.SetCurSel(0);
|
||||
o_size_.SetCurSel(0);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
|
||||
void CDlgZk::regen(void)
|
||||
{
|
||||
std::wstring f(get_item_text(IDC_COMBO_FONT)),
|
||||
fs(get_item_text(IDC_COMBO_SIZE)),
|
||||
t(get_item_text(IDC_EDIT_DATA)),
|
||||
os(get_item_text(IDC_COMBO_SIZE2)),
|
||||
sep(L"×");
|
||||
SIZE out = { _wtoi(os.c_str()), _wtoi(os.c_str() + os.find(sep) + sep.length()) };
|
||||
int h = _wtoi(fs.c_str());
|
||||
wchar_t text[40] = { 0 };
|
||||
HWND hwnd = GetDlgItem(IDC_STATIC_DRAW)->m_hWnd;
|
||||
HDC hdc = ::GetDC(hwnd);
|
||||
char_dc dc(hdc);
|
||||
uint8_t *ptr = NULL;
|
||||
|
||||
dc.set_font(h, f.c_str());
|
||||
sep = L"";
|
||||
for (int i = 0; i < t.length(); ++i)
|
||||
{
|
||||
sep += L"static uint8_t ";
|
||||
text[0] = t[i];
|
||||
text[1] = 0;
|
||||
ptr = dc.lattice(text[0], out);
|
||||
|
||||
std::string ansi(util::u2a(text));
|
||||
ansi = hz_2_py::getLetter(ansi);
|
||||
std::transform(ansi.begin(), ansi.end(), ansi.begin(), tolower);
|
||||
sep += util::a2u(ansi.c_str()) + L"[] = {" + std::to_wstring(out.cx) + L", " + std::to_wstring(out.cy) + L"\r\n\t\t";
|
||||
swprintf_s(text, L", 0x%02X", ptr[0]);
|
||||
sep += text;
|
||||
for (int i = 1; i < out.cx * out.cy / 8; ++i)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
sep += L"\r\n\t\t";
|
||||
else if (i % 8 == 0)
|
||||
sep += L" ";
|
||||
|
||||
if (i % 8 == 0)
|
||||
swprintf_s(text, L", 0x%02X", ptr[i]);
|
||||
else
|
||||
swprintf_s(text, L", 0x%02X", ptr[i]);
|
||||
sep += text;
|
||||
}
|
||||
delete[] ptr;
|
||||
sep += L"\r\n\t};\r\n\r\n";
|
||||
}
|
||||
::ReleaseDC(hwnd, hdc);
|
||||
|
||||
::SetDlgItemTextW(m_hWnd, IDC_EDIT_STATUS, sep.c_str());
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgZk, CDialogEx)
|
||||
ON_EN_CHANGE(IDC_EDIT_DATA, &CDlgZk::OnEnChangeEditData)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_FONT, &CDlgZk::OnCbnSelchangeComboFont)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_SIZE, &CDlgZk::OnCbnSelchangeComboSize)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_SIZE2, &CDlgZk::OnCbnSelchangeComboSize2)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CDlgZk message handlers
|
||||
|
||||
|
||||
void CDlgZk::OnEnChangeEditData()
|
||||
{
|
||||
// TODO: 如果该控件是 RICHEDIT 控件,它将不
|
||||
// 发送此通知,除非重写 CDialogEx::OnInitDialog()
|
||||
// 函数并调用 CRichEditCtrl().SetEventMask(),
|
||||
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
|
||||
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
regen();
|
||||
}
|
||||
|
||||
|
||||
void CDlgZk::OnCbnSelchangeComboFont()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
regen();
|
||||
}
|
||||
|
||||
void CDlgZk::OnCbnSelchangeComboSize()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
regen();
|
||||
}
|
||||
|
||||
void CDlgZk::OnCbnSelchangeComboSize2()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
regen();
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
// CDlgInput dialog
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <utility/known_file.h>
|
||||
#include <coding/coding.h>
|
||||
#include <file/file_util.h>
|
||||
|
||||
|
||||
// Group: 基本设置;图像处理;送纸方式;高级设置;
|
||||
//
|
||||
// Cat: 图像处理;
|
||||
//
|
||||
|
||||
class CDlgZk : public CDialogEx
|
||||
{
|
||||
DECLARE_DYNAMIC(CDlgZk)
|
||||
|
||||
CComboBox font_;
|
||||
CComboBox size_;
|
||||
CComboBox o_size_;
|
||||
|
||||
std::wstring get_item_text(UINT id);
|
||||
|
||||
|
||||
class char_dc
|
||||
{
|
||||
HDC hdc_;
|
||||
HDC src_;
|
||||
HBITMAP bmp_;
|
||||
HBITMAP old_;
|
||||
HFONT font_ = NULL;
|
||||
HFONT oldf_ = NULL;
|
||||
SIZE size_;
|
||||
|
||||
public:
|
||||
char_dc(HDC src) : src_(src)
|
||||
{
|
||||
size_.cx = size_.cy = 256;
|
||||
bmp_ = CreateCompatibleBitmap(src, size_.cx, size_.cy);
|
||||
hdc_ = CreateCompatibleDC(src);
|
||||
old_ = (HBITMAP)SelectObject(hdc_, bmp_);
|
||||
BitBlt(hdc_, 0, 0, size_.cx, size_.cy, src, 0, 0, SRCCOPY);
|
||||
::SetBkMode(hdc_, TRANSPARENT);
|
||||
::SetTextColor(hdc_, RGB(0, 0, 0));
|
||||
}
|
||||
~char_dc()
|
||||
{
|
||||
if (oldf_)
|
||||
::SelectObject(hdc_, oldf_);
|
||||
SelectObject(hdc_, old_);
|
||||
DeleteObject(bmp_);
|
||||
DeleteDC(hdc_);
|
||||
if (font_)
|
||||
DeleteObject(font_);
|
||||
}
|
||||
|
||||
public:
|
||||
bool set_font(int size = 8, const wchar_t* name = L"宋体")
|
||||
{
|
||||
HFONT* old = &oldf_, tmpf = NULL;
|
||||
|
||||
if (font_)
|
||||
{
|
||||
DeleteObject(font_);
|
||||
old = &tmpf;
|
||||
}
|
||||
font_ = ::CreateFontW(size, 0, 0, 0, 0, 0, 0, 0, GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, name);
|
||||
if (font_)
|
||||
*old = (HFONT)::SelectObject(hdc_, font_);
|
||||
|
||||
return font_ != NULL;
|
||||
}
|
||||
uint8_t* lattice(wchar_t ch, SIZE size)
|
||||
{
|
||||
for (int r = 0; r < size_.cy; ++r)
|
||||
{
|
||||
for (int c = 0; c < size_.cx; ++c)
|
||||
{
|
||||
::SetPixel(hdc_, c, r, RGB(255, 255, 255));
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t str[] = { ch, 0 };
|
||||
SIZE rsize = { 0 };
|
||||
POINT center = { 0 };
|
||||
int x = 0,
|
||||
y = 0;
|
||||
uint8_t* buf = NULL, *oper = NULL, val = 0;
|
||||
|
||||
::GetTextExtentPointW(hdc_, str, 1, &rsize);
|
||||
::TextOutW(hdc_, x, y, str, 1);
|
||||
oper = buf = new uint8_t[size.cx * size.cy / 8];
|
||||
center.x = x + rsize.cx / 2;
|
||||
center.y = y + rsize.cy / 2;
|
||||
|
||||
// LCD: 8 lines / unit, from bottom to top, auto increament on x-axis
|
||||
for (int i = 0; i < size.cx * size.cy / 8; ++i)
|
||||
{
|
||||
val = 0;
|
||||
x = i % size.cx;
|
||||
y = i / size.cx * 8;
|
||||
|
||||
#define GET_PIXE(r) \
|
||||
val <<= 1; \
|
||||
val |= ::GetPixel(hdc_, x, r) & 1; \
|
||||
::SetPixel(src_, x, r, ::GetPixel(hdc_, x, r));
|
||||
|
||||
GET_PIXE(y + 7);
|
||||
GET_PIXE(y + 6);
|
||||
GET_PIXE(y + 5);
|
||||
GET_PIXE(y + 4);
|
||||
|
||||
GET_PIXE(y + 3);
|
||||
GET_PIXE(y + 2);
|
||||
GET_PIXE(y + 1);
|
||||
GET_PIXE(y + 0);
|
||||
|
||||
*oper++ = val ^ 0x0ff;
|
||||
BitBlt(src_, size.cx * 2, size.cy * 2, size.cx, size.cy, hdc_, 0, 0, SRCCOPY);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
||||
void regen(void);
|
||||
|
||||
public:
|
||||
CDlgZk(CWnd* pParent = NULL); // standard constructor
|
||||
virtual ~CDlgZk();
|
||||
|
||||
// Dialog Data
|
||||
enum { IDD = IDD_ZK };
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
virtual BOOL OnInitDialog();
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
afx_msg void OnEnChangeEditData();
|
||||
afx_msg void OnCbnSelchangeComboFont();
|
||||
afx_msg void OnCbnSelchangeComboSize();
|
||||
afx_msg void OnCbnSelchangeComboSize2();
|
||||
};
|
Binary file not shown.
|
@ -132,6 +132,7 @@
|
|||
<ClInclude Include="DlgOptJson.h" />
|
||||
<ClInclude Include="DlgRange.h" />
|
||||
<ClInclude Include="DlgTwain.h" />
|
||||
<ClInclude Include="DlgZk.h" />
|
||||
<ClInclude Include="hex_edit.h" />
|
||||
<ClInclude Include="hgjson.h" />
|
||||
<ClInclude Include="hgjsonDlg.h" />
|
||||
|
@ -183,6 +184,7 @@
|
|||
<ClCompile Include="DlgOptJson.cpp" />
|
||||
<ClCompile Include="DlgRange.cpp" />
|
||||
<ClCompile Include="DlgTwain.cpp" />
|
||||
<ClCompile Include="DlgZk.cpp" />
|
||||
<ClCompile Include="hex_edit.cpp" />
|
||||
<ClCompile Include="hgjson.cpp" />
|
||||
<ClCompile Include="hgjsonDlg.cpp" />
|
||||
|
|
|
@ -102,6 +102,9 @@
|
|||
<ClInclude Include="..\..\..\..\code_device\sdk\base\utils.h">
|
||||
<Filter>sane_opt</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DlgZk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="hgjson.cpp">
|
||||
|
@ -173,6 +176,9 @@
|
|||
<ClCompile Include="..\..\..\..\code_device\sdk\base\utils.cpp">
|
||||
<Filter>sane_opt</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DlgZk.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="hgjson.rc">
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue