Fonts and code ligatures¶
The fonts the editor draws with: which ship with it, where it finds font files, how large its text is, and the
ligatures of its code font. A theme names the families and the base size (theme_fonts in
conjure/editor/theme.h). The per-user uiScale and codeLigatures settings live in
conjure/editor/user_settings.h, and conjure/editor/ui/theme_applier.h works out the scale and loads the fonts.
| Name | Fonts and code ligatures |
| Module | Editor |
#include |
conjure/editor/theme.h, conjure/editor/ui/theme_applier.h, conjure/editor/user_settings.h |
| Engineering Handbook | User Interface |
Syntax¶
The UI scale for a setting, a monitor, and a display density, as ui::editor_ui_scale() works it out.
The values in the comments come from the test "editor_ui_scale_for - the user's uiScale times the OS scale over the
framebuffer scale" in tests/editor/ui/test_theme_applier.cpp.
#include "conjure/editor/ui/theme_applier.h"
#include "conjure/editor/user_settings.h"
using namespace conjure;
using namespace conjure::editor;
// A Windows or X11 display at 150 %: the monitor's OS scale is 1.5 and the framebuffer is as large as the window
// (density 1), so the editor's sizes and text grow by half: 1.5 at the default setting, 1.875 at 125 %.
f32 scale_on_a_150_percent_display(u32 uiScalePercent) {
return ui::editor_ui_scale_for(uiScalePercent, 1.5f, 1.0f);
}
// A Retina screen or a scaled Wayland output: an OS scale of 2 and a density of 2 give 1, so the layout keeps its
// size and the glyphs are rasterised finer.
f32 scale_on_a_retina_display() {
return ui::editor_ui_scale_for(DEFAULT_UI_SCALE, 2.0f, 2.0f);
}
At a glance¶
| If you want to... | Then use... |
|---|---|
| choose the UI or the code font | fonts.ui and fonts.mono in a theme |
| use another font, or another version of a bundled one | copy its files into <user config>/fonts, then press Reload on the Font files row of the Theme editor (Font files and the lookup order) |
| make the editor's text and controls larger or smaller | uiScale in editor_settings.json, 50 to 300 percent (Sizes and the UI scale) |
| turn the code ligatures off or on | Edit > Preferences > Code ligatures, or editor.preferences.set {codeLigatures} (Code ligatures) |
| read those preferences from a protocol client | editor.preferences.get |
| know the factors the editor scales and rasterises by | ui::editor_ui_scale(context), ui::editor_rasterizer_density(context) |
Variables and Properties¶
| Name | Access | Purpose |
|---|---|---|
std::string theme_fonts::ui, std::string theme_fonts::mono |
public | the UI and code font families a theme names |
f32 theme_fonts::size |
public | the base size in pixels at 100 %, 8 to 32 (13 in every built-in theme) |
u32 editor_user_settings::uiScale |
public | the UI scale in percent, MIN_UI_SCALE (50) to MAX_UI_SCALE (300), DEFAULT_UI_SCALE (100) |
bool editor_user_settings::codeLigatures |
public | whether the code font's ligatures are drawn; true by default |
std::string_view DEFAULT_UI_FONT, std::string_view DEFAULT_MONO_FONT |
constant | "Inter" and "Fira Code", the families every built-in theme names |
Bundled fonts¶
The editor ships three families in the fonts folder next to its executable (bin/fonts, or
bin/<configuration>/fonts with a multi-configuration generator). Each family comes in the Regular, Medium and
SemiBold weights, with its licence beside it (LICENSE-<Family>.txt, the SIL Open Font License 1.1).
| Family | Files | Role |
|---|---|---|
| Inter 4.1 | Inter-Regular.ttf, Inter-Medium.ttf, Inter-SemiBold.ttf |
fonts.ui of every built-in theme (DEFAULT_UI_FONT) |
| Fira Code 6.2 | FiraCode-Regular.ttf, FiraCode-Medium.ttf, FiraCode-SemiBold.ttf |
fonts.mono of every built-in theme (DEFAULT_MONO_FONT) |
| JetBrains Mono 2.304 | JetBrainsMono-Regular.ttf, JetBrainsMono-Medium.ttf, JetBrainsMono-SemiBold.ttf |
a code family a theme may name instead |
The bundled fonts belong to the editor. A Distribution build neither downloads nor installs them, and an exported game never carries them.
Font files and the lookup order¶
The editor looks for a family's files in two folders, in this order (theme_applier::font_folders):
<user configuration folder>/fonts, when the editor has a user configuration folder;- the
fontsfolder next to the editor's executable, which holds the bundled fonts.
The user folder is searched first, so a file there also replaces a bundled family of the same name.
- File names. A family's file is
<Family>-Regular.ttfor<Family>.ttf(.otfalike), the family compared without spaces, hyphens, underscores, or letter case:FiraCode-Regular.ttfis "Fira Code". Inside one folder,-Regularcomes before the bare family and.ttfbefore.otf. - Weights. The Medium and SemiBold weights (
<Family>-Medium,<Family>-SemiBold) are read from the folder of the family's chosen Regular file, so a family's weights always come from one place. A missing weight falls back to Regular with one warning. - Checks. A file is checked before the rasteriser reads it. It is refused, with one warning naming it, when it
is larger than 32 MiB, is not a font, is cut short, is a collection (
.ttc), has CFF outlines (an OpenType font whose outlines are not TrueType), has no Unicode character map of format 4 or 12, or has tables the rasteriser could not read safely (an em outside 16 to 16384 units, glyphs outside the glyph table). The family's next file in the order above is tried then. - Fallbacks. A family without a usable file falls back as
resolve_theme_fontssays: to the default family (Inter or Fira Code), else to the first family available, with one warning naming every replacement. With no usable file at all, ImGui's built-in font serves every text style, so the UI never goes blank. - Characters. The editor bakes U+0020 to U+00FF, the ellipsis (U+2026) and the arrow (U+2192). A character outside them draws as ImGui's fallback glyph.
Important
After copying font files into <user config>/fonts, press Reload on the Fonts section's Font files row in the
Theme editor (theme_applier::reload_fonts), or start the editor again. Files are not watched.
Sizes and the UI scale¶
The widget kit sets its text in ten type roles, sized in CSS pixels per em at
fonts.size 13 and a UI scale of 100 %:
| Role | Size | Weight | Used for |
|---|---|---|---|
CAPTION |
11 | Regular | the status bar, footers, captions, overlay text |
BODY |
12 | Regular | rows, tabs, labels, text fields |
CONTROL |
12 | Medium | buttons, menu items |
HEADING |
12 | SemiBold | panel and section headers |
TITLE |
13 | Regular | the inspector's entity name |
BADGE |
10 | Regular | tab badges |
AXIS |
10 | SemiBold | axis tags |
MONO |
12 | Regular (code font) | values and paths |
MONO_SMALL |
11 | Regular (code font) | chips, the status bar's frame rate |
LOG |
11.5 | Regular (code font) | console lines |
Every text size, and every widget size measured around the text, is multiplied by the kit's scale:
fonts.size / 13 times the UI scale, held between 0.25 and 6 (kit::kit_scale). One clamp for both keeps the text
inside the widgets at every scale. A fonts.size that is not a positive number counts as 13.
The UI scale is ui::editor_ui_scale(context), which ui::editor_ui_scale_for computes as:
UI scale = uiScale / 100 x the OS UI scale of the monitor under the window's centre / the rasteriser density
uiScaleis the per-user setting, a whole percentage from 50 to 300, default 100, held in that range.- The monitor's OS UI scale is the display scale the operating system gives the monitor (1.5 for a Windows display at 150 %).
- The rasteriser density (
ui::editor_rasterizer_density) is the window's framebuffer width over its window width: 1 on Windows and X11, 2 on a Retina screen. ImGui works in window coordinates, so a finer framebuffer is served by a finer raster rather than by larger sizes.
The scale is read again every frame, so a window dragged to a monitor with another scale is followed in the next frame; Windows raises no event for such a move. Without a window (headless) both scales are 1. When the scale changes, the editor applies the theme again in that frame and bakes its fonts again at the end of it.
Note
The editor reads editor_settings.json when it starts, and no command sets the UI scale: edit uiScale in the
file and start the editor again. A value outside 50 to 300 makes the file unusable, so the defaults apply with one
warning, and the next save first copies the file to editor_settings.json.bak. editor.preferences.get reports
the uiScale setting the editor uses.
The GPU's texture limit. All the editor's text lives in one font texture, which must fit the largest texture
the GPU takes (ui::editor_max_texture_size(context): the device's limit, 16384 without one). When it would not fit,
the editor gives way one step at a time, with one warning per step: first the code ligatures, then sharpness (the
text keeps its size and place but is rasterised less finely), and only past that ImGui's built-in font.
theme_applier::set_font_texture_cap(cap) lowers the limit further, for an embedder that saves memory; it never
raises it. A cap below 512 cannot be met, since ImGui's narrowest font texture is 512 wide.
A legacy module panel's stock ImGui widgets draw with the UI and code fonts at fonts.size, and ignore the UI
scale.
Code ligatures¶
Fira Code is the default code font for its programming ligatures (==, !=, ->, <=>, =>). Dear ImGui draws
one glyph per character and shapes no text, so the editor replays the font's contextual alternates (its calt
feature) itself whenever it draws code text in the MONO, MONO_SMALL, and LOG roles, provided the code font
has a font file of its own whose alternates pass the checks below. Every alternate keeps its character's cell, so
columns, carets, selections, and text widths never change, and copy, paste, and the log always see the characters you
typed. Ligatures show while a field is being edited too.
- On by default. Edit > Preferences > Code ligatures turns them off and on. The menu item sends
editor.preferences.set {codeLigatures}, which saves the choice ineditor_settings.jsonat once; the change shows in the next frame, without baking the fonts again. - Other code fonts. JetBrains Mono's alternates keep their cells too, so it gets ligatures. A font whose alternates would change a character's width, whose tables are damaged, or whose alternates are too many draws its plain glyphs, with one warning naming the file.
- Limits. A style whose alternate glyphs are more than 4 em on a side, or would not fit the font texture (the GPU's texture limit), draws plain glyphs, with one warning per font file.
- Private-use characters. The alternates are stored under codepoints of the Unicode private use area. Such a character in your own text never shows an alternate: it draws as ImGui's fallback glyph, ligatures on or off.
Both preference commands are per-user UI state: not undoable, no revision, and, unlike editor.theme.*, no event.
editor.preferences.set works headless too, since it only stores a setting. persisted is false without a user
configuration folder, or when the file cannot be written (one warning; the choice then lasts for the session).
-> {"id":3,"cmd":"editor.preferences.set","args":{"codeLigatures":false}}
<- {"id":3,"ok":true,"result":{"activeTheme":"Midnight","uiScale":100,"codeLigatures":false,"persisted":true}}
-> {"id":4,"cmd":"editor.preferences.get","args":{}}
<- {"id":4,"ok":true,"result":{"activeTheme":"Midnight","uiScale":100,"codeLigatures":false}}
Functions¶
| Signature | Purpose |
|---|---|
f32 ui::editor_ui_scale(const editor_context &context) |
the UI scale the kit's sizes and text take |
f32 ui::editor_ui_scale_for(u32 uiScalePercent, f32 monitorScale, f32 rasterizerDensity) |
the same scale from its three inputs; pure |
f32 ui::editor_rasterizer_density(const editor_context &context) |
how much finer than the window the glyphs are rasterised |
u32 ui::editor_max_texture_size(const editor_context &context) |
the GPU's largest texture side; 16384 without a device |
u32 ui::theme_applier::font_texture_limit(const editor_context &context) const |
the limit the font texture fits: the GPU's, lowered to the cap |
void ui::theme_applier::set_font_texture_cap(u32 cap), u32 font_texture_cap() const |
a cap below the GPU's limit; 0 for none |
std::vector<std::filesystem::path> ui::theme_applier::font_folders(const editor_context &context) const |
the folders searched for font files, in order |
void ui::theme_applier::set_font_folders(std::vector<std::filesystem::path> folders) |
other font folders, for tests and embedders; an empty list restores the defaults |
void ui::theme_applier::reload_fonts() |
reads the font files again at the next load_fonts() |
bool ui::theme_applier::fonts_due(const editor_context &context) const |
whether the font atlas must be baked again |
bool ui::theme_applier::load_fonts(editor_context &context) |
bakes the fonts again when they are due |
const theme_fonts &ui::theme_applier::loaded_fonts() const |
the families the last load_fonts() baked |
theme_fonts resolve_theme_fonts(const theme &value, std::span<const std::string_view> available) |
the families loaded, with one warning for every replacement |
f32 kit::kit_scale(f32 fontSize, f32 uiScale), f32 kit::kit_font_size(f32 fontSize) |
the widget kit's scale |
editor.preferences.get {}, editor.preferences.set {codeLigatures} |
the preferences from a protocol client |
See also:
- 📘 API: Themes, The widget kit, The workspace UI
- 📘 API: The AI control protocol, Headless mode and the command model
- 🛠 Handbook: User Interface, Widget Kit, Editor Architecture