diff --git a/maker.js/index.d.ts b/maker.js/index.d.ts index d23fe37c3f..7cf55d0448 100644 --- a/maker.js/index.d.ts +++ b/maker.js/index.d.ts @@ -5,7 +5,7 @@ /// /// -/// +/// /** * Root module for Maker.js. @@ -2173,6 +2173,6 @@ declare namespace MakerJs.models { declare namespace MakerJs.models { class Text implements IModel { models: IModelMap; - constructor(font: opentypejs.Font, text: string, fontSize: number, combine?: boolean); + constructor(font: opentype.Font, text: string, fontSize: number, combine?: boolean); } } diff --git a/maker.js/makerjs-tests.ts b/maker.js/makerjs-tests.ts index 534ef9eed7..cc7cc0804d 100644 --- a/maker.js/makerjs-tests.ts +++ b/maker.js/makerjs-tests.ts @@ -1,7 +1,7 @@ function test() { - + var makerjs: typeof MakerJs; var p1: MakerJs.IPoint = [0, 0]; @@ -9,7 +9,7 @@ function test() { var paths = testPaths(); var models = testModels(); var model: MakerJs.IModel = models[0]; - + function testRoot() { makerjs.cloneObject({}); makerjs.createRouteKey([]); @@ -29,7 +29,7 @@ function test() { makerjs.unitType.Millimeter; new makerjs.Collector(); } - + function testAngle() { makerjs.angle.mirror(45, true, false); makerjs.angle.noRevolutions(90); @@ -49,22 +49,22 @@ function test() { makerjs.exporter.toOpenJsCad(model); makerjs.exporter.toPDF({} as PDFKit.PDFDocument, model); makerjs.exporter.toSTL(model); - makerjs.exporter.toSVG(model, - { - annotate: true, - fontSize: '', - origin: [], - scale: 9.9, - stroke: '', - strokeWidth: '', - svgAttrs: {}, - units: '', + makerjs.exporter.toSVG(model, + { + annotate: true, + fontSize: '', + origin: [], + scale: 9.9, + stroke: '', + strokeWidth: '', + svgAttrs: {}, + units: '', useSvgPathOnly: false, viewBox: false }); makerjs.exporter.tryGetModelUnits(model); } - + function testImporter() { makerjs.importer.fromSVGPathData(''); makerjs.importer.parseNumericList(''); @@ -77,7 +77,7 @@ function test() { ({}).metaParameters; ({}).notes; } - + function testMeasure() { makerjs.measure.increase(mp, mm); makerjs.measure.isPointEqual(p1, p2); @@ -102,7 +102,7 @@ function test() { makerjs.measure.isPointOnSlope([], s); makerjs.measure.isSlopeEqual(s, s); } - + function testModel(){ makerjs.model.breakPathsAtIntersections(model, { paths:{ } }); var opts: MakerJs.ICombineOptions = { trimDeadEnds: true, pointMatchingDistance: 2 }; @@ -153,10 +153,10 @@ function test() { new makerjs.models.Slot([0, 0], [1, 1], 7), new makerjs.models.Square(8), new makerjs.models.Star(5, 10, 5), - new makerjs.models.Text({} as opentypejs.Font, 'z', 12) + new makerjs.models.Text({} as opentype.Font, 'z', 12) ]; } - + function testPath() { makerjs.path.breakAtPoint(paths.arc, [0,0]).type; makerjs.path.clone(paths.line); @@ -174,9 +174,9 @@ function test() { makerjs.path.scale(paths.arc, 8); makerjs.path.straighten(paths.arc); } - + function testPaths() { - var paths = { + var paths = { arc: new makerjs.paths.Arc([0,0], 7, 0, 180), circle: new MakerJs.paths.Circle([0,0], 5), line: new makerjs.paths.Line([0,0], [1,1]) @@ -184,20 +184,20 @@ function test() { new makerjs.paths.Chord(paths.arc); new makerjs.paths.Parallel(paths.line, 4, [1,1]); - + //paths.line.layer = "0"; - - var x: MakerJs.IPathLine = { - type: "line", - origin: [9,9], - end: [8,8], + + var x: MakerJs.IPathLine = { + type: "line", + origin: [9,9], + end: [8,8], layer: "4" }; - + return paths; } - - function testPoint() { + + function testPoint() { makerjs.point.add(p1, p2); makerjs.point.average(p1, p2); makerjs.point.clone(p1); @@ -216,14 +216,14 @@ function test() { makerjs.point.subtract(p2, p1); makerjs.point.zero(); } - - function testSolvers() { + + function testSolvers() { makerjs.solvers.solveTriangleASA(4, 4, 4); makerjs.solvers.solveTriangleSSS(9, 9, 9); } - - function testUnits() { + + function testUnits() { makerjs.units.conversionScale(makerjs.unitType.Centimeter, makerjs.unitType.Foot); } - + } \ No newline at end of file diff --git a/opentype.js/index.d.ts b/opentype.js/index.d.ts new file mode 100644 index 0000000000..24df752461 --- /dev/null +++ b/opentype.js/index.d.ts @@ -0,0 +1,240 @@ +// Type definitions for opentype.js +// Project: https://github.com/nodebox/opentype.js +// Definitions by: Dan Marshall +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace opentype; + +interface Contour extends Array { +} + +export class Encoding { + charset: string; + charToGlyphIndex(c: string): number; + font: Font; +} + +interface Field { + name: string; + type: string; + value: any; +} + +export class Font { + private nametoGlyphIndex; + private supported; + constructor(options: FontOptions); + ascender: number; + cffEncoding: Encoding; + charToGlyph(c: string): Glyph; + charToGlyphIndex(s: string): number; + descender: number; + download(): void; + draw(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; + drawMetrics(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; + drawPoints(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; + encoding: Encoding; + forEachGlyph(text: string, x: number, y: number, fontSize: number, options: RenderOptions, callback: { (glyph: Glyph, x: number, y: number, fontSize: number, options?: RenderOptions): void; }): void; + getEnglishName(name: string): string; + getGposKerningValue: { (leftGlyph: Glyph | number, rightGlyph: Glyph | number): number; }; + getKerningValue(leftGlyph: Glyph | number, rightGlyph: Glyph | number): number; + getPath(text: string, x: number, y: number, fontSize: number, options?: RenderOptions): Path; + getPaths(text: string, x: number, y: number, fontSize: number, options?: RenderOptions): Path[]; + glyphs: GlyphSet; + glyphIndexToName(gid: number): string; + glyphNames: GlyphNames; + hasChar(c: string): boolean; + kerningPairs: KerningPairs; + names: FontNames; + nameToGlyph(name: string): Glyph; + nameToGlyphIndex(name: string): number; + numberOfHMetrics: number; + numGlyphs: number; + outlinesFormat: string; + stringToGlyphs(s: string): Glyph[]; + tables: { [tableName: string]: Table; }; + toArrayBuffer(): ArrayBuffer; + toBuffer(): ArrayBuffer; + toTables(): Table; + unitsPerEm: number; + validate(): void; +} + +interface FontNames { + copyright: LocalizedName; + description: LocalizedName; + designer: LocalizedName; + designerURL: LocalizedName; + fontFamily: LocalizedName; + fontSubfamily: LocalizedName; + fullName: LocalizedName; + license: LocalizedName; + licenseURL: LocalizedName; + manufacturer: LocalizedName; + manufacturerURL: LocalizedName; + postScriptName: LocalizedName; + trademark: LocalizedName; + version: LocalizedName; +} + +interface FontOptions { + copyright?: string; + ascender?: number; + descender?: number; + description?: string; + designer?: string; + designerURL?: string; + empty?: boolean; + familyName?: string; + fullName?: string; + glyphs?: Glyph[] | GlyphSet; + license?: string; + licenseURL?: string; + manufacturer?: string; + manufacturerURL?: string; + postScriptName?: string; + styleName?: string; + unitsPerEm?: number; + trademark?: string; + version?: string; +} + +export class Glyph { + private index; + private xMin; + private xMax; + private yMin; + private yMax; + private points; + constructor(options: GlyphOptions); + addUnicode(unicode: number): void; + advanceWidth: number; + bindConstructorValues(options: GlyphOptions): void; + draw(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; + drawMetrics(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; + drawPoints(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; + getContours(): Contour[]; + getMetrics(): Metrics; + getPath(x: number, y: number, fontSize: number): Path; + name: string; + path: Path | { (): Path; }; + unicode: number; + unicodes: number[]; +} + +interface GlyphOptions { + advanceWidth?: number; + index?: number; + font?: Font; + name?: string; + path?: Path; + unicode?: number; + unicodes?: number[]; + xMax?: number; + xMin?: number; + yMax?: number; + yMin?: number; +} + +export class GlyphNames { + private names; + constructor(post: Post); + glyphIndexToName(gid: number): string; + nameToGlyphIndex(name: string): number; +} + +export class GlyphSet { + private font; + private glyphs; + constructor(font: Font, glyphs: Glyph[] | { (): Glyph; }[]); + get(index: number): Glyph; + length: number; + push(index: number, loader: { (): Glyph; }): void; +} + +interface KerningPairs { + [pair: string]: number; +} + +export function load(url: string, callback: { (error: any, font?: Font): void; }): void; + +export function loadSync(url: string): Font; + +interface LocalizedName { + [lang: string]: string; +} + +interface Metrics { + leftSideBearing: number; + rightSideBearing?: number; + xMax: number; + xMin: number; + yMax: number; + yMin: number; +} + +export function parse(buffer: any): Font; + +export class Path { + private fill; + private stroke; + private strokeWidth; + constructor(); + bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): void; + close: () => void; + closePath(): void; + commands: PathCommand[]; + curveTo: (x1: number, y1: number, x2: number, y2: number, x: number, y: number) => void; + draw(ctx: CanvasRenderingContext2D): void; + extend(pathOrCommands: Path | PathCommand[]): void; + lineTo(x: number, y: number): void; + moveTo(x: number, y: number): void; + quadraticCurveTo(x1: number, y1: number, x: number, y: number): void; + quadTo: (x1: number, y1: number, x: number, y: number) => void; + toPathData(decimalPlaces: number): string; + toSVG(decimalPlaces: number): string; + unitsPerEm: number; +} + +interface PathCommand { + type: string; + x?: number; + y?: number; + x1?: number; + y1?: number; + x2?: number; + y2?: number; +} + +interface Point { + lastPointOfContour?: boolean; +} + +interface Post { + glyphNameIndex?: number[]; + isFixedPitch: number; + italicAngle: number; + maxMemType1: number; + minMemType1: number; + maxMemType42: number; + minMemType42: number; + names?: string[]; + numberOfGlyphs?: number; + offset?: number[]; + underlinePosition: number; + underlineThickness: number; + version: number; +} + +interface RenderOptions { + kerning: boolean; +} + +interface Table { + [propName: string]: any; + encode(): number[]; + fields: Field[]; + sizeOf(): number; + tables: Table[]; + tableName: string; +} diff --git a/opentype/opentype-tests.ts b/opentype.js/opentype.js-tests.ts similarity index 100% rename from opentype/opentype-tests.ts rename to opentype.js/opentype.js-tests.ts diff --git a/opentype/tsconfig.json b/opentype.js/tsconfig.json similarity index 92% rename from opentype/tsconfig.json rename to opentype.js/tsconfig.json index da27df64ea..d46b9ebabf 100644 --- a/opentype/tsconfig.json +++ b/opentype.js/tsconfig.json @@ -14,6 +14,6 @@ }, "files": [ "index.d.ts", - "opentype-tests.ts" + "opentype.js-tests.ts" ] } \ No newline at end of file diff --git a/opentype/index.d.ts b/opentype/index.d.ts deleted file mode 100644 index fec42369a1..0000000000 --- a/opentype/index.d.ts +++ /dev/null @@ -1,248 +0,0 @@ -// Type definitions for opentype.js -// Project: https://github.com/nodebox/opentype.js -// Definitions by: Dan Marshall -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace opentypejs { - - interface Contour extends Array { - } - - class Encoding { - charset: string; - charToGlyphIndex(c: string): number; - font: Font; - } - - interface Field { - name: string; - type: string; - value: any; - } - - class Font { - private nametoGlyphIndex; - private supported; - constructor(options: FontOptions); - ascender: number; - cffEncoding: Encoding; - charToGlyph(c: string): Glyph; - charToGlyphIndex(s: string): number; - descender: number; - download(): void; - draw(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; - drawMetrics(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; - drawPoints(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, fontSize: number, options?: RenderOptions): void; - encoding: Encoding; - forEachGlyph(text: string, x: number, y: number, fontSize: number, options: RenderOptions, callback: { (glyph: Glyph, x: number, y: number, fontSize: number, options?: RenderOptions): void; }): void; - getEnglishName(name: string): string; - getGposKerningValue: { (leftGlyph: Glyph | number, rightGlyph: Glyph | number): number; }; - getKerningValue(leftGlyph: Glyph | number, rightGlyph: Glyph | number): number; - getPath(text: string, x: number, y: number, fontSize: number, options?: RenderOptions): Path; - getPaths(text: string, x: number, y: number, fontSize: number, options?: RenderOptions): Path[]; - glyphs: GlyphSet; - glyphIndexToName(gid: number): string; - glyphNames: GlyphNames; - hasChar(c: string): boolean; - kerningPairs: KerningPairs; - names: FontNames; - nameToGlyph(name: string): Glyph; - nameToGlyphIndex(name: string): number; - numberOfHMetrics: number; - numGlyphs: number; - outlinesFormat: string; - stringToGlyphs(s: string): Glyph[]; - tables: { [tableName: string]: Table; }; - toArrayBuffer(): ArrayBuffer; - toBuffer(): ArrayBuffer; - toTables(): Table; - unitsPerEm: number; - validate(): void; - } - - interface FontNames { - copyright: LocalizedName; - description: LocalizedName; - designer: LocalizedName; - designerURL: LocalizedName; - fontFamily: LocalizedName; - fontSubfamily: LocalizedName; - fullName: LocalizedName; - license: LocalizedName; - licenseURL: LocalizedName; - manufacturer: LocalizedName; - manufacturerURL: LocalizedName; - postScriptName: LocalizedName; - trademark: LocalizedName; - version: LocalizedName; - } - - interface FontOptions { - copyright?: string; - ascender?: number; - descender?: number; - description?: string; - designer?: string; - designerURL?: string; - empty?: boolean; - familyName?: string; - fullName?: string; - glyphs?: Glyph[] | GlyphSet; - license?: string; - licenseURL?: string; - manufacturer?: string; - manufacturerURL?: string; - postScriptName?: string; - styleName?: string; - unitsPerEm?: number; - trademark?: string; - version?: string; - } - - class Glyph { - private index; - private xMin; - private xMax; - private yMin; - private yMax; - private points; - constructor(options: GlyphOptions); - addUnicode(unicode: number): void; - advanceWidth: number; - bindConstructorValues(options: GlyphOptions): void; - draw(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; - drawMetrics(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; - drawPoints(ctx: CanvasRenderingContext2D, x: number, y: number, fontSize: number): void; - getContours(): Contour[]; - getMetrics(): Metrics; - getPath(x: number, y: number, fontSize: number): Path; - name: string; - path: Path | { (): Path; }; - unicode: number; - unicodes: number[]; - } - - interface GlyphOptions { - advanceWidth?: number; - index?: number; - font?: Font; - name?: string; - path?: Path; - unicode?: number; - unicodes?: number[]; - xMax?: number; - xMin?: number; - yMax?: number; - yMin?: number; - } - - class GlyphNames { - private names; - constructor(post: Post); - glyphIndexToName(gid: number): string; - nameToGlyphIndex(name: string): number; - } - - class GlyphSet { - private font; - private glyphs; - constructor(font: Font, glyphs: Glyph[] | { (): Glyph; }[]); - get(index: number): Glyph; - length: number; - push(index: number, loader: { (): Glyph; }): void; - } - - interface KerningPairs { - [pair: string]: number; - } - - function load(url: string, callback: { (error: any, font?: Font): void; }): void; - - function loadSync(url: string): Font; - - interface LocalizedName { - [lang: string]: string; - } - - interface Metrics { - leftSideBearing: number; - rightSideBearing?: number; - xMax: number; - xMin: number; - yMax: number; - yMin: number; - } - - function parse(buffer: any): Font; - - class Path { - private fill; - private stroke; - private strokeWidth; - constructor(); - bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): void; - close: () => void; - closePath(): void; - commands: PathCommand[]; - curveTo: (x1: number, y1: number, x2: number, y2: number, x: number, y: number) => void; - draw(ctx: CanvasRenderingContext2D): void; - extend(pathOrCommands: Path | PathCommand[]): void; - lineTo(x: number, y: number): void; - moveTo(x: number, y: number): void; - quadraticCurveTo(x1: number, y1: number, x: number, y: number): void; - quadTo: (x1: number, y1: number, x: number, y: number) => void; - toPathData(decimalPlaces: number): string; - toSVG(decimalPlaces: number): string; - unitsPerEm: number; - } - - interface PathCommand { - type: string; - x?: number; - y?: number; - x1?: number; - y1?: number; - x2?: number; - y2?: number; - } - - interface Point { - lastPointOfContour?: boolean; - } - - interface Post { - glyphNameIndex?: number[]; - isFixedPitch: number; - italicAngle: number; - maxMemType1: number; - minMemType1: number; - maxMemType42: number; - minMemType42: number; - names?: string[]; - numberOfGlyphs?: number; - offset?: number[]; - underlinePosition: number; - underlineThickness: number; - version: number; - } - - interface RenderOptions { - kerning: boolean; - } - - interface Table { - [propName: string]: any; - encode(): number[]; - fields: Field[]; - sizeOf(): number; - tables: Table[]; - tableName: string; - } - -} - -declare var opentype: typeof opentypejs; - -declare module "opentype.js" { - export = opentype; -}