150 lines
3.1 KiB
C++
150 lines
3.1 KiB
C++
#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();
|
|
};
|