Use standard lint config, fix lint errors

This commit is contained in:
Edgar Simson
2018-02-17 22:16:28 +02:00
parent 8b0ad3367a
commit 942e3f71b6
3 changed files with 68 additions and 149 deletions
+29 -34
View File
@@ -1,4 +1,4 @@
// Type definitions for opentype.js 0.7.3
// Type definitions for opentype.js 0.7
// Project: https://github.com/nodebox/opentype.js
// Definitions by: Dan Marshall <https://github.com/danmarshall>
// Edgar Simson <https://github.com/edzis>
@@ -60,15 +60,13 @@ export class Font {
y: number | undefined,
fontSize: number | undefined,
options: RenderOptions | undefined,
callback: {
(
glyph: Glyph,
x: number,
y: number,
fontSize: number,
options?: RenderOptions
): void;
}
callback: (
glyph: Glyph,
x: number,
y: number,
fontSize: number,
options?: RenderOptions
) => void
): number;
getAdvanceWidth(
text: string,
@@ -115,7 +113,7 @@ export type FontConstructorOptions = FontConstructorOptionsBase &
glyphs: Glyph[];
};
interface FontOptions {
export interface FontOptions {
empty?: boolean;
familyName: string;
styleName: string;
@@ -140,7 +138,7 @@ interface FontOptions {
fsSelection?: string;
}
interface FontConstructorOptionsBase {
export interface FontConstructorOptionsBase {
familyName: string;
styleName: string;
unitsPerEm: number;
@@ -148,7 +146,7 @@ interface FontConstructorOptionsBase {
descender: number;
}
interface FontNames {
export interface FontNames {
copyright: LocalizedName;
description: LocalizedName;
designer: LocalizedName;
@@ -165,7 +163,7 @@ interface FontNames {
version: LocalizedName;
}
interface Table {
export interface Table {
[propName: string]: any;
encode(): number[];
fields: Field[];
@@ -174,15 +172,15 @@ interface Table {
tableName: string;
}
interface KerningPairs {
export interface KerningPairs {
[pair: string]: number;
}
interface LocalizedName {
export interface LocalizedName {
[lang: string]: string;
}
interface Field {
export interface Field {
name: string;
type: string;
value: any;
@@ -201,7 +199,7 @@ export class Glyph {
private points;
name: string;
path: Path | { (): Path };
path: Path | (() => Path);
unicode: number;
unicodes: number[];
advanceWidth: number;
@@ -242,7 +240,7 @@ export class Glyph {
font?: Font
): Path;
}
interface GlyphOptions {
export interface GlyphOptions {
advanceWidth?: number;
index?: number;
font?: Font;
@@ -266,13 +264,13 @@ export class GlyphNames {
export class GlyphSet {
private font;
private glyphs;
constructor(font: Font, glyphs: Glyph[] | { (): Glyph }[]);
constructor(font: Font, glyphs: Glyph[] | Array<(() => Glyph)>);
get(index: number): Glyph;
length: number;
push(index: number, loader: { (): Glyph }): void;
push(index: number, loader: () => Glyph): void;
}
interface Post {
export interface Post {
glyphNameIndex?: number[];
isFixedPitch: number;
italicAngle: number;
@@ -288,7 +286,7 @@ interface Post {
version: number;
}
interface RenderOptions {
export interface RenderOptions {
script?: string;
language?: string;
kerning?: boolean;
@@ -310,7 +308,7 @@ export interface Metrics {
export interface Contour extends Array<Point> {}
interface Point {
export interface Point {
lastPointOfContour?: boolean;
}
@@ -355,7 +353,7 @@ export class Path {
unitsPerEm: number;
}
interface PathCommand {
export interface PathCommand {
type: string;
x?: number;
y?: number;
@@ -369,20 +367,17 @@ interface PathCommand {
* UTIL CLASSES
******************************************/
export class BoundingBox {
// TODO add methods
}
export type BoundingBox = () => any;
// TODO add methods
export class Encoding {
export interface Encoding {
charset: string;
charToGlyphIndex(c: string): number;
font: Font;
}
export class Substitution {
constructor(font: Font);
// TODO add methods
}
export type Substitution = (font: Font) => any;
// TODO add methods
/******************************************
* STATIC
@@ -390,7 +385,7 @@ export class Substitution {
export function load(
url: string,
callback: { (error: any, font?: Font): void }
callback: (error: any, font?: Font) => void
): void;
export function loadSync(url: string): Font;
+38 -38
View File
@@ -1,60 +1,60 @@
var x = 0;
var y = 0;
var fontSize = 72;
var ctx: CanvasRenderingContext2D;
const x = 0;
const y = 0;
const fontSize = 72;
let ctx: CanvasRenderingContext2D;
opentype.load('fonts/Roboto-Black.ttf', function(err, font) {
opentype.load('fonts/Roboto-Black.ttf', (err, font) => {
if (err) {
alert('Font could not be loaded: ' + err);
} else {
var path = font.getPath('Hello, World!', 0, 150, 72);
const path = font.getPath('Hello, World!', 0, 150, 72);
// If you just want to draw the text you can also use font.draw(ctx, text, x, y, fontSize).
path.draw(ctx);
}
});
var myBuffer: ArrayBuffer;
var font = opentype.parse(myBuffer);
let myBuffer: ArrayBuffer;
let font = opentype.parse(myBuffer);
font = opentype.loadSync('fonts/Roboto-Black.ttf');
var notdefGlyph = new opentype.Glyph({
const notdefGlyph = new opentype.Glyph({
name: '.notdef',
unicode: 0,
advanceWidth: 650,
path: new opentype.Path()
});
var aPath = new opentype.Path();
const aPath = new opentype.Path();
// more drawing instructions...
var aGlyph = new opentype.Glyph({
const aGlyph = new opentype.Glyph({
name: 'A',
unicode: 65,
advanceWidth: 650,
path: aPath
});
var glyphs = [notdefGlyph, aGlyph];
var font = new opentype.Font({
const glyphs = [notdefGlyph, aGlyph];
const fontGenerated = new opentype.Font({
familyName: 'OpenTypeSans',
styleName: 'Medium',
unitsPerEm: 1000,
ascender: 800,
descender: -200,
glyphs: glyphs
glyphs
});
font.download();
var hasChar: boolean = font.hasChar('a');
var charIndex: number = font.charToGlyphIndex('a');
var charGlyph: opentype.Glyph = font.charToGlyph('a');
var charGlyphs: opentype.Glyph[] = font.stringToGlyphs('abc');
var nameIndex: number = font.nameToGlyphIndex('a');
var nameGlyph: opentype.Glyph = font.nameToGlyph('a');
var indexName: string = font.glyphIndexToName(1);
var kerning: number = font.getKerningValue(notdefGlyph, aGlyph);
const hasChar: boolean = font.hasChar('a');
const charIndex: number = font.charToGlyphIndex('a');
const charGlyph: opentype.Glyph = font.charToGlyph('a');
const charGlyphs: opentype.Glyph[] = font.stringToGlyphs('abc');
const nameIndex: number = font.nameToGlyphIndex('a');
const nameGlyph: opentype.Glyph = font.nameToGlyph('a');
const indexName: string = font.glyphIndexToName(1);
const kerning: number = font.getKerningValue(notdefGlyph, aGlyph);
font.defaultRenderOptions.kerning = false;
var forEachWidth: number = font.forEachGlyph(
const forEachWidth: number = font.forEachGlyph(
'text',
x,
y,
@@ -71,32 +71,32 @@ var forEachWidth: number = font.forEachGlyph(
});
}
);
var fontPath: opentype.Path = font.getPath('text', x, y, fontSize, {});
var fontPaths: opentype.Path[] = font.getPaths('text', x, y, fontSize, {});
var fontWidth: number = font.getAdvanceWidth('text', fontSize, { yScale: 0.5 });
const fontPath: opentype.Path = font.getPath('text', x, y, fontSize, {});
const fontPaths: opentype.Path[] = font.getPaths('text', x, y, fontSize, {});
const fontWidth: number = font.getAdvanceWidth('text', fontSize, { yScale: 0.5 });
font.draw(ctx, 'text');
font.drawPoints(ctx, 'text', x, y, fontSize, { yScale: 0.5 });
font.drawMetrics(ctx, 'text', x, y, fontSize, { xScale: 1.1, yScale: 0.5 });
var engName: string = font.getEnglishName('a');
const engName: string = font.getEnglishName('a');
font.validate();
var tables: opentype.Table = font.toTables();
var ab: ArrayBuffer = font.toArrayBuffer();
const tables: opentype.Table = font.toTables();
const ab: ArrayBuffer = font.toArrayBuffer();
font.download();
font.download('fileName.ttf');
aGlyph.bindConstructorValues({ advanceWidth: 1 });
aGlyph.addUnicode(42);
var glyphBBox: opentype.BoundingBox = aGlyph.getBoundingBox();
var glyphPathBasic: opentype.Path = aGlyph.getPath();
var glyphPathFull: opentype.Path = aGlyph.getPath(
const glyphBBox: opentype.BoundingBox = aGlyph.getBoundingBox();
const glyphPathBasic: opentype.Path = aGlyph.getPath();
const glyphPathFull: opentype.Path = aGlyph.getPath(
x,
y,
fontSize,
{ xScale: 1, yScale: 2 },
font
);
var glyphContours: opentype.Contour = aGlyph.getContours();
var glyphMetrics: opentype.Metrics = aGlyph.getMetrics();
const glyphContours: opentype.Contour = aGlyph.getContours();
const glyphMetrics: opentype.Metrics = aGlyph.getMetrics();
aGlyph.draw(ctx, x, y, fontSize, {});
aGlyph.drawPoints(ctx, x, y, fontSize);
aGlyph.drawMetrics(ctx, x, y, fontSize);
@@ -112,8 +112,8 @@ aPath.closePath();
aPath.extend(aPath);
aPath.extend(aPath.commands);
aPath.extend(aPath.getBoundingBox());
var pathBBox: opentype.BoundingBox = aPath.getBoundingBox();
const pathBBox: opentype.BoundingBox = aPath.getBoundingBox();
aPath.draw(ctx);
var pathData: string = aPath.toPathData(7);
var pathSvg: string = aPath.toSVG(7);
var pathDom: SVGPathElement = aPath.toDOMElement(7);
const pathData: string = aPath.toPathData(7);
const pathSvg: string = aPath.toSVG(7);
const pathDom: SVGPathElement = aPath.toDOMElement(7);
+1 -77
View File
@@ -1,79 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
"extends": "dtslint/dt.json"
}