Export is done (I think)

This commit is contained in:
Anton Mukhin
2023-05-12 10:59:35 +03:00
parent a89bbc59ed
commit 302977c3f4
4 changed files with 157 additions and 86 deletions

View File

@@ -82,6 +82,8 @@ namespace McBitFont {
int lines = cbLines.SelectedIndex;
int format = cbFormat.SelectedIndex;
bool mono = mainForm.monospaced;
int lineslim = (int)nudXLines.Value;
int fcount = mainForm.frames.Count;
int imin, jmin, imax, jmax, idir, jdir;
@@ -130,28 +132,28 @@ namespace McBitFont {
jdir = -1;
}
} else {
if (cbHDir.SelectedIndex == 0) {
// Rows; Left to right
jmin = 0;
jmax = mainForm.dotHeight;
jdir = 1;
} else {
// Rows; Right to left
jmin = mainForm.dotHeight - 1;
jmax = -1;
jdir = -1;
}
if (cbVDir.SelectedIndex == 0) {
// Rows; Top to bottom
// Rows; Left to right
imin = 0;
imax = mainForm.dotWidth;
imax = mainForm.dotHeight;
idir = 1;
} else {
// Rows; Bottom to top
imin = mainForm.dotWidth - 1;
// Rows; Right to left
imin = mainForm.dotHeight - 1;
imax = -1;
idir = -1;
}
if (cbHDir.SelectedIndex == 0) {
// Rows; Top to bottom
jmin = 0;
jmax = mainForm.dotWidth;
jdir = 1;
} else {
// Rows; Bottom to top
jmin = mainForm.dotWidth - 1;
jmax = -1;
jdir = -1;
}
}
@@ -223,7 +225,7 @@ namespace McBitFont {
uint b = 0; // current number bits
int t, x, y; // t - calculated bit number; x - actual x; y - actual y
if (com && lines != 1) {
if (com && lines != 1 && fcount > 1) {
// Comments enabled and other than "1 symbol per line" selected
// Print a symbol comment before its data
output += " // " + f.code.ToString() + " --> " + mainForm.decodeSymbol(f.code) + "\n";
@@ -233,16 +235,27 @@ namespace McBitFont {
output += " ";
numcount = 0;
}
if (!mono && mainForm.frames.Count > 1) {
if (!mono && fcount > 1) {
// Not a single image; Variable width font - lets post the width as a 1st number
// Should we post a prefix to the number?
pref = (!cbZeroes.Checked && ((f.width < 10 && nbase == 16) || (f.width < 2 && nbase == 2))) ? "" : prefix;
output += " " + pref + Convert.ToString(f.width, nbase).PadLeft(pad, '0') + "," + (lines == 1 ? " " : "\n");
output += (lines != 1 ? " " : "") + pref + Convert.ToString(f.width, nbase).PadLeft(pad, '0') + (lines != 0 ? (lines == 1 ? ", " : "") : ",\n");
// Count posted numbers
numcount++;
if (lines != 2) numcount = 0;
if (lines == 2 && numcount >= lineslim) {
numcount = 0;
output += "\n ";
}
}
if (lines == 2 && numcount == 0) {
// "X numbers per line" - first line of a symbol offset
output += " ";
}
//Figure out mins and maxes for variable width fonts
if (!mono) {
if (!mono && fcount > 1) {
if (cbOrder.SelectedIndex == 0) {
if (cbHDir.SelectedIndex == 0) {
// Columns; Left to right
@@ -259,19 +272,19 @@ namespace McBitFont {
jmin = f.height - 1;
}
} else {
if (cbHDir.SelectedIndex == 0) {
if (cbVDir.SelectedIndex == 0) {
// Rows; Left to right
jmax = f.height;
imax = f.height;
} else {
// Rows; Right to left
jmin = f.height - 1;
imin = f.height - 1;
}
if (cbVDir.SelectedIndex == 0) {
if (cbHDir.SelectedIndex == 0) {
// Rows; Top to bottom
imax = f.width;
jmax = f.width;
} else {
// Rows; Bottom to top
imin = f.width - 1;
jmin = f.width - 1;
}
}
}
@@ -315,6 +328,11 @@ namespace McBitFont {
// count posted numbers
numcount++;
if (lines == 2 && numcount >= lineslim && !(j + jdir == jmax && i + idir == imax)) {
// "X numbers per line" - line break
numcount = 0;
output += ",\n ";
}
}
}
if (lines == 0) {
@@ -325,12 +343,18 @@ namespace McBitFont {
if (lines == 1) {
// "1 symbol per line" - closing line
if (!f.Equals(flast)) output += ",";
if (com) {
if (com && fcount > 1) {
//...with a comment
output += " // " + f.code.ToString() + " --> " + mainForm.decodeSymbol(f.code);
}
output += "\n";
}
if (lines == 2) {
// "X numbers per line" - closing line
if (!f.Equals(flast)) output += ",";
output += "\n";
numcount = 0;
}
}
// Close array definition
output += "};\n";
@@ -345,7 +369,7 @@ namespace McBitFont {
MessageBox.Show("Cannot pack the font meta header into 2D array!\nChoose 1D array or disable the meta header.\n(Setting array format to 1D array)", "No header in 2D array!", MessageBoxButtons.OK, MessageBoxIcon.Information);
cbFormat.SelectedIndex = 0;
}
if (!mainForm.monospaced && cbFormat.SelectedIndex == 1) {
if (!mainForm.monospaced && cbFormat.SelectedIndex == 1 && mainForm.frames.Count > 1) {
MessageBox.Show("Cannot pack the variable width font into 2D array!\n(Setting array format to 1D array)", "2D arrays are for monospaced fonts only!", MessageBoxButtons.OK, MessageBoxIcon.Information);
cbFormat.SelectedIndex = 0;
}
@@ -356,5 +380,15 @@ namespace McBitFont {
cbLines.Enabled = true;
}
}
private void cbLines_SelectedIndexChanged(object sender, EventArgs e) {
if (cbLines.SelectedIndex == 2) {
nudXLines.Enabled = true;
lblXLines.Enabled = true;
} else {
nudXLines.Enabled = false;
lblXLines.Enabled = false;
}
}
}
}