Skip to content

Commit 41428ee

Browse files
authored
added deregisterAllFonts to readme (#2328)
* added deregisterAllFonts to readme * Update Readme.md
1 parent 569e8fb commit 41428ee

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Readme.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ This project is an implementation of the Web Canvas API and implements that API
7878
* [createImageData()](#createimagedata)
7979
* [loadImage()](#loadimage)
8080
* [registerFont()](#registerfont)
81+
* [deregisterAllFonts()](#deregisterAllFonts)
82+
8183

8284
### Non-standard APIs
8385

@@ -170,6 +172,35 @@ ctx.fillText('Everyone hates this font :(', 250, 10)
170172
171173
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'`.
172174

175+
### deregisterAllFonts()
176+
177+
> ```ts
178+
> deregisterAllFonts() => void
179+
> ```
180+
181+
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
182+
183+
```ts
184+
const { registerFont, createCanvas, deregisterAllFonts } = require('canvas')
185+
186+
describe('text rendering', () => {
187+
afterEach(() => {
188+
deregisterAllFonts();
189+
})
190+
it('should render text with Comic Sans', () => {
191+
registerFont('comicsans.ttf', { family: 'Comic Sans' })
192+
193+
const canvas = createCanvas(500, 500)
194+
const ctx = canvas.getContext('2d')
195+
196+
ctx.font = '12px "Comic Sans"'
197+
ctx.fillText('Everyone loves this font :)', 250, 10)
198+
199+
// assertScreenshot()
200+
})
201+
})
202+
```
203+
173204
### Image#src
174205

175206
> ```ts

0 commit comments

Comments
 (0)