Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fonts render with the wrong font face #39

Open
schester44 opened this issue Oct 22, 2019 · 5 comments
Open

Some fonts render with the wrong font face #39

schester44 opened this issue Oct 22, 2019 · 5 comments

Comments

@schester44
Copy link

Its hit or miss but it seems like fonts that are more "stylish" or complex are the ones that don't render correctly. A group of fonts within the same family will all render using, what appears to be, the exact same font.

This is occurring on OSX and Freebsd.

Example fonts:
https://drive.google.com/drive/folders/1tBD2RnuEpLHofEdS4Eeg7VvSgk6nt7S1?usp=sharing

The code i'm using:

import text2png from 'text2png'
import fontkit from 'fontkit'

const textToImage = ({ text, file }) => {
	const name = text || fontkit.openSync(file).fullName

	return text2png(name, {
		padding: 10,
		font: `20px ${name}`,
		localFontPath: file,
		localFontName: name
	})
}

export default textToImage

I'll continue my research upstream but wanted to drop an issue on this project in case someone has some info related to this.

@schester44
Copy link
Author

an example of the sort of output i'm getting with those fonts above

https://imgur.com/QDzvhfp

@schester44
Copy link
Author

schester44 commented Oct 22, 2019

It's like the first font is cached and any subsequent calls for similar fonts within the same family are using the first font instead of their own file.

localFontPath: file,
localFontName: name

the values for these options are different for each file so I would think there would be no relation between the files.

@schester44
Copy link
Author

schester44 commented Oct 22, 2019

I believe I found the issue. Opening these fonts in FontForge, their Preferred Family Name is 'SignPainter' and their Style values are 'Regular'. I believe node-canvas is caching these fonts based on their preferred family name and style. The fonts started rendering correctly once I changed the preferred family name to a unique value.

This seems to be related to this comment here..
https://github.com/Automattic/node-canvas/blob/d2d632402b7032fb0ff755be138d20b87766aff6/examples/font.js#L14

and possibly this section of code here ...
https://github.com/Automattic/node-canvas/blob/master/src/register_font.cc#L130

just need to figure out a way to make it work without using FontForge to modify the values....

@angelogulina
Copy link

@schester44 I had a similar case and I can confirm your suggestion worked for me.
Therefore I think this can be closed (and thanks so much for providing such insight!)

@schester44
Copy link
Author

yeah apparently this isn't currently fixable at the node-canvas level (see the referenced issue). Modifying fonts via FontForge isn't really an option for me... open to ideas/suggestions for a fix if anyone comes across this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants