1
0
mirror of synced 2024-12-11 07:16:05 +01:00

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.
This commit is contained in:
KillzXGaming 2019-09-12 21:26:11 -04:00
parent 90e7853412
commit 891e5e0bc3
3 changed files with 51 additions and 4 deletions

View File

@ -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(); System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
@ -151,7 +151,8 @@ namespace FirstPlugin
public void Unload() public void Unload()
{ {
DecryptedFont = null;
GC.WaitForPendingFinalizers();
} }
public void Save(System.IO.Stream stream) public void Save(System.IO.Stream stream)

View File

@ -41,6 +41,7 @@
this.stLabel3 = new Toolbox.Library.Forms.STLabel(); this.stLabel3 = new Toolbox.Library.Forms.STLabel();
this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip(); this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.loadFontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
@ -198,7 +199,8 @@
// stMenuStrip1 // stMenuStrip1
// //
this.stMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 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.Location = new System.Drawing.Point(0, 0);
this.stMenuStrip1.Name = "stMenuStrip1"; this.stMenuStrip1.Name = "stMenuStrip1";
this.stMenuStrip1.Size = new System.Drawing.Size(922, 24); this.stMenuStrip1.Size = new System.Drawing.Size(922, 24);
@ -211,6 +213,13 @@
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20); this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View"; 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 // MSBTEditor
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -256,5 +265,6 @@
private System.Windows.Forms.SplitContainer splitContainer3; private System.Windows.Forms.SplitContainer splitContainer3;
private Toolbox.Library.Forms.STMenuStrip stMenuStrip1; private Toolbox.Library.Forms.STMenuStrip stMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem loadFontToolStripMenuItem;
} }
} }

View File

@ -3,12 +3,13 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Text;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Toolbox.Library.Forms; using Toolbox.Library.Forms;
using Toolbox.Library; using Toolbox.Library;
using Toolbox.Library.IO;
namespace FirstPlugin.Forms 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));
}
}
}
} }
} }