This library calculates text measurements using pre-generated font metrics data for specific fonts and sizes.
For example, this library helps determine the width and height of text strings when rendered in specific fonts and sizes.
This library was initially intended for use with the Scenic framework, but is also usable independently.
Add font_metrics
to your dependencies in mix.exs
to install FontMetrics:
def deps do
[
{:font_metrics, "~> 0.5"},
]
end
Generate font metrics data using the truetype_metrics
package from hex. You can also find metrics data for Roboto and RobotoMono in the Scenic project.
Version 0.5 introduces major changes, including word boundary wrapping and corrects width calculation issues.
It removes serialization in favor of returning the struct directly. This library should not dictate
how to serialize its data. We recommend using something like :erlang.term_to_binary/2
for
serialization. Scenic no longer requires this functionality, which highlighted the need for this
change.