diff --git a/UnitaleFontMaker.suo b/UnitaleFontMaker.suo index 605d420..6efcf0b 100644 Binary files a/UnitaleFontMaker.suo and b/UnitaleFontMaker.suo differ diff --git a/UnitaleFontMaker/Character.cs b/UnitaleFontMaker/Character.cs index d828273..4e26409 100644 --- a/UnitaleFontMaker/Character.cs +++ b/UnitaleFontMaker/Character.cs @@ -3,6 +3,9 @@ namespace UnitaleFontMaker { + /// + /// 单个字符 + /// public class Character { private char _char; @@ -36,6 +39,8 @@ public float Height get { return rect.Height; } set { rect.Height = value; } } + + public RectangleF RectF { get { return this.rect; } } public Character(char character, RectangleF rect) { diff --git a/UnitaleFontMaker/Characters.cs b/UnitaleFontMaker/Characters.cs new file mode 100644 index 0000000..edf6001 --- /dev/null +++ b/UnitaleFontMaker/Characters.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UnitaleFontMaker +{ + /// + /// 多个字符 + /// + public class Characters + { + /// + /// 必须添加的字符 + /// + public const string MUST_CHARS = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "; //注意最后面还有一个空格 + + /// + /// 添加单个字符 + /// + /// 待添加的字符 + public void AddChar(Character c) + { + + } + + /// + /// 添加多个字符 + /// + /// 待添加的字符 + public void AddChars(Character[] c) + { + + } + + /// + /// 添加字符串中的所有字符 + /// + /// 待添加的字符串 + public void AddChars(string s) + { + + } + + + } +} diff --git a/UnitaleFontMaker/FontPainter.cs b/UnitaleFontMaker/FontPainter.cs index 2deecfa..6174ab7 100644 --- a/UnitaleFontMaker/FontPainter.cs +++ b/UnitaleFontMaker/FontPainter.cs @@ -9,6 +9,9 @@ namespace UnitaleFontMaker { + /// + /// 字体绘制 + /// public class FontPainter { private Graphics gImage; @@ -22,13 +25,18 @@ public class FontPainter public Font font; + /// + /// 字体的颜色 + /// public Color TextColor { get { return brush.Color; } set { brush.Color = value; } } - + /// + /// 待绘制的文本 + /// public string Text { get { return str; } @@ -40,7 +48,7 @@ public Size Size get { return new Size(width, height); } set { - Size s = ((Size)value); + Size s = value; width = s.Width; height = s.Height; @@ -70,29 +78,29 @@ public FontPainter(Font font, int width, int height) public void Paint() { - //gImage.FillRectangle(backBrush, 0, 0, this.width, this.height); - gImage.Clear(Color.FromArgb(0, 0, 0, 0)); + gImage.Clear(Color.FromArgb(0, 0, 0, 0)); //使用透明颜色清除背景 + //获取所有字符 Character[] chars = GetCharacters(); if(chars == null) return; + //遍历绘制字符 for (int i = 0; i < chars.Length; i++) { - int x = (int)chars[i].X; - int y = (int)chars[i].Y; - int width = (int)chars[i].Width; - int height = (int)chars[i].Height; - - gImage.DrawString(chars[i].Char.ToString(), font, brush, x, y, format); + gImage.DrawString(chars[i].Char.ToString(), font, brush, chars[i].X, chars[i].Y); } + } + /// + /// 保存图片到指定路径 + /// + /// 图片路径 public void Save(string path) { Paint(); image.Save(path); - } public Bitmap GetImage() diff --git a/UnitaleFontMaker/FontXml.cs b/UnitaleFontMaker/FontXml.cs index 1394c57..a78daea 100644 --- a/UnitaleFontMaker/FontXml.cs +++ b/UnitaleFontMaker/FontXml.cs @@ -54,6 +54,10 @@ public FontXml() font.AppendChild(spriteSheet); } + /// + /// 保存 XML 文件 + /// + /// 保存路径 public void Save(string path) { for (int i = 0; i < Characters.Length; i++) @@ -75,7 +79,12 @@ public void Save(string path) doc.Save(path); } - public string CheckSpecialChar(string str) + /// + /// 检查特殊字符并替换 + /// + /// 待检查的字符 + /// 替换后的结果 + private string CheckSpecialChar(string str) { switch (str) { diff --git a/UnitaleFontMaker/MainForm.Designer.cs b/UnitaleFontMaker/MainForm.Designer.cs index c511d80..2c57d47 100644 --- a/UnitaleFontMaker/MainForm.Designer.cs +++ b/UnitaleFontMaker/MainForm.Designer.cs @@ -46,345 +46,365 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.btnAutoSave = new System.Windows.Forms.Button(); - this.btnSaveFile = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.btnPreview = new System.Windows.Forms.Button(); - this.panel1 = new System.Windows.Forms.Panel(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.btnScan = new System.Windows.Forms.Button(); - this.btnAutoModeHtlp = new System.Windows.Forms.Button(); - this.btnOpenMod = new System.Windows.Forms.Button(); - this.txtboxModPath = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.txtboxLineSpacing = new System.Windows.Forms.TextBox(); - this.label7 = new System.Windows.Forms.Label(); - this.picboxColor = new System.Windows.Forms.PictureBox(); - this.btnChooseColor = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); - this.btnAddEnChar = new System.Windows.Forms.Button(); - this.btnClear = new System.Windows.Forms.Button(); - this.comboxType = new System.Windows.Forms.ComboBox(); - this.label6 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.labCharNum = new System.Windows.Forms.Label(); - this.txtboxX = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.txtboxY = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.btnAddChar = new System.Windows.Forms.Button(); - this.panel1.SuspendLayout(); - this.groupBox2.SuspendLayout(); - this.groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.picboxColor)).BeginInit(); - this.SuspendLayout(); - // - // btnAutoSave - // - this.btnAutoSave.Enabled = false; - this.btnAutoSave.Location = new System.Drawing.Point(12, 375); - this.btnAutoSave.Name = "btnAutoSave"; - this.btnAutoSave.Size = new System.Drawing.Size(104, 42); - this.btnAutoSave.TabIndex = 1; - this.btnAutoSave.Text = "Auto Save"; - this.btnAutoSave.UseVisualStyleBackColor = true; - this.btnAutoSave.Click += new System.EventHandler(this.BtnAutoSaveClick); - // - // btnSaveFile - // - this.btnSaveFile.Location = new System.Drawing.Point(122, 375); - this.btnSaveFile.Name = "btnSaveFile"; - this.btnSaveFile.Size = new System.Drawing.Size(125, 41); - this.btnSaveFile.TabIndex = 2; - this.btnSaveFile.Text = "Save As File"; - this.btnSaveFile.UseVisualStyleBackColor = true; - this.btnSaveFile.Click += new System.EventHandler(this.BtnSaveFileClick); - // - // button2 - // - this.button2.Location = new System.Drawing.Point(253, 375); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(101, 42); - this.button2.TabIndex = 3; - this.button2.Text = "Set Font"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.Button2Click); - // - // btnPreview - // - this.btnPreview.Location = new System.Drawing.Point(360, 375); - this.btnPreview.Name = "btnPreview"; - this.btnPreview.Size = new System.Drawing.Size(93, 41); - this.btnPreview.TabIndex = 4; - this.btnPreview.Text = "Preview"; - this.btnPreview.UseVisualStyleBackColor = true; - this.btnPreview.Click += new System.EventHandler(this.BtnPreviewClick); - // - // panel1 - // - this.panel1.Controls.Add(this.groupBox2); - this.panel1.Controls.Add(this.groupBox1); - this.panel1.Location = new System.Drawing.Point(5, 7); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(494, 359); - this.panel1.TabIndex = 10; - // - // groupBox2 - // - this.groupBox2.Controls.Add(this.btnScan); - this.groupBox2.Controls.Add(this.btnAutoModeHtlp); - this.groupBox2.Controls.Add(this.btnOpenMod); - this.groupBox2.Controls.Add(this.txtboxModPath); - this.groupBox2.Controls.Add(this.label5); - this.groupBox2.Location = new System.Drawing.Point(7, 217); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(487, 100); - this.groupBox2.TabIndex = 12; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Mod Settings"; - // - // btnScan - // - this.btnScan.Location = new System.Drawing.Point(5, 49); - this.btnScan.Name = "btnScan"; - this.btnScan.Size = new System.Drawing.Size(98, 31); - this.btnScan.TabIndex = 9; - this.btnScan.Text = "Auto Scan"; - this.btnScan.UseVisualStyleBackColor = true; - this.btnScan.Click += new System.EventHandler(this.BtnScanClick); - // - // btnAutoModeHtlp - // - this.btnAutoModeHtlp.Location = new System.Drawing.Point(110, 53); - this.btnAutoModeHtlp.Name = "btnAutoModeHtlp"; - this.btnAutoModeHtlp.Size = new System.Drawing.Size(19, 22); - this.btnAutoModeHtlp.TabIndex = 8; - this.btnAutoModeHtlp.Text = "?"; - this.btnAutoModeHtlp.UseVisualStyleBackColor = true; - this.btnAutoModeHtlp.Click += new System.EventHandler(this.BtnAutoModeHtlpClick); - // - // btnOpenMod - // - this.btnOpenMod.Location = new System.Drawing.Point(440, 22); - this.btnOpenMod.Name = "btnOpenMod"; - this.btnOpenMod.Size = new System.Drawing.Size(43, 24); - this.btnOpenMod.TabIndex = 5; - this.btnOpenMod.Text = "..."; - this.btnOpenMod.UseVisualStyleBackColor = true; - this.btnOpenMod.Click += new System.EventHandler(this.BtnOpenModClick); - // - // txtboxModPath - // - this.txtboxModPath.Location = new System.Drawing.Point(86, 21); - this.txtboxModPath.Name = "txtboxModPath"; - this.txtboxModPath.Size = new System.Drawing.Size(349, 25); - this.txtboxModPath.TabIndex = 4; - this.txtboxModPath.Text = "C:\\Users\\Administrator\\Desktop\\杂项\\UNITALE Alpha 0.2.1a for Windows\\Mods\\Examples5" + - "454"; - // - // label5 - // - this.label5.Location = new System.Drawing.Point(6, 24); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(74, 23); - this.label5.TabIndex = 3; - this.label5.Text = "Mod Path"; - // - // groupBox1 - // - this.groupBox1.Controls.Add(this.txtboxLineSpacing); - this.groupBox1.Controls.Add(this.label7); - this.groupBox1.Controls.Add(this.picboxColor); - this.groupBox1.Controls.Add(this.btnChooseColor); - this.groupBox1.Controls.Add(this.label2); - this.groupBox1.Controls.Add(this.btnAddEnChar); - this.groupBox1.Controls.Add(this.btnClear); - this.groupBox1.Controls.Add(this.comboxType); - this.groupBox1.Controls.Add(this.label6); - this.groupBox1.Controls.Add(this.label1); - this.groupBox1.Controls.Add(this.labCharNum); - this.groupBox1.Controls.Add(this.txtboxX); - this.groupBox1.Controls.Add(this.label4); - this.groupBox1.Controls.Add(this.txtboxY); - this.groupBox1.Controls.Add(this.label3); - this.groupBox1.Controls.Add(this.btnAddChar); - this.groupBox1.Location = new System.Drawing.Point(3, 6); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(491, 203); - this.groupBox1.TabIndex = 10; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Font Settings"; - // - // txtboxLineSpacing - // - this.txtboxLineSpacing.Location = new System.Drawing.Point(119, 171); - this.txtboxLineSpacing.Name = "txtboxLineSpacing"; - this.txtboxLineSpacing.Size = new System.Drawing.Size(100, 25); - this.txtboxLineSpacing.TabIndex = 16; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(10, 174); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(103, 15); - this.label7.TabIndex = 15; - this.label7.Text = "Line spacing"; - // - // picboxColor - // - this.picboxColor.Location = new System.Drawing.Point(103, 138); - this.picboxColor.Name = "picboxColor"; - this.picboxColor.Size = new System.Drawing.Size(30, 25); - this.picboxColor.TabIndex = 14; - this.picboxColor.TabStop = false; - // - // btnChooseColor - // - this.btnChooseColor.Location = new System.Drawing.Point(139, 138); - this.btnChooseColor.Name = "btnChooseColor"; - this.btnChooseColor.Size = new System.Drawing.Size(75, 23); - this.btnChooseColor.TabIndex = 13; - this.btnChooseColor.Text = "Choose"; - this.btnChooseColor.UseVisualStyleBackColor = true; - this.btnChooseColor.Click += new System.EventHandler(this.btnChooseColor_Click); - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(10, 142); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(87, 15); - this.label2.TabIndex = 12; - this.label2.Text = "Font color"; - // - // btnAddEnChar - // - this.btnAddEnChar.Location = new System.Drawing.Point(135, 78); - this.btnAddEnChar.Name = "btnAddEnChar"; - this.btnAddEnChar.Size = new System.Drawing.Size(167, 23); - this.btnAddEnChar.TabIndex = 11; - this.btnAddEnChar.Text = "Add English Chars"; - this.btnAddEnChar.UseVisualStyleBackColor = true; - this.btnAddEnChar.Click += new System.EventHandler(this.btnAddEnChar_Click); - // - // btnClear - // - this.btnClear.Location = new System.Drawing.Point(65, 78); - this.btnClear.Name = "btnClear"; - this.btnClear.Size = new System.Drawing.Size(64, 23); - this.btnClear.TabIndex = 10; - this.btnClear.Text = "Clear"; - this.btnClear.UseVisualStyleBackColor = true; - this.btnClear.Click += new System.EventHandler(this.btnClear_Click); - // - // comboxType - // - this.comboxType.FormattingEnabled = true; - this.comboxType.Items.AddRange(new object[] { - "uidialog", - "monster"}); - this.comboxType.Location = new System.Drawing.Point(101, 108); - this.comboxType.Name = "comboxType"; - this.comboxType.Size = new System.Drawing.Size(201, 23); - this.comboxType.TabIndex = 9; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(10, 110); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(79, 15); - this.label6.TabIndex = 8; - this.label6.Text = "Font name"; - // - // label1 - // - this.label1.Location = new System.Drawing.Point(6, 21); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(104, 21); - this.label1.TabIndex = 0; - this.label1.Text = "Image size"; - // - // labCharNum - // - this.labCharNum.Location = new System.Drawing.Point(10, 57); - this.labCharNum.Name = "labCharNum"; - this.labCharNum.Size = new System.Drawing.Size(336, 18); - this.labCharNum.TabIndex = 7; - this.labCharNum.Text = "No characters, please add from text file."; - // - // txtboxX - // - this.txtboxX.Location = new System.Drawing.Point(125, 19); - this.txtboxX.Name = "txtboxX"; - this.txtboxX.Size = new System.Drawing.Size(71, 25); - this.txtboxX.TabIndex = 1; - this.txtboxX.Text = "400"; - // - // label4 - // - this.label4.Location = new System.Drawing.Point(208, 22); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(13, 23); - this.label4.TabIndex = 6; - this.label4.Text = "Y"; - // - // txtboxY - // - this.txtboxY.Location = new System.Drawing.Point(227, 19); - this.txtboxY.Name = "txtboxY"; - this.txtboxY.Size = new System.Drawing.Size(74, 25); - this.txtboxY.TabIndex = 2; - this.txtboxY.Text = "400"; - // - // label3 - // - this.label3.Location = new System.Drawing.Point(106, 21); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(13, 23); - this.label3.TabIndex = 5; - this.label3.Text = "X"; - // - // btnAddChar - // - this.btnAddChar.Location = new System.Drawing.Point(9, 78); - this.btnAddChar.Name = "btnAddChar"; - this.btnAddChar.Size = new System.Drawing.Size(50, 23); - this.btnAddChar.TabIndex = 4; - this.btnAddChar.Text = "Add"; - this.btnAddChar.UseVisualStyleBackColor = true; - this.btnAddChar.Click += new System.EventHandler(this.BtnAddFileClick); - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(511, 429); - this.Controls.Add(this.panel1); - this.Controls.Add(this.btnPreview); - this.Controls.Add(this.button2); - this.Controls.Add(this.btnSaveFile); - this.Controls.Add(this.btnAutoSave); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.Name = "MainForm"; - this.Text = "Unitale Font Maker"; - this.panel1.ResumeLayout(false); - this.groupBox2.ResumeLayout(false); - this.groupBox2.PerformLayout(); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.picboxColor)).EndInit(); - this.ResumeLayout(false); + this.btnAutoSave = new System.Windows.Forms.Button(); + this.btnSaveFile = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.btnPreview = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.btnScan = new System.Windows.Forms.Button(); + this.btnAutoModeHtlp = new System.Windows.Forms.Button(); + this.btnOpenMod = new System.Windows.Forms.Button(); + this.txtboxModPath = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.txtboxLineSpacing = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.picboxColor = new System.Windows.Forms.PictureBox(); + this.btnChooseColor = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.btnClear = new System.Windows.Forms.Button(); + this.comboxType = new System.Windows.Forms.ComboBox(); + this.label6 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.labCharNum = new System.Windows.Forms.Label(); + this.txtboxX = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtboxY = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.btnAddChar = new System.Windows.Forms.Button(); + this.panel1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picboxColor)).BeginInit(); + this.SuspendLayout(); + // + // btnAutoSave + // + this.btnAutoSave.Enabled = false; + this.btnAutoSave.Location = new System.Drawing.Point(9, 300); + this.btnAutoSave.Margin = new System.Windows.Forms.Padding(2); + this.btnAutoSave.Name = "btnAutoSave"; + this.btnAutoSave.Size = new System.Drawing.Size(78, 34); + this.btnAutoSave.TabIndex = 1; + this.btnAutoSave.Text = "Auto Save"; + this.btnAutoSave.UseVisualStyleBackColor = true; + this.btnAutoSave.Click += new System.EventHandler(this.BtnAutoSaveClick); + // + // btnSaveFile + // + this.btnSaveFile.Location = new System.Drawing.Point(92, 300); + this.btnSaveFile.Margin = new System.Windows.Forms.Padding(2); + this.btnSaveFile.Name = "btnSaveFile"; + this.btnSaveFile.Size = new System.Drawing.Size(94, 33); + this.btnSaveFile.TabIndex = 2; + this.btnSaveFile.Text = "Save As File"; + this.btnSaveFile.UseVisualStyleBackColor = true; + this.btnSaveFile.Click += new System.EventHandler(this.BtnSaveFileClick); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(190, 300); + this.button2.Margin = new System.Windows.Forms.Padding(2); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(76, 34); + this.button2.TabIndex = 3; + this.button2.Text = "Set Font"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2Click); + // + // btnPreview + // + this.btnPreview.Location = new System.Drawing.Point(270, 300); + this.btnPreview.Margin = new System.Windows.Forms.Padding(2); + this.btnPreview.Name = "btnPreview"; + this.btnPreview.Size = new System.Drawing.Size(70, 33); + this.btnPreview.TabIndex = 4; + this.btnPreview.Text = "Preview"; + this.btnPreview.UseVisualStyleBackColor = true; + this.btnPreview.Click += new System.EventHandler(this.BtnPreviewClick); + // + // panel1 + // + this.panel1.Controls.Add(this.groupBox2); + this.panel1.Controls.Add(this.groupBox1); + this.panel1.Location = new System.Drawing.Point(4, 6); + this.panel1.Margin = new System.Windows.Forms.Padding(2); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(370, 287); + this.panel1.TabIndex = 10; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.btnScan); + this.groupBox2.Controls.Add(this.btnAutoModeHtlp); + this.groupBox2.Controls.Add(this.btnOpenMod); + this.groupBox2.Controls.Add(this.txtboxModPath); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Location = new System.Drawing.Point(5, 174); + this.groupBox2.Margin = new System.Windows.Forms.Padding(2); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Padding = new System.Windows.Forms.Padding(2); + this.groupBox2.Size = new System.Drawing.Size(365, 80); + this.groupBox2.TabIndex = 12; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Mod Settings"; + // + // btnScan + // + this.btnScan.Enabled = false; + this.btnScan.Location = new System.Drawing.Point(4, 39); + this.btnScan.Margin = new System.Windows.Forms.Padding(2); + this.btnScan.Name = "btnScan"; + this.btnScan.Size = new System.Drawing.Size(74, 25); + this.btnScan.TabIndex = 9; + this.btnScan.Text = "Auto Scan"; + this.btnScan.UseVisualStyleBackColor = true; + this.btnScan.Click += new System.EventHandler(this.BtnScanClick); + // + // btnAutoModeHtlp + // + this.btnAutoModeHtlp.Location = new System.Drawing.Point(82, 42); + this.btnAutoModeHtlp.Margin = new System.Windows.Forms.Padding(2); + this.btnAutoModeHtlp.Name = "btnAutoModeHtlp"; + this.btnAutoModeHtlp.Size = new System.Drawing.Size(14, 18); + this.btnAutoModeHtlp.TabIndex = 8; + this.btnAutoModeHtlp.Text = "?"; + this.btnAutoModeHtlp.UseVisualStyleBackColor = true; + this.btnAutoModeHtlp.Click += new System.EventHandler(this.BtnAutoModeHtlpClick); + // + // btnOpenMod + // + this.btnOpenMod.Location = new System.Drawing.Point(330, 18); + this.btnOpenMod.Margin = new System.Windows.Forms.Padding(2); + this.btnOpenMod.Name = "btnOpenMod"; + this.btnOpenMod.Size = new System.Drawing.Size(32, 19); + this.btnOpenMod.TabIndex = 5; + this.btnOpenMod.Text = "..."; + this.btnOpenMod.UseVisualStyleBackColor = true; + this.btnOpenMod.Click += new System.EventHandler(this.BtnOpenModClick); + // + // txtboxModPath + // + this.txtboxModPath.Location = new System.Drawing.Point(64, 17); + this.txtboxModPath.Margin = new System.Windows.Forms.Padding(2); + this.txtboxModPath.Name = "txtboxModPath"; + this.txtboxModPath.Size = new System.Drawing.Size(263, 21); + this.txtboxModPath.TabIndex = 4; + this.txtboxModPath.Text = "C:\\Users\\Administrator\\Desktop\\杂项\\UNITALE Alpha 0.2.1a for Windows\\Mods\\Examples5" + + "454"; + // + // label5 + // + this.label5.Location = new System.Drawing.Point(4, 19); + this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(56, 18); + this.label5.TabIndex = 3; + this.label5.Text = "Mod Path"; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.txtboxLineSpacing); + this.groupBox1.Controls.Add(this.label7); + this.groupBox1.Controls.Add(this.picboxColor); + this.groupBox1.Controls.Add(this.btnChooseColor); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.btnClear); + this.groupBox1.Controls.Add(this.comboxType); + this.groupBox1.Controls.Add(this.label6); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.labCharNum); + this.groupBox1.Controls.Add(this.txtboxX); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.txtboxY); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.btnAddChar); + this.groupBox1.Location = new System.Drawing.Point(2, 5); + this.groupBox1.Margin = new System.Windows.Forms.Padding(2); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(2); + this.groupBox1.Size = new System.Drawing.Size(368, 162); + this.groupBox1.TabIndex = 10; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Font Settings"; + // + // txtboxLineSpacing + // + this.txtboxLineSpacing.Location = new System.Drawing.Point(89, 137); + this.txtboxLineSpacing.Margin = new System.Windows.Forms.Padding(2); + this.txtboxLineSpacing.Name = "txtboxLineSpacing"; + this.txtboxLineSpacing.Size = new System.Drawing.Size(76, 21); + this.txtboxLineSpacing.TabIndex = 16; + this.txtboxLineSpacing.Text = "32"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(8, 139); + this.label7.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(77, 12); + this.label7.TabIndex = 15; + this.label7.Text = "Line spacing"; + // + // picboxColor + // + this.picboxColor.Location = new System.Drawing.Point(77, 110); + this.picboxColor.Margin = new System.Windows.Forms.Padding(2); + this.picboxColor.Name = "picboxColor"; + this.picboxColor.Size = new System.Drawing.Size(22, 20); + this.picboxColor.TabIndex = 14; + this.picboxColor.TabStop = false; + // + // btnChooseColor + // + this.btnChooseColor.Location = new System.Drawing.Point(104, 110); + this.btnChooseColor.Margin = new System.Windows.Forms.Padding(2); + this.btnChooseColor.Name = "btnChooseColor"; + this.btnChooseColor.Size = new System.Drawing.Size(56, 18); + this.btnChooseColor.TabIndex = 13; + this.btnChooseColor.Text = "Choose"; + this.btnChooseColor.UseVisualStyleBackColor = true; + this.btnChooseColor.Click += new System.EventHandler(this.btnChooseColor_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(8, 114); + this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 12; + this.label2.Text = "Font color"; + // + // btnClear + // + this.btnClear.Location = new System.Drawing.Point(49, 62); + this.btnClear.Margin = new System.Windows.Forms.Padding(2); + this.btnClear.Name = "btnClear"; + this.btnClear.Size = new System.Drawing.Size(48, 18); + this.btnClear.TabIndex = 10; + this.btnClear.Text = "Clear"; + this.btnClear.UseVisualStyleBackColor = true; + this.btnClear.Click += new System.EventHandler(this.btnClear_Click); + // + // comboxType + // + this.comboxType.FormattingEnabled = true; + this.comboxType.Items.AddRange(new object[] { + "uidialog", + "monster"}); + this.comboxType.Location = new System.Drawing.Point(76, 86); + this.comboxType.Margin = new System.Windows.Forms.Padding(2); + this.comboxType.Name = "comboxType"; + this.comboxType.Size = new System.Drawing.Size(152, 20); + this.comboxType.TabIndex = 9; + this.comboxType.Text = "uidialog"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(8, 88); + this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(59, 12); + this.label6.TabIndex = 8; + this.label6.Text = "Font name"; + // + // label1 + // + this.label1.Location = new System.Drawing.Point(8, 19); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(78, 17); + this.label1.TabIndex = 0; + this.label1.Text = "Image size"; + // + // labCharNum + // + this.labCharNum.Location = new System.Drawing.Point(8, 46); + this.labCharNum.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labCharNum.Name = "labCharNum"; + this.labCharNum.Size = new System.Drawing.Size(252, 14); + this.labCharNum.TabIndex = 7; + this.labCharNum.Text = "No characters, please add from text file."; + // + // txtboxX + // + this.txtboxX.Location = new System.Drawing.Point(108, 15); + this.txtboxX.Margin = new System.Windows.Forms.Padding(2); + this.txtboxX.Name = "txtboxX"; + this.txtboxX.Size = new System.Drawing.Size(54, 21); + this.txtboxX.TabIndex = 1; + this.txtboxX.Text = "400"; + // + // label4 + // + this.label4.Location = new System.Drawing.Point(170, 18); + this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(10, 18); + this.label4.TabIndex = 6; + this.label4.Text = "Y"; + // + // txtboxY + // + this.txtboxY.Location = new System.Drawing.Point(184, 15); + this.txtboxY.Margin = new System.Windows.Forms.Padding(2); + this.txtboxY.Name = "txtboxY"; + this.txtboxY.Size = new System.Drawing.Size(56, 21); + this.txtboxY.TabIndex = 2; + this.txtboxY.Text = "400"; + // + // label3 + // + this.label3.Location = new System.Drawing.Point(94, 17); + this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(10, 18); + this.label3.TabIndex = 5; + this.label3.Text = "X"; + // + // btnAddChar + // + this.btnAddChar.Location = new System.Drawing.Point(7, 62); + this.btnAddChar.Margin = new System.Windows.Forms.Padding(2); + this.btnAddChar.Name = "btnAddChar"; + this.btnAddChar.Size = new System.Drawing.Size(38, 18); + this.btnAddChar.TabIndex = 4; + this.btnAddChar.Text = "Add"; + this.btnAddChar.UseVisualStyleBackColor = true; + this.btnAddChar.Click += new System.EventHandler(this.BtnAddFileClick); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(383, 343); + this.Controls.Add(this.panel1); + this.Controls.Add(this.btnPreview); + this.Controls.Add(this.button2); + this.Controls.Add(this.btnSaveFile); + this.Controls.Add(this.btnAutoSave); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Margin = new System.Windows.Forms.Padding(2); + this.MaximizeBox = false; + this.Name = "MainForm"; + this.Text = "Unitale Font Maker"; + this.panel1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picboxColor)).EndInit(); + this.ResumeLayout(false); } private System.Windows.Forms.ComboBox comboxType; private System.Windows.Forms.Label label6; private System.Windows.Forms.Button btnClear; - private System.Windows.Forms.Button btnAddEnChar; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btnChooseColor; private System.Windows.Forms.PictureBox picboxColor; diff --git a/UnitaleFontMaker/MainForm.cs b/UnitaleFontMaker/MainForm.cs index 6f30114..8c649dd 100644 --- a/UnitaleFontMaker/MainForm.cs +++ b/UnitaleFontMaker/MainForm.cs @@ -9,7 +9,7 @@ namespace UnitaleFontMaker { /// - /// Description of MainForm. + /// 主界面 /// public partial class MainForm : Form { @@ -18,7 +18,6 @@ public partial class MainForm : Form private int height; private string chars; private Color fontColor = Color.White; - private const string enChars = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "; private List characters = new List(); public string ModPath { @@ -33,52 +32,10 @@ public MainForm() Brush brush = Brushes.White; painter = new FontPainter(font, 400, 400); picboxColor.BackColor = fontColor; - } - - /// - /// 显示一个带错误图标的信息框 - /// - /// 要显示的信息 - private void ShowError(string str) - { - MessageBox.Show(str, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - private void CopyDir( string srcPath, string aimPath ) - { - try { - /* 检查目标目录是否以目录分割字符结束如果不是则添加 */ - if ( aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar ) - { - aimPath += System.IO.Path.DirectorySeparatorChar; - } - /* 判断目标目录是否存在如果不存在则新建 */ - if ( !System.IO.Directory.Exists( aimPath ) ) - { - System.IO.Directory.CreateDirectory( aimPath ); - } - /* - * 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组 - * 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法 - * string[] fileList = Directory.GetFiles(srcPath); - */ - string[] fileList = System.IO.Directory.GetFileSystemEntries( srcPath ); - /* 遍历所有的文件和目录 */ - foreach ( string file in fileList ) - { - /* 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 */ - if ( System.IO.Directory.Exists( file ) ) - { - CopyDir( file, aimPath + System.IO.Path.GetFileName( file ) ); - } - /* 否则直接Copy文件 */ - else { - System.IO.File.Copy( file, aimPath + System.IO.Path.GetFileName( file ), true ); - } - } - } catch ( Exception e ) { - throw; - } + + //自动添加必须添加的字符 + chars += Characters.MUST_CHARS; + labCharNum.Text = "Character: " + chars.Length; } //自动保存 @@ -97,7 +54,7 @@ private void BtnAutoSaveClick(object sender, EventArgs e) Directory.Move(modFontPath, Path.Combine(new DirectoryInfo(modFontPath).Parent.FullName, "Fonts_backup")); //复制默认字体文件 - CopyDir(defaultFontPath, modFontPath); + Utils.CopyDir(defaultFontPath, modFontPath); //删除要替换的字体文件 File.Delete(Path.Combine(modFontPath, "uidialog.png")); @@ -151,14 +108,14 @@ private bool SaveCheck() //检查字体名称 if (string.IsNullOrWhiteSpace(comboxType.Text)) { - ShowError("Please enter a font name!"); + Utils.ShowError("Please enter a font name!"); return false; } //检查字符是否为空 if(string.IsNullOrEmpty(chars)) { - ShowError("You have not added a character yet!"); + Utils.ShowError("You have not added a character yet!"); return false; } @@ -166,14 +123,14 @@ private bool SaveCheck() Regex regex = new Regex(@"[^\u4e00-\u9fa5]"); if(!regex.IsMatch(chars)) { - ShowError("No English characters found, please add to the font!"); + Utils.ShowError("No English characters found!"); return false; } //检查行距 if(string.IsNullOrWhiteSpace(txtboxLineSpacing.Text)) { - ShowError("Line spacing is empty."); + Utils.ShowError("Line spacing is empty."); return false; } @@ -181,9 +138,9 @@ private bool SaveCheck() { int.Parse(txtboxLineSpacing.Text); } - catch (Exception e) + catch { - ShowError("Invalid line spacing."); + Utils.ShowError("Invalid line spacing."); return false; } @@ -206,9 +163,9 @@ void BtnPreviewClick(object sender, EventArgs e) width = int.Parse(txtboxX.Text); height = int.Parse(txtboxY.Text); } - catch (Exception ex) + catch { - ShowError("Invalid size."); + Utils.ShowError("Invalid size."); } painter.Text = chars; @@ -241,13 +198,6 @@ private void btnClear_Click(object sender, EventArgs e) labCharNum.Text = "No characters, please add from text file."; } - //增加英文字符 - private void btnAddEnChar_Click(object sender, EventArgs e) - { - chars += enChars; - labCharNum.Text = "Character: " + chars.Length; - } - //--------------字体颜色设置部分--------------- //选择颜色 private void btnChooseColor_Click(object sender, EventArgs e) @@ -272,11 +222,11 @@ void BtnOpenModClick(object sender, EventArgs e) if(dialog.ShowDialog() == DialogResult.OK) { string path = dialog.SelectedPath; - if(!Directory.Exists(Path.Combine(path, "Lua"))) + /*if(!Directory.Exists(Path.Combine(path, "Lua"))) { - ShowError("Invalid mod directory(Must have a \"Lua\" directory)."); + Utils.ShowError("Invalid mod directory(Must have a \"Lua\" directory)."); return; - } + } */ txtboxModPath.Text = dialog.SelectedPath; } dialog.Dispose(); @@ -332,10 +282,15 @@ private string[] GetAllStrings(string lua) private void GetAllDirectory(string path, List luaFiles) { DirectoryInfo root = new DirectoryInfo(path); + if (!root.Exists) + { + Utils.ShowError("Lua directory not found!"); + return; + } DirectoryInfo[] dirs = root.GetDirectories(); //扫描所有Lua文件 - FileInfo[] files = GetAllFiles(path); + FileInfo[] files = Utils.GetAllFiles(path); for (int i = 0; i < files.Length; i++) { if(files[i].Extension == ".lua") @@ -349,18 +304,6 @@ private void GetAllDirectory(string path, List luaFiles) } } - - /// - /// 获取指定文件夹中的所有文件 - /// - /// 指定文件夹 - private FileInfo[] GetAllFiles(string path) - { - DirectoryInfo root = new DirectoryInfo(path); - FileInfo[] files = root.GetFiles(); - - return files; - } } diff --git a/UnitaleFontMaker/PreviewForm.Designer.cs b/UnitaleFontMaker/PreviewForm.Designer.cs index 4ead1c4..8211191 100644 --- a/UnitaleFontMaker/PreviewForm.Designer.cs +++ b/UnitaleFontMaker/PreviewForm.Designer.cs @@ -40,75 +40,78 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.imageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.menuStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBox1 - // - this.pictureBox1.Location = new System.Drawing.Point(67, 98); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(136, 87); - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBox1Paint); - // - // menuStrip1 - // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.imageToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(381, 28); - this.menuStrip1.TabIndex = 1; - this.menuStrip1.Text = "menuStrip1"; - // - // imageToolStripMenuItem - // - this.imageToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripComboBox1}); - this.imageToolStripMenuItem.Name = "imageToolStripMenuItem"; - this.imageToolStripMenuItem.Size = new System.Drawing.Size(59, 24); - this.imageToolStripMenuItem.Text = "Scale"; - // - // toolStripComboBox1 - // - this.toolStripComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.toolStripComboBox1.Items.AddRange(new object[] { - "25%", - "50%", - "75%", - "100%", - "125%", - "150%", - "200%"}); - this.toolStripComboBox1.Name = "toolStripComboBox1"; - this.toolStripComboBox1.Size = new System.Drawing.Size(121, 28); - this.toolStripComboBox1.SelectedIndexChanged += new System.EventHandler(this.ToolStripComboBox1SelectedIndexChanged); - // - // PreviewForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(381, 303); - this.Controls.Add(this.pictureBox1); - this.Controls.Add(this.menuStrip1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MainMenuStrip = this.menuStrip1; - this.MaximizeBox = false; - this.Name = "PreviewForm"; - this.Text = "Preview"; - this.Load += new System.EventHandler(this.PreviewFormLoad); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.imageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(70, 82); + this.pictureBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(102, 70); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBox1Paint); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.imageToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(286, 24); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // imageToolStripMenuItem + // + this.imageToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripComboBox1}); + this.imageToolStripMenuItem.Name = "imageToolStripMenuItem"; + this.imageToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.imageToolStripMenuItem.Text = "Scale"; + // + // toolStripComboBox1 + // + this.toolStripComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.toolStripComboBox1.Items.AddRange(new object[] { + "25%", + "50%", + "75%", + "100%", + "125%", + "150%", + "200%"}); + this.toolStripComboBox1.Name = "toolStripComboBox1"; + this.toolStripComboBox1.Size = new System.Drawing.Size(121, 21); + this.toolStripComboBox1.SelectedIndexChanged += new System.EventHandler(this.ToolStripComboBox1SelectedIndexChanged); + // + // PreviewForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(286, 242); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.menuStrip1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.MaximizeBox = false; + this.Name = "PreviewForm"; + this.Text = "Preview"; + this.Load += new System.EventHandler(this.PreviewFormLoad); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); } } diff --git a/UnitaleFontMaker/PreviewForm.cs b/UnitaleFontMaker/PreviewForm.cs index 1e2413a..0d0db4e 100644 --- a/UnitaleFontMaker/PreviewForm.cs +++ b/UnitaleFontMaker/PreviewForm.cs @@ -1,19 +1,11 @@ -/* - * Created by SharpDevelop. - * User: Administrator - * Date: 2019/6/1 星期六 - * Time: 17:36 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ -using System; +using System; using System.Drawing; using System.Windows.Forms; namespace UnitaleFontMaker { /// - /// Description of PreviewForm. + /// 字体图像预览窗口 /// public partial class PreviewForm : Form { @@ -24,6 +16,7 @@ public partial class PreviewForm : Form public PreviewForm(FontPainter painter) { InitializeComponent(); + this.painter = painter; image = painter.GetImage(); imageSize = new Size(image.Width, image.Height); @@ -55,18 +48,15 @@ void ToolStripComboBox1SelectedIndexChanged(object sender, EventArgs e) { string str = toolStripComboBox1.Text; str = str.Replace("%", ""); - try - { - int scale = int.Parse(str) / 100; - int width = (int)(imageSize.Width * scale); - int height = (int)(imageSize.Height * scale); - Resize(width, height); - } - catch (Exception ex) - { - throw; - } - + try + { + int scale = int.Parse(str) / 100; + int width = (int)(imageSize.Width * scale); + int height = (int)(imageSize.Height * scale); + Resize(width, height); + } + catch { throw; } + } } diff --git a/UnitaleFontMaker/UnitaleFontMaker.csproj b/UnitaleFontMaker/UnitaleFontMaker.csproj index 7616f5c..9c742df 100644 --- a/UnitaleFontMaker/UnitaleFontMaker.csproj +++ b/UnitaleFontMaker/UnitaleFontMaker.csproj @@ -51,6 +51,7 @@ + Form @@ -67,6 +68,7 @@ + diff --git a/UnitaleFontMaker/Utils.cs b/UnitaleFontMaker/Utils.cs new file mode 100644 index 0000000..7b88343 --- /dev/null +++ b/UnitaleFontMaker/Utils.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.IO; + +namespace UnitaleFontMaker +{ + class Utils + { + /// + /// 显示一个带错误图标的信息框 + /// + /// 要显示的信息 + public static void ShowError(string str) + { + MessageBox.Show(str, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + /// + /// 获取指定文件夹中的所有文件 + /// + /// 指定文件夹 + public static FileInfo[] GetAllFiles(string path) + { + DirectoryInfo root = new DirectoryInfo(path); + FileInfo[] files = root.GetFiles(); + + return files; + } + + /// + /// 复制文件夹 + /// + /// 源文件夹 + /// 目标文件夹 + public static void CopyDir(string srcPath, string aimPath) + { + try + { + /* 检查目标目录是否以目录分割字符结束如果不是则添加 */ + if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar) + { + aimPath += System.IO.Path.DirectorySeparatorChar; + } + /* 判断目标目录是否存在如果不存在则新建 */ + if (!System.IO.Directory.Exists(aimPath)) + { + System.IO.Directory.CreateDirectory(aimPath); + } + /* + * 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组 + * 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法 + * string[] fileList = Directory.GetFiles(srcPath); + */ + string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath); + /* 遍历所有的文件和目录 */ + foreach (string file in fileList) + { + /* 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 */ + if (System.IO.Directory.Exists(file)) + { + CopyDir(file, aimPath + System.IO.Path.GetFileName(file)); + } + /* 否则直接Copy文件 */ + else + { + System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true); + } + } + } + catch { throw; } + } + } +}