ReadUnsignedShort() public method

public ReadUnsignedShort ( ) : int
return int
        protected void CheckGlyphComposite(int glyph)
        {
            var start = LocaTable[glyph];

            if (start == LocaTable[glyph + 1]) // no contour
            {
                return;
            }

            Rf.Seek(TableGlyphOffset + start);
            int numContours = Rf.ReadShort();

            if (numContours >= 0)
            {
                return;
            }

            Rf.SkipBytes(8);
            for (; ;)
            {
                var flags  = Rf.ReadUnsignedShort();
                var cGlyph = Rf.ReadUnsignedShort();
                if (!GlyphsUsed.ContainsKey(cGlyph))
                {
                    GlyphsUsed[cGlyph] = null;
                    GlyphsInList.Add(cGlyph);
                }
                if ((flags & MoreComponents) == 0)
                {
                    return;
                }

                int skip;
                if ((flags & Arg1And2AreWords) != 0)
                {
                    skip = 4;
                }
                else
                {
                    skip = 2;
                }

                if ((flags & WeHaveAScale) != 0)
                {
                    skip += 2;
                }
                else if ((flags & WeHaveAnXAndYScale) != 0)
                {
                    skip += 4;
                }

                if ((flags & WeHaveATwoByTwo) != 0)
                {
                    skip += 8;
                }

                Rf.SkipBytes(skip);
            }
        }
Esempio n. 2
0
        protected void CreateTableDirectory()
        {
            tableDirectory = new Hashtable();
            rf.Seek(directoryOffset);
            int id = rf.ReadInt();

            if (id != 0x00010000)
            {
                throw new DocumentException(fileName + " is not a true type file.");
            }
            int num_tables = rf.ReadUnsignedShort();

            rf.SkipBytes(6);
            for (int k = 0; k < num_tables; ++k)
            {
                string tag           = ReadStandardString(4);
                int[]  tableLocation = new int[3];
                tableLocation[TABLE_CHECKSUM] = rf.ReadInt();
                tableLocation[TABLE_OFFSET]   = rf.ReadInt();
                tableLocation[TABLE_LENGTH]   = rf.ReadInt();
                tableDirectory[tag]           = tableLocation;
            }
        }
        protected void CreateTableDirectory()
        {
            tableDirectory = new Dictionary <string, int[]>();
            rf.Seek(directoryOffset);
            int id = rf.ReadInt();

            if (id != 0x00010000)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("1.is.not.a.true.type.file", fileName));
            }
            int num_tables = rf.ReadUnsignedShort();

            rf.SkipBytes(6);
            for (int k = 0; k < num_tables; ++k)
            {
                string tag           = ReadStandardString(4);
                int[]  tableLocation = new int[3];
                tableLocation[TABLE_CHECKSUM] = rf.ReadInt();
                tableLocation[TABLE_OFFSET]   = rf.ReadInt();
                tableLocation[TABLE_LENGTH]   = rf.ReadInt();
                tableDirectory[tag]           = tableLocation;
            }
        }
Esempio n. 4
0
 // Utilities
 
 /**
 * Returns the number of image directories (subimages) stored in a
 * given TIFF file, represented by a <code>SeekableStream</code>.
 */
 public static int GetNumDirectories(RandomAccessFileOrArray stream)
 {
     long pointer = stream.FilePointer; // Save stream pointer
     
     stream.Seek(0L);
     int endian = stream.ReadUnsignedShort();
     if (!IsValidEndianTag(endian)) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.endianness.tag.not.0x4949.or.0x4d4d"));
     }
     bool isBigEndian = (endian == 0x4d4d);
     int magic = ReadUnsignedShort(stream, isBigEndian);
     if (magic != 42) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.magic.number.should.be.42"));
     }
     
     stream.Seek(4L);
     long offset = ReadUnsignedInt(stream, isBigEndian);
     
     int numDirectories = 0;
     while (offset != 0L) {
         ++numDirectories;
         
         // EOFException means IFD was probably not properly terminated.
         try {
             stream.Seek(offset);
             int entries = ReadUnsignedShort(stream, isBigEndian);
             stream.Skip(12*entries);
             offset = ReadUnsignedInt(stream, isBigEndian);
         } catch (EndOfStreamException) {
             numDirectories--;
             break;
         }
     }
     
     stream.Seek(pointer); // Reset stream pointer
     return numDirectories;
 }
Esempio n. 5
0
 private static int ReadUnsignedShort(RandomAccessFileOrArray stream,
 bool isBigEndian)
 {
     if (isBigEndian) {
         return stream.ReadUnsignedShort();
     } else {
         return stream.ReadUnsignedShortLE();
     }
 }
Esempio n. 6
0
 /**
 * Constructs a TIFFDirectory by reading a SeekableStream.
 * The ifd_offset parameter specifies the stream offset from which
 * to begin reading; this mechanism is sometimes used to store
 * private IFDs within a TIFF file that are not part of the normal
 * sequence of IFDs.
 *
 * @param stream a SeekableStream to read from.
 * @param ifd_offset the long byte offset of the directory.
 * @param directory the index of the directory to read beyond the
 *        one at the current stream offset; zero indicates the IFD
 *        at the current offset.
 */
 public TIFFDirectory(RandomAccessFileOrArray stream, long ifd_offset, int directory)
 {
     
     long global_save_offset = stream.FilePointer;
     stream.Seek(0L);
     int endian = stream.ReadUnsignedShort();
     if (!IsValidEndianTag(endian)) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.endianness.tag.not.0x4949.or.0x4d4d"));
     }
     isBigEndian = (endian == 0x4d4d);
     
     // Seek to the first IFD.
     stream.Seek(ifd_offset);
     
     // Seek to desired IFD if necessary.
     int dirNum = 0;
     while (dirNum < directory) {
         // Get the number of fields in the current IFD.
         int numEntries = ReadUnsignedShort(stream);
         
         // Skip to the next IFD offset value field.
         stream.Seek(ifd_offset + 12*numEntries);
         
         // Read the offset to the next IFD beyond this one.
         ifd_offset = ReadUnsignedInt(stream);
         
         // Seek to the next IFD.
         stream.Seek(ifd_offset);
         
         // Increment the directory.
         dirNum++;
     }
     
     Initialize(stream);
     stream.Seek(global_save_offset);
 }
Esempio n. 7
0
 /**
 * Constructs a TIFFDirectory from a SeekableStream.
 * The directory parameter specifies which directory to read from
 * the linked list present in the stream; directory 0 is normally
 * read but it is possible to store multiple images in a single
 * TIFF file by maintaing multiple directories.
 *
 * @param stream a SeekableStream to read from.
 * @param directory the index of the directory to read.
 */
 public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
 {
     
     long global_save_offset = stream.FilePointer;
     long ifd_offset;
     
     // Read the TIFF header
     stream.Seek(0L);
     int endian = stream.ReadUnsignedShort();
     if (!IsValidEndianTag(endian)) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.endianness.tag.not.0x4949.or.0x4d4d"));
     }
     isBigEndian = (endian == 0x4d4d);
     
     int magic = ReadUnsignedShort(stream);
     if (magic != 42) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.magic.number.should.be.42"));
     }
     
     // Get the initial ifd offset as an unsigned int (using a long)
     ifd_offset = ReadUnsignedInt(stream);
     
     for (int i = 0; i < directory; i++) {
         if (ifd_offset == 0L) {
             throw new ArgumentException(MessageLocalization.GetComposedMessage("directory.number.too.large"));
         }
         
         stream.Seek(ifd_offset);
         int entries = ReadUnsignedShort(stream);
         stream.Skip(12*entries);
         
         ifd_offset = ReadUnsignedInt(stream);
     }
     
     stream.Seek(ifd_offset);
     Initialize(stream);
     stream.Seek(global_save_offset);
 }
Esempio n. 8
0
 // Utilities
 
 /**
 * Returns the number of image directories (subimages) stored in a
 * given TIFF file, represented by a <code>SeekableStream</code>.
 */
 public static int GetNumDirectories(RandomAccessFileOrArray stream)
 {
     long pointer = stream.FilePointer; // Save stream pointer
     
     stream.Seek(0L);
     int endian = stream.ReadUnsignedShort();
     if (!IsValidEndianTag(endian)) {
         throw new ArgumentException("Bad endianness tag (not 0x4949 or 0x4d4d).");
     }
     bool isBigEndian = (endian == 0x4d4d);
     int magic = ReadUnsignedShort(stream, isBigEndian);
     if (magic != 42) {
         throw new
         ArgumentException("Bad magic number, should be 42.");
     }
     
     stream.Seek(4L);
     long offset = ReadUnsignedInt(stream, isBigEndian);
     
     int numDirectories = 0;
     while (offset != 0L) {
         ++numDirectories;
         
         // EOFException means IFD was probably not properly terminated.
         try {
             stream.Seek(offset);
             int entries = ReadUnsignedShort(stream, isBigEndian);
             stream.Skip(12*entries);
             offset = ReadUnsignedInt(stream, isBigEndian);
         } catch (EndOfStreamException) {
             //numDirectories--;
             break;
         }
     }
     
     stream.Seek(pointer); // Reset stream pointer
     return numDirectories;
 }
Esempio n. 9
0
 /**
 * Constructs a TIFFDirectory from a SeekableStream.
 * The directory parameter specifies which directory to read from
 * the linked list present in the stream; directory 0 is normally
 * read but it is possible to store multiple images in a single
 * TIFF file by maintaing multiple directories.
 *
 * @param stream a SeekableStream to read from.
 * @param directory the index of the directory to read.
 */
 public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
 {
     
     long global_save_offset = stream.FilePointer;
     long ifd_offset;
     
     // Read the TIFF header
     stream.Seek(0L);
     int endian = stream.ReadUnsignedShort();
     if (!IsValidEndianTag(endian)) {
         throw new
         ArgumentException("Bad endianness tag (not 0x4949 or 0x4d4d).");
     }
     isBigEndian = (endian == 0x4d4d);
     
     int magic = ReadUnsignedShort(stream);
     if (magic != 42) {
         throw new
         ArgumentException("Bad magic number, should be 42.");
     }
     
     // Get the initial ifd offset as an unsigned int (using a long)
     ifd_offset = ReadUnsignedInt(stream);
     
     for (int i = 0; i < directory; i++) {
         if (ifd_offset == 0L) {
             throw new
             ArgumentException("Directory number too large.");
         }
         
         stream.Seek(ifd_offset);
         int entries = ReadUnsignedShort(stream);
         stream.Skip(12*entries);
         
         ifd_offset = ReadUnsignedInt(stream);
     }
     
     stream.Seek(ifd_offset);
     Initialize(stream);
     stream.Seek(global_save_offset);
 }