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

How to get the contours of a glyph? #38

Closed
fschutt opened this issue Dec 8, 2020 · 8 comments
Closed

How to get the contours of a glyph? #38

fschutt opened this issue Dec 8, 2020 · 8 comments

Comments

@fschutt
Copy link
Contributor

fschutt commented Dec 8, 2020

I'm trying to extract the glyph as bezier curves / LineTo, QuadraticCurveTo / CubicCurveTo operations to render the glyph to an SVG file, is there a way to extract this information? Thanks.

@wezm
Copy link
Contributor

wezm commented Dec 8, 2020

We don't have anything that interprets the glyph outlines as drawing operations/normalises them to bezier/quadratic curves. However the raw glyph data is available through GlyfTable and CFF. In case it's helpful as an example GlyfTable::subset includes code that loops over the glyphs. Similarly CFF::subset for CFF char strings.

Out of curiosity is this something that you were able to do in your previous implementation? If so, I'd be curious to look over the code as a reference. I also found font_to_svg which translates font outlines to SVG, perhaps that's useful as a reference.

@fschutt
Copy link
Contributor Author

fschutt commented Dec 9, 2020

I've used owned_ttf_parser and rusttype that both have functions to parse glyph outlines, but they only work for ttf fonts. I'm looking to replace my code here:

https://github.com/maps4print/azul/blob/97236351a46bc04e0d71d2829ab2586e4c771329/azulc/src/svg.rs#L819-L828

and here:

https://github.com/maps4print/azul/blob/97236351a46bc04e0d71d2829ab2586e4c771329/azulc/src/svg.rs#L1280-L1317

I want to migrate to allsorts so I can also add support for opentype and WOFF fonts. Since I need this anyway, I'll see if I can make a PR for adding a glyph outline parser. I've looked at the glyf table, doesn't seem that hard.

@fschutt
Copy link
Contributor Author

fschutt commented Dec 9, 2020

Also the corresponding function in rusttype is here: https://docs.rs/rusttype/0.9.2/rusttype/struct.ScaledGlyph.html#method.build_outline

@wezm
Copy link
Contributor

wezm commented Dec 9, 2020

I'll see if I can make a PR for adding a glyph outline parser.

If you can hold off a little while I'll be working on something similar today. I'm going to work on a test harness that allows allsorts to be run against the unicode text-rendering-tests, and this will probably require doing this at the same time.

@fschutt
Copy link
Contributor Author

fschutt commented Dec 18, 2020

Are you still working on this, otherwise I'd go ahead in the next few days to just implement a parser for the glyf table

@wezm
Copy link
Contributor

wezm commented Dec 21, 2020

I am, but I'm holidays until 6 Jan now.

@fschutt
Copy link
Contributor Author

fschutt commented Dec 21, 2020

There is an implementation of a glyf parser in the rust-ttf-parser crate already and the crate author has given me permission to copy the glyf parser code. I have some time between the years, so I'll probably go ahead and just implement it, because I need it before I can release azul.

Enjoy your holiday!

@wezm
Copy link
Contributor

wezm commented Jul 20, 2021

Well this took longer to get into a release than expected but access to glyph contours is present in Allsorts 0.6: https://yeslogic.com/blog/allsorts-rust-font-shaping-engine-0-6/

@wezm wezm closed this as completed Jul 20, 2021
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