/// <summary>Handles a table which is located at 'offset' in the stream and has the given tag.</summary>
        public bool HandleTable(string tag, int offset, FontFace font)
        {
            switch (tag)
            {
            case "head":

                // Load the header:
                if (!HeaderTables.Load(this, offset, font, out IndexToLocFormat))
                {
                    return(false);
                }

                break;

            case "maxp":

                // Maxp table:
                MaxpTables.Load(this, offset, font, out GlyphCount);

                break;

            default:
                // Add to set to load when the rest do:
                Tables[tag] = new TableInfo(offset);
                break;
            }

            // All Ok
            return(true);
        }
Beispiel #2
0
        public static bool Load(FontParser parser, FontFace font, bool full)
        {
            font.RequiresLoad = !full;
            font.Parser       = parser;

            // Read the version:
            int dec;
            int version = parser.ReadFixed(out dec);

            if (version == 1 && dec == 0)
            {
                // TTF outline format.
            }
            else
            {
                // Reset to start:
                parser.Position = 0;

                // OpenType. Read the tag (right at the start):
                string openTypeVersion = parser.ReadTag();

                if (openTypeVersion == "OTTO")
                {
                    // CFF outline format.
                }
                else
                {
                    // Unsupported format.
                    return(false);
                }
            }

            // Table count:
            int numTables = parser.ReadUInt16();

            // Move to p12:
            parser.Position = 12;

            for (int i = 0; i < numTables; i++)
            {
                // Read the tables tag:
                string tag = parser.ReadTag();

                // Move parser along:
                parser.Position += 4;

                // Read the offset:
                int offset = (int)parser.ReadUInt32();

                // Grab the position - this allows the tables to mess it up:
                int basePosition = parser.Position;

                switch (tag)
                {
                case "cmap":

                    parser.CmapOffset = offset;

                    break;

                case "head":

                    // Load the header:
                    if (!HeaderTables.Load(parser, offset, font, out parser.IndexToLocFormat))
                    {
                        return(false);
                    }

                    break;

                case "hhea":

                    parser.HheaOffset = offset;

                    break;

                case "hmtx":
                    parser.HmtxOffset = offset;
                    break;

                case "maxp":

                    // Maxp table:
                    MaxpTables.Load(parser, offset, font, out parser.GlyphCount);

                    break;

                case "name":

                    // General meta:
                    NameTables.Load(parser, offset, font);

                    break;

                case "OS/2":

                    // OS2 table:
                    OS2Tables.Load(parser, offset, font);

                    break;

                case "post":

                    // Postscript info table:
                    parser.PostOffset = offset;

                    break;

                case "glyf":
                    parser.GlyfOffset = offset;
                    break;

                case "loca":
                    parser.LocaOffset = offset;
                    break;

                case "GSUB":

                    // Gsub(stitute) table. Ligatures fall through here.
                    GsubTables.Load(parser, offset, font);

                    break;

                case "CFF ":
                    parser.CffOffset = offset;
                    break;

                case "kern":

                    parser.KernOffset = offset;

                    break;

                case "GPOS":

                    parser.GposOffset = offset;

                    break;
                }

                // Skip meta:
                parser.Position = basePosition + 4;
            }

            if (full)
            {
                return(ReadTables(parser, font));
            }

            return(true);
        }