-
Notifications
You must be signed in to change notification settings - Fork 106
/
SystemFont.cs
126 lines (83 loc) · 5.54 KB
/
SystemFont.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using WpfMath.Exceptions;
namespace WpfMath
{
internal class SystemFont : ITeXFont
{
private readonly FontFamily _fontFamily;
public SystemFont(double size, FontFamily fontFamily)
{
_fontFamily = fontFamily;
Size = size;
}
public bool SupportsMetrics => false;
public double Size { get; }
public ITeXFont DeriveFont(double newSize) => throw MethodNotSupported(nameof(DeriveFont));
public ExtensionChar GetExtension(CharInfo charInfo, TexStyle style) =>
throw MethodNotSupported(nameof(GetExtension));
public CharFont GetLigature(CharFont leftChar, CharFont rightChar) => null;
public CharInfo GetNextLargerCharInfo(CharInfo charInfo, TexStyle style) =>
throw MethodNotSupported(nameof(GetNextLargerCharInfo));
public CharInfo GetDefaultCharInfo(char character, TexStyle style) =>
throw MethodNotSupported(nameof(GetDefaultCharInfo));
public CharInfo GetCharInfo(char character, string textStyle, TexStyle style)
{
var typeface = GetTypeface();
if (!typeface.TryGetGlyphTypeface(out var glyphTypeface))
{
throw new TypeFaceNotFoundException($"Glyph typeface for font {_fontFamily.BaseUri} was not found");
}
var metrics = GetFontMetrics(character, typeface);
return new CharInfo(character, glyphTypeface, 1.0, TexFontUtilities.NoFontId, metrics);
}
public CharInfo GetCharInfo(CharFont charFont, TexStyle style) =>
throw MethodNotSupported(nameof(GetCharInfo));
public CharInfo GetCharInfo(string name, TexStyle style) => throw MethodNotSupported(nameof(GetCharInfo));
public double GetKern(CharFont leftChar, CharFont rightChar, TexStyle style) => 0.0;
public double GetQuad(int fontId, TexStyle style) => throw MethodNotSupported(nameof(GetQuad));
public double GetSkew(CharFont charFont, TexStyle style) => throw MethodNotSupported(nameof(GetSkew));
public bool HasSpace(int fontId) => throw MethodNotSupported(nameof(HasSpace));
public bool HasNextLarger(CharInfo charInfo) => throw MethodNotSupported(nameof(HasNextLarger));
public bool IsExtensionChar(CharInfo charInfo) => throw MethodNotSupported(nameof(IsExtensionChar));
public int GetMuFontId() => throw MethodNotSupported(nameof(GetMuFontId));
public double GetXHeight(TexStyle style, int fontId) => throw MethodNotSupported(nameof(GetXHeight));
public double GetSpace(TexStyle style) => throw MethodNotSupported(nameof(GetSpace));
public double GetAxisHeight(TexStyle style) => throw MethodNotSupported(nameof(GetAxisHeight));
public double GetBigOpSpacing1(TexStyle style) => throw MethodNotSupported(nameof(GetBigOpSpacing1));
public double GetBigOpSpacing2(TexStyle style) => throw MethodNotSupported(nameof(GetBigOpSpacing2));
public double GetBigOpSpacing3(TexStyle style) => throw MethodNotSupported(nameof(GetBigOpSpacing3));
public double GetBigOpSpacing4(TexStyle style) => throw MethodNotSupported(nameof(GetBigOpSpacing4));
public double GetBigOpSpacing5(TexStyle style) => throw MethodNotSupported(nameof(GetBigOpSpacing5));
public double GetSub1(TexStyle style) => throw MethodNotSupported(nameof(GetSub1));
public double GetSub2(TexStyle style) => throw MethodNotSupported(nameof(GetSub2));
public double GetSubDrop(TexStyle style) => throw MethodNotSupported(nameof(GetSubDrop));
public double GetSup1(TexStyle style) => throw MethodNotSupported(nameof(GetSup1));
public double GetSup2(TexStyle style) => throw MethodNotSupported(nameof(GetSup2));
public double GetSup3(TexStyle style) => throw MethodNotSupported(nameof(GetSup3));
public double GetSupDrop(TexStyle style) => throw MethodNotSupported(nameof(GetSupDrop));
public double GetNum1(TexStyle style) => throw MethodNotSupported(nameof(GetNum1));
public double GetNum2(TexStyle style) => throw MethodNotSupported(nameof(GetNum2));
public double GetNum3(TexStyle style) => throw MethodNotSupported(nameof(GetNum3));
public double GetDenom1(TexStyle style) => throw MethodNotSupported(nameof(GetDenom1));
public double GetDenom2(TexStyle style) => throw MethodNotSupported(nameof(GetDenom2));
public double GetDefaultLineThickness(TexStyle style) => throw MethodNotSupported(nameof(GetDefaultLineThickness));
private static TexNotSupportedException MethodNotSupported(string callerMethod)
{
return new TexNotSupportedException(
$"Call of method {callerMethod} on {nameof(SystemFont)} is not supported");
}
private TexFontMetrics GetFontMetrics(char c, Typeface typeface)
{
var formattedText = new FormattedText(c.ToString(),
CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight,
typeface,
1.0,
Brushes.Black);
return new TexFontMetrics(formattedText.Width, formattedText.Height, 0.0, formattedText.Width, 1.0);
}
private Typeface GetTypeface() => new Typeface(_fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); // TODO[F]: Put into lazy field
}
}