Skip to content

Commit 274a1b3

Browse files
committed
Fixed Bugs & Macros
Properly create headers from `.sfl` files, keep the macros uniform for all. And fix the not writing bug for sfl file Fix grammar for psf1 file produced headers
1 parent e39c324 commit 274a1b3

File tree

4 files changed

+44
-58
lines changed

4 files changed

+44
-58
lines changed

inc/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
#define ___str(a) #a
44

5-
#define VERSION ___str(2.1.1)
5+
#define VERSION ___str(2.1.3)

src/translator/psf1.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int Translator::read_psf1(uint16_t font_mode, uint16_t font_height) {
1717
//
1818
// hope that buffer is verified properly
1919

20+
Translator::outputFile.open(Prefs.getOutputFile());
21+
2022
uint16_t length = font_height * PSF1_FONT_WIDTH;
2123
bool has_unicode = (font_mode & 0x02) != 0,
2224
has_unicode_seq = (font_mode & 0x04) != 0;
@@ -76,7 +78,7 @@ int Translator::read_psf1(uint16_t font_mode, uint16_t font_height) {
7678
<< "\n\n\n#define " << definedMacros[1] << " 0"
7779
<< "\n\n#define " << definedMacros[2] << " 0x3604"
7880
<< "\n\n#define " << definedMacros[3] << " " << std::to_string(font_height)
79-
<< "\n\n#define " << definedMacros[4] << " " << std::to_string(PSF1_FONT_WIDTH)
81+
<< "\n\n#define " << definedMacros[4] << " " << std::to_string(PSF1_FONT_WIDTH)
8082
<< "\n\n#define " << definedMacros[5]
8183
<< " \\\n{\\\n\t";
8284

@@ -228,8 +230,14 @@ int Translator::read_psf1(uint16_t font_mode, uint16_t font_height) {
228230
Translator::outputFile << "\\\n\t/* ";
229231

230232
if (Prefs.isFontComments() && has_unicode) {
231-
Translator::outputFile << " \\\n\t\tEquivalent Unicode characters: "
232-
<< conv.to_bytes(mappings[i]) << " \\\n\t\t";
233+
234+
if (mappings[i].length() > 1) {
235+
Translator::outputFile << " \\\n\t\tEquivalent Unicode characters: ";
236+
}
237+
else {
238+
Translator::outputFile << " \\\n\t\tEquivalent Unicode character: ";
239+
}
240+
Translator::outputFile << conv.to_bytes(mappings[i]) << " \\\n\t\t";
233241
}
234242

235243
if (Prefs.isCharInfo()) {

src/translator/sfl.cpp

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -70,74 +70,52 @@ int Translator::sfl() {
7070
{
7171
// write macros to file
7272
std::vector<std::string> definedMacros;
73-
definedMacros.reserve(5);
73+
definedMacros.reserve(6);
7474

75-
line = "____" + std::regex_replace(line, std::regex("-"), "_");
75+
// line = "____" + std::regex_replace(line, std::regex("-"), "_");
76+
line = "____" + fontType + "_" + std::to_string(font_width) + "x"
77+
+ std::to_string(font_height) + "_";
7678
std::transform(line.begin(), line.end(), line.begin(), ::toupper);
7779

7880
definedMacros.push_back(line);
7981

80-
81-
Translator::outputFile << "#ifndef " << line << "\n";
82-
Translator::outputFile << "#define " << line << "\n\n\n";
83-
84-
line = "type_" + fontType + "_" +
85-
std::to_string(font_width) + "x" + std::to_string(font_height);
86-
87-
std::transform(
88-
line.begin(), line.end(),
89-
line.begin(), ::toupper
90-
);
82+
line = "TYPE_PSF1_8X18";
9183
definedMacros.push_back(line);
92-
Translator::outputFile << "#define " << line <<
93-
" ";
94-
95-
if (!Prefs.isCPU()) {
96-
Translator::outputFile << 5;
97-
}
98-
else {
99-
Translator::outputFile << 0;
100-
}
101-
102-
Translator::outputFile << "\n\n";
103-
104-
line = "font_" + fontType + "_" +
105-
std::to_string(font_width) + "x" +
106-
std::to_string(font_height);
107-
tmp = line + "_width";
108-
line.append("_height");
109-
110-
std::transform(
111-
line.begin(), line.end(),
112-
line.begin(), ::toupper
113-
);
114-
std::transform(
115-
tmp.begin(), tmp.end(),
116-
tmp.begin(), ::toupper
117-
);
11884

85+
line = "PSF1_SIGNATURE";
11986
definedMacros.push_back(line);
120-
definedMacros.push_back(tmp);
12187

122-
Translator::outputFile << "#define " << line <<
123-
" " << font_height << "\n\n";
124-
Translator::outputFile << "#define " << tmp <<
125-
" " << font_width << "\n\n\n";
88+
line = fontType + "_" + std::to_string(font_width) + "x"
89+
+ std::to_string(font_height) + "_height";
90+
std::transform(line.begin(), line.end(), line.begin(), ::toupper);
91+
definedMacros.push_back(line);
12692

93+
line = fontType + "_" + std::to_string(font_width) + "x"
94+
+ std::to_string(font_height) + "_width";
95+
std::transform(line.begin(), line.end(), line.begin(), ::toupper);
96+
definedMacros.push_back(line);
12797

128-
line = "decl_" + fontType + "_" +
129-
std::to_string(font_width) + "x" +
130-
std::to_string(font_height);
131-
std::transform(
132-
line.begin(), line.end(),
133-
line.begin(), ::toupper
134-
);
98+
line = "decl_" + fontType + "_" + std::to_string(font_width)
99+
+ "x" + std::to_string(font_height);
100+
std::transform(line.begin(), line.end(), line.begin(), ::toupper);
135101
definedMacros.push_back(line);
136102

137-
Translator::outputFile << "#define " << line <<
138-
" \\\n{\\\n\t";
103+
104+
if (fontType == "psf1") {
105+
line = " 0x3604";
106+
} else {
107+
line = "";
108+
}
139109

140110

111+
Translator::outputFile << "#ifndef " << definedMacros[0]
112+
<< "\n#define " << definedMacros[0]
113+
<< "\n\n\n#define " << definedMacros[1] << " 0"
114+
<< "\n\n#define " << definedMacros[2] << line
115+
<< "\n\n#define " << definedMacros[3] << " " << std::to_string(font_height)
116+
<< "\n\n#define " << definedMacros[4] << " " << std::to_string(font_width)
117+
<< "\n\n#define " << definedMacros[5]
118+
<< " \\\n{\\\n\t";
141119

142120

143121
if (!Prefs.isLogSuppressed()) {

src/translator_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Translator::translate_main() {
3434
return;
3535
}
3636

37-
Translator::outputFile.open(Prefs.getOutputFile());
37+
// Translator::outputFile.open(Prefs.getOutputFile());
3838

3939
if (
4040
std::filesystem::path(Prefs.getInputFile())

0 commit comments

Comments
 (0)