Introducing RustType, a pure Rust alternative to FreeType

RustType is my attempt to make an easy-to-use font rasterisation library in pure Rust. It's part of my roadmap towards making a good GUI library for Rust.
I've really tried to outdo myself with the documentation for this crate. If you do find anything that's unclear or lacking, please open an issue.
Check it out: GitHub - redox-os/rusttype: Mirror of https://gitlab.redox-os.org/redox-os/rusttype

8 Likes

The Readme and crate docs look pretty great (but I have no idea how fonts work)! If you really want to document everything, don't forget to set #![deny(missing_docs}]!

Ah, that's a good point! I'll add that.

Regarding understanding fonts, I have tried to include an explanation of some of the common terminology in the docs, and give a definition of each term used in a function or struct. But really the best way to get a handle on it is to read an article/tutorial on TrueType to understand how a font is put together.

To aid in ease-of-use I have included a convenience function that allows you to simply pass in a string and get back an iterator over a list of things (glyphs) to draw.

I love the example!

Thanks! That example is likely to be most users' first look at using the library, so if you spot anything that could be a bit more idiomatic or clearer, just say.

Here are my two bits:

  1. There could be a blank line before fn main() {.
  2. use rusttype::*; feels a little sloppy. I would prefer an explicit import of names, or use rusttype::prelude::* to make it clear that star import is the intended usage pattern.

Good points. That is a bit sloppy. That's a leftover from when I first started testing things out. In reality I think the number of individual items needed is quite small, so I'll change it to that. Thanks.

Some more nits:

let to_draw: Vec<_> = font.layout("Hello!", scale, offset).collect();

The variable name is vague and it would probably be more helpful to know the element type.

for g in to_draw {

Currently it's difficult to guess what g is.

You might want to run rustfmt over the code to take care of formatting nits.

Right, I've just pushed some changes to make things a bit clearer, before seeing your comment. Still, I didn't change those variable names. Will do.

There we go, things should be much clearer now.

1 Like

I've tweaked the example a bit more, and made the text shown a bit more appropiate ;). Any thoughts?

Why the lowercase point in the use? Aren't Rust types supposed to start with a capital letter?

point isn't a type. It's a function. I figured it would be more convenient to be able to write point(x, y) than Point::new(x, y). The same sort of thing exists with vector.

I get it. However, doesn't that break Rust convention?
Just asking.

How does the library compare with stb_truetype?

I'm not entirely sure about convention regarding this distinction for small types like this. If a strong opinion forms in the community I'll change it. Feel free to open an issue on the repo to discuss stuff like this.

Currently, RustType depends on a translation of stb_truetype to Rust that I've written. This dependency is only for font loading though. I intend to reduce the dependency on stb_truetype over time.

In terms of differences in features, currently the main one is that the rasterisation is more accurate, and potentially faster. RustType also currently doesn't expose methods for querying metadata like font names, authors or copyrights, unlike stb_truetype.

Alright that sound good. Thanks!