Exemplo n.º 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()));
                }
            }
        }
Exemplo n.º 2
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 ArrayList(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 = (HorizontalMetric) metrics[metrics.Count - 1];
                for (int i = numberOfHMetrics; i < numGlyphs; i++) {
                    metrics.Add(
                        new HorizontalMetric(lastHMetric.AdvanceWidth, stream.ReadShort()));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Writes the font subset to the supplied output stream.
        /// </summary>
        public void Generate(MemoryStream output)
        {
            HeaderTable              head = reader.GetHeaderTable();
            MaximumProfileTable      maxp = reader.GetMaximumProfileTable();
            HorizontalHeaderTable    hhea = reader.GetHorizontalHeaderTable();
            ControlValueTable        cvt  = reader.GetControlValueTable();
            FontProgramTable         fpgm = reader.GetFontProgramTable();
            GlyfDataTable            glyf = reader.GetGlyfDataTable();
            ControlValueProgramTable prep = reader.GetControlValueProgramTable();
            IndexToLocationTable     loca = CreateLocaTable(glyf);
            HorizontalMetricsTable   hmtx = CreateHmtxTable(glyf);

            // Since we're reusing the hhea and maxp tables, we must update
            // the numberOfHMetrics and numGlyphs fields to reflect the reduced
            // number of glyphs.
            maxp.GlyphCount   = glyf.Count;
            hhea.HMetricCount = glyf.Count;

            FontFileWriter writer = new FontFileWriter(output);

            writer.Write(head);
            writer.Write(maxp);
            writer.Write(hhea);
            writer.Write(hmtx);
            writer.Write(cvt);
            writer.Write(prep);
            writer.Write(fpgm);
            writer.Write(loca);
            writer.Write(glyf);
            writer.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Reads the contents of the "loca" 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;

            // Glyph offsets can be stored in either short of long format
            bool isShortFormat = reader.GetHeaderTable().IsShortFormat;

            // Number of glyphs including extra entry
            int glyphCount = reader.GetMaximumProfileTable().GlyphCount + 1;

            offsets = new ArrayList(glyphCount);
            for (int i = 0; i < glyphCount; i++) {
                offsets.Insert(i, (isShortFormat) ? (uint) (stream.ReadUShort() << 1) : stream.ReadULong());
            }
        }
        /// <summary>
        ///     Reads the contents of the "loca" 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;

            // Glyph offsets can be stored in either short of long format
            bool isShortFormat = reader.GetHeaderTable().IsShortFormat;

            // Number of glyphs including extra entry
            int glyphCount = reader.GetMaximumProfileTable().GlyphCount + 1;

            offsets = new ArrayList(glyphCount);
            for (int i = 0; i < glyphCount; i++)
            {
                offsets.Insert(i, (isShortFormat) ? (uint)(stream.ReadUShort() << 1) : stream.ReadULong());
            }
        }