WIP: text import

This commit is contained in:
2025-05-26 03:12:03 +03:00
parent d508f0ab35
commit 295b079dab
12 changed files with 458 additions and 36 deletions

View File

@@ -51,7 +51,7 @@ namespace McBitFont {
comments.Add("font_header_map",
"// Font header map:\n" +
"// packed; // Flag for packed font" +
"// packed; // Flag for packed font\n" +
"// width; // Font width in pixels (0 - variable width)\n" +
"// height; // Font height in pixels\n" +
"// space; // Font space in pixels\n" +

View File

@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>

View File

@@ -72,6 +72,7 @@
redoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
selectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
makeVarWidthToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
prependSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -101,7 +102,7 @@
chkHexCodes = new System.Windows.Forms.CheckBox();
chkRectSelect = new System.Windows.Forms.CheckBox();
label3 = new System.Windows.Forms.Label();
selectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
importTextToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)nudX).BeginInit();
((System.ComponentModel.ISupportInitialize)nudY).BeginInit();
panel1.SuspendLayout();
@@ -523,7 +524,7 @@
//
// fileToolStripMenuItem
//
fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { newToolStripMenuItem, openToolStripMenuItem, saveToolStripMenuItem, saveAsToolStripMenuItem, importImageToolStripMenuItem, exportToolStripMenuItem, exitToolStripMenuItem });
fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { newToolStripMenuItem, openToolStripMenuItem, saveToolStripMenuItem, saveAsToolStripMenuItem, importTextToolStripMenuItem1, importImageToolStripMenuItem, exportToolStripMenuItem, exitToolStripMenuItem });
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
fileToolStripMenuItem.Text = "File";
@@ -616,7 +617,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(180, 22);
undoToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
undoToolStripMenuItem.Text = "Undo";
undoToolStripMenuItem.ToolTipText = "Undo last canvas change";
undoToolStripMenuItem.Click += undoToolStripMenuItem_Click;
@@ -626,7 +627,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(180, 22);
redoToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
redoToolStripMenuItem.Text = "Redo";
redoToolStripMenuItem.ToolTipText = "Redo canvas change";
redoToolStripMenuItem.Click += redoToolStripMenuItem_Click;
@@ -638,7 +639,7 @@
copyToolStripMenuItem.Name = "copyToolStripMenuItem";
copyToolStripMenuItem.ShortcutKeyDisplayString = "";
copyToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C;
copyToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
copyToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
copyToolStripMenuItem.Text = "Copy";
copyToolStripMenuItem.ToolTipText = "Copy current symbol to clipboard";
copyToolStripMenuItem.Click += copyToolStripMenuItem_Click;
@@ -650,11 +651,19 @@
pasteToolStripMenuItem.Name = "pasteToolStripMenuItem";
pasteToolStripMenuItem.ShortcutKeyDisplayString = "";
pasteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V;
pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
pasteToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
pasteToolStripMenuItem.Text = "Paste";
pasteToolStripMenuItem.ToolTipText = "Paste from clipboard to current symbol";
pasteToolStripMenuItem.Click += pasteToolStripMenuItem_Click;
//
// selectToolStripMenuItem
//
selectToolStripMenuItem.Image = Properties.Resources.fam_rectt;
selectToolStripMenuItem.Name = "selectToolStripMenuItem";
selectToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
selectToolStripMenuItem.Text = "Select";
selectToolStripMenuItem.Click += selectToolStripMenuItem_Click;
//
// fontToolStripMenuItem
//
fontToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { makeVarWidthToolStripMenuItem, prependSymbolToolStripMenuItem, appendSymbolToolStripMenuItem, removeSymbolToolStripMenuItem, removeBeforeToolStripMenuItem, removeAfterToolStripMenuItem, CodeShiftToolStripMenuItem });
@@ -956,13 +965,13 @@
label3.TabIndex = 21;
label3.Text = "Cursor:";
//
// selectToolStripMenuItem
// importTextToolStripMenuItem1
//
selectToolStripMenuItem.Image = Properties.Resources.fam_rectt;
selectToolStripMenuItem.Name = "selectToolStripMenuItem";
selectToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
selectToolStripMenuItem.Text = "Select";
selectToolStripMenuItem.Click += selectToolStripMenuItem_Click;
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
//
@@ -1090,6 +1099,7 @@
private System.Windows.Forms.ToolStripMenuItem FillToolStripMenuItem;
private System.Windows.Forms.CheckBox chkRectSelect;
private System.Windows.Forms.ToolStripMenuItem selectToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem importTextToolStripMenuItem1;
}
}

View File

@@ -711,13 +711,9 @@ namespace McBitFont {
}
private void newToolStripMenuItem_Click(object sender, EventArgs e) {
checkModifiedFrame();
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) {
saveToolStripMenuItem.PerformClick();
return;
}
}
CheckModifiedFrame();
if (CheckModifiedProject()) return;
New form = new New(this);
if (form.ShowDialog() == DialogResult.OK) {
Cursor.Current = Cursors.WaitCursor;
@@ -797,7 +793,7 @@ namespace McBitFont {
private void MiniList_SelectedIndexChanged(object sender, EventArgs e) {
if (miniList.FocusedItem == null) return;
checkModifiedFrame();
CheckModifiedFrame();
if (miniList.SelectedItems.Count == 0) {
removeSymbolToolStripMenuItem.Enabled = false;
removeBeforeToolStripMenuItem.Enabled = false;
@@ -852,7 +848,7 @@ namespace McBitFont {
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) {
checkModifiedFrame();
CheckModifiedFrame();
if (dlgSave.ShowDialog() == DialogResult.OK) {
SaveProject(dlgSave.FileName);
}
@@ -935,13 +931,13 @@ namespace McBitFont {
this.Text = "McBitFont v" + version + " - " + prjName;
}
private void openToolStripMenuItem_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) == DialogResult.Yes) {
saveAsToolStripMenuItem.PerformClick();
return;
}
}
CheckModifiedFrame();
if (CheckModifiedProject()) return;
dlgOpen.FilterIndex = 1;
if (dlgOpen.ShowDialog() == DialogResult.OK) {
LoadProject(dlgOpen.FileName);
}
@@ -1035,7 +1031,7 @@ namespace McBitFont {
}
// Check modified / Save frame
private void checkModifiedFrame() {
private void CheckModifiedFrame() {
if (modified) {
if (MessageBox.Show("Current symbol is modified.\nDo you want to save the changes?", "Symbol was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
SaveFrame();
@@ -1044,11 +1040,22 @@ namespace McBitFont {
}
}
// Check if project was modified
private bool CheckModifiedProject() {
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) {
saveToolStripMenuItem.PerformClick();
return true;
}
}
return false;
}
private void saveToolStripMenuItem_Click_1(object sender, EventArgs e) {
if (prjFileName == "") {
saveAsToolStripMenuItem.PerformClick();
} else {
checkModifiedFrame();
CheckModifiedFrame();
SaveProject(prjFileName);
}
@@ -1160,7 +1167,7 @@ namespace McBitFont {
private void CodeShiftToolStripMenuItem_Click(object sender, EventArgs e) {
if (!monospaced && frames.Count == 1) return;
checkModifiedFrame();
CheckModifiedFrame();
CodeShift csform = new CodeShift(this);
if (csform.ShowDialog() == DialogResult.OK) {
@@ -1240,5 +1247,82 @@ namespace McBitFont {
chkRectSelect.Checked = !chkRectSelect.Checked;
selectToolStripMenuItem.Checked = !selectToolStripMenuItem.Checked;
}
private void importTextToolStripMenuItem1_Click(object sender, EventArgs e) {
if (CheckModifiedProject()) return;
dlgOpen.FilterIndex = 2;
if (dlgOpen.ShowDialog() == DialogResult.OK) {
var lines = File.ReadAllLines(dlgOpen.FileName);
int bits = 0;
List<uint> data = [];
foreach (var line in lines) {
if (line.TrimStart().StartsWith("//")) continue; // Ignore comments
if (line.Trim().Length < 1) continue; // Ignore empty lines
if (bits == 0) {
if (line.Contains("uint8_t")) bits = 8; // Found 8 bit array
if (line.Contains("uint16_t")) bits = 16; // Found 16 bit array
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
var words = s.Split(','); // split a line by commas
string w;
foreach (var word in words) {
int numBase = 10;
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
w = w.Remove(w.IndexOf("0b"), 2);
numBase = 2;
}
try { // Try to convert a number from text
data.Add(Convert.ToUInt32(w, numBase));
}
catch {
continue;
}
//MessageBox.Show(w + ": Length: " + w.Length + " Bits: " + bits + " Converted: " + data.Last() + "\nData length: " + data.Count);
}
}
if (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) + "\nDo you want to load it?", "Import from text file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
// Font header
bool packed = data.ElementAt(0) == 1;
int width= (int)data.ElementAt(1);
int height = (int)data.ElementAt(2);
int first = (int)data.ElementAt(4);
int last = (int)data.ElementAt(5);
frames.Clear();
miniList.Clear();
ilMiniatures.Images.Clear();
FrameMiniature newf;
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++;
}
newf = new(curFrame + first, neww, height);
}
// TODO: fill frame.data with current byte
// increment NumIndex
}
}
//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));
}
}
}
}

View File

@@ -32,6 +32,10 @@
<ItemGroup>
<Content Include="icon.ico" />
<Content Include="icon_64.ico" />
<PackageReference Include="Costura.Fody" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MessagePack" Version="3.1.3" />
<PackageReference Include="MessagePack.Annotations" Version="3.1.3" />
<PackageReference Include="MessagePackAnalyzer" Version="3.1.3" />

View File

@@ -250,6 +250,16 @@ namespace McBitFont.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap folder_table {
get {
object obj = ResourceManager.GetObject("folder_table", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -142,9 +142,6 @@
<data name="arrow_redo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\redo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Famfamfam-Silk-Disk.16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Famfamfam-Silk-Disk.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -196,12 +193,18 @@
<data name="z_redo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrow_redo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fam_base" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fam_base.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fam_rectt" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fam_rectt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Famfamfam-Silk-Page-white.16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Famfamfam-Silk-Page-white.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Famfamfam-Silk-Disk.16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Famfamfam-Silk-Disk.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Canvas_Fill" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Canvas_Fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -220,7 +223,7 @@
<data name="icon_64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fam_base" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fam_base.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="folder_table" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\folder_table.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B