Introducing RustType, a pure Rust alternative to FreeType


#1

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: https://github.com/dylanede/rusttype


#2

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}]!


#3

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.


#4

I love the example!


#5

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.


#6

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.

#7

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.


#8

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.


#9

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.


#10

There we go, things should be much clearer now.


#11

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


#12

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


#13

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.


#14

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


#15

How does the library compare with stb_truetype?


#16

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.


#17

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.


#18

Alright that sound good. Thanks!