|
| 1 | +import * as loader from '@assemblyscript/loader'; |
| 2 | +import * as BABYLON from 'babylonjs'; |
| 3 | + |
| 4 | +interface IPathCommand { |
| 5 | + type: string; |
| 6 | + x?: number; |
| 7 | + y?: number; |
| 8 | + x1?: number; |
| 9 | + y1?: number; |
| 10 | + x2?: number; |
| 11 | + y2?: number; |
| 12 | +} |
| 13 | +declare type Header = { |
| 14 | + compile(bytesUsed: number, fmt: string, ppc: number, eps: number): number; |
| 15 | +}; |
| 16 | +declare type Instaniated = loader.ResultObject & { |
| 17 | + exports: loader.ASUtil & Header; |
| 18 | +}; |
| 19 | +declare type Vertex = [number, number]; |
| 20 | +declare type Polygon = Vertex[]; |
| 21 | +declare type Shape = { |
| 22 | + fill: Polygon; |
| 23 | + holes: Polygon[]; |
| 24 | +}; |
| 25 | +declare class Compiler { |
| 26 | + private wasm; |
| 27 | + constructor(wasm: Instaniated); |
| 28 | + static Build(wasmUrl?: string): Promise<Compiler>; |
| 29 | + encode(cmds: IPathCommand[], buffer: ArrayBuffer): number; |
| 30 | + compileEncoded(buffer: ArrayBuffer, bytesUsed: number, fmt: string, ppc: number, eps: number): Shape[]; |
| 31 | + compile(cmds: IPathCommand[], fmt: string, ppc: number, eps: number): Shape[]; |
| 32 | +} |
| 33 | + |
| 34 | +declare type PolygonMeshOption = { |
| 35 | + backUVs?: BABYLON.Vector4; |
| 36 | + depth?: number; |
| 37 | + faceColors?: BABYLON.Color4[]; |
| 38 | + faceUV?: BABYLON.Vector4[]; |
| 39 | + frontUVs?: BABYLON.Vector4; |
| 40 | + sideOrientation?: number; |
| 41 | + updatable?: boolean; |
| 42 | +}; |
| 43 | +declare class Font { |
| 44 | + raw: opentype.Font; |
| 45 | + private compiler; |
| 46 | + private constructor(); |
| 47 | + static Install(fontUrl: string, compiler: Compiler, opentype: any): Promise<Font>; |
| 48 | + measure(name: string, size: number): Metrics; |
| 49 | + static Compile(font: Font, name: string, size: number, ppc: number, eps: number): Shape[]; |
| 50 | +} |
| 51 | +interface IBabylon { |
| 52 | + Mesh: typeof BABYLON.Mesh; |
| 53 | + MeshBuilder: typeof BABYLON.MeshBuilder; |
| 54 | + Vector3: typeof BABYLON.Vector3; |
| 55 | +} |
| 56 | +declare class TextMeshBuilder { |
| 57 | + private babylon; |
| 58 | + private earcut; |
| 59 | + constructor(babylon: IBabylon, earcut: any); |
| 60 | + private createFromShapes; |
| 61 | + create({ font, text, size, ppc, eps, ...option }: { |
| 62 | + font: Font; |
| 63 | + text: string; |
| 64 | + size: number; |
| 65 | + ppc: number; |
| 66 | + eps: number; |
| 67 | + } & PolygonMeshOption, scene?: BABYLON.Scene): BABYLON.Mesh; |
| 68 | +} |
| 69 | +declare class Metrics { |
| 70 | + private font; |
| 71 | + private name; |
| 72 | + private size; |
| 73 | + constructor(font: Font, name: string, size: number); |
| 74 | + get ascender(): number; |
| 75 | + get descender(): number; |
| 76 | + get advanceWidth(): number; |
| 77 | +} |
| 78 | + |
| 79 | +export { Compiler, Font, Metrics, Shape, TextMeshBuilder }; |
0 commit comments