Automattic / Automattic/node-canvas

Add unregisterFont

Open
#1,697 6 comments 1 reaction 0 assignees View on GitHub
Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

Provide a way to unregisterFont

## Issue or Feature
Currently it's possible to register font but not to unregister it.
I use different temporary paths for fonts that get deleted after their usage.
I tried calling registerFont multiple times hoping that would use the last provided path but for some reason it keeps references to the previous registered font (same family, style and weight)

## Steps to Reproduce
- Download font file 1
- Call registerFont
- Render
- Delete font file 1
- Download font file 2
- Call registerFont with same font settings (family, style, weight)
- Render

I get those warnings:
```
(process:1096958): Pango-WARNING **: failed to create cairo scaled font, expect ugly output. the offending font is 'Bowlby One SC Ultra-Condensed 142.5'

(process:1096958): Pango-WARNING **: font_face status is: file not found

(process:1096958): Pango-WARNING **: scaled_font status is: file not found

(process:1096958): Pango-WARNING **: shaping failure, expect ugly output. shape-engine='PangoFcShapeEngine', font='Bowlby One SC Ultra-Condensed 142.5', text='IN '
```

## Your Environment
```
% node -v
v13.7.0
% npm list canvas
@storyteq/node-common@3.2.0 /home/user/Projects/node-services/packages/node-common
├── canvas@2.6.1
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the existing registerFont entry point in node-canvas and how registered fonts are retained across calls. Define the unregisterFont behavior around the reported temporary-font lifecycle, then verify that registering a replacement font no longer uses the deleted file and that rendering completes without the reported warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.