예제 #1
0
        /**
         * <summary>Loads general tables.</summary>
         */
        private void LoadTables()
        {
            // Font Header ('head' table).
            int tableOffset;

            if (!tableOffsets.TryGetValue("head", out tableOffset))
            {
                throw new ParseException("'head' table does NOT exist.");
            }

            // Go to the font flags!
            FontData.Seek(tableOffset + 16);
            Metrics.Flags      = FontData.ReadUnsignedShort();
            Metrics.UnitsPerEm = FontData.ReadUnsignedShort();
            Metrics.UnitNorm   = 1000f / Metrics.UnitsPerEm;
            // Go to the bounding box limits!
            FontData.Skip(16);
            Metrics.XMin     = FontData.ReadShort();
            Metrics.YMin     = FontData.ReadShort();
            Metrics.XMax     = FontData.ReadShort();
            Metrics.YMax     = FontData.ReadShort();
            Metrics.MacStyle = FontData.ReadUnsignedShort();

            // Font Header ('OS/2' table).
            if (tableOffsets.TryGetValue("OS/2", out tableOffset))
            {
                FontData.Seek(tableOffset);
                int version = FontData.ReadUnsignedShort();
                // Go to the ascender!
                FontData.Skip(66);
                Metrics.STypoAscender  = FontData.ReadShort();
                Metrics.STypoDescender = FontData.ReadShort();
                Metrics.STypoLineGap   = FontData.ReadShort();
                if (version >= 2)
                {
                    FontData.Skip(12);
                    Metrics.SxHeight   = FontData.ReadShort();
                    Metrics.SCapHeight = FontData.ReadShort();
                }
                else
                {
                    /*
                     * NOTE: These are just rule-of-thumb values,
                     * in case the xHeight and CapHeight fields aren't available.
                     */
                    Metrics.SxHeight   = (short)(.5 * Metrics.UnitsPerEm);
                    Metrics.SCapHeight = (short)(.7 * Metrics.UnitsPerEm);
                }
            }

            // Horizontal Header ('hhea' table).
            if (!tableOffsets.TryGetValue("hhea", out tableOffset))
            {
                throw new ParseException("'hhea' table does NOT exist.");
            }

            // Go to the ascender!
            FontData.Seek(tableOffset + 4);
            Metrics.Ascender            = FontData.ReadShort();
            Metrics.Descender           = FontData.ReadShort();
            Metrics.LineGap             = FontData.ReadShort();
            Metrics.AdvanceWidthMax     = FontData.ReadUnsignedShort();
            Metrics.MinLeftSideBearing  = FontData.ReadShort();
            Metrics.MinRightSideBearing = FontData.ReadShort();
            Metrics.XMaxExtent          = FontData.ReadShort();
            Metrics.CaretSlopeRise      = FontData.ReadShort();
            Metrics.CaretSlopeRun       = FontData.ReadShort();
            // Go to the horizontal metrics count!
            FontData.Skip(12);
            Metrics.NumberOfHMetrics = FontData.ReadUnsignedShort();

            // PostScript ('post' table).
            if (!tableOffsets.TryGetValue("post", out tableOffset))
            {
                throw new ParseException("'post' table does NOT exist.");
            }

            // Go to the italic angle!
            FontData.Seek(tableOffset + 4);
            Metrics.ItalicAngle        = FontData.ReadFixed32();
            Metrics.UnderlinePosition  = FontData.ReadShort();
            Metrics.UnderlineThickness = FontData.ReadShort();
            Metrics.IsFixedPitch       = (FontData.ReadInt() != 0);
        }