Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2435-alglib_3_15/HeuristicLab.Persistence/3.3/Transformers/FontTransformer.cs @ 16724

Last change on this file since 16724 was 16559, checked in by jkarder, 6 years ago

#2520: renamed Fossil to Attic and set version to 1.0.0-pre01

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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
22using System;
23using System.Drawing;
24using HEAL.Attic;
25
26namespace HeuristicLab.Persistence.Transformers {
27
28  [Transformer("AFF27987-3301-4D70-9601-EFCA31BDA0DB", 405)]
29  [StorableType("B9F9A371-4DCB-478B-B0D4-6F87A15C02B5")]
30  internal sealed class FontTransformer : BoxTransformer<Font> {
31    protected override void Populate(Box box, Font value, Mapper mapper) {
32      var uints = box.UInts;
33      uints.Add(mapper.GetStringId(GetFontFamilyName(value.FontFamily)));
34      uints.Add(mapper.GetBoxId(value.Size));
35      uints.Add(mapper.GetBoxId(value.Style));
36      uints.Add(mapper.GetBoxId(value.Unit));
37      uints.Add(mapper.GetBoxId(value.GdiCharSet));
38      uints.Add(mapper.GetBoxId(value.GdiVerticalFont));
39    }
40
41    protected override Font Extract(Box box, Type type, Mapper mapper) {
42      var fontData = box.UInts;
43      return new Font(
44        GetFontFamily(mapper.GetString(fontData[0])),
45        (float)mapper.GetObject(fontData[1]),
46        (FontStyle)mapper.GetObject(fontData[2]),
47        (GraphicsUnit)mapper.GetObject(fontData[3]),
48        (byte)mapper.GetObject(fontData[4]),
49        (bool)mapper.GetObject(fontData[5])
50      );
51    }
52
53    public const string GENERIC_MONOSPACE_NAME = "_GenericMonospace";
54    public const string GENERIC_SANS_SERIF_NAME = "_GenericSansSerif";
55    public const string GENERIC_SERIF_NAME = "_GenericSerif";
56
57    public static FontFamily GetFontFamily(string name) {
58      if (name == GENERIC_MONOSPACE_NAME) return FontFamily.GenericMonospace;
59      if (name == GENERIC_SANS_SERIF_NAME) return FontFamily.GenericSansSerif;
60      if (name == GENERIC_SERIF_NAME) return FontFamily.GenericSerif;
61      return new FontFamily(name);
62    }
63
64    public static string GetFontFamilyName(FontFamily ff) {
65      if (ff.Equals(FontFamily.GenericMonospace)) return GENERIC_MONOSPACE_NAME;
66      if (ff.Equals(FontFamily.GenericSansSerif)) return GENERIC_SANS_SERIF_NAME;
67      if (ff.Equals(FontFamily.GenericSerif)) return GENERIC_SERIF_NAME;
68      return ff.Name;
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.