From 891e5e0bc381ee476ad36d693bf7fdbe9472b931 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 12 Sep 2019 21:26:11 -0400 Subject: [PATCH] Allow loading custom fonts for msbt. Note bffnt is not loadable for this yet because idk how to create fonts from bitmaps yet for the text editor. --- File_Format_Library/FileFormats/Font/BFTTF.cs | 5 ++- .../GUI/Message/MSBTEditor.Designer.cs | 12 +++++- File_Format_Library/GUI/Message/MSBTEditor.cs | 38 ++++++++++++++++++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/File_Format_Library/FileFormats/Font/BFTTF.cs b/File_Format_Library/FileFormats/Font/BFTTF.cs index aa212ecf..798adf7d 100644 --- a/File_Format_Library/FileFormats/Font/BFTTF.cs +++ b/File_Format_Library/FileFormats/Font/BFTTF.cs @@ -102,7 +102,7 @@ namespace FirstPlugin } } - private System.Drawing.Font ToFont(int Size = 72) + public System.Drawing.Font ToFont(float Size = 72) { System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection(); @@ -151,7 +151,8 @@ namespace FirstPlugin public void Unload() { - + DecryptedFont = null; + GC.WaitForPendingFinalizers(); } public void Save(System.IO.Stream stream) diff --git a/File_Format_Library/GUI/Message/MSBTEditor.Designer.cs b/File_Format_Library/GUI/Message/MSBTEditor.Designer.cs index 09153152..cd676ffa 100644 --- a/File_Format_Library/GUI/Message/MSBTEditor.Designer.cs +++ b/File_Format_Library/GUI/Message/MSBTEditor.Designer.cs @@ -41,6 +41,7 @@ this.stLabel3 = new Toolbox.Library.Forms.STLabel(); this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip(); this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.loadFontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -198,7 +199,8 @@ // stMenuStrip1 // this.stMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.viewToolStripMenuItem}); + this.viewToolStripMenuItem, + this.loadFontToolStripMenuItem}); this.stMenuStrip1.Location = new System.Drawing.Point(0, 0); this.stMenuStrip1.Name = "stMenuStrip1"; this.stMenuStrip1.Size = new System.Drawing.Size(922, 24); @@ -211,6 +213,13 @@ this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20); this.viewToolStripMenuItem.Text = "View"; // + // loadFontToolStripMenuItem + // + this.loadFontToolStripMenuItem.Name = "loadFontToolStripMenuItem"; + this.loadFontToolStripMenuItem.Size = new System.Drawing.Size(72, 20); + this.loadFontToolStripMenuItem.Text = "Load Font"; + this.loadFontToolStripMenuItem.Click += new System.EventHandler(this.loadFontToolStripMenuItem_Click); + // // MSBTEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -256,5 +265,6 @@ private System.Windows.Forms.SplitContainer splitContainer3; private Toolbox.Library.Forms.STMenuStrip stMenuStrip1; private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem loadFontToolStripMenuItem; } } \ No newline at end of file diff --git a/File_Format_Library/GUI/Message/MSBTEditor.cs b/File_Format_Library/GUI/Message/MSBTEditor.cs index cc286650..6c531c26 100644 --- a/File_Format_Library/GUI/Message/MSBTEditor.cs +++ b/File_Format_Library/GUI/Message/MSBTEditor.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.Drawing.Text; using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; using Toolbox.Library.Forms; using Toolbox.Library; +using Toolbox.Library.IO; namespace FirstPlugin.Forms { @@ -94,5 +95,40 @@ namespace FirstPlugin.Forms } } } + + private void UpdateFont(Font font) + { + editTextTB.Font = font; + originalTextTB.Font = font; + } + + private void loadFontToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Supported Formats|*.bfttf; *.ttf;*.otf|" + + "Binary Cafe True Type Font |*.bfttf|" + + "True Type Font |*.ttf|" + + "Open Type Font |*.otf|" + + "All files(*.*)|*.*"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + if (Utils.GetExtension(ofd.FileName) == ".bfttf") + { + BFTTF bfttf = (BFTTF)STFileLoader.OpenFileFormat(ofd.FileName); + var font = bfttf.ToFont(editTextTB.Font.Size); + UpdateFont(font); + bfttf.Unload(); + } + else if (Utils.GetExtension(ofd.FileName) == ".ttf" || + Utils.GetExtension(ofd.FileName) == ".otf") + { + PrivateFontCollection privateFonts = new PrivateFontCollection(); + privateFonts.AddFontFile(ofd.FileName); + var font = privateFonts.Families[0]; + UpdateFont(new Font(privateFonts.Families[0], editTextTB.Font.Size)); + } + } + } } }