コード例 #1
0
        /// <summary>
        ///     Reads the contents of the "kern" table from the current position
        ///     in the supplied stream.
        /// </summary>
        /// <param name="reader"></param>
        protected internal override void Read(FontFileReader reader)
        {
            FontFileStream stream = reader.Stream;

            // Skip version field
            stream.Skip(PrimitiveSizes.UShort);

            // Number of subtables
            int numTables = stream.ReadUShort();

            for (int i = 0; i < numTables; i++)
            {
                // Another pesky version field
                stream.Skip(PrimitiveSizes.UShort);

                // Length of the subtable, in bytes (including header).
                ushort length = stream.ReadUShort();

                // Type of information is contained in this table.
                ushort coverage = stream.ReadUShort();

                // Only interested in horiztonal kerning values in format 0
                if ((coverage & HoriztonalMask) == 1 &&
                    (coverage & MinimumMask) == 0 &&
                    ((coverage >> 8) == 0))
                {
                    // The number of kerning pairs in the table.
                    int numPairs = stream.ReadUShort();

                    hasKerningInfo = true;
                    pairs          = new KerningPairs(numPairs);

                    // Skip pointless shit
                    stream.Skip(3 * PrimitiveSizes.UShort);

                    for (int j = 0; j < numPairs; j++)
                    {
                        pairs.Add(
                            stream.ReadUShort(), // Left glyph index
                            stream.ReadUShort(), // Right glyph index
                            stream.ReadFWord()); // Kerning amount
                    }
                }
                else
                {
                    stream.Skip(length - 3 * PrimitiveSizes.UShort);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Reads the Offset and Directory tables.  If the FontFileStream represents
        ///     a TrueType collection, this method will look for the aforementioned
        ///     tables belonging to <i>fontName</i>.
        /// </summary>
        /// <remarks>
        ///     This method can handle a TrueType collection.
        /// </remarks>
        protected void ReadTableHeaders()
        {
            // Check for possible TrueType collection
            string tag = Encoding.ASCII.GetString(stream.ReadTag());

            if (tag == TableNames.Ttcf)
            {
                // Skip Version field - will be either 1.0 or 2.0
                stream.Skip(PrimitiveSizes.ULong);

                // Number of fonts in TrueType collection
                int numFonts = (int)stream.ReadULong();

                bool foundFont = false;
                for (int i = 0; i < numFonts && !foundFont; i++)
                {
                    // Offset from beginning of file to a font's subtable
                    uint directoryOffset = stream.ReadULong();

                    // Set a restore point since the code below will alter the stream position
                    stream.SetRestorePoint();
                    stream.Position = directoryOffset;

                    header = new TrueTypeHeader();
                    header.Read(stream);

                    // To ascertain whether this font is the one we're looking for,
                    // we must read the 'name' table.
                    if (!header.Contains(TableNames.Name))
                    {
                        throw new Exception("Unable to parse TrueType collection - missing 'head' table.");
                    }

                    // If font name is not supplied, select the first font in the colleciton;
                    // otherwise must have an exact match
                    NameTable nameTable = (NameTable)GetTable(TableNames.Name);
                    if (fontName == String.Empty || nameTable.FullName == fontName)
                    {
                        foundFont = true;
                    }

                    // Stream will now point to the next directory offset
                    stream.Restore();
                }

                // We were unable to locate font in collection
                if (!foundFont)
                {
                    throw new Exception("Unable to locate font '" + fontName + "' in TrueType collection");
                }
            }
            else
            {
                stream.Position = 0;

                // Read Offset and Directory tables
                header = new TrueTypeHeader();
                header.Read(stream);
            }
        }
コード例 #3
0
        private void WriteTableDirectory()
        {
            stream.SetRestorePoint();
            stream.Position = 0;
            stream.Skip(OffsetTableSize);

            foreach (FontTable table in tables.Values)
            {
                stream.WriteULong(table.Tag);
                stream.WriteULong(table.Entry.CheckSum);
                stream.WriteULong(table.Entry.Offset);
                stream.WriteULong(table.Entry.Length);
            }

            stream.Restore();
        }
コード例 #4
0
ファイル: TrueTypeHeader.cs プロジェクト: nholik/Fo.Net
        protected internal void Read(FontFileStream stream) {
            // Skip sfnt version (0x00010000 for version 1.0).
            stream.Skip(PrimitiveSizes.Fixed);

            // Number of tables
            int numTables = stream.ReadUShort();

            // Skip searchRange, entrySelector and rangeShift entries (3 x ushort)
            stream.Skip(PrimitiveSizes.UShort*3);

            directoryEntries = new Hashtable(numTables);
            for (int i = 0; i < numTables; i++) {
                DirectoryEntry entry = new DirectoryEntry(
                    stream.ReadTag(), // 4-byte identifier.
                    stream.ReadULong(), // CheckSum for this table. 
                    stream.ReadULong(), // Offset from beginning of TrueType font file. 
                    stream.ReadULong() // Length of this table. 
                    );
                directoryEntries.Add(entry.TableName, entry);
            }
        }
コード例 #5
0
        protected internal void Read(FontFileStream stream)
        {
            // Skip sfnt version (0x00010000 for version 1.0).
            stream.Skip(PrimitiveSizes.Fixed);

            // Number of tables
            int numTables = stream.ReadUShort();

            // Skip searchRange, entrySelector and rangeShift entries (3 x ushort)
            stream.Skip(PrimitiveSizes.UShort * 3);

            directoryEntries = new Hashtable(numTables);
            for (int i = 0; i < numTables; i++)
            {
                DirectoryEntry entry = new DirectoryEntry(
                    stream.ReadTag(),   // 4-byte identifier.
                    stream.ReadULong(), // CheckSum for this table.
                    stream.ReadULong(), // Offset from beginning of TrueType font file.
                    stream.ReadULong()  // Length of this table.
                    );
                directoryEntries.Add(entry.TableName, entry);
            }
        }