public void Read(FileReader reader, FFNT header, List <CWDH> CharacterWidths) { long pos = reader.Position; reader.ReadSignature(4, "CWDH"); SectionSize = reader.ReadUInt32(); StartIndex = reader.ReadUInt16(); EndIndex = reader.ReadUInt16(); uint NextWidthSectionOffset = reader.ReadUInt32(); for (ushort i = StartIndex; i <= EndIndex; i++) { var entry = new CharacterWidthEntry(); entry.LeftWidth = reader.ReadSByte(); entry.GlyphWidth = reader.ReadByte(); entry.Width = reader.ReadByte(); WidthEntries.Add(entry); } if (NextWidthSectionOffset != 0) { reader.SeekBegin((int)NextWidthSectionOffset - 8); NextWidthSection = new CWDH(); NextWidthSection.Read(reader, header, CharacterWidths); CharacterWidths.Add(NextWidthSection); } else { reader.SeekBegin(pos + SectionSize); } }
public void Read(FileReader reader, FFNT header) { CharacterWidths = new List <CWDH>(); CodeMaps = new List <CMAP>(); string Signature = reader.ReadString(4, Encoding.ASCII); if (Signature != "FINF") { throw new Exception($"Invalid signature {Signature}! Expected FINF."); } Size = reader.ReadUInt32(); if (header.Platform <= FFNT.PlatformType.Ctr && header.Version < 0x04000000) { Type = reader.ReadEnum <FontType>(true); LineFeed = reader.ReadByte(); AlterCharIndex = reader.ReadUInt16(); DefaultLeftWidth = reader.ReadByte(); DefaultGlyphWidth = reader.ReadByte(); DefaultCharWidth = reader.ReadByte(); CharEncoding = reader.ReadEnum <CharacterCode>(true); uint tglpOffset = reader.ReadUInt32(); uint cwdhOffset = reader.ReadUInt32(); uint cmapOffset = reader.ReadUInt32(); Height = reader.ReadByte(); Width = reader.ReadByte(); Ascent = reader.ReadByte(); reader.ReadByte(); //Padding //Add counter for TGLP //Note the other counters are inside sections due to recusive setup header.BlockCounter += 1; TextureGlyph = new TGLP(); using (reader.TemporarySeek(tglpOffset - 8, SeekOrigin.Begin)) TextureGlyph.Read(reader, header); CharacterWidth = new CWDH(); CharacterWidths.Add(CharacterWidth); using (reader.TemporarySeek(cwdhOffset - 8, SeekOrigin.Begin)) CharacterWidth.Read(reader, header, CharacterWidths); CodeMap = new CMAP(); CodeMaps.Add(CodeMap); using (reader.TemporarySeek(cmapOffset - 8, SeekOrigin.Begin)) CodeMap.Read(reader, header, CodeMaps); } else { Type = reader.ReadEnum <FontType>(true); Height = reader.ReadByte(); Width = reader.ReadByte(); Ascent = reader.ReadByte(); LineFeed = reader.ReadUInt16(); AlterCharIndex = reader.ReadUInt16(); DefaultLeftWidth = reader.ReadByte(); DefaultGlyphWidth = reader.ReadByte(); DefaultCharWidth = reader.ReadByte(); CharEncoding = reader.ReadEnum <CharacterCode>(true); uint tglpOffset = reader.ReadUInt32(); uint cwdhOffset = reader.ReadUInt32(); uint cmapOffset = reader.ReadUInt32(); //Add counter for TGLP //Note the other counters are inside sections due to recusive setup header.BlockCounter += 1; TextureGlyph = new TGLP(); using (reader.TemporarySeek(tglpOffset - 8, SeekOrigin.Begin)) TextureGlyph.Read(reader, header); CharacterWidth = new CWDH(); CharacterWidths.Add(CharacterWidth); using (reader.TemporarySeek(cwdhOffset - 8, SeekOrigin.Begin)) CharacterWidth.Read(reader, header, CharacterWidths); CodeMap = new CMAP(); CodeMaps.Add(CodeMap); using (reader.TemporarySeek(cmapOffset - 8, SeekOrigin.Begin)) CodeMap.Read(reader, header, CodeMaps); } }