WIP: Packed fonts...

This commit is contained in:
Anton Mukhin
2025-05-20 17:08:42 +03:00
parent ca42d3819f
commit 5e55c0a5ea
5 changed files with 333 additions and 306 deletions

View File

@@ -38,16 +38,16 @@ namespace McBitFont {
"//\n" +
"//\n"
);
comments.Add("scan_order", "// Scan order: ");
comments.Add("scan_hdir", "// Horizontal direction: ");
comments.Add("scan_vdir", "// Vertical direction: ");
comments.Add("scan_order", "// Scan order: ");
comments.Add("scan_hdir", "// Horizontal direction: ");
comments.Add("scan_vdir", "// Vertical direction: ");
comments.Add("num_bit_order", "// Bit order: ");
comments.Add("num_base", "// Numbers base: ");
comments.Add("num_size", "// Numbers size: ");
comments.Add("num_base", "// Numbers base: ");
comments.Add("num_size", "// Numbers size: ");
comments.Add("text_format", "// Text format: ");
comments.Add("text_lines", "// Numbers per line: ");
comments.Add("text_format", "// Text format: ");
comments.Add("text_lines", "// Numbers per line: ");
comments.Add("font_header_map",
"// Font header map:\n" +
@@ -79,6 +79,7 @@ namespace McBitFont {
txtOutput.Clear();
bool com = cbComments.Checked;
bool hdr = cbHeader.Checked;
bool packed = cbPacked.Checked;
int lines = cbLines.SelectedIndex;
int format = cbFormat.SelectedIndex;
bool mono = mainForm.monospaced;
@@ -156,7 +157,7 @@ namespace McBitFont {
}
}
// C data type selection
ushort bits = 8;
string dataType = "uint8_t";
switch (cbNumSize.SelectedIndex) {
@@ -197,9 +198,10 @@ namespace McBitFont {
}
// Array definition
if ( format == 0 || format == 1 ) output += "const " + dataType + " " + mainForm.prjName + "[]" + (format==1?"[]":"") + " = {\n";
if (format == 0 || format == 1) output += "const " + dataType + " " + mainForm.prjName + "[]" + (format == 1 ? "[]" : "") + " = {\n";
// Should we add the meta header?
// TODO: PACKED FONT FLAG!!!! ==================================
if (hdr) {
output +=
" // Meta header\n" +
@@ -210,17 +212,17 @@ namespace McBitFont {
" " + mainForm.frames.Last().code.ToString() + ", // Last character code\n"
;
}
// Brackets for 2D array definition
string obracket = format == 1 ? "{ " : "";
string cbracket = format == 1 ? " }" : "";
// Number output counter
int numcount = 0;
if (com) output += " // Data:\n";
MainForm.FrameMiniature flast = mainForm.frames.Last();
foreach ( MainForm.FrameMiniature f in mainForm.frames) {
foreach (MainForm.FrameMiniature f in mainForm.frames) {
// For each frame
uint b = 0; // current number bits
int t, x, y; // t - calculated bit number; x - actual x; y - actual y
@@ -289,6 +291,7 @@ namespace McBitFont {
}
}
t = jdir < 0 ? bits+1 : -1;
for (int i = imin; i != imax; i += idir) {
if (lines == 0) {
// "Column/Row per line" - new line offset
@@ -296,8 +299,13 @@ namespace McBitFont {
numcount = 0;
}
for (int j = jmin; j != jmax; j += jdir) {
if (jdir < 0) t = jmin - j;
else t = j;
if (packed) {
t += jdir;
if (t < 0 || t % bits == 0) t = jdir < 0 ? bits : 0;
} else {
if (jdir < 0) t = jmin - j;
else t = j;
}
if (t % bits == 0) b = 0;
if (cbOrder.SelectedIndex == 0) { // Columns
@@ -314,9 +322,9 @@ namespace McBitFont {
// MSB on top/Left
b |= (uint)(1 << (bits - (t % bits) - 1));
}
}
if (((t + 1) % bits == 0) || j + jdir == jmax) {
if (((t + 1) % bits == 0) || (j + jdir == jmax && !packed)) {
// we have filled a number with bits - let's post it
// should we post a comma before the number?
@@ -337,9 +345,19 @@ namespace McBitFont {
}
if (lines == 0) {
// "Column/Row per line" - closing line
output += cbracket + ((i+idir==imax) && f.Equals(flast) ? "" : ",") + "\n";
output += cbracket + ((i + idir == imax) && f.Equals(flast) ? "" : ",") + "\n";
}
}
if (packed && (f.width * f.height / 8) % bits > 0) {
// post leftovers in last byte
// should we post a prefix to the number?
pref = (!cbZeroes.Checked && ((b < 10 && nbase == 16) || (b < 2 && nbase == 2))) ? "" : prefix;
output += ", " + pref + Convert.ToString(b, nbase).PadLeft(pad, '0');
// count posted numbers
numcount++;
}
if (lines == 1) {
// "1 symbol per line" - closing line
if (!f.Equals(flast) && f.width > 0) output += ",";
@@ -390,5 +408,10 @@ namespace McBitFont {
lblXLines.Enabled = false;
}
}
private void cbPacked_CheckedChanged(object sender, EventArgs e) {
cbLines.Enabled = !cbPacked.Checked;
if (cbPacked.Checked) cbLines.SelectedIndex = 1;
}
}
}