Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorConverters/FontFamilyVisitor.cs @ 14071

Last change on this file since 14071 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 7.9 KB
Line 
1using System;
2using System.Collections.Generic;
3
4using System.Windows;
5using System.Windows.Media;
6
7using SharpVectors.Renderers.Wpf;
8
9namespace SharpVectors.Converters
10{
11    public sealed class FontFamilyVisitor : WpfFontFamilyVisitor
12    {
13        private FontFamily _arialFamily;
14
15        public FontFamilyVisitor()
16        {
17            _arialFamily = new FontFamily("Arial");
18        }
19
20        public override WpfFontFamilyInfo Visit(string fontName, WpfFontFamilyInfo familyInfo,
21            WpfDrawingContext context)
22        {
23            if (String.IsNullOrEmpty(fontName))
24            {
25                return null;
26            }
27
28            if (fontName.StartsWith("Arial", StringComparison.OrdinalIgnoreCase) &&
29                fontName.Length > 5)
30            {
31                if (String.Equals(fontName, "ArialMT",
32                    StringComparison.OrdinalIgnoreCase))
33                {
34                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
35                        familyInfo.Style, familyInfo.Stretch);
36                }
37                else if (String.Equals(fontName, "Arial-BoldMT",
38                    StringComparison.OrdinalIgnoreCase))
39                {
40                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
41                        familyInfo.Style, familyInfo.Stretch);
42                }
43                else if (String.Equals(fontName, "Arial-ItalicMT",
44                    StringComparison.OrdinalIgnoreCase))
45                {
46                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
47                        FontStyles.Italic, familyInfo.Stretch);
48                }
49                else if (String.Equals(fontName, "Arial-BoldItalicMT",
50                    StringComparison.OrdinalIgnoreCase))
51                {
52                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
53                        FontStyles.Italic, familyInfo.Stretch);
54                }
55                else if (String.Equals(fontName, "Arial Unicode MS",
56                    StringComparison.OrdinalIgnoreCase))
57                {
58                    return null;
59                }
60
61                return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
62                    familyInfo.Style, familyInfo.Stretch);
63            }
64            else if (fontName.StartsWith("Helvetica", StringComparison.OrdinalIgnoreCase))
65            {
66                if (String.Equals(fontName, "Helvetica", StringComparison.OrdinalIgnoreCase))
67                {
68                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
69                        familyInfo.Style, familyInfo.Stretch);
70                }
71                else if (String.Equals(fontName, "Helvetica-Bold",
72                    StringComparison.OrdinalIgnoreCase))
73                {
74                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
75                        familyInfo.Style, familyInfo.Stretch);
76                }
77                else if (String.Equals(fontName, "Helvetica-Oblique",
78                    StringComparison.OrdinalIgnoreCase))
79                {
80                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
81                        FontStyles.Italic, familyInfo.Stretch);
82                }
83                else if (String.Equals(fontName, "Helvetica-BoldOblique",
84                    StringComparison.OrdinalIgnoreCase))
85                {
86                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
87                        FontStyles.Italic, familyInfo.Stretch);
88                }
89
90                return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
91                    familyInfo.Style, familyInfo.Stretch);
92            }
93            else if (fontName.StartsWith("TimesNewRomanPS", StringComparison.OrdinalIgnoreCase))
94            {
95                if (String.Equals(fontName, "TimesNewRomanPSMT", StringComparison.OrdinalIgnoreCase))
96                {
97                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
98                        familyInfo.Style, familyInfo.Stretch);
99                }
100                else if (String.Equals(fontName, "TimesNewRomanPS-BoldMT",
101                    StringComparison.OrdinalIgnoreCase))
102                {
103                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
104                        familyInfo.Style, familyInfo.Stretch);
105                }
106                else if (String.Equals(fontName, "TimesNewRomanPS-ItalicMT",
107                    StringComparison.OrdinalIgnoreCase))
108                {
109                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
110                        FontStyles.Italic, familyInfo.Stretch);
111                }
112                else if (String.Equals(fontName, "TimesNewRomanPS-BoldItalicMT",
113                    StringComparison.OrdinalIgnoreCase))
114                {
115                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
116                        FontStyles.Italic, familyInfo.Stretch);
117                }
118
119                return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
120                    familyInfo.Style, familyInfo.Stretch);
121            }
122            else if (fontName.StartsWith("CourierNewPS", StringComparison.OrdinalIgnoreCase))
123            {
124                if (String.Equals(fontName, "CourierNewPSMT", StringComparison.OrdinalIgnoreCase))
125                {
126                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
127                        familyInfo.Style, familyInfo.Stretch);
128                }
129                else if (String.Equals(fontName, "CourierNewPS-BoldMT",
130                    StringComparison.OrdinalIgnoreCase))
131                {
132                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
133                        familyInfo.Style, familyInfo.Stretch);
134                }
135                else if (String.Equals(fontName, "CourierNewPS-ItalicMT",
136                    StringComparison.OrdinalIgnoreCase))
137                {
138                    return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
139                        FontStyles.Italic, familyInfo.Stretch);
140                }
141                else if (String.Equals(fontName, "CourierNewPS-BoldItalicMT",
142                    StringComparison.OrdinalIgnoreCase))
143                {
144                    return new WpfFontFamilyInfo(_arialFamily, FontWeights.Bold,
145                        FontStyles.Italic, familyInfo.Stretch);
146                }
147
148                return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
149                    familyInfo.Style, familyInfo.Stretch);
150            }
151            else if (fontName.Equals("MS-Gothic", StringComparison.OrdinalIgnoreCase))
152            {
153                return new WpfFontFamilyInfo(new FontFamily("MS Gothic"), familyInfo.Weight,
154                    familyInfo.Style, familyInfo.Stretch);
155                //return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
156                //    familyInfo.Style, familyInfo.Stretch);
157            }
158            else if (fontName.Equals("MS-PGothic", StringComparison.OrdinalIgnoreCase))
159            {
160                return new WpfFontFamilyInfo(new FontFamily("MS PGothic"), familyInfo.Weight,
161                    familyInfo.Style, familyInfo.Stretch);
162            }
163            else if (fontName.Equals("MS Pゴシック", StringComparison.OrdinalIgnoreCase))
164            {
165                return new WpfFontFamilyInfo(new FontFamily("MS PGothic"), familyInfo.Weight,
166                    familyInfo.Style, familyInfo.Stretch);
167            }
168
169            return null;
170            //return new WpfFontFamilyInfo(_arialFamily, familyInfo.Weight,
171            //    familyInfo.Style, familyInfo.Stretch);
172        }
173    }
174}
Note: See TracBrowser for help on using the repository browser.