diff --git a/.gitignore b/.gitignore index f635fe4..75316d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore examples/tests/32x32/ +examples/tests/PNGout/ # User-specific files *.rsuser diff --git a/McBitFont/FontTester.Designer.cs b/McBitFont/FontTester.Designer.cs index a1d2b70..4fc6680 100644 --- a/McBitFont/FontTester.Designer.cs +++ b/McBitFont/FontTester.Designer.cs @@ -134,6 +134,12 @@ toolTip1.SetToolTip(cbZoom, "Zoom level"); cbZoom.SelectedIndexChanged += ZoomChanged; // + // toolTip1 + // + toolTip1.AutoPopDelay = 10000; + toolTip1.InitialDelay = 500; + toolTip1.ReshowDelay = 100; + // // chkBaseline // chkBaseline.AutoSize = true; diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index edc507f..cec5515 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -67,6 +67,7 @@ importTextToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); importImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + exportFontLayoutPNGToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -83,6 +84,7 @@ removeBeforeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); removeAfterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); CodeShiftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + testFontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); canvasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); FillToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -107,7 +109,10 @@ lblSelectionLabel = new System.Windows.Forms.Label(); lblSelection = new System.Windows.Forms.Label(); lblModified = new System.Windows.Forms.Label(); - testFontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + dlgSavePNG = new System.Windows.Forms.SaveFileDialog(); + toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); ((System.ComponentModel.ISupportInitialize)nudX).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudY).BeginInit(); panel1.SuspendLayout(); @@ -528,9 +533,9 @@ // // fileToolStripMenuItem // - fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { newToolStripMenuItem, openToolStripMenuItem, saveToolStripMenuItem, saveAsToolStripMenuItem, importTextToolStripMenuItem1, importImageToolStripMenuItem, exportToolStripMenuItem, exitToolStripMenuItem }); + fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { newToolStripMenuItem, openToolStripMenuItem, saveToolStripMenuItem, saveAsToolStripMenuItem, toolStripSeparator1, importTextToolStripMenuItem1, importImageToolStripMenuItem, exportToolStripMenuItem, exportFontLayoutPNGToolStripMenuItem, toolStripSeparator2, exitToolStripMenuItem }); fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + fileToolStripMenuItem.Size = new System.Drawing.Size(122, 20); fileToolStripMenuItem.Text = "File"; // // newToolStripMenuItem @@ -583,6 +588,7 @@ importTextToolStripMenuItem1.Name = "importTextToolStripMenuItem1"; importTextToolStripMenuItem1.Size = new System.Drawing.Size(224, 22); importTextToolStripMenuItem1.Text = "Import text file (very limited)"; + importTextToolStripMenuItem1.ToolTipText = "Import a font from a C array in a file"; importTextToolStripMenuItem1.Click += importTextToolStripMenuItem1_Click; // // importImageToolStripMenuItem @@ -605,6 +611,15 @@ exportToolStripMenuItem.ToolTipText = "Configure and export data"; exportToolStripMenuItem.Click += button1_Click; // + // exportFontLayoutPNGToolStripMenuItem + // + exportFontLayoutPNGToolStripMenuItem.Image = Properties.Resources.picture_go; + exportFontLayoutPNGToolStripMenuItem.Name = "exportFontLayoutPNGToolStripMenuItem"; + exportFontLayoutPNGToolStripMenuItem.Size = new System.Drawing.Size(224, 22); + exportFontLayoutPNGToolStripMenuItem.Text = "Export font layout PNG"; + exportFontLayoutPNGToolStripMenuItem.ToolTipText = "Create an image with all a table showing all 256 symbols"; + exportFontLayoutPNGToolStripMenuItem.Click += ExportPNG; + // // exitToolStripMenuItem // exitToolStripMenuItem.Image = Properties.Resources.Famfamfam_Silk_Door_out_16; @@ -629,7 +644,7 @@ undoToolStripMenuItem.Image = Properties.Resources.arrow_undo; undoToolStripMenuItem.Name = "undoToolStripMenuItem"; undoToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Z; - undoToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + undoToolStripMenuItem.Size = new System.Drawing.Size(180, 22); undoToolStripMenuItem.Text = "Undo"; undoToolStripMenuItem.ToolTipText = "Undo last canvas change"; undoToolStripMenuItem.Click += undoToolStripMenuItem_Click; @@ -639,7 +654,7 @@ redoToolStripMenuItem.Image = Properties.Resources.arrow_redo; redoToolStripMenuItem.Name = "redoToolStripMenuItem"; redoToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y; - redoToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + redoToolStripMenuItem.Size = new System.Drawing.Size(180, 22); redoToolStripMenuItem.Text = "Redo"; redoToolStripMenuItem.ToolTipText = "Redo canvas change"; redoToolStripMenuItem.Click += redoToolStripMenuItem_Click; @@ -650,7 +665,7 @@ copyToolStripMenuItem.Name = "copyToolStripMenuItem"; copyToolStripMenuItem.ShortcutKeyDisplayString = ""; copyToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C; - copyToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + copyToolStripMenuItem.Size = new System.Drawing.Size(180, 22); copyToolStripMenuItem.Text = "Copy"; copyToolStripMenuItem.ToolTipText = "Copy current symbol to clipboard"; copyToolStripMenuItem.Click += copyToolStripMenuItem_Click; @@ -662,7 +677,7 @@ pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; pasteToolStripMenuItem.ShortcutKeyDisplayString = ""; pasteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V; - pasteToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); pasteToolStripMenuItem.Text = "Paste"; pasteToolStripMenuItem.ToolTipText = "Paste from clipboard to current symbol"; pasteToolStripMenuItem.Click += pasteToolStripMenuItem_Click; @@ -672,8 +687,9 @@ selectToolStripMenuItem.Image = Properties.Resources.fam_rectt; selectToolStripMenuItem.Name = "selectToolStripMenuItem"; selectToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.R; - selectToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + selectToolStripMenuItem.Size = new System.Drawing.Size(180, 22); selectToolStripMenuItem.Text = "Select"; + selectToolStripMenuItem.ToolTipText = "Toggle Rectangle selection tool"; selectToolStripMenuItem.Click += selectToolStripMenuItem_Click; // // selectAllToolStripMenuItem @@ -682,13 +698,14 @@ selectAllToolStripMenuItem.Image = Properties.Resources.arrow_out; selectAllToolStripMenuItem.Name = "selectAllToolStripMenuItem"; selectAllToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A; - selectAllToolStripMenuItem.Size = new System.Drawing.Size(164, 22); + selectAllToolStripMenuItem.Size = new System.Drawing.Size(180, 22); selectAllToolStripMenuItem.Text = "Select All"; + selectAllToolStripMenuItem.ToolTipText = "Select entire canvas"; selectAllToolStripMenuItem.Click += selectAllToolStripMenuItem_Click; // // fontToolStripMenuItem // - fontToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { makeVarWidthToolStripMenuItem, prependSymbolToolStripMenuItem, appendSymbolToolStripMenuItem, removeSymbolToolStripMenuItem, removeBeforeToolStripMenuItem, removeAfterToolStripMenuItem, CodeShiftToolStripMenuItem, testFontToolStripMenuItem }); + fontToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { makeVarWidthToolStripMenuItem, prependSymbolToolStripMenuItem, appendSymbolToolStripMenuItem, removeSymbolToolStripMenuItem, removeBeforeToolStripMenuItem, removeAfterToolStripMenuItem, CodeShiftToolStripMenuItem, toolStripSeparator3, testFontToolStripMenuItem }); fontToolStripMenuItem.Name = "fontToolStripMenuItem"; fontToolStripMenuItem.Size = new System.Drawing.Size(43, 20); fontToolStripMenuItem.Text = "Font"; @@ -768,6 +785,15 @@ CodeShiftToolStripMenuItem.ToolTipText = "Shift the font on the code line"; CodeShiftToolStripMenuItem.Click += CodeShiftToolStripMenuItem_Click; // + // testFontToolStripMenuItem + // + testFontToolStripMenuItem.Image = Properties.Resources.font; + testFontToolStripMenuItem.Name = "testFontToolStripMenuItem"; + testFontToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + testFontToolStripMenuItem.Text = "Test font"; + testFontToolStripMenuItem.ToolTipText = "Open dialog where you can test the font with any text you type"; + testFontToolStripMenuItem.Click += TestFont_Click; + // // canvasToolStripMenuItem // canvasToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { ClearToolStripMenuItem, FillToolStripMenuItem, shiftUpToolStripMenuItem, shiftDownToolStripMenuItem, shiftLeftToolStripMenuItem, shiftRightToolStripMenuItem, invertToolStripMenuItem, mirrorXToolStripMenuItem, mirrorYToolStripMenuItem, applyToolStripMenuItem }); @@ -1024,13 +1050,25 @@ lblModified.Text = "Frame modified"; lblModified.Visible = false; // - // testFontToolStripMenuItem + // dlgSavePNG // - testFontToolStripMenuItem.Image = Properties.Resources.font; - testFontToolStripMenuItem.Name = "testFontToolStripMenuItem"; - testFontToolStripMenuItem.Size = new System.Drawing.Size(215, 22); - testFontToolStripMenuItem.Text = "Test font"; - testFontToolStripMenuItem.Click += TestFont_Click; + dlgSavePNG.DefaultExt = "png"; + dlgSavePNG.Filter = "PNG Image|*.png;*.PNG"; + // + // toolStripSeparator1 + // + toolStripSeparator1.Name = "toolStripSeparator1"; + toolStripSeparator1.Size = new System.Drawing.Size(221, 6); + // + // toolStripSeparator2 + // + toolStripSeparator2.Name = "toolStripSeparator2"; + toolStripSeparator2.Size = new System.Drawing.Size(221, 6); + // + // toolStripSeparator3 + // + toolStripSeparator3.Name = "toolStripSeparator3"; + toolStripSeparator3.Size = new System.Drawing.Size(212, 6); // // MainForm // @@ -1167,6 +1205,11 @@ private System.Windows.Forms.ToolStripMenuItem selectAllToolStripMenuItem; private System.Windows.Forms.Label lblModified; private System.Windows.Forms.ToolStripMenuItem testFontToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem exportFontLayoutPNGToolStripMenuItem; + private System.Windows.Forms.SaveFileDialog dlgSavePNG; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; } } diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 5c628f4..3977053 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; +using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -57,7 +58,7 @@ namespace McBitFont { public bool monospaced = false; private bool modified = false; private bool prjModified = false; - public const string version = "2.2"; + public const string version = "2.3"; public string prjName = "Untitled"; public string prjFileName = ""; public int codepage = 1251; @@ -932,6 +933,8 @@ namespace McBitFont { prjFileName = filename; prjName = Path.GetFileNameWithoutExtension(filename); + dlgSavePNG.FileName = prjName + ".png"; + dlgSave.FileName = prjName + ".mbfont"; SetWindowCap(); miniList.Items[0].Selected = true; @@ -1429,5 +1432,100 @@ namespace McBitFont { var tester = new FontTester(codepage, dotHeight, baseline, frames); tester.ShowDialog(); } + + private void ExportPNG(object sender, EventArgs e) { + CheckModifiedFrame(); + CheckModifiedProject(); + + if (dlgSavePNG.ShowDialog() == DialogResult.OK) { + int pixelSize = 3; + int symbolMargin = 2 * pixelSize; + int headerHeight = 100; + int maxWidth = 0; + int i, j, v, h, x, y; + string s; + + foreach (FrameMiniature f in frames) { + if (f.width > maxWidth) maxWidth = f.width; + } + + int cellWidth = (pixelSize * maxWidth + 2 * symbolMargin); + int cellHeight = (pixelSize * dotHeight + 2 * symbolMargin); + if (cellWidth < 10) cellWidth = 10; + if (cellHeight < 10) cellHeight = 10; + + int width = cellWidth * 16 + 17 + 50; + int height = cellHeight * 16 + 17 + 25 + headerHeight; + + Bitmap bmp = new(width > 450 ? width : 450, height); + Graphics g = Graphics.FromImage(bmp); + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; + Font font = new("Consolas", 14, FontStyle.Bold); + Brush tb = Brushes.Black; + + + // Draw basic information + g.DrawString("Font project name: " + prjName, font, tb, 10, 10); + + g.DrawString("Font height: " + dotHeight, font, tb, 10, 38); + g.DrawString("Font max width: " + maxWidth, font, tb, 10, 62); + g.DrawString("Symbols count: " + frames.Count, font, tb, 10, 86); + + g.DrawString("First code: " + frames.First().code.ToString(), font, tb, 250, 38); + g.DrawString("Last code: " + frames.Last().code.ToString(), font, tb, 250, 62); + g.DrawString("Codepage: " + codepage.ToString(), font, tb, 250, 86); + + + // Draw grid + Pen p = new(Color.FromArgb(64, 0, 0, 0), 1); + SolidBrush b = new SolidBrush(Color.FromArgb(160, Color.Black)); + //Brush b = Brushes.Black; + + int xCapOffset = cellWidth / 2 - 8; + int yCapOffset = cellHeight / 2 - 10; + for (i = 0; i < 17; i++) { + x = 50 + 17 + i * cellWidth - 1; + y = headerHeight + 17 + 25 + i * cellHeight - 1; + g.DrawLine(p, 1, y, width - 1, y); + g.DrawLine(p, x, headerHeight + 20, x, headerHeight + height - 20); + + if (i != 16) { + s = Convert.ToString(i, 16).ToUpper(); + g.DrawString(s, font, b, x + xCapOffset, headerHeight + 20); + s = "0x" + Convert.ToString(i * 16, 16).PadLeft(2, '0').ToUpper(); + g.DrawString(s, font, b, 10, y + yCapOffset); + } + } + + // Draw symbols + int code; + List ff; + Rectangle rect; + // Cycle through grid cells + for (v = 0; v < 16; v++) { + for (h = 0; h < 16; h++) { + // Check if the font has a symbol with the code + code = 16 * v + h; + ff = frames.FindAll(x => x.code == code); + if (ff.Count == 1) { + x = 50 + 17 + h * cellWidth + symbolMargin; + y = headerHeight + 17 + 25 + v * cellHeight + symbolMargin; + // Cycly through symbol's pixels and draw the black ones + for (i = 0; i < ff[0].width; i++) { + for (j = 0; j < ff[0].height; j++) { + if (ff[0].data[i, j]) { + rect = new Rectangle(x + i * pixelSize, y + j * pixelSize, pixelSize, pixelSize); + g.FillRectangle(tb, rect); + } + } + } + } + } + } + + bmp.Save(dlgSavePNG.FileName, ImageFormat.Png); + } + + } } } diff --git a/McBitFont/Form1.resx b/McBitFont/Form1.resx index fb11a13..5800d67 100644 --- a/McBitFont/Form1.resx +++ b/McBitFont/Form1.resx @@ -135,6 +135,9 @@ 336, 17 + + 644, 17 + diff --git a/McBitFont/McBitFont.csproj b/McBitFont/McBitFont.csproj index 591cff5..5f7f705 100644 --- a/McBitFont/McBitFont.csproj +++ b/McBitFont/McBitFont.csproj @@ -20,9 +20,9 @@ true true icon_64.ico - 2.2.0.0 - 2.2.0.0 - $(VersionPrefix)2.2.0 + 2.3.0.0 + 2.3.0.0 + $(VersionPrefix)2.3.0 Anton Mukhin diff --git a/McBitFont/Properties/Resources.Designer.cs b/McBitFont/Properties/Resources.Designer.cs index b19e4f2..99698dd 100644 --- a/McBitFont/Properties/Resources.Designer.cs +++ b/McBitFont/Properties/Resources.Designer.cs @@ -310,6 +310,16 @@ namespace McBitFont.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap picture_go { + get { + object obj = ResourceManager.GetObject("picture_go", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/McBitFont/Properties/Resources.resx b/McBitFont/Properties/Resources.resx index 063342b..a99b88d 100644 --- a/McBitFont/Properties/Resources.resx +++ b/McBitFont/Properties/Resources.resx @@ -136,12 +136,18 @@ ..\Resources\Famfamfam-Silk-Page-copy.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\font.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\arrow_inout.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\redo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Famfamfam-Silk-Disk.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -202,9 +208,6 @@ ..\Resources\Famfamfam-Silk-Page-white.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\Famfamfam-Silk-Disk.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\folder_table.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -229,7 +232,7 @@ ..\Resources\icon_64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\font.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\picture_go.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/McBitFont/Resources/picture_go.png b/McBitFont/Resources/picture_go.png new file mode 100644 index 0000000..27c63c5 Binary files /dev/null and b/McBitFont/Resources/picture_go.png differ diff --git a/README.md b/README.md index 6892589..70829fa 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,7 @@ Import Image dialog Code Shift dialog ![Code Shift](/images/Screenshot_Code-shift.png) + +Font PNG export example + +![PNG export example](/images/Font_Minecraft_Rus_5x7_vw.png) diff --git a/TODO.txt b/TODO.txt index 06f8ced..4e808ca 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,7 +4,7 @@ Application: Functionality: V Allow to add frames to Single-frame "fonts" V Type a string to see the result (test the font) -- Export image with All characers table +V Export image with All characers table Bugs: - In some cases after switching to a symbol dotPanel mouse move causes "Out of range" exception (history.Pre after width change?) diff --git a/icons/famfamfam/picture_go.png b/icons/famfamfam/picture_go.png new file mode 100644 index 0000000..27c63c5 Binary files /dev/null and b/icons/famfamfam/picture_go.png differ diff --git a/images/Font_Minecraft_Rus_5x7_vw.png b/images/Font_Minecraft_Rus_5x7_vw.png new file mode 100644 index 0000000..e7ef398 Binary files /dev/null and b/images/Font_Minecraft_Rus_5x7_vw.png differ