7 Commits

Author SHA1 Message Date
Anton Mukhin
cc161169f1 Add icons 9x9 example 2023-05-12 16:28:12 +03:00
Anton Mukhin
0ba03444d1 Add/Remove symbols 2023-05-12 14:08:21 +03:00
Anton Mukhin
302977c3f4 Export is done (I think) 2023-05-12 10:59:35 +03:00
a89bbc59ed Merge branch 'rich-text-experiment' 2023-05-12 04:37:24 +03:00
691b87b842 WIP: working on text formats 2023-05-12 04:35:26 +03:00
Anton Mukhin
ceddd5f66f WIP: export text formats 2023-05-11 17:21:07 +03:00
Anton Mukhin
84561f1ac1 rich text box test 1 2023-05-11 14:00:37 +03:00
5 changed files with 351 additions and 161 deletions

View File

@@ -37,8 +37,8 @@
this.cbNumSize = new System.Windows.Forms.ComboBox();
this.cbNumBase = new System.Windows.Forms.ComboBox();
this.gbText = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.lblXLines = new System.Windows.Forms.Label();
this.nudXLines = new System.Windows.Forms.NumericUpDown();
this.cbLines = new System.Windows.Forms.ComboBox();
this.cbFormat = new System.Windows.Forms.ComboBox();
this.btnGenerate = new System.Windows.Forms.Button();
@@ -47,7 +47,7 @@
this.gbOptions.SuspendLayout();
this.gbNumbers.SuspendLayout();
this.gbText.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudXLines)).BeginInit();
this.SuspendLayout();
//
// txtOutput
@@ -65,6 +65,7 @@
this.txtOutput.Size = new System.Drawing.Size(529, 507);
this.txtOutput.TabIndex = 0;
this.txtOutput.Text = "";
this.txtOutput.WordWrap = false;
//
// gbScan
//
@@ -216,8 +217,8 @@
//
// gbText
//
this.gbText.Controls.Add(this.label1);
this.gbText.Controls.Add(this.numericUpDown1);
this.gbText.Controls.Add(this.lblXLines);
this.gbText.Controls.Add(this.nudXLines);
this.gbText.Controls.Add(this.cbLines);
this.gbText.Controls.Add(this.cbFormat);
this.gbText.Location = new System.Drawing.Point(5, 234);
@@ -227,34 +228,34 @@
this.gbText.TabStop = false;
this.gbText.Text = "Text format";
//
// label1
// lblXLines
//
this.label1.AutoSize = true;
this.label1.Enabled = false;
this.label1.Location = new System.Drawing.Point(10, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 9;
this.label1.Text = "X numbers:";
this.lblXLines.AutoSize = true;
this.lblXLines.Enabled = false;
this.lblXLines.Location = new System.Drawing.Point(10, 76);
this.lblXLines.Name = "lblXLines";
this.lblXLines.Size = new System.Drawing.Size(60, 13);
this.lblXLines.TabIndex = 9;
this.lblXLines.Text = "X numbers:";
//
// numericUpDown1
// nudXLines
//
this.numericUpDown1.Enabled = false;
this.numericUpDown1.Location = new System.Drawing.Point(76, 73);
this.numericUpDown1.Maximum = new decimal(new int[] {
this.nudXLines.Enabled = false;
this.nudXLines.Location = new System.Drawing.Point(76, 73);
this.nudXLines.Maximum = new decimal(new int[] {
64,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
this.nudXLines.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(55, 20);
this.numericUpDown1.TabIndex = 8;
this.numericUpDown1.Value = new decimal(new int[] {
this.nudXLines.Name = "nudXLines";
this.nudXLines.Size = new System.Drawing.Size(55, 20);
this.nudXLines.TabIndex = 8;
this.nudXLines.Value = new decimal(new int[] {
8,
0,
0,
@@ -272,6 +273,7 @@
this.cbLines.Name = "cbLines";
this.cbLines.Size = new System.Drawing.Size(121, 21);
this.cbLines.TabIndex = 7;
this.cbLines.SelectedIndexChanged += new System.EventHandler(this.cbLines_SelectedIndexChanged);
//
// cbFormat
//
@@ -333,7 +335,7 @@
this.gbNumbers.ResumeLayout(false);
this.gbText.ResumeLayout(false);
this.gbText.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudXLines)).EndInit();
this.ResumeLayout(false);
}
@@ -353,8 +355,8 @@
private System.Windows.Forms.ComboBox cbNumSize;
private System.Windows.Forms.ComboBox cbNumBase;
private System.Windows.Forms.GroupBox gbText;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label lblXLines;
private System.Windows.Forms.NumericUpDown nudXLines;
private System.Windows.Forms.ComboBox cbLines;
private System.Windows.Forms.ComboBox cbFormat;
private System.Windows.Forms.Button btnGenerate;

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace McBitFont {
public partial class Export : Form {
@@ -73,84 +74,40 @@ namespace McBitFont {
}
}
void ParseLine(string line) {
Regex r = new Regex("([ \\t{}():;])");
string[] tokens = r.Split(line);
string[] keywords = { "const", "array", "char", "byte" };
string[] datatypes = { "uint8_t", "uint16_t", "uint32_t" };
foreach (string token in tokens) {
// Set the tokens default color and font.
txtOutput.SelectionColor = Color.Black;
txtOutput.SelectionFont = new Font("Courier New", (float)9.75, FontStyle.Regular);
// Check for a comment.
if (token == "//" || token.StartsWith("//")) {
// Find the start of the comment and then extract the whole comment.
int index = line.IndexOf("//");
string comment = line.Substring(index, line.Length - index);
txtOutput.SelectionColor = Color.FromArgb(0xFF, 0x3F, 0x7F, 0x5F);
txtOutput.SelectionFont = new Font("Courier New", (float)9.75, FontStyle.Regular);
txtOutput.SelectedText = comment;
break;
}
// Check whether the token is a keyword.
for (int i = 0; i < keywords.Length; i++) {
if (keywords[i] == token) {
// Apply alternative color and font to highlight keyword.
txtOutput.SelectionColor = Color.FromArgb(0xFF, 0x7F, 0x00, 0x55);
txtOutput.SelectionFont = new Font("Courier New", (float)9.75, FontStyle.Bold);
break;
}
}
for (int i = 0; i < datatypes.Length; i++) {
if (datatypes[i] == token) {
// Apply alternative color and font to highlight data type.
txtOutput.SelectionColor = Color.FromArgb(0xFF, 0x00, 0x50, 0x32); ;
txtOutput.SelectionFont = new Font("Courier New", (float)9.75, FontStyle.Regular);
break;
}
}
txtOutput.SelectedText = token;
}
txtOutput.SelectedText = "\n";
}
void ParseText() {
foreach (string l in txtOutput.Lines) {
ParseLine(l);
}
}
private void btnGenerate_Click(object sender, EventArgs e) {
//string output = "";
string output = "";
txtOutput.Clear();
bool com = cbComments.Checked;
bool hdr = cbHeader.Checked;
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;
if (com) {
//Header comments
txtOutput.AppendText(comments["header"]);
txtOutput.AppendText(comments["scan_order"] + cbOrder.Text + "\n");
txtOutput.AppendText(comments["scan_hdir"] + cbHDir.Text + "\n");
txtOutput.AppendText(comments["scan_vdir"] + cbVDir.Text + "\n\n");
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";
txtOutput.AppendText(comments["num_bit_order"] + cbBitOrder.Text + "\n");
txtOutput.AppendText(comments["num_base"] + cbNumBase.Text + "\n");
txtOutput.AppendText(comments["num_size"] + cbNumSize.Text + "\n\n");
output += comments["num_bit_order"] + cbBitOrder.Text + "\n";
output += comments["num_base"] + cbNumBase.Text + "\n";
output += comments["num_size"] + cbNumSize.Text + "\n\n";
txtOutput.AppendText(comments["text_format"] + cbFormat.Text + "\n");
txtOutput.AppendText(comments["text_lines"] + cbLines.Text + "\n\n");
output += comments["text_format"] + cbFormat.Text + "\n";
output += comments["text_lines"] + cbLines.Text + "\n\n";
if (hdr) {
// comment about meta header map
txtOutput.AppendText(comments["font_header_map"] + "\n\n");
output += comments["font_header_map"] + "\n\n";
}
}
int imin, jmin, imax, jmax, idir, jdir;
//Figure out mins and maxes
if (cbOrder.SelectedIndex == 0) {
if (cbHDir.SelectedIndex == 0) {
// Columns; Left to right
@@ -175,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;
}
}
@@ -239,23 +196,105 @@ namespace McBitFont {
break;
}
//Array definition
txtOutput.AppendText("const " + dataType + " " + mainForm.prjName + "[] = {\n");
// Array definition
if ( format == 0 || format == 1 ) output += "const " + dataType + " " + mainForm.prjName + "[]" + (format==1?"[]":"") + " = {\n";
if (com) txtOutput.AppendText(" // Data:\n");
// Should we add the meta header?
if (hdr) {
output +=
" // Meta header\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"
;
}
// 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) {
// For each frame
string str;
uint b = 0;
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
txtOutput.AppendText(" // " + f.code.ToString() + " --> \n");
output += " // " + f.code.ToString() + " --> " + mainForm.decodeSymbol(f.code) + "\n";
}
if (lines == 1) {
// "1 symbol per line" - new line offset
output += " ";
numcount = 0;
}
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 += (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 && fcount > 1) {
if (cbOrder.SelectedIndex == 0) {
if (cbHDir.SelectedIndex == 0) {
// Columns; Left to right
imax = f.width;
} else {
// Columns; Right to left
imin = f.width - 1;
}
if (cbVDir.SelectedIndex == 0) {
// Columns; Top to bottom
jmax = f.height;
} else {
// Columns; Bottom to top
jmin = f.height - 1;
}
} else {
if (cbVDir.SelectedIndex == 0) {
// Rows; Left to right
imax = f.height;
} else {
// Rows; Right to left
imin = f.height - 1;
}
if (cbHDir.SelectedIndex == 0) {
// Rows; Top to bottom
jmax = f.width;
} else {
// Rows; Bottom to top
jmin = f.width - 1;
}
}
}
for (int i = imin; i != imax; i += idir) {
str = " ";
if (lines == 0) {
// "Column/Row per line" - new line offset
output += " " + obracket;
numcount = 0;
}
for (int j = jmin; j != jmax; j += jdir) {
if (jdir < 0) t = jmin - j;
else t = j;
@@ -278,21 +317,49 @@ namespace McBitFont {
}
if (((t + 1) % bits == 0) || j + jdir == jmax) {
if (str.Length > 2) str += " ";
// we have filled a number with bits - let's post it
// should we post a comma before the number?
output += numcount == 0 ? "" : ", ";
// should we post a prefix to the number?
pref = (!cbZeroes.Checked && ((b < 10 && nbase == 16) || (b < 2 && nbase == 2))) ? "" : prefix;
str += pref + Convert.ToString(b, nbase).PadLeft(pad, '0') + ',';
output += pref + Convert.ToString(b, nbase).PadLeft(pad, '0');
// 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 ";
}
}
}
txtOutput.AppendText(str);
txtOutput.AppendText(Environment.NewLine);
if (lines == 0) {
// "Column/Row per line" - closing line
output += cbracket + ((i+idir==imax) && f.Equals(flast) ? "" : ",") + "\n";
}
}
if (lines == 1) {
// "1 symbol per line" - closing line
if (!f.Equals(flast)) output += ",";
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;
}
txtOutput.AppendText(Environment.NewLine);
}
// Close array definition
txtOutput.AppendText("};\n");
output += "};\n";
txtOutput.SelectAll();
ParseText();
txtOutput.Text = output;
txtOutput.SelectionStart = 0;
txtOutput.ScrollToCaret();
}
@@ -302,6 +369,26 @@ 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 && 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;
}
if (cbFormat.SelectedIndex == 1) {
cbLines.SelectedIndex = 0;
cbLines.Enabled = false;
} else {
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;
}
}
}
}

View File

@@ -55,8 +55,8 @@
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.applyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shiftUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shiftDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -65,11 +65,12 @@
this.invertToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mirrorXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mirrorYToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dlgSave = new System.Windows.Forms.SaveFileDialog();
this.dlgOpen = new System.Windows.Forms.OpenFileDialog();
this.applyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.prependSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.appendSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudY)).BeginInit();
this.panel1.SuspendLayout();
@@ -324,6 +325,7 @@
this.miniList.ShowGroups = false;
this.miniList.Size = new System.Drawing.Size(343, 395);
this.miniList.SmallImageList = this.ilMiniatures;
this.miniList.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.miniList.TabIndex = 12;
this.miniList.TabStop = false;
this.miniList.TileSize = new System.Drawing.Size(50, 50);
@@ -407,7 +409,9 @@
//
this.newToolStripMenuItem.Image = global::McBitFont.Properties.Resources.file;
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
this.newToolStripMenuItem.Size = new System.Drawing.Size(112, 22);
this.newToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+N";
this.newToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
this.newToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.newToolStripMenuItem.Text = "New";
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
//
@@ -415,7 +419,9 @@
//
this.openToolStripMenuItem.Image = global::McBitFont.Properties.Resources.folder_open;
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(112, 22);
this.openToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+O";
this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.openToolStripMenuItem.Text = "Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
@@ -423,35 +429,30 @@
//
this.saveToolStripMenuItem.Image = global::McBitFont.Properties.Resources.save;
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(112, 22);
this.saveToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+S";
this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveToolStripMenuItem.Text = "Save as";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(112, 22);
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addSymbolToolStripMenuItem,
this.prependSymbolToolStripMenuItem,
this.appendSymbolToolStripMenuItem,
this.removeSymbolToolStripMenuItem,
this.applyToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
this.editToolStripMenuItem.Text = "Edit";
//
// addSymbolToolStripMenuItem
//
this.addSymbolToolStripMenuItem.Enabled = false;
this.addSymbolToolStripMenuItem.Image = global::McBitFont.Properties.Resources.action_add;
this.addSymbolToolStripMenuItem.Name = "addSymbolToolStripMenuItem";
this.addSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addSymbolToolStripMenuItem.Text = "Add symbol";
//
// removeSymbolToolStripMenuItem
//
this.removeSymbolToolStripMenuItem.Enabled = false;
@@ -459,6 +460,14 @@
this.removeSymbolToolStripMenuItem.Name = "removeSymbolToolStripMenuItem";
this.removeSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.removeSymbolToolStripMenuItem.Text = "Remove symbol";
this.removeSymbolToolStripMenuItem.Click += new System.EventHandler(this.removeSymbolToolStripMenuItem_Click);
//
// applyToolStripMenuItem
//
this.applyToolStripMenuItem.Name = "applyToolStripMenuItem";
this.applyToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.applyToolStripMenuItem.Text = "Apply";
this.applyToolStripMenuItem.Click += new System.EventHandler(this.button2_Click);
//
// toolsToolStripMenuItem
//
@@ -479,7 +488,9 @@
//
this.shiftUpToolStripMenuItem.Image = global::McBitFont.Properties.Resources.arrow_top;
this.shiftUpToolStripMenuItem.Name = "shiftUpToolStripMenuItem";
this.shiftUpToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.shiftUpToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Up";
this.shiftUpToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Up)));
this.shiftUpToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.shiftUpToolStripMenuItem.Text = "Shift Up";
this.shiftUpToolStripMenuItem.Click += new System.EventHandler(this.btnShiftUp_Click);
//
@@ -487,7 +498,9 @@
//
this.shiftDownToolStripMenuItem.Image = global::McBitFont.Properties.Resources.arrow_down;
this.shiftDownToolStripMenuItem.Name = "shiftDownToolStripMenuItem";
this.shiftDownToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.shiftDownToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Down";
this.shiftDownToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Down)));
this.shiftDownToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.shiftDownToolStripMenuItem.Text = "Shift Down";
this.shiftDownToolStripMenuItem.Click += new System.EventHandler(this.btnShiftDown_Click);
//
@@ -495,7 +508,9 @@
//
this.shiftLeftToolStripMenuItem.Image = global::McBitFont.Properties.Resources.arrow_back;
this.shiftLeftToolStripMenuItem.Name = "shiftLeftToolStripMenuItem";
this.shiftLeftToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.shiftLeftToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Left";
this.shiftLeftToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Left)));
this.shiftLeftToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.shiftLeftToolStripMenuItem.Text = "Shift left";
this.shiftLeftToolStripMenuItem.Click += new System.EventHandler(this.btnShiftLeft_Click);
//
@@ -503,31 +518,48 @@
//
this.shiftRightToolStripMenuItem.Image = global::McBitFont.Properties.Resources.arrow_next;
this.shiftRightToolStripMenuItem.Name = "shiftRightToolStripMenuItem";
this.shiftRightToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.shiftRightToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Right";
this.shiftRightToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Right)));
this.shiftRightToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.shiftRightToolStripMenuItem.Text = "Shift Right";
this.shiftRightToolStripMenuItem.Click += new System.EventHandler(this.btnShiftRight_Click);
//
// invertToolStripMenuItem
//
this.invertToolStripMenuItem.Name = "invertToolStripMenuItem";
this.invertToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.invertToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+I";
this.invertToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.I)));
this.invertToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.invertToolStripMenuItem.Text = "Invert";
this.invertToolStripMenuItem.Click += new System.EventHandler(this.btnInvert_Click);
//
// mirrorXToolStripMenuItem
//
this.mirrorXToolStripMenuItem.Name = "mirrorXToolStripMenuItem";
this.mirrorXToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.mirrorXToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+X";
this.mirrorXToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.X)));
this.mirrorXToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.mirrorXToolStripMenuItem.Text = "Mirror X";
this.mirrorXToolStripMenuItem.Click += new System.EventHandler(this.btnMirrorX_Click);
//
// mirrorYToolStripMenuItem
//
this.mirrorYToolStripMenuItem.Name = "mirrorYToolStripMenuItem";
this.mirrorYToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.mirrorYToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Y";
this.mirrorYToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y)));
this.mirrorYToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.mirrorYToolStripMenuItem.Text = "Mirror Y";
this.mirrorYToolStripMenuItem.Click += new System.EventHandler(this.btnMirrorY_Click);
//
// exportToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
this.exportToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+E";
this.exportToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E)));
this.exportToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
this.exportToolStripMenuItem.Text = "Export";
this.exportToolStripMenuItem.Click += new System.EventHandler(this.button1_Click);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Enabled = false;
@@ -545,19 +577,23 @@
this.dlgOpen.DefaultExt = "mbf";
this.dlgOpen.Filter = "McBitFont files|*.mbf|All files|*.*";
//
// applyToolStripMenuItem
// prependSymbolToolStripMenuItem
//
this.applyToolStripMenuItem.Name = "applyToolStripMenuItem";
this.applyToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.applyToolStripMenuItem.Text = "Apply";
this.applyToolStripMenuItem.Click += new System.EventHandler(this.button2_Click);
this.prependSymbolToolStripMenuItem.Enabled = false;
this.prependSymbolToolStripMenuItem.Image = global::McBitFont.Properties.Resources.action_add;
this.prependSymbolToolStripMenuItem.Name = "prependSymbolToolStripMenuItem";
this.prependSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.prependSymbolToolStripMenuItem.Text = "Prepend symbol";
this.prependSymbolToolStripMenuItem.Click += new System.EventHandler(this.prependSymbolToolStripMenuItem_Click);
//
// exportToolStripMenuItem
// appendSymbolToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
this.exportToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exportToolStripMenuItem.Text = "Export";
this.exportToolStripMenuItem.Click += new System.EventHandler(this.button1_Click);
this.appendSymbolToolStripMenuItem.Enabled = false;
this.appendSymbolToolStripMenuItem.Image = global::McBitFont.Properties.Resources.action_add;
this.appendSymbolToolStripMenuItem.Name = "appendSymbolToolStripMenuItem";
this.appendSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.appendSymbolToolStripMenuItem.Text = "Append symbol";
this.appendSymbolToolStripMenuItem.Click += new System.EventHandler(this.prependSymbolToolStripMenuItem_Click);
//
// MainForm
//
@@ -630,7 +666,6 @@
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem addSymbolToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem removeSymbolToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toolsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem shiftUpToolStripMenuItem;
@@ -645,6 +680,8 @@
private System.Windows.Forms.OpenFileDialog dlgOpen;
private System.Windows.Forms.ToolStripMenuItem applyToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem prependSymbolToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem appendSymbolToolStripMenuItem;
}
}

View File

@@ -35,6 +35,7 @@ namespace McBitFont {
[Serializable]
public struct SaveBlock {
public bool monospaced;
public int codepage;
public List<FrameMiniature> frames;
}
@@ -45,11 +46,12 @@ namespace McBitFont {
private int pixelOffset = 5;
private int gap;
private int w, h;
bool monospaced = false;
public bool monospaced = false;
bool modified = false;
bool prjModified = false;
public const string version = "1.0";
public string prjName = "Untitled";
public int codepage = 1251;
public MainForm() {
InitializeComponent();
@@ -136,6 +138,8 @@ namespace McBitFont {
ilMiniatures.Images.Add(s, (Image)bmp);
miniList.Items[s].ImageKey = s;
}
} else {
if (nudX.Focused) modified = true;
}
prjModified = true;
dotResize((int)nudX.Value, dotHeight);
@@ -387,7 +391,7 @@ namespace McBitFont {
frames[index] = f;
var sizedBMP = getMiniPictue(f);
string s = f.code.ToString();
string s = f.code.ToString().PadLeft(3, '0');
ilMiniatures.Images.RemoveByKey(s);
ilMiniatures.Images.Add(s, (Image)sizedBMP);
sizedBMP.Dispose();
@@ -441,6 +445,12 @@ namespace McBitFont {
Application.Exit();
}
public string decodeSymbol(int code) {
var enc = Encoding.GetEncoding(codepage);
if (code < 32) return "";
return enc.GetString(new byte[] { (byte)code });
}
private void newToolStripMenuItem_Click(object sender, EventArgs e) {
if (prjModified) {
if (MessageBox.Show("The project is modified.\nDo you want to save it first?", "Project was modified!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
@@ -457,6 +467,8 @@ namespace McBitFont {
string append = "";
int neww = (int)form.nudNewX.Value;
int newh = (int)form.nudNewY.Value;
nudX.Value = neww;
nudY.Value = newh;
if (form.cbSingle.Checked) {
frames.Add( new FrameMiniature(0, neww, newh));
//f = frames.Find(x => x.code == 0);
@@ -480,14 +492,12 @@ namespace McBitFont {
}
lblType.Text = monospaced ? "Monospaced" : "Variable width / Single";
foreach (FrameMiniature ff in frames) {
var s = ff.code.ToString();
var s = ff.code.ToString().PadLeft(3, '0');
ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff));
var enc = Encoding.GetEncoding((form.cbEncoding.SelectedItem as New.EncodingItem).Code);
var sss = enc.GetString(new byte[] { (byte)ff.code });
codepage =(form.cbEncoding.SelectedItem as New.EncodingItem).Code;
var sss = decodeSymbol(ff.code);
miniList.Items.Add(s, s+' '+append+sss, s);
}
nudX.Value =neww;
nudY.Value = newh;
f = copyFrame(frames.First());
dotPanel.Refresh();
miniList.Refresh();
@@ -495,6 +505,8 @@ namespace McBitFont {
prjName = "Untitled";
this.Text = "McBitFont " + version + " - " + prjName;
modified = false;
checkForAdd();
}
}
@@ -507,7 +519,9 @@ namespace McBitFont {
modified = false;
}
if (miniList.SelectedItems.Count == 0) {
miniList.Items[0].Selected = true;
removeSymbolToolStripMenuItem.Enabled = false;
return;
//miniList.Items[0].Selected = true;
}
var sel = miniList.SelectedItems[0];
int code = Convert.ToInt32(sel.ImageKey);
@@ -516,6 +530,12 @@ namespace McBitFont {
nudY.Value = ff.height;
f = ff;
dotPanel.Refresh();
ff = frames.Find(x => x.code == code);
if (frames.Count > 1 && (ff.Equals(frames.First()) || ff.Equals(frames.Last()))) {
removeSymbolToolStripMenuItem.Enabled = true;
} else {
removeSymbolToolStripMenuItem.Enabled = false;
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
@@ -523,6 +543,7 @@ namespace McBitFont {
SaveBlock sav;
sav.monospaced = monospaced;
sav.frames = frames;
sav.codepage = codepage;
BinaryFormatter formatter = new BinaryFormatter();
using (Stream ms = File.OpenWrite(dlgSave.FileName)) {
formatter.Serialize(ms, sav);
@@ -542,7 +563,6 @@ namespace McBitFont {
}
}
if (dlgOpen.ShowDialog() == DialogResult.OK) {
//MessageBox.Show(dlgOpen.FileName);
SaveBlock sav;
BinaryFormatter formatter = new BinaryFormatter();
@@ -551,6 +571,7 @@ namespace McBitFont {
fs.Close();
}
monospaced = sav.monospaced;
codepage = sav.codepage;
lblType.Text = monospaced ? "Monospaced" : "Variable width / Single";
frames = sav.frames;
miniList.Items.Clear();
@@ -575,6 +596,49 @@ namespace McBitFont {
prjName = Path.GetFileNameWithoutExtension(dlgOpen.FileName);
this.Text = "McBitFont " + version + " - " + prjName;
checkForAdd();
}
}
private void removeSymbolToolStripMenuItem_Click(object sender, EventArgs e) {
if (miniList.SelectedItems.Count == 0) {
removeSymbolToolStripMenuItem.Enabled = false;
return;
}
var sel = miniList.SelectedItems[0].ImageKey;
int code = Convert.ToInt32(miniList.SelectedItems[0].ImageKey);
FrameMiniature ff = frames.Find(x => x.code == code);
frames.Remove(ff);
miniList.SelectedItems[0].Remove();
//miniList.Items[0].Selected = true;
}
private void prependSymbolToolStripMenuItem_Click(object sender, EventArgs e) {
FrameMiniature ff;
if (sender == prependSymbolToolStripMenuItem) {
ff = new FrameMiniature(frames.First().code - 1, dotWidth, dotHeight);
frames.Insert(0, ff);
} else {
ff = new FrameMiniature(frames.Last().code + 1, dotWidth, dotHeight);
frames.Add(ff);
}
var s = ff.code.ToString().PadLeft(3, '0');
ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff));
var sss = decodeSymbol(ff.code);
miniList.Items.Add(s, s + ' ' + sss, s);
checkForAdd();
}
private void checkForAdd() {
if (frames.Count > 1) {
if (frames.First().code > 0) prependSymbolToolStripMenuItem.Enabled = true;
else prependSymbolToolStripMenuItem.Enabled = false;
if (frames.Last().code < 255) appendSymbolToolStripMenuItem.Enabled = true;
else appendSymbolToolStripMenuItem.Enabled = false;
} else {
prependSymbolToolStripMenuItem.Enabled = false;
appendSymbolToolStripMenuItem.Enabled = false;
}
}

BIN
icons_9x9.mbf Normal file

Binary file not shown.