A library for calculating the width of and spacing text/components in Minecraft: Java Edition.
Chasm provides the ability to calculate the display width of any text using any font. By default, it provides a simplified version of Minecraft's default font but provided with a resource pack it can load the fonts within and provide width calculations for them. For loading of all of Minecraft's default fonts the chasm-plugin is available.
Use Chasm as a library dependency from your Gradle project.
repositories {
mavenCentral()
maven("https://repo.hboyd.dev/snapshots/")
}
dependencies {
implementation("dev.hboyd:chasm-lib:1.0.1")
}A glyph is the specific visual representation of character or a 'slot' in text. It isn't necessarily a single character, however. A glyph can be made up of multiple characters that are then visually displayed as a single character or text 'unit'.
For example the glyph 'x̣' visually appears as one character but is actually made up of the Unicode characters/codepoints '0074' and '0323'.
For more examples and a detailed see the Unicode 17.0.0 standard 2.2.3.
A GlyphDefinitionProvider provides the widths for a set of glyphs. There are five standard providers,
BitmapGlyphDefinitionProvider, SpaceGlyphDefinitionProvider, TrueTypeGlypDefinitionProvider
and UnihexDefinitionProvider which represent the Minecraft bitmap,
space, TTF,
and Unihex font providers respectively. Additionally, there is the
BuiltinGlyphDefinitionProvider which is a hard coded singleton provider of the glyphs in the default
minecraft:font/include and minecraft:include/space fonts.
A MinecraftFont is a keyed set of multiple GlyphDefinitionProviders. A static BUILTIN instance is accessible which
contains the previously mentioned BuiltinGlyphDefinitionProvider provider.
A MinecraftFontRegistry is a mutable set of multiple MinecraftFonts with accessors for font's based on key. A static
GLOBAL instance is accessible which contains the previously mentioned BUILTIN MinecraftFont instance.
Additionally, the Chasm companion plugin adds the fonts it generates to this instance.
The MinecraftFontGenerator builds GlyphDefinitionProviders to form MinecraftFonts using a given resource pack and
registers the fonts to the set registry.
TextWidthProvider calculates the rendered width of Adventure components, strings, codepoints, and StyledGlyphs. The
TextWidthProvider uses fonts registered with the FontRegistry it is created with.
The Chasm companion plugin provides the default Minecraft fonts for use by the library. Fonts generated by the plugin
are registered to the GLOBAL font registry. The library has a built-in subset of the glyphs provided by the default
resource pack. This means that the plugin is not required but the widths for glyphs outside of the
The Chasm companion plugin provides these fonts by downloading the Minecraft client jar and deriving the widths from the included default resource pack.
All releases are signed with a subkey of the PGP key 215992666EB8628661E8FDEF3C66DE485B9143DE
This project is licensed under the GNU Lesser General Public License v3.0. See LICENSE.md.