Ejemplo n.º 1
0
        private void initialize(Reader reader, long parallax)
        {
            reader.Position = 0;
            uint tag = (uint)reader.ReadUint32();

            if (tag == 1953784678) //ttc tag
            {
                Point version = new Point();
                version.X = reader.ReadUint16();
                version.Y = reader.ReadUint16();

                uint numFonts    = (uint)reader.ReadUint32();
                uint offsetTable = (uint)reader.ReadUint32();

                reader.Position = (int)(offsetTable + 4);
            }

            ushort             numTables     = (ushort)reader.ReadUint16();
            ushort             searchRange   = (ushort)reader.ReadUint16();
            ushort             entrySelector = (ushort)reader.ReadUint16();
            ushort             rangeShift    = (ushort)reader.ReadUint16();
            List <OffsetTable> offsetsTables = new List <OffsetTable>();

            for (int i = 0; i < numTables; ++i)
            {
                OffsetTable table = new OffsetTable();
                table.Read(reader);
                offsetsTables.Add(table);
            }

            loadRequiredTables(offsetsTables, reader, parallax);
        }
Ejemplo n.º 2
0
        protected virtual void loadRequiredTables(List <OffsetTable> offsetsTables, Reader reader, long parallax)
        {
            string[] tags = { "head", "hhea", "maxp", "loca", "cmap", "glyf", "hmtx", "name", "post" };
            for (int i = 0; i < tags.Length; ++i)
            {
                int index = findTable(offsetsTables, tags[i]);
                if (index == -1)
                {
                    throw new PDFWrongFontFileException();
                }

                OffsetTable offsetTable = offsetsTables[index];
                switch (tags[i])
                {
                case "head":
                    offsetTable.Table = new HeadTable();
                    break;

                case "hhea":
                    offsetTable.Table = new HHeaTable();
                    break;

                case "maxp":
                    offsetTable.Table = new MaxpTable();
                    break;

                case "loca":
                    short  indexToLocFormat = (_tables["head"].Table as HeadTable).IndexToLocFormat;
                    ushort numGlyphs        = (_tables["maxp"].Table as MaxpTable).NumGlyphs;
                    offsetTable.Table = new LocaTable(indexToLocFormat, numGlyphs);
                    break;

                case "cmap":
                    offsetTable.Table = new CMapTable();
                    break;

                case "glyf":
                    offsetTable.Table = new GlyphTable((_tables["loca"].Table as LocaTable).Offsets);
                    break;

                case "hmtx":
                    ushort numGlyph            = (_tables["maxp"].Table as MaxpTable).NumGlyphs;
                    ushort numOfLongHorMetrics = (_tables["hhea"].Table as HHeaTable).NumOfLongHorMetrics;
                    offsetTable.Table = new HMtxTable(numOfLongHorMetrics, numGlyph);
                    break;

                case "name":
                    offsetTable.Table = new NameTable();
                    break;

                case "post":
                    offsetTable.Table = new PostTable();
                    break;
                }

                offsetTable.Table.Read(reader, (int)(offsetTable.Offset - parallax), (int)offsetTable.Length);
                _tables.Add(tags[i], offsetTable);
            }
        }
Ejemplo n.º 3
0
        public override void Write(System.IO.Stream stream, ushort[] glyfIndexes, FontMap map)
        {
            string[] tags  = { "CFF ", "head", "hhea", "hmtx", "maxp", "name", "post" };
            int      count = tags.Length;

            writeHeader(stream, 1330926671);

            byte[][] bytes    = new byte[count][];
            long     offset   = 12 + 16 * count;
            int      curTable = 0;

            for (int i = 0; i < tags.Length; ++i)
            {
                if (Tables.ContainsKey(tags[i]))
                {
                    OffsetTable table = Tables[tags[i]];
                    byte[]      buffer;
                    if (table.Table is CMapTable)
                    {
                        buffer = (table.Table as CMapTable).GetData(map);
                    }
                    else
                    {
                        buffer = table.Table.GetData(glyfIndexes);
                    }

                    bytes[curTable] = buffer;
                    table.Length    = buffer.Length;
                    table.Checksum  = calculateCheckSum(buffer);
                    table.Offset    = offset;

                    table.Write(stream);

                    offset += buffer.Length;
                    ++curTable;
                }
            }

            for (int i = 0; i < bytes.Length; ++i)
            {
                byte[] buf = bytes[i];
                stream.Write(buf, 0, buf.Length);
            }
        }