Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/11 18:36:22 (14 years ago)
Author:
abeham
Message:

#1465

  • Updated branch with changes from the trunk
  • Updated Font2XmlSerializer according to Erik's suggestions
Location:
branches/histogram
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • 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  
    2222using System;
    2323using System.Drawing;
    24 using System.Xml;
     24using System.Globalization;
    2525
    2626namespace HeuristicLab.Persistence.Default.Xml.Primitive {
     
    2828
    2929    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"));
    3530      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());
    3935      }
    40       return new XmlString(fontNode.OuterXml);
     36      return new XmlString(string.Empty);
    4137    }
    4238
    4339    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;
    4843      float size = 12.0f;
    49       if (!float.TryParse(tr.GetAttribute("Size"), out size)) return null;
    5044      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);
    5354    }
    5455  }
Note: See TracChangeset for help on using the changeset viewer.