@@ -210,11 +210,14 @@ export class CanvasRenderingContext2D {
210210 clip ( fillRule ?: CanvasFillRule ) : void ;
211211 fill ( fillRule ?: CanvasFillRule ) : void ;
212212 stroke ( ) : void ;
213+ fillText ( text : string , x : number , y : number , maxWidth ?: number ) : void ;
214+ strokeText ( text : string , x : number , y : number , maxWidth ?: number ) : void ;
213215 fillRect ( x : number , y : number , w : number , h : number ) : void ;
214216 strokeRect ( x : number , y : number , w : number , h : number ) : void ;
215217 clearRect ( x : number , y : number , w : number , h : number ) : void ;
216218 rect ( x : number , y : number , w : number , h : number ) : void ;
217219 roundRect ( x : number , y : number , w : number , h : number , radii ?: number | number [ ] ) : void ;
220+ measureText ( text : string ) : TextMetrics ;
218221 moveTo ( x : number , y : number ) : void ;
219222 lineTo ( x : number , y : number ) : void ;
220223 bezierCurveTo ( cp1x : number , cp1y : number , cp2x : number , cp2y : number , x : number , y : number ) : void ;
@@ -250,6 +253,30 @@ export class CanvasRenderingContext2D {
250253 shadowBlur : number ;
251254 /** _Non-standard_. Sets the antialiasing mode. */
252255 antialias : 'default' | 'gray' | 'none' | 'subpixel'
256+ /**
257+ * Defaults to 'path'. The effect depends on the canvas type:
258+ *
259+ * * **Standard (image)** `'glyph'` and `'path'` both result in rasterized
260+ * text. Glyph mode is faster than path, but may result in lower-quality
261+ * text, especially when rotated or translated.
262+ *
263+ * * **PDF** `'glyph'` will embed text instead of paths into the PDF. This
264+ * is faster to encode, faster to open with PDF viewers, yields a smaller
265+ * file size and makes the text selectable. The subset of the font needed
266+ * to render the glyphs will be embedded in the PDF. This is usually the
267+ * mode you want to use with PDF canvases.
268+ *
269+ * * **SVG** glyph does not cause `<text>` elements to be produced as one
270+ * might expect ([cairo bug](https://gitlab.freedesktop.org/cairo/cairo/issues/253)).
271+ * Rather, glyph will create a `<defs>` section with a `<symbol>` for each
272+ * glyph, then those glyphs be reused via `<use>` elements. `'path'` mode
273+ * creates a `<path>` element for each text string. glyph mode is faster
274+ * and yields a smaller file size.
275+ *
276+ * In glyph mode, `ctx.strokeText()` and `ctx.fillText()` behave the same
277+ * (aside from using the stroke and fill style, respectively).
278+ */
279+ textDrawingMode : 'path' | 'glyph'
253280 /**
254281 * _Non-standard_. Defaults to 'good'. Like `patternQuality`, but applies to
255282 * transformations affecting more than just patterns.
@@ -259,7 +286,12 @@ export class CanvasRenderingContext2D {
259286 currentTransform : DOMMatrix
260287 fillStyle : string | CanvasGradient | CanvasPattern ;
261288 strokeStyle : string | CanvasGradient | CanvasPattern ;
289+ font : string ;
290+ textBaseline : CanvasTextBaseline ;
291+ textAlign : CanvasTextAlign ;
262292 canvas : Canvas ;
293+ direction : 'ltr' | 'rtl' ;
294+ lang : string ;
263295}
264296
265297export class CanvasGradient {
@@ -346,6 +378,35 @@ export function createImageData(width: number, height: number): ImageData
346378 */
347379export function loadImage ( src : string | Buffer , options ?: any ) : Promise < Image >
348380
381+ interface FontFaceDescriptors {
382+ weight ?: number ;
383+ style ?: string ;
384+ }
385+
386+ export class FontFace {
387+ constructor (
388+ family : string ,
389+ url : string | ArrayBuffer | Uint8Array ,
390+ descriptors ?: FontFaceDescriptors
391+ ) ;
392+
393+ family : string ;
394+ style : string ;
395+ weight : string ;
396+ status : 'loaded' | 'unloaded' | 'error' ;
397+ }
398+
399+ declare class FontFaceSet {
400+ add ( face : FontFace ) : void ;
401+ has ( face : FontFace ) : boolean ;
402+ clear ( ) : void ;
403+ delete ( face : FontFace ) : boolean ;
404+ [ Symbol . iterator ] ( ) : Iterator < FontFace > ;
405+ size : number ;
406+ }
407+
408+ export const fonts : FontFaceSet ;
409+
349410/** This class must not be constructed directly; use `canvas.createPNGStream()`. */
350411export class PNGStream extends Readable { }
351412/** This class must not be constructed directly; use `canvas.createJPEGStream()`. */
0 commit comments