-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBmGenData.cs
126 lines (116 loc) · 3.11 KB
/
BmGenData.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.Xml.Serialization;
namespace HudLibFontGen
{
public struct Vector2
{
public float X;
public float Y;
public static Vector2 operator +(Vector2 a, Vector2 b)
{
return new Vector2() { X = a.X + b.X, Y = a.Y + b.Y };
}
public static Vector2 operator -(Vector2 a, Vector2 b)
{
return new Vector2() { X = a.X - b.X, Y = a.Y - b.Y };
}
}
/// <summary>
/// Type used to store deserialized XML font data.
/// </summary>
[XmlType("font")]
public class BmGenData
{
[XmlAttribute("base")]
public float baseline;
[XmlAttribute]
public float height;
[XmlAttribute("face")]
public string faceName;
/// <summary>
/// Size of the font in points
/// </summary>
[XmlAttribute("size")]
public float ptSize;
[XmlAttribute]
public string style;
/// <summary>
/// Texture atlases used to render the characters
/// </summary>
[XmlArray("bitmaps")]
public BitmapData[] bitmaps;
[XmlArray("glyphs")]
public GlyphData[] glyphs;
[XmlArray("kernpairs")]
public KerningPairData[] kernPairs;
/// <summary>
/// Converts a string representing a 2D vector whose elements are separated by an 'x' or ',' into
/// a <see cref="Vector2"/>.
/// </summary>
public static Vector2 ParseVector(string value)
{
string[] members = value.Split('x', ',');
return new Vector2()
{
X = float.Parse(members[0]),
Y = float.Parse(members[1])
};
}
}
[XmlType("bitmap")]
public class BitmapData
{
[XmlAttribute]
public int id;
[XmlAttribute]
public string name;
[XmlAttribute]
public string size;
}
[XmlType("glyph")]
public class GlyphData
{
/// <summary>
/// Glyph char value
/// </summary>
[XmlAttribute]
public string ch;
/// <summary>
/// Bitmap ID
/// </summary>
[XmlAttribute("bm")]
public int bitmapID;
/// <summary>
/// Offset from texture origin
/// </summary>
[XmlAttribute]
public string origin;
/// <summary>
/// Dimensions
/// </summary>
[XmlAttribute]
public string size;
/// <summary>
/// Advance Width
/// </summary>
[XmlAttribute("aw")]
public float advanceWidth;
/// <summary>
/// Left Side Bearing
/// </summary>
[XmlAttribute("lsb")]
public float leftSideBearing;
}
/// <summary>
/// Stores data needed adjusting the spacing between a given character pair for a given font.
/// </summary>
[XmlType("kernpair")]
public class KerningPairData
{
[XmlAttribute]
public string left;
[XmlAttribute]
public string right;
[XmlAttribute]
public float adjust;
}
}