From 41428ee2dfa2622b82f65e4fccd3adfefd1e0a72 Mon Sep 17 00:00:00 2001 From: Stepan Mikhailiuk Date: Thu, 28 Dec 2023 15:01:14 -0800 Subject: [PATCH] added deregisterAllFonts to readme (#2328) * added deregisterAllFonts to readme * Update Readme.md --- Readme.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Readme.md b/Readme.md index c029e27cb..b84df72db 100644 --- a/Readme.md +++ b/Readme.md @@ -78,6 +78,8 @@ This project is an implementation of the Web Canvas API and implements that API * [createImageData()](#createimagedata) * [loadImage()](#loadimage) * [registerFont()](#registerfont) +* [deregisterAllFonts()](#deregisterAllFonts) + ### Non-standard APIs @@ -170,6 +172,35 @@ ctx.fillText('Everyone hates this font :(', 250, 10) The second argument is an object with properties that resemble the CSS properties that are specified in `@font-face` rules. You must specify at least `family`. `weight`, and `style` are optional and default to `'normal'`. +### deregisterAllFonts() + +> ```ts +> deregisterAllFonts() => void +> ``` + +Use `deregisterAllFonts` to unregister all fonts that have been previously registered. This method is useful when you want to remove all registered fonts, such as when using the canvas in tests + +```ts +const { registerFont, createCanvas, deregisterAllFonts } = require('canvas') + +describe('text rendering', () => { + afterEach(() => { + deregisterAllFonts(); + }) + it('should render text with Comic Sans', () => { + registerFont('comicsans.ttf', { family: 'Comic Sans' }) + + const canvas = createCanvas(500, 500) + const ctx = canvas.getContext('2d') + + ctx.font = '12px "Comic Sans"' + ctx.fillText('Everyone loves this font :)', 250, 10) + + // assertScreenshot() + }) +}) +``` + ### Image#src > ```ts