/// <summary> /// Reads the contents of the "os/2" table from the supplied stream /// at the current position. /// </summary> /// <param name="reader"></param> protected internal override void Read(FontFileReader reader) { FontFileStream stream = reader.Stream; version = stream.ReadUShort(); avgCharWidth = stream.ReadShort(); usWeightClass = stream.ReadUShort(); usWidthClass = stream.ReadUShort(); // According to the OpenType spec, bit 0 must be zero. fsType = (ushort)(stream.ReadUShort() & ~1); subscriptXSize = stream.ReadShort(); subscriptYSize = stream.ReadShort(); subscriptXOffset = stream.ReadShort(); subscriptYOffset = stream.ReadShort(); superscriptXSize = stream.ReadShort(); superscriptYSize = stream.ReadShort(); superscriptXOffset = stream.ReadShort(); superscriptYOffset = stream.ReadShort(); strikeoutSize = stream.ReadShort(); strikeoutPosition = stream.ReadShort(); short familyClass = stream.ReadShort(); classID = (byte)(familyClass >> 8); subclassID = (byte)(familyClass & 255); stream.Read(panose, 0, panose.Length); unicodeRange1 = stream.ReadULong(); unicodeRange2 = stream.ReadULong(); unicodeRange3 = stream.ReadULong(); unicodeRange4 = stream.ReadULong(); vendorID[0] = stream.ReadChar(); vendorID[1] = stream.ReadChar(); vendorID[2] = stream.ReadChar(); vendorID[3] = stream.ReadChar(); fsSelection = stream.ReadUShort(); usFirstCharIndex = stream.ReadUShort(); usLastCharIndex = stream.ReadUShort(); typoAscender = stream.ReadShort(); typoDescender = stream.ReadShort(); typoLineGap = stream.ReadShort(); usWinAscent = stream.ReadUShort(); usWinDescent = stream.ReadUShort(); codePageRange1 = stream.ReadULong(); codePageRange2 = stream.ReadULong(); sxHeight = stream.ReadShort(); sCapHeight = stream.ReadShort(); usDefaultChar = stream.ReadUShort(); usBreakChar = stream.ReadUShort(); usMaxContext = stream.ReadUShort(); }
/// <summary> /// Reads a string from the storage area beginning at <i>offset</i> /// consisting of <i>length</i> bytes. The returned string will be /// converted using the Unicode encoding. /// </summary> /// <param name="stream">Big-endian font stream.</param> /// <param name="stringOffset"> /// The offset in bytes from the beginning of the string storage area. /// </param> /// <param name="length">The length of the string in bytes.</param> /// <returns></returns> private string ReadString(FontFileStream stream, int stringOffset, int length) { // Set a restore point stream.SetRestorePoint(); // Navigate to beginning of string stream.Position = Entry.Offset + storageOffset + stringOffset; // Read string data byte[] buffer = new byte[length]; stream.Read(buffer, 0, length); stream.Restore(); // Convert to a little-endian Unicode string return(Encoding.BigEndianUnicode.GetString(buffer)); }
/// <summary> /// Reads a string from the storage area beginning at <i>offset</i> /// consisting of <i>length</i> bytes. The returned string will be /// converted using the Unicode encoding. /// </summary> /// <param name="stream">Big-endian font stream.</param> /// <param name="stringOffset"> /// The offset in bytes from the beginning of the string storage area. /// </param> /// <param name="length">The length of the string in bytes.</param> /// <returns></returns> private string ReadString(FontFileStream stream, int stringOffset, int length) { // Set a restore point stream.SetRestorePoint(); // Navigate to beginning of string stream.Position = Entry.Offset + storageOffset + stringOffset; // Read string data byte[] buffer = new byte[length]; stream.Read(buffer, 0, length); stream.Restore(); // Convert to a little-endian Unicode string return Encoding.BigEndianUnicode.GetString(buffer); }