类 ReadableFontData

java.lang.Object
com.google.typography.font.sfntly.data.FontData
com.google.typography.font.sfntly.data.ReadableFontData
直接已知子类:
WritableFontData

public class ReadableFontData extends FontData
Writable font data wrapper. Supports reading of data primitives in the TrueType / OpenType spec.

The data types used are as listed:

BYTE 8-bit unsigned integer.
CHAR 8-bit signed integer.
USHORT 16-bit unsigned integer.
SHORT 16-bit signed integer.
UINT24 24-bit unsigned integer.
ULONG 32-bit unsigned integer.
LONG 32-bit signed integer.
Fixed 32-bit signed fixed-point number (16.16)
FUNIT Smallest measurable distance in the em space.
FWORD 16-bit signed integer (SHORT) that describes a quantity in FUnits.
UFWORD 16-bit unsigned integer (USHORT) that describes a quantity in FUnits.
F2DOT14 16-bit signed fixed number with the low 14 bits of fraction (2.14).
LONGDATETIME Date represented in number of seconds since 12:00 midnight, January 1, 1904. The value is represented as a signed 64-bit integer.
作者:
Stuart Gill
另请参阅:
  • 字段详细资料

    • checksumSet

      private volatile boolean checksumSet
      Flag on whether the checksum has been set.
    • checksumLock

      private final Object checksumLock
      Lock on all operations that will affect the value of the checksum.
    • checksum

      private volatile long checksum
    • checksumRange

      private volatile int[] checksumRange
  • 构造器详细资料

    • ReadableFontData

      protected ReadableFontData(ByteArray<? extends ByteArray<?>> array)
      Constructor.
      参数:
      array - byte array to wrap
    • ReadableFontData

      protected ReadableFontData(ReadableFontData data, int offset)
      Constructor. Creates a bounded wrapper of another ReadableFontData from the given offset until the end of the original ReadableFontData.
      参数:
      data - data to wrap
      offset - the start of this data's view of the original data
    • ReadableFontData

      protected ReadableFontData(ReadableFontData data, int offset, int length)
      Constructor. Creates a bounded wrapper of another ReadableFontData from the given offset until the end of the original ReadableFontData.
      参数:
      data - data to wrap
      offset - the start of this data's view of the original data
      length - the length of the other FontData to use
  • 方法详细资料

    • createReadableFontData

      public static ReadableFontData createReadableFontData(byte[] b)
    • slice

      public ReadableFontData slice(int offset, int length)
      Makes a slice of this FontData. The returned slice will share the data with the original FontData.
      指定者:
      slice 在类中 FontData
      参数:
      offset - the start of the slice
      length - the number of bytes in the slice
      返回:
      a slice of the original FontData
    • slice

      public ReadableFontData slice(int offset)
      Makes a bottom bound only slice of this array. The returned slice will share the data with the original FontData.
      指定者:
      slice 在类中 FontData
      参数:
      offset - the start of the slice
      返回:
      a slice of the original FontData
    • toString

      public String toString(int length)
      Generates a String representation of the object with a certain number of data bytes.
      参数:
      length - number of bytes of the data to include in the String
      返回:
      String representation of the object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • checksum

      public long checksum()
      Gets a computed checksum for the data. This checksum uses the OpenType spec calculation. Every ULong value (32 bit unsigned) in the data is summed and the resulting value is truncated to 32 bits. If the data length in bytes is not an integral multiple of 4 then any remaining bytes are treated as the start of a 4 byte sequence whose remaining bytes are zero.
      返回:
      the checksum
    • computeChecksum

      private void computeChecksum()
      Computes the checksum for the font data using any ranges set for the calculation. Updates the internal state of this object in a threadsafe way.
    • computeCheckSum

      private long computeCheckSum(int lowBound, int highBound)
      Do the actual computation of the checksum for a range using the TrueType/OpenType checksum algorithm. The range used is from the low bound to the high bound in steps of four bytes. If any of the bytes within that 4 byte segment are not readable then it will considered a zero for calculation.

      Only called from within a synchronized method so it does not need to be synchronized itself.

      参数:
      lowBound - first position to start a 4 byte segment on
      highBound - last possible position to start a 4 byte segment on
      返回:
      the checksum for the total range
    • setCheckSumRanges

      public void setCheckSumRanges(int... ranges)
      Sets the ranges to use for computing the checksum. These ranges are in begin and end pairs. If an odd number is given then the final range is assumed to extend to the end of the data. The lengths of each range must be a multiple of 4.
      参数:
      ranges - the range bounds to use for the checksum
    • checkSumRange

      public int[] checkSumRange()
      Gets the ranges that are used for computing the checksum. These ranges are in begin and end pairs. If an odd number is given then the final range is assumed to extend to the end of the data. The lengths of each range must be a multiple of 4.
      返回:
      the range bounds used for the checksum
    • readUByte

      public int readUByte(int index)
      Reads the UBYTE at the given index.
      参数:
      index - index into the font data
      返回:
      the UBYTE; -1 if outside the bounds of the font data
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readByte

      public int readByte(int index)
      Reads the BYTE at the given index.
      参数:
      index - index into the font data
      返回:
      the BYTE
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readBytes

      public int readBytes(int index, byte[] b, int offset, int length)
      Reads the bytes at the given index into the array.
      参数:
      index - index into the font data
      b - the destination for the bytes read
      offset - offset in the byte array to place the bytes
      length - the length of bytes to read
      返回:
      the number of bytes actually read; -1 if the index is outside the bounds of the font data
    • readChar

      public int readChar(int index)
      Reads the CHAR at the given index.
      参数:
      index - index into the font data
      返回:
      the CHAR
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readUShort

      public int readUShort(int index)
      Reads the USHORT at the given index.
      参数:
      index - index into the font data
      返回:
      the USHORT
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readShort

      public int readShort(int index)
      Reads the SHORT at the given index.
      参数:
      index - index into the font data
      返回:
      the SHORT
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readUInt24

      public int readUInt24(int index)
      Reads the UINT24 at the given index.
      参数:
      index - index into the font data
      返回:
      the UINT24
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readULong

      public long readULong(int index)
      Reads the ULONG at the given index.
      参数:
      index - index into the font data
      返回:
      the ULONG
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readULongAsInt

      public int readULongAsInt(int index)
      Reads the ULONG at the given index as an int.
      参数:
      index - index into the font data
      返回:
      the ULONG
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
      ArithmeticException - if the value will not fit into an integer
    • readULongLE

      public long readULongLE(int index)
      Reads the ULONG at the given index, little-endian variant.
      参数:
      index - index into the font data
      返回:
      the ULONG
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readLong

      public int readLong(int index)
      Reads the LONG at the given index.
      参数:
      index - index into the font data
      返回:
      the LONG
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readFixed

      public int readFixed(int index)
      Reads the Fixed at the given index.
      参数:
      index - index into the font data
      返回:
      the Fixed
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readF2Dot14

      public BigDecimal readF2Dot14(int index)
      Reads the F2DOT14 at the given index.
      参数:
      index - index into the font data
      返回:
      the F2DOT14
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readDateTimeAsLong

      public long readDateTimeAsLong(int index)
      Reads the LONGDATETIME at the given index.
      参数:
      index - index into the font data
      返回:
      the LONGDATETIME
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readLongDateTime

      public Date readLongDateTime(int index)
      Reads the LONGDATETIME at the given index.
      参数:
      index - index into the font data
      返回:
      the F2DOT14
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readFUnit

      public int readFUnit(int index)
      Reads the FUNIT at the given index.
      参数:
      index - index into the font data
      返回:
      the FUNIT
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readFWord

      public int readFWord(int index)
      Reads the FWORD at the given index.
      参数:
      index - index into the font data
      返回:
      the FWORD
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • readUFWord

      public int readUFWord(int index)
      Reads the UFWORD at the given index.
      参数:
      index - index into the font data
      返回:
      the UFWORD
      抛出:
      IndexOutOfBoundsException - if index is outside the FontData's range
    • copyTo

      public int copyTo(OutputStream os) throws IOException
      Copy the FontData to an OutputStream.
      参数:
      os - the destination
      返回:
      number of bytes copied
      抛出:
      IOException
    • copyTo

      public int copyTo(WritableFontData wfd)
      Copies the FontData to a WritableFontData.
      参数:
      wfd - the destination
      返回:
      number of bytes copied
    • searchUShort

      public int searchUShort(int startIndex, int startOffset, int endIndex, int endOffset, int length, int key)
      Search for the key value in the range tables provided. The search looks through the start-end pairs looking for the key value. It is assumed that the start-end pairs are both represented by UShort values, ranges do not overlap, and are monotonically increasing.
      参数:
      startIndex - the position to read the first start value from
      startOffset - the offset between subsequent start values
      endIndex - the position to read the first end value from
      endOffset - the offset between subsequent end values
      length - the number of start-end pairs
      key - the value to search for
      返回:
      the index of the start-end pairs in which the key was found; -1 otherwise
    • searchULong

      public int searchULong(int startIndex, int startOffset, int endIndex, int endOffset, int length, int key)
      Search for the key value in the range tables provided. The search looks through the start-end pairs looking for the key value. It is assumed that the start-end pairs are both represented by ULong values that can be represented within 31 bits, ranges do not overlap, and are monotonically increasing.
      参数:
      startIndex - the position to read the first start value from
      startOffset - the offset between subsequent start values
      endIndex - the position to read the first end value from
      endOffset - the offset between subsequent end values
      length - the number of start-end pairs
      key - the value to search for
      返回:
      the index of the start-end pairs in which the key was found; -1 otherwise
    • searchUShort

      public int searchUShort(int startIndex, int startOffset, int length, int key)
      Search for the key value in the table provided. The search looks through the values looking for the key value. It is assumed that the are represented by UShort values and are monotonically increasing.
      参数:
      startIndex - the position to read the first start value from
      startOffset - the offset between subsequent start values
      length - the number of start-end pairs
      key - the value to search for
      返回:
      the index of the start-end pairs in which the key was found; -1 otherwise