Skip to content

Parse font using parse-css-font and units-css #891

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

Merged
merged 1 commit into from
Mar 18, 2017

Conversation

lulu-berlin
Copy link
Contributor

@lulu-berlin lulu-berlin commented Mar 17, 2017

This pull request address issue #566

My issue was in using node-canvas to test code that uses pixi.js, which always specifies fully the style, variant and weight in ctx.font, and currently it falls back to the default size.

The problem seems to be in the parsing of the font style. I found the modules parse-css-font and units-css that provide functions to parse the font style and could be used as a drop in replacement to the current code. Both modules are shipped with the MIT license, so I don't think that this dependency should be an issue.

The font-variant property is currently not passed to the c code and not processed by pango. I managed to implement this, but still couldn't get pango to render "small-caps" (see my branch font-variant). In the meantime, I am only sharing in this pull-request the solution for the font style parsing issue.

@chearon
Copy link
Collaborator

chearon commented Mar 17, 2017

Always hated that regex, appreciate this! Have you tried creating a test program in C which calls Pango and asks for a small-caps font? The example code here is easy to modify to test things like that... I have found a lot of holes in support for less-used features like this in OSX and Windows. Or it might only work on TTFs that identify as a small caps variant, I don't know if Pango will do the "fake" small caps that browsers do

@lulu-berlin
Copy link
Contributor Author

lulu-berlin commented Mar 17, 2017

Hi @chearon. Thank you. I wasn't sure whether there's some policy in this project against using external packages.

I haven't tried yet to create a test program. I might have some time to do that over the weekend.

Anyway, I think the pull request has value even without implementing the actual rendering of font variants, because it parses the font style correctly and doesn't fall back to a default size when the variant is included.

@LinusU
Copy link
Collaborator

LinusU commented Mar 18, 2017

I wasn't sure whether there's some policy in this project against using external packages.

I'm all for using external packages 👍 the less code we have the better 🎉

@LinusU LinusU merged commit 9129399 into Automattic:master Mar 18, 2017
LinusU added a commit to LinusU/node-canvas that referenced this pull request Mar 18, 2017
Parse font using parse-css-font and units-css
LinusU added a commit that referenced this pull request Mar 18, 2017
@LinusU
Copy link
Collaborator

LinusU commented Mar 18, 2017

Released as v1.6.5

@lulu-berlin
Copy link
Contributor Author

Thank you! :)

I'll create a new issue for the problem with small-caps in pango

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

Successfully merging this pull request may close these issues.

3 participants