Glyph object
Glyph()
and $Glyph()
shortcut#
#
Syntax#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
meta_obj | Required | object (string as keys, number or string as values) | N/A | object of the meta information |
font | Required | Font object | N/A | The font the glyph belongs to |
#
Return valueGlyph object
#
DescriptionInitialize a Glyph object. Load a object of meta information and the font the glyph belongs.
The shortcut $Glyph(meta_obj, font)
is equivalent to new Glyph(meta_obj, font)
, use it for convenience.
note
Usually you get the glyph object from font.glyph(character) and do not need to use Glyph()
.
.meta
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
Typeobject (string as keys, number or string or array as values)
#
DescriptionThe glyph's meta data.
Glyph meta information's names (keys), value types, and their descriptions in the BDF spec:
'glyphname'
: (string) seeSTARTCHAR
'codepoint'
: (number) seeENCODING
'bbw'
: (number) seeBBX
'bbh'
: (number) seeBBX
'bbxoff'
: (number) seeBBX
'bbyoff'
: (number) seeBBX
'swx0'
: (number) seeSWIDTH
'swy0'
: (number) seeSWIDTH
'dwx0'
: (number) seeDWIDTH
'dwy0'
: (number) seeDWIDTH
'swx1'
: (number) seeSWIDTH1
'swy1'
: (number) seeSWIDTH1
'dwx1'
: (number) seeDWIDTH1
'dwy1'
: (number) seeDWIDTH1
'vvectorx'
: (number) seeVVECTOR
'vvectory'
: (number) seeVVECTOR
'hexdata'
: (array of strings) the glyph's shape data in the form of array of hexadecimal-encoded string
note
.font
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
TypeFont object
#
DescriptionIt's a reference to the glyph's font object.
.cp()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersNo parameters
#
Return value(number) codepoint of the glyph
#
DescriptionGet the codepoint of the glyph.
.chr()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersNo parameters
#
Return value(string) character (one character string) of the glyph
#
DescriptionGet the character of the glyph.
.draw()
#
#
Syntax#
ExamplesIn these examples, we use the "quoteright" ('
) glyph in the BDF spec's example figure 3.
- JavaScript (CJS)
- TypeScript (strict)
Click to see the output of quoteright.draw().toString()
(with default mode 0)
Click to see the output of quoteright.draw(1).toString()
Click to see the output of quoteright.draw(2).toString()
Click to see the output of quoteright.draw(-1, [6, 17, 1, 1]).toString()
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
mode | Optional | number | 0 | See below |
bb | Optional | tuple? of four numbers | None | See below |
mode
can be:
0
(default): area represented by the bitmap hex data, positioned and resized (cropped) (fbbx
×fbby
) according toFONTBOUNDINGBOX
(the font's global bounding box)1
: area represented by the bitmap hex data, resized (cropped) according toBBX
(bbw
×bbh
), which is the individual glyph bounding box, without unnecessary blank margin (but still possible to have blank margin sometimes)2
: area represented by the bitmap hex data, original, without removing the right-padded'0'
s-1
: user specified area.bb
parameter is useless when mode-1
is not chosen. But if mode-1
is chosen, you MUST specifybb
parameter, which is a tuple?[bbx, bby, bbxoff, bbyoff]
representing your customized font bounding box. Similar toFONTBOUNDINGBOX
,bbx
andbby
represent the size,bbxoff
andbbyoff
represent the relative position (displacement) of the starting (bottom-left) point from the origin
#
Return valueBitmap object
#
DescriptionDraw the glyph to a Bitmap object.
.origin()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
(in options ) mode | Optional | number | 0 | Same as .draw() 's mode parameter |
(in options ) fromorigin | Optional | boolean | false | false : to the origintrue : from the origin |
(in options ) xoff | Optional | numbers | None | See below |
(in options ) yoff | Optional | numbers | None | See below |
Similar to .draw()
, xoff
and yoff
parameters are useless when mode -1
is not chosen, but if mode: -1
in .origin()
, you MUST specify xoff
and yoff
, which are equivalent to bb[2]
("bbxoff") and bb[3]
("bbyoff") in the method .draw()
.
#
Return value(tuple? of two numbers) The relative position (displacement) represented by [x, y]
tuple? (where right and top directions are positive)
#
DescriptionGet the relative position (displacement) of the origin from the left bottom corner of the bitmap drawn by the method .draw()
, or vice versa (i.e. displacement of the left bottom corner of the bitmap from the origin).
.toString()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Click to see the output of quoteright.toString()
#
Description(string) .toString()
gets a human-readable (multi-line) string representation of the Glyph object. It's actually the string converted from .draw()
with default parameters.
See also toString()
for Bitmap object
.repr()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Click to see the output of quoteright.repr()
#
Description(string) It gets a programmer-readable string representation of the Glyph object.