private TrueTypeFontTable ReadHorizontalMetrics(uint length, TrueTypeTableEntryList list, BigEndianReader reader) { var pos = reader.Position; //Get the number of entries for the hMetrics list from the horizontal header table. TrueTypeTableEntry hhead = list["hhea"]; if (hhead == null) { throw new ArgumentNullException("No horizontal header (hhea) has been specified in the font file, this is needed to load the hroizontal metrics"); } if (hhead.Table == null) { TrueTypeFontTable tbl = this.ReadTable(hhead, list, reader); if (tbl == null) { throw new ArgumentNullException("No horizontal header (hhea) has been specified in the font file, this is needed to load the hroizontal metrics"); } hhead.SetTable(tbl); } TrueTypeTableEntry os2 = list["OS/2"]; if (os2 == null) { throw new ArgumentNullException("No OS2 table has been specified in the font file, this is a required table and needed to load the horizontal metrics"); } if (os2.Table == null) { TrueTypeFontTable tbl = this.ReadTable(os2, list, reader); if (tbl == null) { throw new ArgumentNullException("No OS/2 has been specified in the font file, this is needed to load the hroizontal metrics"); } os2.SetTable(tbl); } if (reader.Position != pos) { reader.Position = pos; } int firstcharindex = (os2.Table as OS2Table).FirstCharIndex; HorizontalMetrics hm = new HorizontalMetrics(reader.Position); ushort count = (hhead.Table as SubTables.HorizontalHeader).NumberOfHMetrics; List <HMetric> metrics = new List <HMetric>(); for (int i = 0; i < count; i++) { SubTables.HMetric metric = new HMetric(reader.ReadUInt16(), reader.ReadInt16(), (char)(i + firstcharindex)); metrics.Add(metric); } hm.HMetrics = metrics; return(hm); }
public override char RegisterGlyph(char c) { WidthMetric metric; if (!_char2offset.TryGetValue(c, out metric)) { int offset = this.CharacterMappings.GetCharacterGlyphOffset(c); int hmindex = offset; if (hmindex >= this.HMetrics.HMetrics.Count) { hmindex = this.HMetrics.HMetrics.Count - 1; } HMetric found = this.HMetrics.HMetrics[hmindex]; int width = (found.AdvanceWidth * this.GlyphUnits) / UnitsPerEm; metric = new WidthMetric() { Width = width, Glyph = offset }; _char2offset.Add(c, metric); if (!_offset2char.ContainsKey(offset)) { _offset2char[offset] = c; } //else //{ // System.Diagnostics.Debug.WriteLine("offset '" + offset + "' is already assigned to chararcter '" + _offset2char[offset] + "'"); //} if (offset < this.MinGlyphIndex) { this.MinGlyphIndex = offset; } if (offset > this.MaxGlyphIndex) { this.MaxGlyphIndex = offset; } if (c < this.FirstChar) { this.FirstChar = c; } if (c > this.LastChar) { this.LastChar = c; } } return((char)metric.Glyph); }