private bool LoadBitmapFromXml(string filename) { bool result = false; try { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc.DocumentElement; if (root.Attributes["type"] != null) { if (root.Attributes["type"].Value == "image") { XmlNode nodeBitmap = root.SelectSingleNode("bitmap"); if (nodeBitmap != null) { this.mEditor.BmpEditor.Bmp = BitmapHelper.LoadFromXml(nodeBitmap); result = true; } else { throw new Exception("Invalid format of file, 'bitmap' node not found"); } } else { throw new Exception("Invalid format of file, attribute 'type' must be equal to 'image'"); } } else { throw new Exception("Invalid format of file, attribute 'type' not defined"); } } catch (Exception exc) { MessageBox.Show(exc.Message, "Error while loading file", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(result); }
private bool LoadFontFromXml(string filename) { bool result = false; try { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc.DocumentElement; if (root.Attributes["type"] != null) { if (root.Attributes["type"].Value == "font") { XmlNodeList nodesChar = root.SelectNodes("chars/char"); if (nodesChar != null && nodesChar.Count > 0) { List <byte> bytes = new List <byte>(); this.mFontEdCtrl.FontContainer.CharBitmaps.Clear(); foreach (XmlNode nodeChar in nodesChar) { XmlNodeList nodeEncodingBytes = nodeChar.SelectNodes("encoding[@codepage=65001]/bytes/byte"); bytes.Clear(); foreach (XmlNode nodeByte in nodeEncodingBytes) { bytes.Add(Convert.ToByte(nodeByte.InnerText, 16)); } char c = Encoding.UTF8.GetString(bytes.ToArray())[0]; XmlNode nodeBitmap = nodeChar["bitmap"]; Bitmap charBitmap = BitmapHelper.LoadFromXml(nodeBitmap); this.mFontEdCtrl.FontContainer.CharBitmaps.Add(c, charBitmap); } if (root["family"] != null) { this.mFontEdCtrl.FontContainer.FontFamily = new FontFamily(root["family"].InnerText); } if (root["size"] != null) { this.mFontEdCtrl.FontContainer.Size = Convert.ToInt32(root["size"].InnerText, CultureInfo.InvariantCulture); } if (root["style"] != null) { this.mFontEdCtrl.FontContainer.Style = (FontStyle)Enum.Parse(typeof(FontStyle), root["style"].InnerText); } this.mFontEdCtrl.ApplyContainer(); result = true; } else { throw new Exception("Invalid format of file, 'char' nodes not found"); } } else { throw new Exception("Invalid format of file, attribute 'type' must be equal to 'font'"); } } else { throw new Exception("Invalid format of file, attribute 'type' not defined"); } } catch (Exception exc) { MessageBox.Show(exc.Message, "Error while loading file", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(result); }