Skip to content

Commit

Permalink
added deregisterAllFonts to readme (#2328)
Browse files Browse the repository at this point in the history
* added deregisterAllFonts to readme

* Update Readme.md
  • Loading branch information
stepancar authored Dec 28, 2023
1 parent 569e8fb commit 41428ee
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 41428ee

Please sign in to comment.