Exemple #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()));
                }
            }
        }
        /// <summary>
        ///     Reads the contents of the "hhea" table from the current position
        ///     in the supplied stream.
        /// </summary>
        /// <param name="reader"></param>
        protected internal override void Read(FontFileReader reader)
        {
            FontFileStream stream = reader.Stream;

            versionNo           = stream.ReadFixed();
            ascender            = stream.ReadFWord();
            decender            = stream.ReadFWord();
            lineGap             = stream.ReadFWord();
            advanceWidthMax     = stream.ReadUFWord();
            minLeftSideBearing  = stream.ReadFWord();
            minRightSideBearing = stream.ReadFWord();
            xMaxExtent          = stream.ReadFWord();
            caretSlopeRise      = stream.ReadShort();
            caretSlopeRun       = stream.ReadShort();
            caretOffset         = stream.ReadShort();
            stream.ReadShort();
            stream.ReadShort();
            stream.ReadShort();
            stream.ReadShort();
            metricDataFormat = stream.ReadShort();
            numberOfHMetrics = stream.ReadUShort();
        }
Exemple #3
0
        /// <summary>
        ///     Reads the contents of the "head" table from the current position
        ///     in the supplied stream.
        /// </summary>
        /// <param name="reader"></param>
        protected internal override void Read(FontFileReader reader)
        {
            FontFileStream stream = reader.Stream;

            versionNo          = stream.ReadFixed();
            fontRevision       = stream.ReadFixed();
            checkSumAdjustment = stream.ReadULong();
            magicNumber        = stream.ReadULong();
            flags       = stream.ReadUShort();
            unitsPermEm = stream.ReadUShort();
            // Some fonts have dodgy date offsets that cause AddSeconds to throw an exception
            createDate        = GetDate(stream.ReadLongDateTime());
            updateDate        = GetDate(stream.ReadLongDateTime());
            xMin              = stream.ReadShort();
            yMin              = stream.ReadShort();
            xMax              = stream.ReadShort();
            yMax              = stream.ReadShort();
            macStyle          = stream.ReadUShort();
            lowestRecPPEM     = stream.ReadUShort();
            fontDirectionHint = stream.ReadShort();
            indexToLocFormat  = stream.ReadShort();
            glyphDataFormat   = stream.ReadShort();
        }
Exemple #4
0
        /// <summary>
        ///     Reads the contents of the "os/2" 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;

            version       = stream.ReadUShort();
            avgCharWidth  = stream.ReadShort();
            usWeightClass = stream.ReadUShort();
            usWidthClass  = stream.ReadUShort();
            // According to the OpenType spec, bit 0 must be zero.
            fsType             = (ushort)(stream.ReadUShort() & ~1);
            subscriptXSize     = stream.ReadShort();
            subscriptYSize     = stream.ReadShort();
            subscriptXOffset   = stream.ReadShort();
            subscriptYOffset   = stream.ReadShort();
            superscriptXSize   = stream.ReadShort();
            superscriptYSize   = stream.ReadShort();
            superscriptXOffset = stream.ReadShort();
            superscriptYOffset = stream.ReadShort();
            strikeoutSize      = stream.ReadShort();
            strikeoutPosition  = stream.ReadShort();
            short familyClass = stream.ReadShort();

            classID    = (byte)(familyClass >> 8);
            subclassID = (byte)(familyClass & 255);
            stream.Read(panose, 0, panose.Length);
            unicodeRange1    = stream.ReadULong();
            unicodeRange2    = stream.ReadULong();
            unicodeRange3    = stream.ReadULong();
            unicodeRange4    = stream.ReadULong();
            vendorID[0]      = stream.ReadChar();
            vendorID[1]      = stream.ReadChar();
            vendorID[2]      = stream.ReadChar();
            vendorID[3]      = stream.ReadChar();
            fsSelection      = stream.ReadUShort();
            usFirstCharIndex = stream.ReadUShort();
            usLastCharIndex  = stream.ReadUShort();
            typoAscender     = stream.ReadShort();
            typoDescender    = stream.ReadShort();
            typoLineGap      = stream.ReadShort();
            usWinAscent      = stream.ReadUShort();
            usWinDescent     = stream.ReadUShort();
            codePageRange1   = stream.ReadULong();
            codePageRange2   = stream.ReadULong();
            sxHeight         = stream.ReadShort();
            sCapHeight       = stream.ReadShort();
            usDefaultChar    = stream.ReadUShort();
            usBreakChar      = stream.ReadUShort();
            usMaxContext     = stream.ReadUShort();
        }