Example #1
0
        private byte[] BuildOS2Table()
        {
            OS2WindowsMetricsTable os2 = ttf.OS2Windows;

            if (os2 == null || uniToGID.Count == 0 || keepTables != null && !keepTables.Contains("OS/2", StringComparer.Ordinal))
            {
                return(null);
            }

            using (var bos = new MemoryStream())
                using (var output = new BinaryWriter(bos))
                {
                    WriteUint16(output, os2.Version);
                    WriteSInt16(output, os2.AverageCharWidth);
                    WriteUint16(output, os2.WeightClass);
                    WriteUint16(output, os2.WidthClass);

                    WriteSInt16(output, os2.FsType);

                    WriteSInt16(output, os2.SubscriptXSize);
                    WriteSInt16(output, os2.SubscriptYSize);
                    WriteSInt16(output, os2.SubscriptXOffset);
                    WriteSInt16(output, os2.SubscriptYOffset);

                    WriteSInt16(output, os2.SuperscriptXSize);
                    WriteSInt16(output, os2.SuperscriptYSize);
                    WriteSInt16(output, os2.SuperscriptXOffset);
                    WriteSInt16(output, os2.SuperscriptYOffset);

                    WriteSInt16(output, os2.StrikeoutSize);
                    WriteSInt16(output, os2.StrikeoutPosition);
                    WriteSInt16(output, (short)os2.FamilyClass);
                    output.Write(os2.Panose);

                    WriteUint32(output, 0);
                    WriteUint32(output, 0);
                    WriteUint32(output, 0);
                    WriteUint32(output, 0);

                    output.Write(Charset.ASCII.GetBytes(os2.AchVendId));

                    WriteUint16(output, os2.FsSelection);
                    WriteUint16(output, uniToGID.Keys.First());
                    WriteUint16(output, uniToGID.Keys.Last());
                    WriteUint16(output, os2.TypoAscender);
                    WriteUint16(output, os2.TypoDescender);
                    WriteUint16(output, os2.TypoLineGap);
                    WriteUint16(output, os2.WinAscent);
                    WriteUint16(output, os2.WinDescent);

                    output.Flush();
                    return(bos.ToArray());
                }
        }
Example #2
0
        private TTFTable ReadTableDirectory(TrueTypeFont font, TTFDataStream raf)
        {
            TTFTable table;
            string   tag = raf.ReadString(4);

            switch (tag)
            {
            case CmapTable.TAG:
                table = new CmapTable(font);
                break;

            case GlyphTable.TAG:
                table = new GlyphTable(font);
                break;

            case HeaderTable.TAG:
                table = new HeaderTable(font);
                break;

            case HorizontalHeaderTable.TAG:
                table = new HorizontalHeaderTable(font);
                break;

            case HorizontalMetricsTable.TAG:
                table = new HorizontalMetricsTable(font);
                break;

            case IndexToLocationTable.TAG:
                table = new IndexToLocationTable(font);
                break;

            case MaximumProfileTable.TAG:
                table = new MaximumProfileTable(font);
                break;

            case NamingTable.TAG:
                table = new NamingTable(font);
                break;

            case OS2WindowsMetricsTable.TAG:
                table = new OS2WindowsMetricsTable(font);
                break;

            case PostScriptTable.TAG:
                table = new PostScriptTable(font);
                break;

            case DigitalSignatureTable.TAG:
                table = new DigitalSignatureTable(font);
                break;

            case KerningTable.TAG:
                table = new KerningTable(font);
                break;

            case VerticalHeaderTable.TAG:
                table = new VerticalHeaderTable(font);
                break;

            case VerticalMetricsTable.TAG:
                table = new VerticalMetricsTable(font);
                break;

            case VerticalOriginTable.TAG:
                table = new VerticalOriginTable(font);
                break;

            case GlyphSubstitutionTable.TAG:
                table = new GlyphSubstitutionTable(font);
                break;

            default:
                table = ReadTable(font, tag);
                break;
            }
            table.Tag      = tag;
            table.CheckSum = raf.ReadUnsignedInt();
            table.Offset   = raf.ReadUnsignedInt();
            table.Length   = raf.ReadUnsignedInt();

            // skip tables with zero length (except glyf)
            if (table.Length == 0 && !tag.Equals(GlyphTable.TAG, StringComparison.Ordinal))
            {
                return(null);
            }

            return(table);
        }