Changeset 6027
- Timestamp:
- 04/19/11 12:37:16 (14 years ago)
- Location:
- branches/histogram/HeuristicLab.Persistence/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Font2XmlSerializer.cs
r6022 r6027 22 22 using System; 23 23 using System.Drawing; 24 using System.Globalization;25 24 26 25 namespace HeuristicLab.Persistence.Default.Xml.Primitive { … … 28 27 29 28 public override XmlString Format(Font font) { 30 if (font != null) {31 return new XmlString(font.Name32 + ";" + font.SizeInPoints.ToString(CultureInfo.InvariantCulture.NumberFormat)33 + ";" + font.Style.ToString("d")34 + ";" + font.GdiCharSet.ToString());35 }36 return new XmlString(string.Empty);29 return new XmlString(string.Format("{0};{1};{2};{3};{4};{5}", 30 font.Name, 31 Float2XmlSerializer.FormatG8(font.Size), 32 font.Style, 33 font.Unit, 34 font.GdiCharSet, 35 font.GdiVerticalFont)); 37 36 } 38 37 39 38 public override Font Parse(XmlString fontData) { 40 if (string.IsNullOrEmpty(fontData.Data)) return null;41 39 string[] tokens = fontData.Data.Split(';'); 42 if (tokens.Length < 4) return null; 43 float size = 12.0f; 44 FontStyle style = FontStyle.Regular; 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); 40 return new Font( 41 tokens[0], 42 Float2XmlSerializer.ParseG8(tokens[1]), 43 (FontStyle)Enum.Parse(typeof(FontStyle), tokens[2]), 44 (GraphicsUnit)Enum.Parse(typeof(GraphicsUnit), tokens[3]), 45 byte.Parse(tokens[4]), 46 bool.Parse(tokens[5])); 54 47 } 55 48 } -
branches/histogram/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r5698 r6027 1255 1255 } 1256 1256 1257 [TestMethod] 1258 public void FontTest() { 1259 List<Font> fonts = new List<Font>() { 1260 new Font(FontFamily.Families.First(), 12), 1261 new Font("Times New Roman", 21, FontStyle.Bold, GraphicsUnit.Pixel), 1262 new Font("Courier New", 10, FontStyle.Underline, GraphicsUnit.Document), 1263 new Font("Helvetica", 21, FontStyle.Strikeout, GraphicsUnit.Inch, 0, true), 1264 }; 1265 XmlGenerator.Serialize(fonts, tempFile); 1266 var newFonts = XmlParser.Deserialize<List<Font>>(tempFile); 1267 Assert.AreEqual(fonts[0], newFonts[0]); 1268 Assert.AreEqual(fonts[1], newFonts[1]); 1269 Assert.AreEqual(fonts[2], newFonts[2]); 1270 Assert.AreEqual(fonts[3], newFonts[3]); 1271 } 1272 1257 1273 1258 1274
Note: See TracChangeset
for help on using the changeset viewer.