private void toolStripButton_add_Click(object sender, EventArgs e) { string tOut; if (DialogResult.OK == Dialog_InputBox.OpenDialog("要添加字符的个数:", "添加字符", "1", out tOut)) { int tCount = 0; try { tCount = Convert.ToInt32(tOut); } catch (Exception Expt) { Helper.ShowErr("无效值:" + Expt.Message); return; } for (int i = 0; i < tCount; ++i) { _Def.CharList.Add(new FontDef.CharDef()); } RefreshAll(); } }
public static DialogResult OpenDialog(string TipText, string Caption, string Default, out string InputText) { Dialog_InputBox tForm = new Dialog_InputBox(TipText, Caption, Default); DialogResult tRet = tForm.ShowDialog(); InputText = tForm.InputText; return tRet; }
public static DialogResult OpenDialog(string TipText, string Caption, string Default, out string InputText) { Dialog_InputBox tForm = new Dialog_InputBox(TipText, Caption, Default); DialogResult tRet = tForm.ShowDialog(); InputText = tForm.InputText; return(tRet); }
private void ToolStripMenuItem_usersize_Click(object sender, EventArgs e) { string tOutWidth; string tOutHeight; int tWidth; int tHeight; if (DialogResult.OK == Dialog_InputBox.OpenDialog("请输入纹理宽度", "纹理宽度", _Def.TexWidth.ToString(), out tOutWidth)) { try { tWidth = Convert.ToInt32(tOutWidth); } catch (Exception Expt) { Helper.ShowErr("格式不正确: " + Expt.Message); return; } if (DialogResult.OK == Dialog_InputBox.OpenDialog("请输入纹理高度", "纹理高度", _Def.TexHeight.ToString(), out tOutHeight)) { try { tHeight = Convert.ToInt32(tOutHeight); } catch (Exception Expt) { Helper.ShowErr("格式不正确: " + Expt.Message); return; } } else { return; } } else { return; } ToolStripMenuItem_256x256.Checked = false; ToolStripMenuItem_512x512.Checked = false; ToolStripMenuItem_1024x1024.Checked = false; ToolStripMenuItem_2048x2048.Checked = false; ToolStripMenuItem_usersize.Checked = true; _Def.TexWidth = tWidth; _Def.TexHeight = tHeight; RefreshAll(); }
private void ToolStripMenuItem_setbaseline_Click(object sender, EventArgs e) { if (listView_charmap.SelectedItems.Count > 0) { string tOut; if (DialogResult.OK == Dialog_InputBox.OpenDialog("请输入基线值, 前缀@表示相对量:", "设置字体基线", "0", out tOut)) { bool tOffset = false; if (tOut.Length > 0 && tOut[0] == '@') { tOffset = true; tOut = tOut.Remove(0, 1); } int tValue; try { tValue = Convert.ToInt32(tOut); } catch (Exception Expt) { Helper.ShowErr("格式不正确: " + Expt.Message); return; } foreach (ListViewItem x in listView_charmap.SelectedItems) { FontDef.CharDef tDef = (FontDef.CharDef)x.Tag; if (tOffset) { tDef.Baseline += tValue; } else { tDef.Baseline = tValue; } } } } Repaint(); }
private void ToolStripMenuItem_export_Click(object sender, EventArgs e) { // 检查字符表 HashSet <char> tCharset = new HashSet <char>(); foreach (FontDef.CharDef x in _Def.CharList) { if (tCharset.Contains(x.Character)) { Helper.ShowErr("字符表中存在重复字符: " + x.Character.ToString()); return; } else if (x.Character == '\0') { Helper.ShowErr("字符表中存在无效字符。"); return; } else { tCharset.Add(x.Character); } } // 决定保存路径 string tPathToSave; if (DialogResult.Cancel == saveFileDialog_savexml.ShowDialog()) { return; } tPathToSave = saveFileDialog_savexml.FileName; string tOut; if (DialogResult.Cancel == Dialog_InputBox.OpenDialog("请输入行间距:", "设置行间距", "0", out tOut)) { return; } int tLineGap; try { tLineGap = Convert.ToInt32(tOut); } catch (Exception Expt) { Helper.ShowErr("格式不正确: " + Expt.Message); return; } XmlDocument tDoc = new XmlDocument(); XmlElement tRoot = tDoc.CreateElement("f2dTexturedFont"); XmlElement tMeasure = tDoc.CreateElement("Measure"); tMeasure.SetAttribute("LineHeight", (_Def.MaxLineHeight + tLineGap).ToString()); tMeasure.SetAttribute("Ascender", _Def.MaxLineHeight.ToString()); tMeasure.SetAttribute("Descender", "0"); tRoot.AppendChild(tMeasure); // 追加字符表 XmlElement tCharTable = tDoc.CreateElement("CharList"); foreach (FontDef.CharDef x in _Def.CharList) { XmlElement tItem = tDoc.CreateElement("Item"); tItem.SetAttribute("Char", x.Character.ToString()); tItem.SetAttribute("Pos", String.Format("{0},{1}", x.Location.X, x.Location.Y)); tItem.SetAttribute("Size", String.Format("{0},{1}", x.CharSize.Width, x.CharSize.Height)); tItem.SetAttribute("BrushPos", String.Format("{0},{1}", x.ImageMargin, x.CharSize.Height - x.ImageMargin + x.Baseline)); tItem.SetAttribute("Advance", String.Format("{0},{1}", x.CharSize.Width - x.ImageMargin * 2 + x.Advance, 0)); tCharTable.AppendChild(tItem); } tRoot.AppendChild(tCharTable); tDoc.AppendChild(tRoot); try { Helper.WriteFSTGXmlType(tDoc, tPathToSave); } catch (Exception Expt) { Helper.ShowErr("保存失败!\n" + Expt.Message); } }