public Font LoadFont(String filepath) { if (filepath == null) throw new ArgumentNullException("filepath"); if (m_fontcache.Contains(filepath) == true) return m_fontcache[filepath]; Point size = new Point(0, 0); Texture2D pixels = null; Texture2D palette = null; IO.TextFile textfile = null; using (IO.File file = GetSubSystem<IO.FileSystem>().OpenFile(filepath)) { IO.FileHeaders.FontFileHeader header = new IO.FileHeaders.FontFileHeader(file); file.SeekFromBeginning(header.ImageOffset); LoadImage(file, header.ImageSize, out size, out pixels, out palette); file.SeekFromBeginning(header.ImageOffset + header.ImageSize); textfile = GetSubSystem<IO.FileSystem>().BuildTextFile(file); } Sprite sprite = new Sprite(size, new Point(0, 0), true, pixels, true, palette, false); IO.TextSection data = textfile.GetSection("Def"); IO.TextSection textmap = textfile.GetSection("Map"); Int32 colors = data.GetAttribute<Int32>("colors"); Point defaultcharsize = data.GetAttribute<Point>("size"); Int32 numchars = 0; Dictionary<Char, Rectangle> sizemap = new Dictionary<Char, Rectangle>(); foreach (String line in textmap.Lines) { Match m = m_fontlinemapregex.Match(line); if (m.Success == false) continue; Char c = GetChar(m.Groups[1].Value); Point offset = (m.Groups[2].Value == "") ? new Point(defaultcharsize.X * numchars, 0) : new Point(Int32.Parse(m.Groups[2].Value), 0); Point charsize = (m.Groups[3].Value == "") ? defaultcharsize : new Point(Int32.Parse(m.Groups[3].Value), sprite.Size.Y); if (sizemap.ContainsKey(c) == false) { Rectangle r = new Rectangle(offset.X, offset.Y, charsize.X, charsize.Y); sizemap.Add(c, r); } ++numchars; } Font font = new Font(this, filepath, sprite, new ReadOnlyDictionary<Char, Rectangle>(sizemap), defaultcharsize, colors); m_fontcache.Add(font); return font; }
public Font LoadFont(string filepath) { if (filepath == null) { throw new ArgumentNullException(nameof(filepath)); } if (m_fontcache.Contains(filepath)) { return(m_fontcache[filepath]); } Point size; Texture2D pixels; Texture2D palette; IO.TextFile textfile; using (var file = GetSubSystem <IO.FileSystem>().OpenFile(filepath)) { var header = new IO.FileHeaders.FontFileHeader(file); file.SeekFromBeginning(header.ImageOffset); LoadImage(file, header.ImageSize, out size, out pixels, out palette); file.SeekFromBeginning(header.ImageOffset + header.ImageSize); textfile = GetSubSystem <IO.FileSystem>().BuildTextFile(file); } var sprite = new Sprite(size, new Point(0, 0), true, pixels, true, palette, false); var data = textfile.GetSection("Def"); var textmap = textfile.GetSection("Map"); var colors = data.GetAttribute <int>("colors"); var defaultcharsize = data.GetAttribute <Point>("size"); var numchars = 0; var sizemap = new Dictionary <char, Rectangle>(); foreach (var line in textmap.Lines) { var m = m_fontlinemapregex.Match(line); if (m.Success == false) { continue; } var c = GetChar(m.Groups[1].Value); var offset = m.Groups[2].Value == "" ? new Point(defaultcharsize.X * numchars, 0) : new Point(int.Parse(m.Groups[2].Value), 0); var charsize = m.Groups[3].Value == "" ? defaultcharsize : new Point(int.Parse(m.Groups[3].Value), sprite.Size.Y); if (sizemap.ContainsKey(c) == false) { var r = new Rectangle(offset.X, offset.Y, charsize.X, charsize.Y); sizemap.Add(c, r); } ++numchars; } var font = new Font(this, filepath, sprite, new ReadOnlyDictionary <char, Rectangle>(sizemap), defaultcharsize, colors); m_fontcache.Add(font); return(font); }