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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// license:BSD-3-Clause
// copyright-holders:Maurizio Petrarota
/***************************************************************************
ui/cmdrender.h
UI command render fonts.
***************************************************************************/
#include "ui/uicmd14.fh"
#include "ui/cmddata.h"
void convert_command_glyph(std::string &str)
{
int j;
int len = str.length();
int buflen = (len + 2) * 2;
char *d = global_alloc_array(char, buflen);
for (int i = j = 0; i < len;)
{
fix_command_t *fixcmd = nullptr;
char32_t uchar;
int ucharcount = uchar_from_utf8(&uchar, str.substr(i).c_str(), len - i);
if (ucharcount == -1)
break;
else if (ucharcount != 1)
goto process_next;
else if (str[i] == '\n')
uchar = '\n';
else if (str[i] == COMMAND_CONVERT_TEXT)
{
if (str[i] == str[i + 1])
++i;
else
{
fix_strings_t *fixtext = convert_text;
for (; fixtext->glyph_code; ++fixtext)
{
if (!fixtext->glyph_str_len)
fixtext->glyph_str_len = strlen(fixtext->glyph_str);
if (strncmp(fixtext->glyph_str, str.substr(i + 1).c_str(), fixtext->glyph_str_len) == 0)
{
uchar = fixtext->glyph_code + COMMAND_UNICODE;
i += strlen(fixtext->glyph_str);
break;
}
}
}
}
else if (str[i] == COMMAND_DEFAULT_TEXT)
fixcmd = default_text;
else if (str[i] == COMMAND_EXPAND_TEXT)
fixcmd = expand_text;
if (fixcmd)
{
if (str[i] == str[i + 1])
i++;
else
{
for (; fixcmd->glyph_code; ++fixcmd)
if (str[i + 1] == fixcmd->glyph_char)
{
uchar = fixcmd->glyph_code + COMMAND_UNICODE;
++i;
break;
}
}
}
process_next:
i += ucharcount;
ucharcount = utf8_from_uchar(d + j, buflen - j - 1, uchar);
if (ucharcount == -1)
break;
j += ucharcount;
}
d[j] = '\0';
str = d;
global_free_array(d);
}
void render_font::render_font_command_glyph()
{
emu_file ramfile(OPEN_FLAG_READ);
if (ramfile.open_ram(font_uicmd14, sizeof(font_uicmd14)) == osd_file::error::NONE)
load_cached_cmd(ramfile, 0);
}
bool render_font::load_cached_cmd(emu_file &file, uint32_t hash)
{
uint64_t filesize = file.size();
uint8_t header[CACHED_HEADER_SIZE];
uint32_t bytes_read = file.read(header, CACHED_HEADER_SIZE);
if (bytes_read != CACHED_HEADER_SIZE)
return false;
if (header[0] != 'f' || header[1] != 'o' || header[2] != 'n' || header[3] != 't')
return false;
if (header[4] != (uint8_t)(hash >> 24) || header[5] != (uint8_t)(hash >> 16) || header[6] != (uint8_t)(hash >> 8) || header[7] != (uint8_t)hash)
return false;
m_height_cmd = (header[8] << 8) | header[9];
m_yoffs_cmd = (int16_t)((header[10] << 8) | header[11]);
uint32_t numchars = (header[12] << 24) | (header[13] << 16) | (header[14] << 8) | header[15];
if (filesize - CACHED_HEADER_SIZE < numchars * CACHED_CHAR_SIZE)
return false;
m_rawdata_cmd.resize(filesize - CACHED_HEADER_SIZE);
bytes_read = file.read(&m_rawdata_cmd[0], filesize - CACHED_HEADER_SIZE);
if (bytes_read != filesize - CACHED_HEADER_SIZE)
{
m_rawdata_cmd.clear();
return false;
}
uint64_t offset = numchars * CACHED_CHAR_SIZE;
for (int chindex = 0; chindex < numchars; chindex++)
{
const uint8_t *info = reinterpret_cast<uint8_t *>(&m_rawdata_cmd[chindex * CACHED_CHAR_SIZE]);
int chnum = (info[0] << 8) | info[1];
if (!m_glyphs_cmd[chnum / 256])
m_glyphs_cmd[chnum / 256] = new glyph[256];
glyph &gl = m_glyphs_cmd[chnum / 256][chnum % 256];
if (chnum >= COMMAND_UNICODE && chnum < COMMAND_UNICODE + COLOR_BUTTONS)
gl.color = color_table[chnum - COMMAND_UNICODE];
gl.width = (info[2] << 8) | info[3];
gl.xoffs = (int16_t)((info[4] << 8) | info[5]);
gl.yoffs = (int16_t)((info[6] << 8) | info[7]);
gl.bmwidth = (info[8] << 8) | info[9];
gl.bmheight = (info[10] << 8) | info[11];
gl.rawdata = &m_rawdata_cmd[offset];
offset += (gl.bmwidth * gl.bmheight + 7) / 8;
if (offset > filesize - CACHED_HEADER_SIZE)
{
m_rawdata_cmd.clear();
return false;
}
}
return true;
}
|