This is a cgo-free library that implements the much of the FreeType C API. It is a relatively thin wrapper around the excellent libfreetype, providing a slightly more Go friendly API.
A degree of familiarity with FreeType's API will be required. The Freetype Tutorial is a good starting point.
The API attempts to balance Go conventions with FreeType conventions. And while it violates both from time to time, hopefully it doesn't stray too far from either.
For the most part there is a one-to-one mapping between C API function and Go functions.
Non-private struct fields are exported, with a few exceptions.
- Where there are a pair of fields with a count and a pointer to an array, they will not be exported. Instead a method that returns a slice is exported.
- Fields that are a pointer to a zero-terminated string are not exported. Instead there will be an exported method with the same name, and it will return a Go string.
Most C types defined by FreeType have a corresponding Go type.
Most FreeType C macros do not need to be exposed. One exception is the Font Testing Macros. They are exposed as functions, such as HasHorizontal.
Simple examples can be found in the example
directory.
Most types and functions in the Core API are implemented. That should suffice for many glyph rasterization needs.
While this library has its benefits there are alternatives that should be considered.
- modernc.org/libfreetype -
This is the library that this library wraps.
It is the result of using ccgo to compile the FreeType C source code to Go.
The main challenge with using it is that its API is a little tricky to use.
Pointers are represented with
uintptr
. An instance of libc.TLS must be used, and passed to all functions. It does not export many constants that are needed. - github.com/golang/freetype - This is a Go port of the C FreeType library. It has some limitations, a number of open bugs, and has not been updated in 8 years. However it's a good library, and will likely suffice for many use cases.
- FreeType - It's perfectly possible to use cgo to use the FreeType library itself. This requires the library to be installed, for building apps the headers available, and a knowledge of C and cgo.
Many source files are named after one of the sections in the FreeType API Reference. The types and functions in those files are maintained in the same order as they appear in their section's documentation.
There are configuration files for linting and other checks. To use a git pre-commit hook for the checks
- install
goimports
if not already installed - install
golangci-lint
if not already installed - install the
pre-commit
application if not already installed - install a git pre-commit hook in this repo's workspace
pre-commit install