Class BmFontBuilder
- Namespace
- KernSmith
- Assembly
- KernSmith.dll
Fluent builder for configuring and generating bitmap fonts.
public sealed class BmFontBuilder
- Inheritance
-
BmFontBuilder
- Inherited Members
Methods
Build()
Generates the bitmap font, returning the descriptor model and atlas texture pages.
public BmFontResult Build()
Returns
- BmFontResult
The generated bitmap font result.
FromConfig(BmfcConfig)
Loads settings from a parsed configuration (from a .bmfc or .hiero file) as a starting point.
public BmFontBuilder FromConfig(BmfcConfig config)
Parameters
configBmfcConfigThe parsed configuration. BmfcConfig is the shared model for both the BMFont
.bmfcand libGDX Hiero.hieroformats.
Returns
- BmFontBuilder
This builder.
FromConfig(string)
Loads settings from a config file (.bmfc or .hiero) as a starting point.
public BmFontBuilder FromConfig(string bmfcPath)
Parameters
bmfcPathstringPath to a configuration file. Despite the name, this accepts both
.bmfcand.hierofiles (auto-detected by inspecting the file content; the extension is used only as a fallback when the content is inconclusive).
Returns
- BmFontBuilder
This builder.
WithAntiAlias(AntiAliasMode)
Sets the anti-aliasing mode.
public BmFontBuilder WithAntiAlias(AntiAliasMode mode)
Parameters
modeAntiAliasModeAnti-aliasing mode.
Returns
- BmFontBuilder
This builder.
WithAutofitTexture(bool)
If true, shrinks the texture to fit the glyphs tightly.
public BmFontBuilder WithAutofitTexture(bool autofit = true)
Parameters
autofitboolEnable auto-fit.
Returns
- BmFontBuilder
This builder.
WithBackend(RasterizerBackend)
Sets the rasterizer backend to use for glyph rendering.
public BmFontBuilder WithBackend(RasterizerBackend backend)
Parameters
backendRasterizerBackendThe backend to use.
Returns
- BmFontBuilder
This builder.
WithBold(bool)
Requests bold. Uses a native bold face when available, falling back to synthetic.
public BmFontBuilder WithBold(bool bold = true)
Parameters
boldboolEnable bold.
Returns
- BmFontBuilder
This builder.
WithChannelPacking(bool)
If true, packs multiple glyphs into separate RGBA channels to save space.
public BmFontBuilder WithChannelPacking(bool channelPacking = true)
Parameters
channelPackingboolEnable channel packing.
Returns
- BmFontBuilder
This builder.
WithChannels(ChannelConfig)
Sets how each RGBA channel is used in the output texture.
public BmFontBuilder WithChannels(ChannelConfig config)
Parameters
configChannelConfigChannel configuration.
Returns
- BmFontBuilder
This builder.
WithChannels(ChannelContent, ChannelContent, ChannelContent, ChannelContent, bool, bool, bool, bool)
Sets what each RGBA channel contains and whether to invert it.
public BmFontBuilder WithChannels(ChannelContent alpha = ChannelContent.Glyph, ChannelContent red = ChannelContent.Glyph, ChannelContent green = ChannelContent.Glyph, ChannelContent blue = ChannelContent.Glyph, bool invertAlpha = false, bool invertRed = false, bool invertGreen = false, bool invertBlue = false)
Parameters
alphaChannelContentWhat the alpha channel holds.
redChannelContentWhat the red channel holds.
greenChannelContentWhat the green channel holds.
blueChannelContentWhat the blue channel holds.
invertAlphaboolInvert alpha channel.
invertRedboolInvert red channel.
invertGreenboolInvert green channel.
invertBlueboolInvert blue channel.
Returns
- BmFontBuilder
This builder.
WithCharacters(CharacterSet)
Sets which characters to include in the output.
public BmFontBuilder WithCharacters(CharacterSet characters)
Parameters
charactersCharacterSetThe character set to render.
Returns
- BmFontBuilder
This builder.
WithCollectMetrics(bool)
Enables collection of pipeline performance metrics on the result.
public BmFontBuilder WithCollectMetrics(bool collect = true)
Parameters
collectboolWhether to collect metrics (default true).
Returns
- BmFontBuilder
This builder.
WithColorFont(bool)
If true, renders color font layers (emoji, etc.).
public BmFontBuilder WithColorFont(bool colorFont = true)
Parameters
colorFontboolEnable color font rendering.
Returns
- BmFontBuilder
This builder.
WithColorPaletteIndex(int)
Selects which CPAL color palette to use for color fonts.
public BmFontBuilder WithColorPaletteIndex(int index)
Parameters
indexintZero-based palette index.
Returns
- BmFontBuilder
This builder.
WithCustomGlyph(int, CustomGlyph)
Adds a custom bitmap for a specific character code.
public BmFontBuilder WithCustomGlyph(int codepoint, CustomGlyph glyph)
Parameters
codepointintUnicode character code to replace.
glyphCustomGlyphThe custom glyph data.
Returns
- BmFontBuilder
This builder.
WithCustomGlyph(int, int, int, byte[], PixelFormat, int?)
Adds a custom bitmap for a specific character code from raw pixels.
public BmFontBuilder WithCustomGlyph(int codepoint, int width, int height, byte[] pixelData, PixelFormat format = PixelFormat.Rgba32, int? xAdvance = null)
Parameters
codepointintUnicode character code to replace.
widthintGlyph width in pixels.
heightintGlyph height in pixels.
pixelDatabyte[]Raw pixel data.
formatPixelFormatPixel format of the data.
xAdvanceint?Custom horizontal advance, or null to auto-calculate.
Returns
- BmFontBuilder
This builder.
WithDpi(int)
Sets the DPI used for font size calculation.
public BmFontBuilder WithDpi(int dpi)
Parameters
dpiintDots per inch.
Returns
- BmFontBuilder
This builder.
WithEncoder(IAtlasEncoder)
Uses a custom atlas encoder instead of the default.
public BmFontBuilder WithEncoder(IAtlasEncoder encoder)
Parameters
encoderIAtlasEncoderEncoder to use.
Returns
- BmFontBuilder
This builder.
WithEqualizeCellHeights(bool)
If true, makes all glyph cells the same height.
public BmFontBuilder WithEqualizeCellHeights(bool equalize = true)
Parameters
equalizeboolEnable equal cell heights.
Returns
- BmFontBuilder
This builder.
WithFaceIndex(int)
Selects which face to use in a font collection (.ttc) file.
public BmFontBuilder WithFaceIndex(int faceIndex)
Parameters
faceIndexintZero-based face index.
Returns
- BmFontBuilder
This builder.
WithFallbackCharacter(char)
Sets the character shown when a glyph is missing from the font.
public BmFontBuilder WithFallbackCharacter(char fallbackChar)
Parameters
fallbackCharcharFallback character.
Returns
- BmFontBuilder
This builder.
WithFallbackCodepoint(int)
Sets the fallback codepoint used when a requested character is not available in the font. Supports supplementary plane characters (above U+FFFF) unlike WithFallbackCharacter(char).
public BmFontBuilder WithFallbackCodepoint(int codepoint)
Parameters
codepointintUnicode codepoint to use as fallback (e.g., 0x25A1 for '□').
Returns
- BmFontBuilder
This builder.
WithFont(byte[])
Loads a font from raw byte data.
public BmFontBuilder WithFont(byte[] fontData)
Parameters
fontDatabyte[]The font file bytes.
Returns
- BmFontBuilder
This builder.
WithFont(string)
Loads a font from a file path.
public BmFontBuilder WithFont(string fontPath)
Parameters
fontPathstringPath to a .ttf, .otf, or .woff file.
Returns
- BmFontBuilder
This builder.
WithFontReader(IFontReader)
Uses a custom font reader instead of the default.
public BmFontBuilder WithFontReader(IFontReader reader)
Parameters
readerIFontReaderFont reader to use.
Returns
- BmFontBuilder
This builder.
WithForceOffsetsToZero(bool)
If true, forces all glyph x/y offsets to zero.
public BmFontBuilder WithForceOffsetsToZero(bool force = true)
Parameters
forceboolEnable zeroed offsets.
Returns
- BmFontBuilder
This builder.
WithForceSyntheticBold(bool)
Forces synthetic bold even when a native bold face exists.
public BmFontBuilder WithForceSyntheticBold(bool force = true)
Parameters
forceboolEnable forced synthetic bold.
Returns
- BmFontBuilder
This builder.
WithForceSyntheticItalic(bool)
Forces synthetic italic even when a native italic face exists.
public BmFontBuilder WithForceSyntheticItalic(bool force = true)
Parameters
forceboolEnable forced synthetic italic.
Returns
- BmFontBuilder
This builder.
WithGradient((byte R, byte G, byte B), (byte R, byte G, byte B), float, float)
Applies a color gradient across all glyphs.
public BmFontBuilder WithGradient((byte R, byte G, byte B) startColor, (byte R, byte G, byte B) endColor, float angleDegrees = 90, float midpoint = 0.5)
Parameters
startColor(byte R, byte G, byte B)Start color as (R, G, B).
endColor(byte R, byte G, byte B)End color as (R, G, B).
angleDegreesfloatAngle in degrees. 0 = left-to-right, 90 = top-to-bottom.
midpointfloatWhere the midpoint falls, 0.0 to 1.0.
Returns
- BmFontBuilder
This builder.
WithHardShadow(bool)
Uses a hard (binarized) shadow silhouette instead of the antialiased glyph alpha.
public BmFontBuilder WithHardShadow(bool enabled = true)
Parameters
enabledboolEnable hard shadow.
Returns
- BmFontBuilder
This builder.
WithHeightPercent(int)
Scales glyph height as a percentage. 100 = normal, 200 = double height.
public BmFontBuilder WithHeightPercent(int percent)
Parameters
percentintHeight as a percentage.
Returns
- BmFontBuilder
This builder.
WithHinting(bool)
If true, enables font hinting for sharper small text.
public BmFontBuilder WithHinting(bool enable = true)
Parameters
enableboolEnable hinting.
Returns
- BmFontBuilder
This builder.
WithItalic(bool)
Requests italic. Uses a native italic face when available, falling back to synthetic.
public BmFontBuilder WithItalic(bool italic = true)
Parameters
italicboolEnable italic.
Returns
- BmFontBuilder
This builder.
WithKerning(bool)
If true, includes kerning pairs in the output.
public BmFontBuilder WithKerning(bool kerning = true)
Parameters
kerningboolEnable kerning.
Returns
- BmFontBuilder
This builder.
WithMatchCharHeight(bool)
If true, scales custom glyph advances to match the font's character height.
public BmFontBuilder WithMatchCharHeight(bool match = true)
Parameters
matchboolEnable height matching.
Returns
- BmFontBuilder
This builder.
WithMaxTextureSize(int)
Sets the max texture size (both width and height) in pixels.
public BmFontBuilder WithMaxTextureSize(int size)
Parameters
sizeintMax width and height in pixels.
Returns
- BmFontBuilder
This builder.
WithMaxTextureSize(int, int)
Sets the max texture width and height separately.
public BmFontBuilder WithMaxTextureSize(int width, int height)
Parameters
Returns
- BmFontBuilder
This builder.
WithOutline(int)
Adds an outline around each glyph.
public BmFontBuilder WithOutline(int outline)
Parameters
outlineintOutline width in pixels.
Returns
- BmFontBuilder
This builder.
WithOutline(int, byte, byte, byte)
Adds a colored outline around each glyph.
public BmFontBuilder WithOutline(int width, byte r, byte g = 0, byte b = 0)
Parameters
Returns
- BmFontBuilder
This builder.
WithPacker(IAtlasPacker)
Uses a custom atlas packer instead of the default.
public BmFontBuilder WithPacker(IAtlasPacker packer)
Parameters
packerIAtlasPackerPacker to use.
Returns
- BmFontBuilder
This builder.
WithPackingAlgorithm(PackingAlgorithm)
Sets the atlas packing algorithm.
public BmFontBuilder WithPackingAlgorithm(PackingAlgorithm algorithm)
Parameters
algorithmPackingAlgorithmPacking algorithm.
Returns
- BmFontBuilder
This builder.
WithPackingEfficiency(float)
Sets the expected packing efficiency for atlas size estimation. 0.0 = worst, 1.0 = perfect.
public BmFontBuilder WithPackingEfficiency(float efficiency)
Parameters
efficiencyfloatPacking efficiency between 0.0 and 1.0.
Returns
- BmFontBuilder
This builder.
WithPadding(int)
Sets uniform glyph padding on all sides.
public BmFontBuilder WithPadding(int all)
Parameters
allintPadding in pixels for every side.
Returns
- BmFontBuilder
This builder.
WithPadding(int, int, int, int)
Sets per-side glyph padding in pixels.
public BmFontBuilder WithPadding(int up, int right, int down, int left)
Parameters
Returns
- BmFontBuilder
This builder.
WithPostProcessor(IGlyphPostProcessor)
Adds a custom post-processing step that runs on each glyph after rasterization.
public BmFontBuilder WithPostProcessor(IGlyphPostProcessor processor)
Parameters
processorIGlyphPostProcessorThe post-processor to add.
Returns
- BmFontBuilder
This builder.
WithPowerOfTwo(bool)
If true, rounds texture dimensions up to powers of two.
public BmFontBuilder WithPowerOfTwo(bool powerOfTwo = true)
Parameters
powerOfTwoboolEnable power-of-two sizing.
Returns
- BmFontBuilder
This builder.
WithRasterizer(IRasterizer)
Uses a custom rasterizer instead of the default FreeType one.
public BmFontBuilder WithRasterizer(IRasterizer rasterizer)
Parameters
rasterizerIRasterizerRasterizer to use.
Returns
- BmFontBuilder
This builder.
WithSdf(bool)
If true, generates signed distance field (SDF) output instead of bitmaps.
public BmFontBuilder WithSdf(bool sdf = true)
Parameters
sdfboolEnable SDF.
Returns
- BmFontBuilder
This builder.
WithShadow(int, int, int, (byte R, byte G, byte B)?, float)
Adds a drop shadow behind each glyph.
public BmFontBuilder WithShadow(int offsetX = 2, int offsetY = 2, int blur = 0, (byte R, byte G, byte B)? color = null, float opacity = 1)
Parameters
offsetXintHorizontal offset in pixels.
offsetYintVertical offset in pixels.
blurintBlur radius in pixels.
color(byte R, byte G, byte B)?Shadow color as (R, G, B); defaults to black.
opacityfloatShadow opacity, 0.0 to 1.0.
Returns
- BmFontBuilder
This builder.
WithSize(float)
Sets the font size in points. Fractional values are supported on FreeType, StbTrueType, and DirectWrite backends; the GDI backend rounds to the nearest integer.
public BmFontBuilder WithSize(float size)
Parameters
sizefloatFont size in points.
Returns
- BmFontBuilder
This builder.
WithSpacing(int)
Sets uniform glyph spacing in the atlas.
public BmFontBuilder WithSpacing(int both)
Parameters
bothintGap in pixels for both axes.
Returns
- BmFontBuilder
This builder.
WithSpacing(int, int)
Sets the gap between glyphs in the atlas.
public BmFontBuilder WithSpacing(int horizontal, int vertical)
Parameters
Returns
- BmFontBuilder
This builder.
WithSuperSampling(int)
Sets the super-sampling level (1 = off, 2 = 2x, 4 = 4x). Higher values give smoother edges.
public BmFontBuilder WithSuperSampling(int level)
Parameters
levelintSuper-sampling multiplier.
Returns
- BmFontBuilder
This builder.
WithSystemFont(string)
Uses a system-installed font by family name (e.g., "Arial").
public BmFontBuilder WithSystemFont(string familyName)
Parameters
familyNamestringFont family name.
Returns
- BmFontBuilder
This builder.
WithTextureFormat(TextureFormat)
Sets the output texture format (PNG, TGA, or DDS).
public BmFontBuilder WithTextureFormat(TextureFormat format)
Parameters
formatTextureFormatTexture format.
Returns
- BmFontBuilder
This builder.
WithVariationAxis(string, float)
Sets a variable font axis value (e.g., "wght" = 700 for bold weight).
public BmFontBuilder WithVariationAxis(string tag, float value)
Parameters
Returns
- BmFontBuilder
This builder.