text/v2
is Coming
Issues with the text
Package
There were the following issues with the existing text
package.
- Once used,
font.Face
is cached and not released (#498). - Does not support languages requiring complex rendering like Arabic or Thai (#675).
- Unable to handle glyph vector data (#1937).
- Does not support text alignment such as right or center alignment (#2143).
- Does not support OpenType font features and variants (#2454).
- Unable to handle
font.Face
that cannot be hashed (#2669).
The text
package only dealt with the semi-standard library golang.org/x/image/font
. This package's Face
interface represents a font face. This interface is simple, assuming that 1 code point corresponds to 1 glyph. Therefore, it was not possible to use complex rendering, such as Arabic where glyphs change depending on the context, or OpenType features.
The text/v2
package solves all these issues. The text/v2
package uses the implementation of the github.com/go-text/typesetting
package in addition to the semi-standard library's font.Face
. The typesetting
package internally uses a Go port of HarfBuzz, enabling complex rendering. In addition, not only the implementation but also the fundamental redesign of the text
package's API design has made it possible to do things like right or center alignment that were not possible before, and fix resource leak bugs that couldn't be fixed.
Samples of text/v2
Here are some samples currently in development.
Multilingual Rendering
It will support complex languages such as Arabic, Hindi, Burmese, Thai, as well as vertical Mongolian and vertical Japanese.
Vector
You will be able to easily obtain glyph vector data. For example, you can draw just the outline of characters by combining it with the vector
package.
Features
You can specify font features for rendering. For example, you can specify the presence of ligatures or variations for each character.
Variable Fonts
You can render variable fonts. From one font file, you can specify the thickness and weight as a continuous value.
Future Plans
The existing text
package will remain as is, and a new package with v2
will be added to Ebitengine. This is similar to the recent proposal in Go itself to add math/rand/v2
. The official package name for text/v2
will be github.com/hajimehoshi/ebiten/v2/text/v2
, which is a bit long.
While Ebitengine is at version 2, the text
and text/v2
packages will coexist. Existing code should continue to work as is. New code will use the text/v2
package. When Ebitengine moves to version 3, the text
package may be deprecated.
text/v2
is currently under active development. The API of text/v2
may change until Ebitengine v2.7.0 is released.