1
+
export as namespace fontkit;
2
+
3
+
/**
4
+
* Represents a glyph bounding box
5
+
*/
6
+
export interface BoundingBox {
7
+
minX: number; /** The minimum X position in the bounding box */
8
+
minY: number; /** The minimum Y position in the bounding box */
9
+
maxX: number; /** The maxmimum X position in the bounding box */
10
+
maxY: number; /** The maxmimum Y position in the bounding box */
11
+
width: number; /** The width of the bounding box */
12
+
height: number; /** The height of the bounding box */
13
+
}
14
+
15
+
16
+
/**
17
+
* Path objects are returned by glyphs and represent the actual vector outlines
18
+
* for each glyph in the font. Paths can be converted to SVG path data strings,
19
+
* or to functions that can be applied to render the path to a graphics context.
20
+
*/
21
+
export interface Path {
22
+
23
+
/**
24
+
* This property represents the path’s bounding box, i.e. the smallest
25
+
* rectangle that contains the entire path shape. This is the exact
26
+
* bounding box, taking into account control points that may be outside the
27
+
* visible shape.
28
+
*/
29
+
bbox: BoundingBox;
30
+
31
+
/**
32
+
* This property represents the path’s control box. It is like the
33
+
* bounding box, but it includes all points of the path, including control
34
+
* points of bezier segments. It is much faster to compute than the real
35
+
* bounding box, but less accurate if there are control points outside of the
36
+
* visible shape.
37
+
*/
38
+
cbox: BoundingBox;
39
+
40
+
41
+
/**
42
+
* Moves the virtual pen to the given x, y coordinates.
43
+
*/
44
+
moveTo(x: number, y: number);
45
+
46
+
/**
47
+
* Adds a line to the path from the current point to the
48
+
* given x, y coordinates.
49
+
*/
50
+
lineTo(x: number, y: number);
51
+
52
+
/**
53
+
* Adds a quadratic curve to the path from the current point to the
54
+
* given x, y coordinates using cpx, cpy as a control point.
55
+
*/
56
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number);
57
+
58
+
/**
59
+
* Adds a bezier curve to the path from the current point to the
60
+
* given x, y coordinates using cp1x, cp1y and cp2x, cp2y as control points.
61
+
*/
62
+
bezierCurveTo(
63
+
cp1x: number,
64
+
cp1y: number,
65
+
cp2x: number,
66
+
cp2y: number,
67
+
x: number,
68
+
y: number
69
+
);
70
+
71
+
/**
72
+
* Closes the current sub-path by drawing a straight line back to the
73
+
* starting point.
74
+
*/
75
+
closePath();
76
+
77
+
/**
78
+
* Compiles the path to a JavaScript function that can be applied with a
79
+
* graphics context in order to render the path.
80
+
*/
81
+
toFunction();
82
+
83
+
/**
84
+
* Converts the path to an SVG path data string.
85
+
*/
86
+
toSVG();
87
+
}
88
+
89
+
/**
90
+
* Glyph objects represent a glyph in the font. They have various properties for
91
+
* accessing metrics and the actual vector path the glyph represents, and
92
+
* methods for rendering the glyph to a graphics context.
93
+
*
94
+
* You do not create glyph objects directly. They are created by various methods
95
+
* on the Font object. There are several subclasses of the base Glyph class
96
+
* internally that may be returned depending on the font format, but they all
97
+
* include the following API.
98
+
*/
99
+
export interface Glyph {
100
+
// Properties
101
+
id: number; /** The glyph's id in the font */
102
+
/**
103
+
* An array of unicode code points that are represented by this glyph. There
104
+
* can be multiple code points in the case of ligatures and other glyphs that
105
+
* represent multiple visual characters.
106
+
*/
107
+
codePoints: number[];
108
+
path: Path; /** Vector Path object representing the glyph */
109
+
/**
110
+
* The Glyph’s bounding box, i.e. the rectangle that encloses the glyph
111
+
* outline as tightly as possible.
112
+
*/
113
+
bbox: BoundingBox;
114
+
/**
115
+
* The Glyph’s control box. This is often the same as the bounding box, but is
116
+
* faster to compute. Because of the way bezier curves are defined, some of
117
+
* the control points can be outside of the bounding box. Where bbox takes
118
+
* this into account, cbox does not. Thus, cbox is less accurate, but faster
119
+
* to compute.
120
+
*/
121
+
cbox: BoundingBox;
122
+
advanceWidth: number; /** The Glyph's advance width */
123
+
124
+
// Methods
125
+
/**
126
+
* Renders the glyph to the given graphics context, at the specified
127
+
* font size.
128
+
*/
129
+
render(context: any, size: number);
130
+
131
+
// Color Glyph Properties/Methods
132
+
/**
133
+
* For SBIX glyphs, which are bitmap based, this returns an object containing
134
+
* some properties about the image, along with the image data itself
135
+
* (usually PNG).
136
+
*/
137
+
getImageForSize(size: number);
138
+
139
+
/**
140
+
* For COLR glyphs, which are vector based, this returns an array of objects
141
+
* representing the glyphs and colors for each layer in render order.
142
+
*/
143
+
layers: any[];
144
+
}
145
+
146
+
/**
147
+
* Represents positioning information for a glyph in a GlyphRun.
148
+
*/
149
+
export interface GlyphPosition {
150
+
/**
151
+
* The amount to move the virtual pen in the X direction after rendering
152
+
* this glyph.
153
+
*/
154
+
xAdvance: number;
155
+
156
+
/**
157
+
* The amount to move the virtual pen in the Y direction after rendering
158
+
* this glyph.
159
+
*/
160
+
yAdvance: number;
161
+
162
+
/**
163
+
* The offset from the pen position in the X direction at which to render
164
+
* this glyph.
165
+
*/
166
+
xOffset: number;
167
+
168
+
/**
169
+
* The offset from the pen position in the Y direction at which to render
170
+
* this glyph.
171
+
*/
172
+
yOffset: number;
173
+
}
174
+
175
+
/**
176
+
* Represents a run of Glyph and GlyphPosition objects.
177
+
* Returned by the Font.layout method.
178
+
*/
179
+
export interface GlyphRun {
180
+
/**
181
+
* An array of Glyph objects in the run
182
+
*/
183
+
glyphs: Glyph[];
184
+
185
+
/**
186
+
* An array of GlyphPosition objects for each glyph in the run
187
+
*/
188
+
positions: GlyphPosition[];
189
+
190
+
/**
191
+
* The script that was requested for shaping. This was either passed in or detected automatically.
192
+
*/
193
+
script: string;
194
+
195
+
/**
196
+
* The language requested for shaping, as passed in. If `null`, the default language for the
197
+
* script was used.
198
+
*/
199
+
language: string | null;
200
+
201
+
/**
202
+
* The direction requested for shaping, as passed in (either ltr or rtl).
203
+
* If `null`, the default direction of the script is used.
204
+
*/
205
+
direction: 'ltr' | 'rtl' | null;
206
+
207
+
/**
208
+
* The features requested during shaping. This is a combination of user
209
+
* specified features and features chosen by the shaper.
210
+
*/
211
+
features: object;
212
+
213
+
/**
214
+
* The total advance width of the run.
215
+
*/
216
+
advanceWidth: number;
217
+
218
+
/**
219
+
* The total advance height of the run.
220
+
*/
221
+
advanceHeight: number;
222
+
223
+
/**
224
+
* The bounding box containing all glyphs in the run.
225
+
*/
226
+
bbox: BoundingBox;
227
+
}
228
+
229
+
export interface Subset {
230
+
/**
231
+
* Includes the given glyph object or glyph ID in the subset.
232
+
*/
233
+
includeGlyph(glyph: number | Glyph);
234
+
235
+
/**
236
+
* Returns a stream containing the encoded font file that can be piped to a
237
+
* destination, such as a file.
238
+
*/
239
+
encodeStream();
240
+
}
241
+
242
+
/**
243
+
* There are several different types of font objects that are returned by
244
+
* fontkit depending on the font format. They all inherit from the TTFFont class
245
+
* and have the same public API.
246
+
*/
247
+
export interface Font {
248
+
// Metadata properties
249
+
postscriptName: string | null;
250
+
fullName: string | null;
251
+
familyName: string | null;
252
+
subfamilyName: string | null;
253
+
copyright: string | null;
254
+
version: string | null;
255
+
256
+
// Metrics properties
257
+
unitsPerEm: number; /** Size of the font’s internal coordinate grid */
258
+
ascent: number; /** The font’s ascender */
259
+
descent: number; /** The font’s descender */
260
+
lineGap: number; /** Amount of space that should be included between lines */
261
+
underlinePosition: number; /** Offset from the normal underline position that should be used */
262
+
underlineThickness: number; /** Weight of the underline that should be used */
263
+
italicAngle: number; /** If this is an italic font, the angle the cursor should be drawn at to match the font design */
264
+
capHeight: number; /** Height of capital letters above the baseline. */
265
+
xHeight: number; /** Height of lower case letters. */
266
+
bbox: number; /** Font’s bounding box, i.e. the box that encloses all glyphs in the font */
267
+
268
+
// Other properties
269
+
numGlyphs: number; /** Number of glyphs in the font */
270
+
characterSet: number[]; /** Array of all of the unicode code points supported by the font */
271
+
availableFeatures: any[]; /** Array of all OpenType feature tags (or mapped AAT tags) supported by the font */
272
+
273
+
// Character to Glyph Mapping Methods
274
+
275
+
/**
276
+
* Maps a single unicode code point (number) to a Glyph object.
277
+
* Does not perform any advanced substitutions (there is no context to do so).
278
+
*/
279
+
glyphForCodePoint(codePoint: number): Glyph;
280
+
281
+
/**
282
+
* Returns whether there is glyph in the font for the given
283
+
* unicode code point.
284
+
*/
285
+
hasGlyphForCodePoint(codePoint: number): boolean;
286
+
287
+
/**
288
+
* This method returns an array of Glyph objects for the given string.
289
+
* This is only a one-to-one mapping from characters to glyphs. For most uses,
290
+
* you should use Font.layout, which provides a much more advanced mapping
291
+
* supporting AAT and OpenType shaping.
292
+
*/
293
+
glyphsForString(string: string): Glyph[];
294
+
295
+
// Glyph Metrics and Layout Methods
296
+
297
+
/**
298
+
* Returns the advance width (described above) for a single glyph id.
299
+
*/
300
+
widthOfGlyph(glyphId: number): number;
301
+
302
+
/**
303
+
* This method returns a GlyphRun object, which includes an array of Glyphs
304
+
* and GlyphPositions for the given string. Glyph objects are described below.
305
+
* GlyphPosition objects include 4 properties: xAdvance, yAdvance, xOffset,
306
+
* and yOffset.
307
+
*
308
+
* The features parameter is an array of OpenType feature tags to be applied
309
+
* in addition to the default set. If this is an AAT font, the OpenType
310
+
* feature tags are mapped to AAT features.
311
+
*/
312
+
layout(string: string, features: any[]): GlyphRun;
313
+
314
+
// Other Methods
315
+
316
+
/**
317
+
* Returns a glyph object for the given glyph id. You can pass the array of
318
+
* code points this glyph represents for your use later, and it will be
319
+
* stored in the glyph object.
320
+
*/
321
+
getGlyph(glyphId: number, codePoints: number[]): Glyph;
322
+
323
+
/**
324
+
* Returns a Subset object for this font.
325
+
*/
326
+
createSubset(): Subset;
327
+
}
328
+
329
+
export function create(buffer: Uint8Array, postscriptName?: string): Font;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4