public DestCharInfo(SourceCharInfo info) { Id = (ushort)info.Id; X = info.X; Y = info.Y; Width = (byte)info.Width; Height = (byte)info.Height; XOffset = (sbyte)info.XOffset; YOffset = (sbyte)info.YOffset; XAdvance = (byte)info.XAdvance; }
private bool Read(string filename) { try { var data = File.ReadAllBytes(filename); // file identifier: BMF3 if (data[0] != 66 || data[1] != 77 || data[2] != 70 || data[3] != 3) { return(false); } using (var mr = new MemoryStream(data)) { using (var br = new BinaryReader(mr)) { // file identifier br.ReadInt32(); // block type 1: info // read type identifier and size br.ReadByte(); var block1Size = br.ReadInt32(); // read content FontSize = br.ReadInt16(); var bitField = new BitArray(new[] { br.ReadByte() }); Smooth = bitField.Get(0); Unicode = bitField.Get(1); Italic = bitField.Get(2); Bold = bitField.Get(3); FixedHeight = bitField.Get(4); Charset = br.ReadByte(); StretchH = br.ReadUInt16(); Antialiasing = br.ReadByte(); Padding = new Padding(br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte()); Spacing = new Spacing(br.ReadByte(), br.ReadByte()); Outline = br.ReadByte(); FontName = new string(br.ReadChars(block1Size - 14)); // block type 2: common // read type identifier and size br.ReadByte(); br.ReadInt32(); // read content LineHeight = br.ReadUInt16(); Base = br.ReadUInt16(); ScaleW = br.ReadUInt16(); ScaleH = br.ReadUInt16(); Pages = br.ReadUInt16(); // skip bit field br.ReadByte(); AlphaChannel = br.ReadByte(); RedChannel = br.ReadByte(); GreenChannel = br.ReadByte(); BlueChannel = br.ReadByte(); // block type 3: pages // read type identifier and size br.ReadByte(); var block3Size = br.ReadInt32(); // read content // assume we have no more than 1 page here DdsFilename = new string(br.ReadChars(block3Size)); // block type 4: chars // read type identifier and size br.ReadByte(); var block4Size = br.ReadInt32(); // read content CharsCount = block4Size / 20; Chars = new SourceCharInfo[CharsCount]; for (var i = 0; i < CharsCount; i++) { Chars[i] = new SourceCharInfo(br.ReadUInt32(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadInt16(), br.ReadInt16(), br.ReadInt16(), br.ReadByte(), br.ReadByte()); } // skip block 5 } } return(true); } catch (Exception) { return(false); } }