예제 #1
0
        /// <summary>
        ///     Reads the contents of the "hmtx" table from the supplied stream
        ///     at the current position.
        /// </summary>
        /// <param name="reader"></param>
        protected internal override void Read(FontFileReader reader)
        {
            FontFileStream stream = reader.Stream;

            // Obtain number of horizonal metrics from 'hhea' table
            int numberOfHMetrics = reader.GetHorizontalHeaderTable().HMetricCount;

            // Obtain glyph count from 'maxp' table
            int numGlyphs = reader.GetMaximumProfileTable().GlyphCount;

            // Metrics might not be supplied for each glyph.  For example, if
            // the font is monospaced the hMetrics array will only contain a
            // single entry
            int metricsSize = (numGlyphs > numberOfHMetrics) ? numGlyphs : numberOfHMetrics;

            metrics = new List <HorizontalMetric>();//(metricsSize);

            for (int i = 0; i < numberOfHMetrics; i++)
            {
                metrics.Add(new HorizontalMetric(stream.ReadUShort(), stream.ReadShort()));
            }

            // Fill in missing widths
            if (numberOfHMetrics < metricsSize)
            {
                HorizontalMetric lastHMetric = metrics[metrics.Count - 1];
                for (int i = numberOfHMetrics; i < numGlyphs; i++)
                {
                    metrics.Add(
                        new HorizontalMetric(lastHMetric.AdvanceWidth, stream.ReadShort()));
                }
            }
        }
예제 #2
0
        protected internal override void Write(FontFileWriter writer)
        {
            FontFileStream stream = writer.Stream;

            for (int i = 0; i < metrics.Count; i++)
            {
                HorizontalMetric metric = metrics[i];
                stream.WriteUShort(metric.AdvanceWidth);
                stream.WriteShort(metric.LeftSideBearing);
            }
        }