From d2926ee528cbf291ca7976277e79ad6c1493b448 Mon Sep 17 00:00:00 2001 From: hikerpig Date: Fri, 4 Jan 2019 14:09:05 +0800 Subject: [PATCH] [opentype.js] add annotations for BoundingBox and some tests, finish prev todo --- types/opentype.js/index.d.ts | 15 +++++++++++++-- types/opentype.js/opentype.js-tests.ts | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/types/opentype.js/index.d.ts b/types/opentype.js/index.d.ts index 8dc449784d..5fdc257362 100644 --- a/types/opentype.js/index.d.ts +++ b/types/opentype.js/index.d.ts @@ -367,8 +367,19 @@ export interface PathCommand { * UTIL CLASSES ******************************************/ -export type BoundingBox = () => any; -// TODO add methods +export class BoundingBox { + x1: number; + y1: number; + x2: number; + y2: number; + + isEmpty(): boolean; + addPoint(x: number, y: number): void; + addX(x: number): void; + addY(y: number): void; + addBezier(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x: number, y: number): void; + addQuad(x0: number, y0: number, x1: number, y1: number, x: number, y: number): void; +} export interface Encoding { charset: string; diff --git a/types/opentype.js/opentype.js-tests.ts b/types/opentype.js/opentype.js-tests.ts index 04781d5415..e3695944db 100644 --- a/types/opentype.js/opentype.js-tests.ts +++ b/types/opentype.js/opentype.js-tests.ts @@ -113,6 +113,8 @@ aPath.extend(aPath); aPath.extend(aPath.commands); aPath.extend(aPath.getBoundingBox()); const pathBBox: opentype.BoundingBox = aPath.getBoundingBox(); +pathBBox.addQuad(1, 1, 1, 1, 1, 1); +const yDist = pathBBox.y2 - pathBBox.y1; aPath.draw(ctx); const pathData: string = aPath.toPathData(7); const pathSvg: string = aPath.toSVG(7);