bdfjs: Initial commit (#27507)

This commit is contained in:
Olegs Jeremejevs
2018-07-23 12:21:30 -07:00
committed by Andy
parent a2e4f5b348
commit 06fe69973a
4 changed files with 150 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { parse, draw, trim, Font, Bitmap } from "bdfjs";
parse(); // $ExpectError
parse(123); // $ExpectError
parse('abc'); // $ExpectType Font
parse('abc', { allprops: true, onlymeta: true }); // $ExpectType Font
const font: Font = parse(Buffer.from([1, 2, 3]));
draw(); // $ExpectError
draw(123); // $ExpectError
draw(font); // $ExpectError
draw(font, 123); // $ExpectError
draw(font, 'abc', { kerningBias: 123 }); // $ExpectType Bitmap | undefined
const bitmap: Bitmap = draw(font, 'abc')!;
trim(); // $ExpectError
trim(123); // $ExpectError
trim(bitmap); // $ExpectType Bitmap
+108
View File
@@ -0,0 +1,108 @@
// Type definitions for bdfjs 0.0
// Project: https://github.com/zswang/bdfjs
// Definitions by: Olegs Jeremejevs <https://github.com/jeremejevs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
// https://www.x.org/docs/BDF/bdf.pdf
// https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5005.BDF_Spec.pdf
export interface ParseOptions {
allprops?: boolean;
onlymeta?: boolean;
}
export interface BoundingBox {
width: number;
height: number;
x: number;
y: number;
}
export interface Glyph {
bitmap: number[][];
boundingBox: BoundingBox;
bytes: number[];
char: string;
code: number;
deviceWidthX: number;
deviceWidthY: number;
name: string;
scalableWidthX: number;
scalableWidthY: number;
}
export interface Properties {
defaultChar: number;
fontAscent: number;
fontDescent: number;
addStyleName?: string;
averageWidth?: number;
capHeight?: number;
charsetEncoding?: string;
charsetRegistry?: string;
copyright?: string;
faceName?: string;
familyName?: string;
font?: string;
fontnameRegistry?: string;
fontVersion?: string;
foundry?: string;
notice?: string;
pixelSize?: number;
pointSize?: number;
resolutionX?: number;
resolutionY?: number;
setwidthName?: string;
slant?: string;
spacing?: string;
weightName?: string;
xHeight?: number;
[key: string]: string | number | undefined;
}
export interface Size {
points: number;
resolutionX: number;
resolutionY: number;
}
export interface Meta {
boundingBox: BoundingBox;
name: string;
// The spec says that `properties` is optional, but then goes on to point out
// that without `defaultChar`, `fontAscent` and `fontDescent` it's not really
// a valid font, so I chose to not mark them as a maybe.
properties: Properties;
size: Size;
totalChars: number;
version: string;
}
export interface Font {
meta: Meta;
glyphs: { [key: number]: Glyph }; // This is NOT a list
}
export function parse(text: string | Buffer, options?: ParseOptions): Font;
export interface DrawOptions {
kerningBias?: number;
}
export interface Bitmap {
width: number;
height: number;
[row: number]: number[]; // Yep, this how the library does it, unfortunately
}
export function draw(
font: Font,
text: string,
options?: DrawOptions
): Bitmap | undefined;
export function trim(bitmap: Bitmap): Bitmap;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"bdfjs-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }