private static UOFont LoadAscii(byte id) { if (id >= _Ascii.Length) { return(null); } const UOEncoding enc = UOEncoding.Ascii; var idx = (byte)enc; if (_Chars.InBounds(idx, id) && _Chars[idx][id] != null) { return(_Ascii[id] ?? (_Ascii[id] = Instantiate(enc, id))); } var fonts = _Chars[idx] ?? (_Chars[idx] = new UOChar[_Ascii.Length][]); var chars = fonts[id] ?? (fonts[id] = new UOChar[256]); var path = Core.FindDataFile("fonts.mul"); if (path == null || !File.Exists(path)) { chars.SetAll(NewEmptyChar(enc)); return(_Ascii[id] ?? (_Ascii[id] = Instantiate(enc, id))); } using (var fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var bin = new BinaryReader(fs)) { for (var i = 0; i <= id; i++) { bin.ReadByte(); // header if (i == id) { for (var c = 0; c < 32; c++) { chars[c] = NewEmptyChar(enc); } } for (var c = 32; c < chars.Length; c++) { var width = bin.ReadByte(); var height = bin.ReadByte(); bin.ReadByte(); // unk if (i == id) { var buffer = _EmptyBuffer; if (width * height > 0) { buffer = bin.ReadBytes((width * height) * 2); } chars[c] = new UOChar(enc, 0, 0, GetImage(width, height, buffer, enc)); } else { bin.BaseStream.Seek((width * height) * 2, SeekOrigin.Current); } } } } } return(_Ascii[id] ?? (_Ascii[id] = Instantiate(enc, id))); }
private static UOFont LoadUnicode(byte id) { if (id >= _Unicode.Length) { return(null); } const UOEncoding enc = UOEncoding.Unicode; var idx = (byte)enc; if (_Chars.InBounds(idx, id) && _Chars[idx][id] != null) { return(_Unicode[id] ?? (_Unicode[id] = Instantiate(enc, id))); } var fonts = _Chars[idx] ?? (_Chars[idx] = new UOChar[_Unicode.Length][]); var chars = fonts[id] ?? (fonts[id] = new UOChar[65536]); var filePath = Core.FindDataFile("unifont{0:#}.mul", id); if (filePath == null) { chars.SetAll(NewEmptyChar(enc)); return(_Unicode[id] ?? (_Unicode[id] = Instantiate(enc, id))); } using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var bin = new BinaryReader(fs)) { for (int c = 0, o; c < chars.Length; c++) { fs.Seek(c * 4, SeekOrigin.Begin); o = bin.ReadInt32(); if (o <= 0 || o >= fs.Length) { chars[c] = NewEmptyChar(enc); continue; } fs.Seek(o, SeekOrigin.Begin); var x = bin.ReadSByte(); // x-offset var y = bin.ReadSByte(); // y-offset var width = bin.ReadByte(); var height = bin.ReadByte(); var buffer = _EmptyBuffer; if (width * height > 0) { buffer = bin.ReadBytes(height * (((width - 1) / 8) + 1)); } chars[c] = new UOChar(enc, x, y, GetImage(width, height, buffer, enc)); } } } return(_Unicode[id] ?? (_Unicode[id] = Instantiate(enc, id))); }