Exemple #1
0
        public static bool ReadTables(FontParser parser, FontFace font)
        {
            int hmMetricCount = 0;

            if (parser.HheaOffset != 0)
            {
                // Hhea table:
                HheaTables.Load(parser, parser.HheaOffset, font, out hmMetricCount);
            }

            Glyph[] glyphs = null;

            if (parser.GlyfOffset != 0 && parser.LocaOffset != 0)
            {
                bool shortVersion = (parser.IndexToLocFormat == 0);

                // Load a loca table (temporary):
                uint[] locaTable = LocaTables.Load(parser, parser.LocaOffset, parser.GlyphCount, shortVersion);

                // Load the glyph set:
                glyphs = GlyfTables.Load(parser, parser.GlyfOffset, locaTable, font);

                HmtxTables.Load(parser, parser.HmtxOffset, font, glyphs, hmMetricCount);
            }
            else if (parser.CffOffset != 0)
            {
                if (parser.PostOffset != 0)
                {
                    // Post table:
                    int postGlyphCount;
                    PostTables.Load(parser, parser.PostOffset, font, out postGlyphCount);

                    if (parser.GlyphCount == 0 && postGlyphCount != -1)
                    {
                        parser.GlyphCount = postGlyphCount;
                    }
                }

                // Load the CFF (PostScript glyph) table:
                glyphs = CffTables.Load(parser, parser.CffOffset, font);
            }
            else
            {
                // Unrecognised/ bad font.
                return(false);
            }

            if (parser.KernOffset != 0)
            {
                // Kerning table:
                KerningTables.Load(parser, parser.KernOffset, font, glyphs);
            }
            else if (parser.GposOffset != 0)
            {
                // GPOS table (also kerning data):
                GposTables.Load(parser, parser.GposOffset, font, glyphs);
            }

            // Finally, the character map:
            if (parser.CmapOffset != 0)
            {
                // Load a charmap:
                CharMapTables.Load(parser, parser.CmapOffset, font, glyphs);
            }

            if (Fonts.Preload)
            {
                font.AllGlyphsLoaded();
            }

            return(true);
        }
        public static bool ReadTables(FontParser parser, FontFace font)
        {
            int hmMetricCount = 0;

            int tableOffset = parser.TableOffset("OS/2");

            if (tableOffset != 0)
            {
                // OS/2 table:
                OS2Tables.Load(parser, tableOffset, font);
            }

            tableOffset = parser.TableOffset("hhea");

            if (tableOffset != 0)
            {
                // Hhea table (always after OS/2):
                HheaTables.Load(parser, tableOffset, font, out hmMetricCount);
            }

            // Handle meta if it's not been loaded yet:
            if (font.Ascender == 0f)
            {
                // Requires info from both HHEA and OS/2:
                parser.ApplyWindowsMetrics(font);
            }


            // General metadata - the name table:
            tableOffset = parser.TableOffset("name");

            if (tableOffset != 0)
            {
                NameTables.Load(parser, tableOffset, font);
            }

            // Glyph data next!

            Glyph[] glyphs = null;

            int locaOffset = parser.TableOffset("loca");

            tableOffset = parser.TableOffset("glyf");

            if (tableOffset != 0 && locaOffset != 0)
            {
                bool shortVersion = (parser.IndexToLocFormat == 0);

                // Load a loca table (temporary):
                uint[] locaTable = LocaTables.Load(parser, locaOffset, parser.GlyphCount, shortVersion);

                // Load the glyph set:
                glyphs = GlyfTables.Load(parser, tableOffset, locaTable, font);

                HmtxTables.Load(parser, parser.TableOffset("hmtx"), font, glyphs, hmMetricCount);
            }
            else
            {
                tableOffset = parser.TableOffset("CFF ");

                if (tableOffset != 0)
                {
                    int postOffset = parser.TableOffset("post");

                    if (postOffset != 0)
                    {
                        // Post table:
                        int postGlyphCount;
                        PostTables.Load(parser, postOffset, font, out postGlyphCount);

                        if (parser.GlyphCount == 0 && postGlyphCount != -1)
                        {
                            parser.GlyphCount = postGlyphCount;
                        }
                    }

                    // Load the CFF (PostScript glyph) table:
                    glyphs = CffTables.Load(parser, tableOffset, font);
                }
                else
                {
                    // Unrecognised/ bad font.
                    return(false);
                }
            }

            if (glyphs != null && glyphs.Length > 0)
            {
                font.NotDefined = glyphs[0];
            }

            // Kerning table next:
            tableOffset = parser.TableOffset("kern");

            if (tableOffset != 0)
            {
                // Kerning table:
                KerningTables.Load(parser, tableOffset, font, glyphs);
            }
            else
            {
                // Try GPOS instead:
                tableOffset = parser.TableOffset("GPOS");

                if (tableOffset != 0)
                {
                    // GPOS table (also kerning data):
                    GposTables.Load(parser, tableOffset, font, glyphs);
                }
            }

            // GSUB(stitution):
            tableOffset = parser.TableOffset("GSUB");

            if (tableOffset != 0)
            {
                GsubTables.Load(parser, tableOffset, font);
            }

            // Finally, the character map:
            tableOffset = parser.TableOffset("cmap");

            if (tableOffset != 0)
            {
                // Load the charmap:
                CharMapTables.Load(parser, tableOffset, font, glyphs);
            }

            if (Fonts.Preload)
            {
                font.AllGlyphsLoaded();
            }

            return(true);
        }