Skip to content

FreeType: Add variable font axes support#9199

Open
PeterDimov wants to merge 2 commits intoocornut:masterfrom
PeterDimov:freetype-variable-axes
Open

FreeType: Add variable font axes support#9199
PeterDimov wants to merge 2 commits intoocornut:masterfrom
PeterDimov:freetype-variable-axes

Conversation

@PeterDimov
Copy link

@PeterDimov PeterDimov commented Jan 26, 2026

This PR adds support for configuring variable font axes (weight, width, slant, optical size, etc.) when using the FreeType font loader.

Features

  • ImFontConfigVarAxes - New struct to specify axis values in ImFontConfig
  • IM_FONT_TAG() - Macro to create OpenType axis tags (e.g., IM_FONT_TAG('w','g','h','t') for weight)
  • ImGuiFreeType::GetFontAxes() - Utility to query axis metadata from font files
  • New example: example_win32_directx11_freetype - Interactive font preview demonstrating variable font support

Usage

// Query axes from font file
ImFontVarAxisInfo axes[16];
int axis_count = ImGuiFreeType::GetFontAxes("RobotoFlex.ttf", axes, 16);

// Configure axes when adding font
ImFontConfigVarAxis my_axes[] = {
    { IM_FONT_TAG('w','g','h','t'), 700.0f },  // Bold weight
    { IM_FONT_TAG('w','d','t','h'), 100.0f },  // Normal width
};
ImFontConfig config;
config.VarAxes.Axes = my_axes;
config.VarAxes.AxesCount = IM_ARRAYSIZE(my_axes);
io.Fonts->AddFontFromFileTTF("RobotoFlex.ttf", 16.0f, &config);

###Screenshots
These show the example app with Bahnschrift and RobotoFlex variable fonts and axes adjustments:
image
image
image

###Notes

  • Requires IMGUI_ENABLE_FREETYPE and FreeType library
  • No changes to non-FreeType code paths

@ocornut ocornut modified the milestones: v1.92, v1.93 Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants