Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/26/14 13:24:43 (10 years ago)
Author:
epitzer
Message:

#2111 Distinguish between generic fonts and fonts instantiated by name during persistence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Font2XmlSerializer.cs

    r9988 r10889  
    2828    public override XmlString Format(Font font) {
    2929      return new XmlString(string.Format("{0};{1};{2};{3};{4};{5}",
    30         font.FontFamily.Name,
     30        GetFontFamilyName(font.FontFamily),
    3131        Float2XmlSerializer.FormatG8(font.Size),
    3232        font.Style,
     
    3939      string[] tokens = fontData.Data.Split(';');
    4040      return new Font(
    41         tokens[0],
     41        GetFontFamily(tokens[0]),
    4242        Float2XmlSerializer.ParseG8(tokens[1]),
    4343        (FontStyle)Enum.Parse(typeof(FontStyle), tokens[2]),
     
    4646        bool.Parse(tokens[5]));
    4747    }
     48
     49    public const string GENERIC_MONOSPACE_NAME = "_GenericMonospace";
     50    public const string GENERIC_SANS_SERIF_NAME = "_GenericSansSerif";
     51    public const string GENERIC_SERIF_NAME = "_GenericSerif";
     52
     53    public static FontFamily GetFontFamily(string name) {
     54      if (name == GENERIC_MONOSPACE_NAME) return FontFamily.GenericMonospace;
     55      if (name == GENERIC_SANS_SERIF_NAME) return FontFamily.GenericSansSerif;
     56      if (name == GENERIC_SERIF_NAME) return FontFamily.GenericSerif;
     57      return new FontFamily(name);
     58    }
     59
     60    public string GetFontFamilyName(FontFamily ff) {
     61      if (ff.Equals(FontFamily.GenericMonospace)) return GENERIC_MONOSPACE_NAME;
     62      if (ff.Equals(FontFamily.GenericSansSerif)) return GENERIC_SANS_SERIF_NAME;
     63      if (ff.Equals(FontFamily.GenericSerif)) return GENERIC_SERIF_NAME;
     64      return ff.Name;
     65    }
     66
    4867  }
    4968}
Note: See TracChangeset for help on using the changeset viewer.