@kurgm/kage-engine / Kage
The entry point for KAGE engine (Kanji-glyph Automatic Generating Engine). It generates glyph outlines from a kanji's stroke data described in a dedicated intermediate format called KAGE data.
KAGE data may contain references to other glyphs (components), which are resolved using a storage at its kBuhin property. The data for the referenced glyphs must be registered to the storage prior to generating the outline.
The font (mincho or gothic) can be changed with its kShotai property. The font parameters (stroke width, etc.) can be configured with properties of kFont.
See
Kage.makeGlyph, Kage.makeGlyph2, Kage.makeGlyph3 and Kage.makeGlyphSeparated for usage examples.
• new Kage(size?
)
Name | Type |
---|---|
size? |
number |
• kBuhin: Buhin
A storage from which components are looked up.
• kFont: Font
Provides the way to configure parameters of the currently selected font. Its parameters are reset to the default values when Kage.kShotai is set.
Example
const kage = new Kage();
kage.kFont.kRate = 50;
kage.kFont.kWidth = 3;
• Readonly
kGothic: kGothic
= KShotai.kGothic
An alias of KShotai.kGothic.
See
Kage.kShotai for usage.
• Readonly
kMincho: kMincho
= KShotai.kMincho
An alias of KShotai.kMincho.
See
Kage.kShotai for usage.
▪ Static
Readonly
Buhin: typeof Buhin
= Buhin
An alias of Buhin constructor.
▪ Static
Readonly
Polygons: typeof Polygons
= Polygons
An alias of Polygons constructor.
• get
kShotai(): KShotai
Gets or sets the font as KShotai. Setting this property resets all the font parameters in Kage.kFont. Defaults to KShotai.kMincho.
Example
const kage = new Kage();
kage.kShotai = kage.kGothic;
• set
kShotai(shotai
): void
Name | Type |
---|---|
shotai |
KShotai |
void
• get
kUseCurve(): boolean
Whether to generate contours with off-curve points. An alias of Kage.kFont.kUseCurve.
boolean
• set
kUseCurve(value
): void
Name | Type |
---|---|
value |
boolean |
void
▸ makeGlyph(polygons
, buhin
): void
Renders the glyph of the given name. Existing data in polygons
(if any) are
NOT cleared; new glyph is "overprinted".
Name | Type | Description |
---|---|---|
polygons |
Polygons |
A Polygons instance on which the glyph is rendered. |
buhin |
string |
The name of the glyph to be rendered. |
void
Example
const kage = new Kage();
kage.kBuhin.push("uXXXX", "1:0:2:32:31:176:31$2:22:7:176:31:170:43:156:63");
const polygons = new Polygons();
kage.makeGlyph(polygons, "uXXXX");
const svg = polygons.generateSVG(); // now `svg` has the string of the rendered glyph
▸ makeGlyph2(polygons
, data
): void
Renders the glyph of the given KAGE data. Existing data in polygons
(if any) are
NOT cleared; new glyph is "overprinted".
Name | Type | Description |
---|---|---|
polygons |
Polygons |
A Polygons instance on which the glyph is rendered. |
data |
string |
The KAGE data to be rendered (in which lines are delimited by "$" ). |
void
Example
const kage = new Kage();
const polygons = new Polygons();
kage.makeGlyph2(polygons, "1:0:2:32:31:176:31$2:22:7:176:31:170:43:156:63");
const svg = polygons.generateSVG(); // now `svg` has the string of the rendered glyph
▸ makeGlyph3(data
): Polygons
[]
Renders each stroke of the given KAGE data on separate instances of Polygons.
Name | Type | Description |
---|---|---|
data |
string |
The KAGE data to be rendered (in which lines are delimited by "$" ). |
Polygons
[]
An array of Polygons instances holding the rendered data of each stroke in the glyph.
Example
const kage = new Kage();
const array = kage.makeGlyph3("1:0:2:32:31:176:31$2:22:7:176:31:170:43:156:63");
console.log(array.length); // => 2
console.log(array[0] instanceof Polygons); // => true
▸ makeGlyphSeparated(data
): Polygons
[]
Renders each KAGE data fragment in the given array on separate instances of Polygons, with stroke parameters adjusted as if all the fragments joined together compose a single glyph.
Name | Type | Description |
---|---|---|
data |
readonly string [] |
An array of KAGE data fragments (in which lines are delimited by "$" ) to be rendered. |
Polygons
[]
An array of Polygons instances holding the rendered data of each KAGE data fragment.
Example
const kage = new Kage();
const array = kage.makeGlyphSeparated([
"2:7:8:31:16:32:53:16:65",
"1:2:2:32:31:176:31$2:22:7:176:31:170:43:156:63",
]);
console.log(array.length); // => 2
console.log(array[0] instanceof Polygons); // => true