Skip to content

Latest commit

 

History

History
345 lines (197 loc) · 7.31 KB

File metadata and controls

345 lines (197 loc) · 7.31 KB

@kurgm/kage-engine


@kurgm/kage-engine / Kage

Class: Kage

Defined in: kage.ts:22

The entry point for the KAGE engine (Kanji-glyph Automatic Generating Engine). It generates glyph outlines from kanji 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 in its kBuhin property. The data for the referenced glyphs must be registered in the storage prior to generating the outline.

The font (mincho or gothic) can be changed using the kShotai property. Font parameters (stroke width, etc.) can be configured using properties of kFont.

See

Kage.makeGlyph, Kage.makeGlyph2, Kage.makeGlyph3 and Kage.makeGlyphSeparated for usage examples.

Constructors

Constructor

new Kage(size?): Kage

Defined in: kage.ts:86

Parameters

size?

number

Returns

Kage

Properties

kBuhin

kBuhin: Buhin

Defined in: kage.ts:80

A storage used to look up components.


kFont

kFont: Font

Defined in: kage.ts:49

Allows configuration of the parameters for the currently selected font. Its parameters reset to their default values when Kage.kShotai is set.

Example

const kage = new Kage();
kage.kFont.kRate = 50;
kage.kFont.kWidth = 3;

kGothic

readonly kGothic: kGothic = KShotai.kGothic

Defined in: kage.ts:37

An alias for KShotai.kGothic.

See

Kage.kShotai for usage.


kMincho

readonly kMincho: kMincho = KShotai.kMincho

Defined in: kage.ts:32

An alias for KShotai.kMincho.

See

Kage.kShotai for usage.


Buhin

readonly static Buhin: typeof Buhin

Defined in: kage.ts:24

An alias for Buhin constructor.


Polygons

readonly static Polygons: typeof Polygons

Defined in: kage.ts:26

An alias for Polygons constructor.

Accessors

kShotai

Get Signature

get kShotai(): KShotai

Defined in: kage.ts:61

Gets or sets the font as KShotai. Setting this property resets all font parameters in Kage.kFont. Defaults to KShotai.kMincho.

Example
const kage = new Kage();
kage.kShotai = kage.kGothic;
Returns

KShotai

Set Signature

set kShotai(shotai): void

Defined in: kage.ts:64

Parameters
shotai

KShotai

Returns

void


kUseCurve

Get Signature

get kUseCurve(): boolean

Defined in: kage.ts:72

Whether to generate contours with off-curve points. An alias of Kage.kFont.kUseCurve.

Returns

boolean

Set Signature

set kUseCurve(value): void

Defined in: kage.ts:75

Parameters
value

boolean

Returns

void

Methods

makeGlyph()

makeGlyph(polygons, buhin): void

Defined in: kage.ts:106

Renders the glyph of the given name. Existing data in polygons (if any) are NOT cleared; the new glyph is "overprinted".

Parameters

polygons

Polygons

A Polygons instance on which the glyph is rendered.

buhin

string

The name of the glyph to be rendered.

Returns

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()

makeGlyph2(polygons, data): void

Defined in: kage.ts:124

Renders the glyph of the given KAGE data. Existing data in polygons (if any) are NOT cleared; the new glyph is "overprinted".

Parameters

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 "$").

Returns

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()

makeGlyph3(data): Polygons[]

Defined in: kage.ts:147

Renders each stroke of the given KAGE data on separate instances of Polygons.

Parameters

data

string

The KAGE data to be rendered (in which lines are delimited by "$").

Returns

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()

makeGlyphSeparated(data): Polygons[]

Defined in: kage.ts:181

Renders each KAGE data fragment in the given array on separate instances of Polygons, with stroke parameters adjusted as if all fragments together compose a single glyph.

Parameters

data

readonly string[]

An array of KAGE data fragments (in which lines are delimited by "$") to be rendered.

Returns

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