Beispiel #1
0
        private byte[] BuildPostTable()
        {
            PostScriptTable post = ttf.PostScript;

            if (post == null || keepTables != null && !keepTables.Contains("post", StringComparer.Ordinal))
            {
                return(null);
            }

            using (var bos = new MemoryStream())
                using (var output = new BinaryWriter(bos))
                {
                    WriteFixed(output, 2.0); // version
                    WriteFixed(output, post.ItalicAngle);
                    WriteSInt16(output, post.UnderlinePosition);
                    WriteSInt16(output, post.UnderlineThickness);
                    WriteUint32(output, post.IsFixedPitch);
                    WriteUint32(output, post.MinMemType42);
                    WriteUint32(output, post.MaxMemType42);
                    WriteUint32(output, post.MinMemType1);
                    WriteUint32(output, post.MaxMemType1);

                    // version 2.0

                    // numberOfGlyphs
                    WriteUint16(output, glyphIds.Count);

                    // glyphNameIndex[numGlyphs]
                    ConcurrentDictionary <string, int> names = new ConcurrentDictionary <string, int>(StringComparer.Ordinal);
                    foreach (int gid in glyphIds)
                    {
                        string name = post.GetName(gid);
                        if (WGL4Names.MAC_GLYPH_NAMES_INDICES.TryGetValue(name, out int macId))
                        {
                            // the name input implicit, as it's from MacRoman
                            WriteUint16(output, macId);
                        }
                        else
                        {
                            // the name will be written explicitly
                            int ordinal = names.GetOrAdd(name, (p) => names.Count);
                            WriteUint16(output, 258 + ordinal);
                        }
                    }

                    // names[numberNewGlyphs]
                    foreach (string name in names.Keys)
                    {
                        byte[] buf = Charset.ASCII.GetBytes(name);
                        WriteUint8(output, buf.Length);
                        output.Write(buf);
                    }

                    output.Flush();
                    return(bos.ToArray());
                }
        }