private void Load(CharacterMapChunk map, CharacterWidthChunk widths, CharacterGlyphChunk glyphs) { this.characters = new List <Character>(map.Mappings.Count); this.type = map.MapType; foreach (int code in map.Mappings.Keys) { int index = map.Mappings[code]; if (index != Blank) { Character c = new Character(code, glyphs.Glyphs[index], widths.XOffsets[index], widths.Widths[index], widths.NextOffsets[index]); this.characters.Add(c); } } }
/// <summary> /// Reads the font from its associated file. /// </summary> public void Load() { byte[] fileData = StreamHelper.ReadFile(this.fileName); this.header = new NitroHeader("RTFN"); this.header.ReadFrom(fileData, 0); this.finfChunk = new FontInfoSection(); int finfOffset = this.header.Size; this.finfChunk.ReadFrom(fileData, finfOffset); this.cwdhChunk = new CharacterWidthChunk(); this.cwdhChunk.ReadFrom(fileData, this.finfChunk.WidthSectionOffset); int characterCount = this.cwdhChunk.Widths.Count; this.cglpChunk = new CharacterGlyphChunk(characterCount); this.cglpChunk.ReadFrom(fileData, this.finfChunk.GlyphSectionOffset); int cmapCount = this.header.SectionCount - 3; int cmapOffset = this.finfChunk.MapSectionOffset; this.cmapChunks = new List <CharacterMapChunk>(); this.characterSets = new List <CharacterSet>(); for (int i = 0; i < cmapCount; i++) { CharacterMapChunk cmapChunk = new CharacterMapChunk(); cmapChunk.ReadFrom(fileData, cmapOffset); cmapOffset = cmapChunk.NextChunkOffset; this.cmapChunks.Add(cmapChunk); this.characterSets.Add(new CharacterSet(cmapChunk, this.cwdhChunk, this.cglpChunk)); } this.RebuildIndices(); }
/// <summary> /// Initializes a new instance of the CharacterSet class by reading the appropriate chunks from the font. /// </summary> /// <param name="map">The map between characters and their numerical codes.</param> /// <param name="widths">The width and offset data for all characters in the font.</param> /// <param name="glyphs">The graphical glyphs for all characters in the font.</param> public CharacterSet(CharacterMapChunk map, CharacterWidthChunk widths, CharacterGlyphChunk glyphs) { this.Load(map, widths, glyphs); }