New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Variable font weight support for variable OTF fonts #7477
Comments
I am not sure how this would translate into Freetype directives or if Freetype can handle it. Have you looked into it? |
As a quick workaround, there are some ready to use fixed versions of Cantarell in the Debian package, e.g., the .deb file here https://ftp.debian.org/debian/pool/main/f/fonts-cantarell/. That said, variable font support would be nice. |
I briefly looked into it and it looks like variable font parameters are controlled via FreeType's Multiple Masters interface. It looks non-trivial to work with due to its flexible nature. (Although maybe a lot of it can be ignored if we narrow the scope to OpenType variable fonts?) Additional flags would not be a great solution. Variable fonts expose much more than just weight, and a lot of the point of their existence is that the values are continuous rather than discrete. (See the examples at the top of this page.) Exposing The easiest route might be to just offer a callback for users to further customize the Or if we want to go a step further we could offer in-box customization of the registered OpenType axis tags -- see also MDN. (My assumption is that most variable fonts are OpenType fonts because that's what the web supports.) The main issue would be how to get this information to the struct ImFontConfig
{
//...
unsigned int FontBuilderFlags; // 0 // Settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure.
void* FontBuilderSettings; // NULL // Settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. THE POINTER NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Leave as NULL if unsure.
//...
}; struct ImGuiFreeTypeBuilderSettings
{
// Variable font axis values (Only used for variable OpenType fonts!)
float Weight; // 400 // wght
float Width; // 100 // wdth
float Slant; // 0 // slnt
float Italic; // 0 // ital
// opsz is intentionally omitted, my understanding is it's meant to be controlled programatically based on DPI outside of unusual circumstances that advanced users could handle in the callback.
void (*AdvancedCustomizationCallback)(FT_Face face, const ImFontConfig& cfg, ImGuiFreeTypeBuilderFlags atlas_flags);
}; This has the minor downside of needing to keep the |
Version/Branch of Dear ImGui:
Version 1.90.2, Branch: master
Back-ends:
imgui_impl_GLFW.cpp + imgui_impl_Vulkan.cpp
Compiler, OS:
Windows 11 + (MinGW's GCC / Clang(MSVC) / Clang(MInGW) / MSVC)
Full config/build information:
Details:
Feature Request
Hi! I'm loading Catarell font from GNOME FOUNDATION (Link), using imgui_freetype. It was loaded perfectly but I've noticed that the font weight is too thin and it didn't match my expectation. I've tried specifying
FontBuilderFlags
inImFontConfig
, whereImGuiFreeTypeBuilderFlags_Bold
made the font thicker than expectation, andImGuiFreeTypeBuilderFlags_ForceAutoHint
simply didn't affect the font weight.Since the Catarell font is a VARIABLE Opentype font, as described in the release page, I'm requesting for a feature that adds more control over font weight for the freetype rasterizer.
ImFontConfig
, eg. usingenum ImFontWeight
(Explanation: it's often the case where regular stands for font weight 400, and bold stands for font weight 500)
or
ImFontConfig cfg; cfg.FontWeight = 500;
ImGuiFreeTypeBuilderFlags
in headerimgui_freetype.h
and add support in the implementationAdditional Info
Resolution and size of my monitor: 2560*1600, 16 inches
Windows DPI: 150%
Screenshots/Video:
Regular
Thinner than I expected
Bold
With
ImGuiFreeTypeBuilderFlags_Bold
specified inImFontConfig
:This bolds too much, more than I expected.
The whole idea about this feature request is to have more control over the font weight, if the font supports, so that I can tweak to have effects I expected.
Minimal, Complete and Verifiable Example code:
Regular
Bold
(Explanation:
scale
stands for content scale acquired from GLFW api)The text was updated successfully, but these errors were encountered: