The SamsaBuffer
object is a subclass of the standard JavaScript DataView
. Unlike DataView
it has a pointer property, p
, that is updated when binary structures are read or written.
For highly optimized operations, it may be better to use a Uint8Array
view onto the underlying buffer of the SamsaBuffer
. In this case, the client must handle the pointer during the optimized operation and update the pointer of the SamsaBuffer
afterwards. But be careful of using similar multi-byte arrays such as Uint16Array
and Uint32Array
: their byte order is “in the platform byte order”, which for x86 and Apple M-series is little-endian, unlike TrueType which is big-endian throughout.
SamsaBuffer()
-
SamsaBuffer.buffer
The underlyingArrayBuffer
which stores the data of theSamsaBuffer
. -
SamsaBuffer.byteOffset
The offset from the start of the underlyingArrayBuffer
to the start of theSamsaBuffer
. -
SamsaBuffer.byteLength
The length of theSamsaBuffer
buffer in bytes. This may be less than the length of the underlyingArrayBuffer
.
SamsaBuffer.p
The offset from the start of theSamsaBuffer
, where reading and writing will next take place. Attempting to read or write whenp
is not in the range [0,SamsaBuffer.byteLength
- 1] is an error. Clients may update it directly, but there are also tell(), seek() and seekr() methods. Note thatSamsaBuffer.byteOffset
+SamsaBuffer.p
is always <=SamsaBuffer.buffer.byteLength
.
-
SamsaBuffer.tell()
Returns the current value of the pointerp
. -
SamsaBuffer.seek(pos)
Sets the buffer pointerSamsaBuffer.p
topos
. No return value. -
SamsaBuffer.seekr(rpos)
Increments the buffer pointerSamsaBuffer.p
byrpos
. EquivalentSamsaBuffer.p
+=rpos
. No return value.
-
SamsaBuffer.u8
Getter and setter for an unsigned 8-bit integer. -
SamsaBuffer.u16
Getter and setter for an unsigned 16-bit integer. -
SamsaBuffer.u24
Getter and setter for an unsigned 24-bit integer. -
SamsaBuffer.u32
Getter and setter for an unsigned 32-bit integer. -
SamsaBuffer.i8
Getter and setter for a signed 8-bit integer. -
SamsaBuffer.i16
Getter and setter for a signed 16-bit integer. -
SamsaBuffer.i24
Getter and setter for a signed 24-bit integer. -
SamsaBuffer.i32
Getter and setter for a signed 32-bit integer. -
SamsaBuffer.tag
Getter and setter for an ASCII string of length 4.
-
SamsaBuffer.decodeGlyph()
Decodes a glyph from the buffer. Returns aSamsaGlyph
object. -
SamsaBuffer.encodeGlyph()
Encodes a glyph into the buffer. Returns the number of bytes written. -
SamsaBuffer.encodeInstance()
Encodes an instance, being an entire static TrueType font, into the buffer. Returns the number of bytes written.