The SamsaGlyph
object represents a glyph as either:
- a simple glyph (an array of points and an array of end points for each contour)
- a composite glyph (an array of components)
SamsaGlyph()
SamsaGlyph.components
Array of glyph components. It is empty for simple glyphs. Note that thepoints
property still contains the 4 phantom points.SamsaGlyph.endPts
Array of indices into thepoints
array that indicate the last point of each contour.SamsaGlyph.font
TheSamsaFont
object that the glyph belongs to.SamsaGlyph.instructionLength
The number of bytes in the glyph’s instructions.SamsaGlyph.instructions
IfSamsaGlyph.instructionLength
is non-zero, this is aSamsaBuffer
object containing the instruction bytes for the glyph; otherwise it isundefined
.SamsaGlyph.name
The name of the glyph (often not used).SamsaGlyph.numberOfContours
The number of contours in the glyph.SamsaGlyph.numPoints
The number of points in the glyph. It excludes the 4 phantom points.SamsaGlyph.points
Array of points (each point is an array of integers of the form[x, y, onCurve]
, whereonCurve
is 0 for off-curve points and 1 for on-curve points). Note that the length of this array is 4 more thanSamsaGlyph.numPoints
, because 4 phantom points are appended.SamsaGlyph.tvts
Array of tuple variation tables (TVTs), which are used in variations. Each TVT specifies a ‘region’ in a variable font’s designspace in which variation is to be applied, and a set of ‘deltas’, where each delta is a vector representing the maximum displacement of a point in x and y.
SamsaGlyph.decompose()
Returns a newSamsaGlyph
object that is a simple glyph, by recursively decomposing the glyph if it is composite. The new glyph is visually identical to the original glyph. Thecomponents
array of the returned glyph will be empty. It is valid to call this method on a simple glyph, in which case the method returns a new glyph that is a copy of the original.SamsaGlyph.instantiate()
Returns a newSamsaGlyph
object, being a new version of this glyph transformed according to theSamsaInstance
object passed as an argument.SamsaGlyph.svgPath()
Returns a path string representing the glyph, suitable for use as thed
attribute of an SVG<path>
element.
// display the array of points for the glyph for the character "A"
const nodeBuffer = fs.readFileSync(filename);
const arrayBuffer = nodeBuffer.buffer;
const samsaBuffer = new SamsaBuffer(arrayBuffer);
const font = new SamsaFont(samsaBuffer);
const string = "A";
const glyphId = font.glyphIdFromUnicode(string.codePointAt(0));
const glyph = font.loadGlyphById(glyphId);
console.log(glyph.points);