plotters icon indicating copy to clipboard operation
plotters copied to clipboard

Add `ab_glyph` font backend

Open Monadic-Cat opened this issue 3 years ago • 4 comments
trafficstars

I've been using plotters in a situation where caring about system fonts is unimportant, and having font-kit in my dependency tree has been causing me unnecessary problems. This PR introduces a feature gated font rendering backend based on https://github.com/alexheretic/ab-glyph, which doesn't have those problems for me.

I am willing to restructure or completely rewrite this code as necessary to get some form of this feature merged- I can't say I'm certain this is the best API for it. I can also, and probably should also, add documentation and tests for it. Lemme know what you think is best and I'll do it.

Monadic-Cat avatar Nov 29 '21 13:11 Monadic-Cat

Hi there, sorry for a long delay. This is very helpful, and I just rebased the code. Just wondering if you are still interested in working on this PR, if yes I can send a PR to you for the rebase, otherwise I am going to work on my branch to finish this.

Please check https://github.com/plotters-rs/plotters/tree/ab_glyph_font_backend for the rebase

Thanks for the contribution and please don't mind the delay!

38 avatar Jun 26 '22 05:06 38

Yes! I'm absolutely still interested in working on this.

Monadic-Cat avatar Jul 01 '22 17:07 Monadic-Cat

Thanks a lot for working on this! I am using plotters in my home automation system which runs on a Pi. Without font-kit cross-compiling will be a breeze!

dvdsk avatar Jul 01 '22 23:07 dvdsk

I just did a clean interactive rebase against master, after staring at the changes and your own rebased branch. Gonna do some testing to make sure it still works, then the next thing to do will be redesigning the API. There's some internal stuff that definitely needs fixing, as this code relies on unwinding to break out of a callback on failure.

Monadic-Cat avatar Aug 02 '22 17:08 Monadic-Cat

I have a branch here which fixes the vertical alignment of glyphs.

Zoxc avatar Aug 21 '22 13:08 Zoxc

I have a branch here which fixes the vertical alignment of glyphs.

Cool. I've tested it in my case and it looks like it works, so I'll go ahead and pull your branch here.

Monadic-Cat avatar Aug 29 '22 15:08 Monadic-Cat

I gave up on trying to refactor things to avoid the panic reliance, and just added a buffer instead. As of now, this branch is functional enough to merge. It works where I've been using it (just as it has for... a while). All that's left to do is fix the tests I guess I broke, and maybe bikeshed the register_fonts API if anyone cares to.

Monadic-Cat avatar Aug 29 '22 16:08 Monadic-Cat

I've now added support for passing a FontStyle to register_font, and I believe CI should pass this now.

Monadic-Cat avatar Aug 31 '22 16:08 Monadic-Cat

I've renamed the ab_glyph_ feature to ab_glyph, using the dep: syntax available in Cargo.toml since Rust 1.60 (which postdates this PR being opened, lol).

Monadic-Cat avatar Aug 31 '22 18:08 Monadic-Cat

Woops, those Clippy warnings tipped me off to my having forgotten to do the ab_glyph_ -> ab_glyph feature rename in one file. I had also forgotten I'd git stashed the changes to the project I depend on this in so it wasn't using a path dependency for local testing. Fixed now.

Monadic-Cat avatar Sep 01 '22 02:09 Monadic-Cat

I just tried this out it works perfect on my side. And this makes us away from libfontconfig dependency which has frequently asked by many people.

It would be nice if you have the clippy warning fixed. Besides that everything looks good to me.

Thanks for the awesome work!

38 avatar Sep 08 '22 09:09 38

Thanks!

AaronErhardt avatar Sep 08 '22 16:09 AaronErhardt