From 4d39b3586e3886b822c23e0162b0af6fb0998888 Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Wed, 21 May 2025 12:16:44 +0300 Subject: [PATCH] TODO features: V "Packed" fonts export V "Bytes total comment in export --- McBitFont/Export.cs | 24 +++++++++++++++++++----- TODO.txt | 3 ++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/McBitFont/Export.cs b/McBitFont/Export.cs index 7c8ce21..f4c593e 100644 --- a/McBitFont/Export.cs +++ b/McBitFont/Export.cs @@ -76,6 +76,7 @@ namespace McBitFont { private void btnGenerate_Click(object sender, EventArgs e) { string output = ""; + int bTotal = 0; txtOutput.Clear(); bool com = cbComments.Checked; bool hdr = cbHeader.Checked; @@ -90,7 +91,7 @@ namespace McBitFont { if (com) { // Header comments - output += comments["header"]; + //output += comments["header"]; output += comments["scan_order"] + cbOrder.Text + "\n"; output += comments["scan_hdir"] + cbHDir.Text + "\n"; output += comments["scan_vdir"] + cbVDir.Text + "\n\n"; @@ -201,16 +202,17 @@ namespace McBitFont { 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" + + " " + (packed ? "1" : "0") + ", // Is it a packed font?\n" + " " + (mono ? mainForm.frames.First().width.ToString() : "0") + ", // Font width in pixels; 0 - variable width\n" + " " + mainForm.frames.First().height.ToString() + ", // Font height in pixels\n" + " 0, // Font space (between symbols) in pixels\n" + " " + mainForm.frames.First().code.ToString() + ", // First character code\n" + " " + mainForm.frames.Last().code.ToString() + ", // Last character code\n" ; + bTotal += 6; // Count bytes total } // Brackets for 2D array definition @@ -243,6 +245,7 @@ namespace McBitFont { // Should we post a prefix to the number? pref = (!cbZeroes.Checked && ((f.width < 10 && nbase == 16) || (f.width < 2 && nbase == 2))) ? "" : prefix; output += (lines != 1 ? " " : "") + pref + Convert.ToString(f.width, nbase).PadLeft(pad, '0') + (lines != 0 ? (lines == 1 ? ", " : "") : ",\n"); + bTotal++; // Count bytes total // Count posted numbers numcount++; if (lines != 2) numcount = 0; @@ -333,6 +336,7 @@ namespace McBitFont { // 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'); + bTotal++; // Count bytes total // count posted numbers numcount++; @@ -353,7 +357,8 @@ namespace McBitFont { // 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'); + output += (numcount > 0? ", " : "") + pref + Convert.ToString(b, nbase).PadLeft(pad, '0'); + bTotal++; // Count bytes total // count posted numbers numcount++; @@ -377,6 +382,12 @@ namespace McBitFont { // Close array definition output += "};\n"; + // Add header and bytes total counter + if (com) { + output = "// Bytes total: " + bTotal.ToString() + "\n" + output; + output = comments["header"] + output; + } + txtOutput.Text = output; txtOutput.SelectionStart = 0; txtOutput.ScrollToCaret(); @@ -400,6 +411,10 @@ namespace McBitFont { } private void cbLines_SelectedIndexChanged(object sender, EventArgs e) { + if (cbLines.SelectedIndex == 0 && cbPacked.Checked) { + MessageBox.Show("Cannot make one line per column/row in packed font as there are bytes used in several columns/rows!\n(Setting text format to 1 Symbol per line)", "No 1 Symbol per line for packed fonts!", MessageBoxButtons.OK, MessageBoxIcon.Information); + cbLines.SelectedIndex = 1; + } if (cbLines.SelectedIndex == 2) { nudXLines.Enabled = true; lblXLines.Enabled = true; @@ -410,8 +425,7 @@ namespace McBitFont { } private void cbPacked_CheckedChanged(object sender, EventArgs e) { - cbLines.Enabled = !cbPacked.Checked; - if (cbPacked.Checked) cbLines.SelectedIndex = 1; + if (cbPacked.Checked && cbLines.SelectedIndex == 0) cbLines.SelectedIndex = 1; } } } diff --git a/TODO.txt b/TODO.txt index b52b3f5..ccf8c6a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -11,6 +11,7 @@ V Delete symbols before/after selected - Image import from a file - Import from a text array - Rectangle selection to mass-paint, shift and mirror pixels -- "Packed" fonts export +V "Packed" fonts export +V "Bytes total comment in export Bugs: