TODO feature: Import from a text array; Little Export fix
This commit is contained in:
@@ -207,7 +207,7 @@ namespace McBitFont {
|
||||
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" +
|
||||
" " + (mono || mainForm.frames.Count == 1 ? 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" +
|
||||
@@ -353,7 +353,7 @@ namespace McBitFont {
|
||||
output += cbracket + ((i + idir == imax) && f.Equals(flast) ? "" : ",") + "\n";
|
||||
}
|
||||
}
|
||||
if (packed && (f.width * f.height / 8) % bits > 0) {
|
||||
if (packed && (f.width * f.height) % bits > 0) {
|
||||
// post leftovers in last number
|
||||
|
||||
// should we post a prefix to the number?
|
||||
|
32
McBitFont/Form1.Designer.cs
generated
32
McBitFont/Form1.Designer.cs
generated
@@ -64,6 +64,7 @@
|
||||
openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
importTextToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
importImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -102,7 +103,6 @@
|
||||
chkHexCodes = new System.Windows.Forms.CheckBox();
|
||||
chkRectSelect = new System.Windows.Forms.CheckBox();
|
||||
label3 = new System.Windows.Forms.Label();
|
||||
importTextToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)nudX).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)nudY).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
@@ -535,7 +535,7 @@
|
||||
newToolStripMenuItem.Name = "newToolStripMenuItem";
|
||||
newToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+N";
|
||||
newToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N;
|
||||
newToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
newToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
newToolStripMenuItem.Text = "New";
|
||||
newToolStripMenuItem.ToolTipText = "Create new project";
|
||||
newToolStripMenuItem.Click += newToolStripMenuItem_Click;
|
||||
@@ -546,7 +546,7 @@
|
||||
openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||
openToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+O";
|
||||
openToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O;
|
||||
openToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
openToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
openToolStripMenuItem.Text = "Open";
|
||||
openToolStripMenuItem.ToolTipText = "Open from file";
|
||||
openToolStripMenuItem.Click += openToolStripMenuItem_Click;
|
||||
@@ -557,7 +557,7 @@
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+S";
|
||||
saveToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S;
|
||||
saveToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
saveToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
saveToolStripMenuItem.Text = "Save";
|
||||
saveToolStripMenuItem.ToolTipText = "Save changes";
|
||||
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click_1;
|
||||
@@ -568,16 +568,24 @@
|
||||
saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
|
||||
saveAsToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+S";
|
||||
saveAsToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift | System.Windows.Forms.Keys.S;
|
||||
saveAsToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
saveAsToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
saveAsToolStripMenuItem.Text = "Save as";
|
||||
saveAsToolStripMenuItem.ToolTipText = "Save changes to another file";
|
||||
saveAsToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// importTextToolStripMenuItem1
|
||||
//
|
||||
importTextToolStripMenuItem1.Image = Properties.Resources.folder_table;
|
||||
importTextToolStripMenuItem1.Name = "importTextToolStripMenuItem1";
|
||||
importTextToolStripMenuItem1.Size = new System.Drawing.Size(224, 22);
|
||||
importTextToolStripMenuItem1.Text = "Import text file (very limited)";
|
||||
importTextToolStripMenuItem1.Click += importTextToolStripMenuItem1_Click;
|
||||
//
|
||||
// importImageToolStripMenuItem
|
||||
//
|
||||
importImageToolStripMenuItem.Image = Properties.Resources.z_folder_image;
|
||||
importImageToolStripMenuItem.Name = "importImageToolStripMenuItem";
|
||||
importImageToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
importImageToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
importImageToolStripMenuItem.Text = "Import image";
|
||||
importImageToolStripMenuItem.ToolTipText = "Import image from a file";
|
||||
importImageToolStripMenuItem.Click += importImageToolStripMenuItem_Click;
|
||||
@@ -588,7 +596,7 @@
|
||||
exportToolStripMenuItem.Name = "exportToolStripMenuItem";
|
||||
exportToolStripMenuItem.ShortcutKeyDisplayString = "";
|
||||
exportToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E;
|
||||
exportToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
exportToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
exportToolStripMenuItem.Text = "Export";
|
||||
exportToolStripMenuItem.ToolTipText = "Configure and export data";
|
||||
exportToolStripMenuItem.Click += button1_Click;
|
||||
@@ -599,7 +607,7 @@
|
||||
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
exitToolStripMenuItem.ShortcutKeyDisplayString = "Alt+X";
|
||||
exitToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.X;
|
||||
exitToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
|
||||
exitToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
|
||||
exitToolStripMenuItem.Text = "Exit";
|
||||
exitToolStripMenuItem.ToolTipText = "Quit application";
|
||||
exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
|
||||
@@ -965,14 +973,6 @@
|
||||
label3.TabIndex = 21;
|
||||
label3.Text = "Cursor:";
|
||||
//
|
||||
// importTextToolStripMenuItem1
|
||||
//
|
||||
importTextToolStripMenuItem1.Image = Properties.Resources.folder_table;
|
||||
importTextToolStripMenuItem1.Name = "importTextToolStripMenuItem1";
|
||||
importTextToolStripMenuItem1.Size = new System.Drawing.Size(184, 22);
|
||||
importTextToolStripMenuItem1.Text = "Import text file";
|
||||
importTextToolStripMenuItem1.Click += importTextToolStripMenuItem1_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
|
@@ -1265,7 +1265,9 @@ namespace McBitFont {
|
||||
if (line.Contains("uint31_t")) bits = 32; // Found 32 bit array
|
||||
}
|
||||
string s = line;
|
||||
if (s.IndexOf("//") >= 0) s = s.Remove(s.IndexOf("//")); // Remove comments
|
||||
if (s.Contains("//")) s = s[..s.IndexOf("//")]; // Remove comments
|
||||
if (s.Contains('{')) s = s[(s.IndexOf('{') + 1)..]; // Remove everything before '{'
|
||||
|
||||
var words = s.Split(','); // split a line by commas
|
||||
string w;
|
||||
foreach (var word in words) {
|
||||
@@ -1274,14 +1276,15 @@ namespace McBitFont {
|
||||
w = word.Trim();
|
||||
if (w.Length < 1) continue;
|
||||
|
||||
if (w.IndexOf("0x") >= 0) { // Check if value is written as hexadecimal
|
||||
w = w.Remove(w.IndexOf("0x"), 2);
|
||||
numBase = 16;
|
||||
}
|
||||
if (w.IndexOf("0b") >= 0) { // Check if value is written as binary
|
||||
if (w.Contains("0b") && !w.Contains("0x")) { // Check if value is written as binary
|
||||
w = w.Remove(w.IndexOf("0b"), 2);
|
||||
numBase = 2;
|
||||
}
|
||||
if (w.Contains("0x") ) { // Check if value is written as hexadecimal
|
||||
w = w.Remove(w.IndexOf("0x"), 2);
|
||||
numBase = 16;
|
||||
}
|
||||
|
||||
|
||||
try { // Try to convert a number from text
|
||||
data.Add(Convert.ToUInt32(w, numBase));
|
||||
@@ -1305,21 +1308,52 @@ namespace McBitFont {
|
||||
miniList.Clear();
|
||||
ilMiniatures.Images.Clear();
|
||||
|
||||
FrameMiniature newf;
|
||||
FrameMiniature newf = new();
|
||||
int neww = width;
|
||||
int curFrame = 0;
|
||||
int frameNumIndex = 0;
|
||||
for (int i = 0; i < data.Count; i++) {
|
||||
if (frameNumIndex == 0) {
|
||||
if (width == 0) {
|
||||
neww = (int)data.ElementAt(i);
|
||||
frameNumIndex++;
|
||||
}
|
||||
int curFrame = -1;
|
||||
bool newFrame = true;
|
||||
int i = 0, j = 0;
|
||||
for (int b = 6; b < data.Count; b++) {
|
||||
if (newFrame) {
|
||||
newFrame = false;
|
||||
curFrame++;
|
||||
i = 0; j = 0;
|
||||
if (width == 0) neww = (int)data[b];
|
||||
newf = new(curFrame + first, neww, height);
|
||||
if (width == 0 && neww != 0) continue;
|
||||
}
|
||||
// Fill frame data with current number
|
||||
if (neww != 0)
|
||||
for (int bit = 0; bit < bits; bit++) {
|
||||
if (j >= height) {
|
||||
j = 0;
|
||||
i++;
|
||||
if (!packed && bit != 0) break;
|
||||
}
|
||||
if (i >= neww) break;
|
||||
newf.data[i, j] = (data[b] & (1 << bit)) > 0;
|
||||
j++;
|
||||
}
|
||||
if (i >= neww || b == data.Count - 1 || (i == neww - 1 && j == height) || neww == 0) {
|
||||
newFrame = true;
|
||||
frames.Add(newf);
|
||||
|
||||
var s = (last - first > 0) ? newf.code.ToString().PadLeft(3, '0') : "000";
|
||||
var sHex = (last - first > 0) ? 'x' + Convert.ToString(newf.code, 16).PadLeft(2, '0').ToUpper() : "0x0";
|
||||
var sss = (last - first > 0) ? decodeSymbol(newf.code) : "Single";
|
||||
ilMiniatures.Images.Add(s, (Image)GetMiniPictue(newf));
|
||||
miniList.Items.Add(s, (chkHexCodes.Checked ? sHex : s) + ' ' + sss, s);
|
||||
}
|
||||
// TODO: fill frame.data with current byte
|
||||
// increment NumIndex
|
||||
}
|
||||
prjModified = true;
|
||||
if (miniList.Items.Count > 0) miniList.Items[0].Selected = true;
|
||||
f = frames[0];
|
||||
dotWidth = f.width;
|
||||
dotHeight = f.height;
|
||||
SetNewWH();
|
||||
|
||||
miniList.Refresh();
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
//MessageBox.Show(bits + "-font found. " + data.Count + " numbers (" + data.Count * bits / 8 + " bytes) total\n" + "Start code: " + data.ElementAt(4) + " End code: " + data.ElementAt(5));
|
||||
}
|
||||
|
Reference in New Issue
Block a user