Changeset 6022 for branches/histogram/HeuristicLab.Persistence
- Timestamp:
- 04/18/11 18:36:22 (14 years ago)
- Location:
- branches/histogram
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram
- Property svn:mergeinfo changed
/trunk/sources merged: 6019,6021
- Property svn:mergeinfo changed
-
branches/histogram/HeuristicLab.Persistence
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/histogram/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Font2XmlSerializer.cs
r6020 r6022 22 22 using System; 23 23 using System.Drawing; 24 using System. Xml;24 using System.Globalization; 25 25 26 26 namespace HeuristicLab.Persistence.Default.Xml.Primitive { … … 28 28 29 29 public override XmlString Format(Font font) { 30 XmlDocument doc = new XmlDocument();31 XmlNode fontNode = doc.CreateElement("Font");32 fontNode.Attributes.Append(doc.CreateAttribute("Name"));33 fontNode.Attributes.Append(doc.CreateAttribute("Size"));34 fontNode.Attributes.Append(doc.CreateAttribute("Style"));35 30 if (font != null) { 36 fontNode.Attributes["Name"].Value = font.Name; 37 fontNode.Attributes["Size"].Value = font.Size.ToString(); 38 fontNode.Attributes["Style"].Value = font.Style.ToString("d"); 31 return new XmlString(font.Name 32 + ";" + font.SizeInPoints.ToString(CultureInfo.InvariantCulture.NumberFormat) 33 + ";" + font.Style.ToString("d") 34 + ";" + font.GdiCharSet.ToString()); 39 35 } 40 return new XmlString( fontNode.OuterXml);36 return new XmlString(string.Empty); 41 37 } 42 38 43 39 public override Font Parse(XmlString fontData) { 44 XmlTextReader tr = new XmlTextReader(fontData.Data, XmlNodeType.Element, null); 45 if (!tr.Read() || tr.Name != "Font") return null; 46 string name = tr.GetAttribute("Name"); 47 if (string.IsNullOrEmpty(name)) return null; 40 if (string.IsNullOrEmpty(fontData.Data)) return null; 41 string[] tokens = fontData.Data.Split(';'); 42 if (tokens.Length < 4) return null; 48 43 float size = 12.0f; 49 if (!float.TryParse(tr.GetAttribute("Size"), out size)) return null;50 44 FontStyle style = FontStyle.Regular; 51 if (!Enum.TryParse<FontStyle>(tr.GetAttribute("Style"), out style)) return null; 52 return new Font(name, size, style); 45 byte gdiCharSet = 1; 46 if (!float.TryParse(tokens[1], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out size)) 47 return null; 48 if (!Enum.TryParse(tokens[2], out style)) 49 return null; 50 if (!byte.TryParse(tokens[3], out gdiCharSet)) 51 return null; 52 53 return new Font(tokens[0], size, style, GraphicsUnit.Point, gdiCharSet); 53 54 } 54 55 }
Note: See TracChangeset
for help on using the changeset viewer.