1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#include "winfont.h"
#include <windows.h>
struct font_win32 {
HFONT font;
HDC dc;
HBITMAP bitmap;
HBRUSH white;
HBRUSH black;
uint8_t *data;
uint8_t buf[16];
};
#include "jisunih.h"
uint16_t jis2unih(uint8_t jis) {
if (jis & 0x80) {
const uint16_t *tab = jis2unicode_h;
while (tab[0]) {
if (tab[0] == jis) return tab[1];
tab += 2;
}
return 0;
} else {
return jis;
}
}
#include "jisuni.h"
uint16_t jis2uni(uint16_t jis) {
if ((jis>>8) == 0x29) {
return jis2unih(jis & 0xff);
}
const uint16_t *tab = jis2unicode;
while (tab[0]) {
if (tab[0] == jis) return tab[1];
tab += 2;
}
return 0;
}
static const void *winfont_get(const struct fmdsp_font *font,
uint16_t c, enum fmdsp_font_type type) {
struct font_win32 *fw = (struct font_win32 *)font->data;
RECT r = {
0, 0, 8, 16
};
FillRect(fw->dc, &r, fw->white);
wchar_t text[2] = {0};
switch (type) {
case FMDSP_FONT_ANK:
text[0] = jis2unih(c);
TextOut(fw->dc, 0, 0, text, 1);
break;
case FMDSP_FONT_JIS_LEFT:
text[0] = jis2uni(c);
TextOut(fw->dc, 0, 0, text, 1);
break;
case FMDSP_FONT_JIS_RIGHT:
text[0] = jis2uni(c);
TextOut(fw->dc, -8, 0, text, 1);
break;
}
GdiFlush();
// return fw->data;
for (int y = 0; y < 16; y++) {
fw->buf[y] = fw->data[y*4];
}
return fw->buf;
}
struct BITMAPINFO_mono {
BITMAPINFOHEADER bmihead;
RGBQUAD bmicolors[2];
};
bool fmdsp_font_win(struct fmdsp_font *font) {
struct font_win32 *fw = HeapAlloc(
GetProcessHeap(), 0, sizeof(struct font_win32)
);
if (!fw) goto err;
fw->font = CreateFont(16, 0, 0, 0,
FW_NORMAL, FALSE, FALSE, FALSE,
SHIFTJIS_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
NONANTIALIASED_QUALITY, FIXED_PITCH,
L"MS Gothic");
if (!fw->font) goto err_fw;
fw->dc = CreateCompatibleDC(0);
if (!fw->dc) goto err_font;
struct BITMAPINFO_mono bmi = {0};
bmi.bmihead.biSize = sizeof(bmi.bmihead);
bmi.bmihead.biWidth = 8;
bmi.bmihead.biHeight = -16;
bmi.bmihead.biPlanes = 1;
bmi.bmihead.biBitCount = 1;
bmi.bmihead.biCompression = BI_RGB;
bmi.bmihead.biSizeImage = 16;
bmi.bmihead.biClrUsed = 2;
bmi.bmicolors[0].rgbRed = 0xff;
bmi.bmicolors[0].rgbGreen = 0xff;
bmi.bmicolors[0].rgbBlue = 0xff;
fw->bitmap = CreateDIBSection(
fw->dc, (BITMAPINFO *)&bmi,
DIB_RGB_COLORS, (void **)&fw->data,
0, 0);
if (!fw->bitmap) {
MessageBox(0, L"a", L"b", 0);
goto err_dc;
}
SelectObject(fw->dc, fw->bitmap);
SelectObject(fw->dc, fw->font);
fw->white = CreateSolidBrush(RGB(0xff, 0xff, 0xff));
fw->black = CreateSolidBrush(RGB(0x00, 0x00, 0x00));
font->get = winfont_get;
font->data = fw;
font->width_half = 8;
font->height = 16;
return true;
err_dc:
DeleteDC(fw->dc);
err_font:
DeleteObject(fw->font);
err_fw:
HeapFree(GetProcessHeap(), 0, fw);
err:
return false;
}
|