public void SaveTo(string FilePath) { XmlDocument tDoc = new XmlDocument(); XmlElement tRoot = tDoc.CreateElement("FontDef"); tRoot.SetAttribute("TexWidth", TexWidth.ToString()); tRoot.SetAttribute("TexHeight", TexHeight.ToString()); tRoot.SetAttribute("AntiAlias", ((int)AntiAlias).ToString()); foreach (FontDef.CharDef x in _CharList) { XmlElement tElement = tDoc.CreateElement("Char"); tElement.SetAttribute("Advance", x.Advance.ToString()); tElement.SetAttribute("Baseline", x.Baseline.ToString()); tElement.SetAttribute("Character", x.Character.ToString()); tElement.SetAttribute("ImageMargin", x.ImageMargin.ToString()); tElement.SetAttribute("FontColor", x.FontColor.ToArgb().ToString()); if (x.SrcFont != null) { tElement.SetAttribute("Bold", x.SrcFont.Bold.ToString()); tElement.SetAttribute("Italic", x.SrcFont.Italic.ToString()); tElement.SetAttribute("Strikeout", x.SrcFont.Strikeout.ToString()); tElement.SetAttribute("Underline", x.SrcFont.Underline.ToString()); tElement.SetAttribute("FontName", x.SrcFont.FontFamily.Name); tElement.SetAttribute("FontSize", x.SrcFont.Size.ToString()); } else { tElement.SetAttribute("Bold", "False"); tElement.SetAttribute("Italic", "False"); tElement.SetAttribute("Strikeout", "False"); tElement.SetAttribute("Underline", "False"); tElement.SetAttribute("FontName", "宋体"); tElement.SetAttribute("FontSize", "12"); } tRoot.AppendChild(tElement); } tDoc.AppendChild(tRoot); tDoc.Save(FilePath); }
private void Import_Click(object sender, RoutedEventArgs e) { UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".png"; dlg.Filter = "PNG files (.png)|*.png|All files|*"; if (dlg.ShowDialog() == true) { try { Bitmap bmp; using (var ms = new MemoryStream(TextureWorker.ReadTextureBlob(dlg.FileName))) { bmp = new Bitmap(ms); } bmp.SetResolution(96.0F, 96.0F); var width = (uint)bmp.Width; var height = (uint)bmp.Height; if ((width & (width - 1)) != 0 || (height & (height - 1)) != 0) { mainWindow.ShowWarning("WARNING: texture page dimensions are not powers of 2. Sprite blurring is very likely in game.", "Unexpected texture dimensions"); } using (var stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); target.TextureData.TextureBlob = stream.ToArray(); TexWidth.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); TexHeight.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); } } catch (Exception ex) { mainWindow.ShowError("Failed to import file: " + ex.Message, "Failed to import file"); } } }