[6020] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
[6022] | 24 | using System.Globalization;
|
---|
[6020] | 25 |
|
---|
| 26 | namespace HeuristicLab.Persistence.Default.Xml.Primitive {
|
---|
| 27 | internal sealed class Font2XmlSerializer : PrimitiveXmlSerializerBase<Font> {
|
---|
| 28 |
|
---|
| 29 | public override XmlString Format(Font font) {
|
---|
| 30 | if (font != null) {
|
---|
[6022] | 31 | return new XmlString(font.Name
|
---|
| 32 | + ";" + font.SizeInPoints.ToString(CultureInfo.InvariantCulture.NumberFormat)
|
---|
| 33 | + ";" + font.Style.ToString("d")
|
---|
| 34 | + ";" + font.GdiCharSet.ToString());
|
---|
[6020] | 35 | }
|
---|
[6022] | 36 | return new XmlString(string.Empty);
|
---|
[6020] | 37 | }
|
---|
| 38 |
|
---|
| 39 | public override Font Parse(XmlString fontData) {
|
---|
[6022] | 40 | if (string.IsNullOrEmpty(fontData.Data)) return null;
|
---|
| 41 | string[] tokens = fontData.Data.Split(';');
|
---|
| 42 | if (tokens.Length < 4) return null;
|
---|
[6020] | 43 | float size = 12.0f;
|
---|
| 44 | FontStyle style = FontStyle.Regular;
|
---|
[6022] | 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);
|
---|
[6020] | 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|