@@ -108,6 +108,7 @@ namespace ImFontManager
108
108
BLFontFace FontFace[FT_Total];
109
109
#endif
110
110
FontCollectionFile Files;
111
+ bool AutoScale = false ;
111
112
};
112
113
113
114
struct FontMatchInfo
@@ -170,12 +171,13 @@ namespace ImFontManager
170
171
}
171
172
}
172
173
173
- bool LoadFonts (std::string_view family, const FontCollectionFile& files, float size, ImFontConfig config)
174
+ bool LoadFonts (std::string_view family, const FontCollectionFile& files, float size, ImFontConfig config, bool autoScale )
174
175
{
175
176
ImGuiIO& io = ImGui::GetIO ();
176
177
FontStore[family].Files = files;
177
178
178
179
auto & ffamily = FontStore[family];
180
+ ffamily.AutoScale = autoScale;
179
181
LoadFont (io, ffamily, FT_Normal, size, config, 0 );
180
182
181
183
#ifdef IMGUI_ENABLE_FREETYPE
@@ -234,10 +236,10 @@ namespace ImFontManager
234
236
#endif
235
237
236
238
#ifdef IM_RICHTEXT_TARGET_IMGUI
237
- static void LoadDefaultProportionalFont (float sz, const ImFontConfig& fconfig)
239
+ static void LoadDefaultProportionalFont (float sz, const ImFontConfig& fconfig, bool autoScale )
238
240
{
239
241
#ifdef _WIN32
240
- LoadFonts (IM_RICHTEXT_DEFAULT_FONTFAMILY, { WINDOWS_DEFAULT_FONT }, sz, fconfig);
242
+ LoadFonts (IM_RICHTEXT_DEFAULT_FONTFAMILY, { WINDOWS_DEFAULT_FONT }, sz, fconfig, autoScale );
241
243
#elif __linux__
242
244
std::filesystem::path fedoradir = " /usr/share/fonts/open-sans" ;
243
245
std::filesystem::path ubuntudir = " /usr/share/fonts/truetype/freefont" ;
@@ -250,10 +252,10 @@ namespace ImFontManager
250
252
// TODO: Add default fonts for other platforms
251
253
}
252
254
253
- static void LoadDefaultMonospaceFont (float sz, const ImFontConfig& fconfig)
255
+ static void LoadDefaultMonospaceFont (float sz, const ImFontConfig& fconfig, bool autoScale )
254
256
{
255
257
#ifdef _WIN32
256
- LoadFonts (IM_RICHTEXT_MONOSPACE_FONTFAMILY, { WINDOWS_DEFAULT_MONOFONT }, sz, fconfig);
258
+ LoadFonts (IM_RICHTEXT_MONOSPACE_FONTFAMILY, { WINDOWS_DEFAULT_MONOFONT }, sz, fconfig, autoScale );
257
259
#elif __linux__
258
260
std::filesystem::path fedoradir = " /usr/share/fonts/liberation-mono" ;
259
261
std::filesystem::path ubuntudir = " /usr/share/fonts/truetype/freefont" ;
@@ -305,7 +307,8 @@ namespace ImFontManager
305
307
using ImWchar = uint32_t ;
306
308
#endif
307
309
308
- static bool LoadDefaultFonts (float sz, const FontFileNames* names, bool skipProportional, bool skipMonospace, const ImWchar* glyphs)
310
+ static bool LoadDefaultFonts (float sz, const FontFileNames* names, bool skipProportional, bool skipMonospace,
311
+ bool autoScale, const ImWchar* glyphs)
309
312
{
310
313
#ifdef IM_RICHTEXT_TARGET_IMGUI
311
314
ImFontConfig fconfig;
@@ -328,8 +331,8 @@ namespace ImFontManager
328
331
if (names == nullptr )
329
332
{
330
333
#ifdef IM_RICHTEXT_TARGET_IMGUI
331
- if (!skipProportional) LoadDefaultProportionalFont (sz, fconfig);
332
- if (!skipMonospace) LoadDefaultMonospaceFont (sz, fconfig);
334
+ if (!skipProportional) LoadDefaultProportionalFont (sz, fconfig, autoScale );
335
+ if (!skipMonospace) LoadDefaultMonospaceFont (sz, fconfig, autoScale );
333
336
#endif
334
337
#ifdef IM_RICHTEXT_TARGET_BLEND2D
335
338
if (!skipProportional) LoadDefaultProportionalFont (sz);
@@ -367,7 +370,7 @@ namespace ImFontManager
367
370
files.Files [FT_Italics] = copyFileName (names->Proportional .Files [FT_Italics], baseFontPath, startidx);
368
371
files.Files [FT_BoldItalics] = copyFileName (names->Proportional .Files [FT_BoldItalics], baseFontPath, startidx);
369
372
#ifdef IM_RICHTEXT_TARGET_IMGUI
370
- LoadFonts (IM_RICHTEXT_DEFAULT_FONTFAMILY, files, sz, fconfig);
373
+ LoadFonts (IM_RICHTEXT_DEFAULT_FONTFAMILY, files, sz, fconfig, autoScale );
371
374
#endif
372
375
#ifdef IM_RICHTEXT_TARGET_BLEND2D
373
376
LoadFonts (IM_RICHTEXT_DEFAULT_FONTFAMILY, files, sz);
@@ -376,7 +379,7 @@ namespace ImFontManager
376
379
else
377
380
{
378
381
#ifdef IM_RICHTEXT_TARGET_IMGUI
379
- if (!skipProportional) LoadDefaultProportionalFont (sz, fconfig);
382
+ if (!skipProportional) LoadDefaultProportionalFont (sz, fconfig, autoScale );
380
383
#endif
381
384
#ifdef IM_RICHTEXT_TARGET_BLEND2D
382
385
if (!skipProportional) LoadDefaultProportionalFont (sz);
@@ -390,7 +393,7 @@ namespace ImFontManager
390
393
files.Files [FT_Italics] = copyFileName (names->Monospace .Files [FT_Italics], baseFontPath, startidx);
391
394
files.Files [FT_BoldItalics] = copyFileName (names->Monospace .Files [FT_BoldItalics], baseFontPath, startidx);
392
395
#ifdef IM_RICHTEXT_TARGET_IMGUI
393
- LoadFonts (IM_RICHTEXT_MONOSPACE_FONTFAMILY, files, sz, fconfig);
396
+ LoadFonts (IM_RICHTEXT_MONOSPACE_FONTFAMILY, files, sz, fconfig, autoScale );
394
397
#endif
395
398
#ifdef IM_RICHTEXT_TARGET_BLEND2D
396
399
LoadFonts (IM_RICHTEXT_MONOSPACE_FONTFAMILY, files, sz);
@@ -399,7 +402,7 @@ namespace ImFontManager
399
402
else
400
403
{
401
404
#ifdef IM_RICHTEXT_TARGET_IMGUI
402
- if (!skipMonospace) LoadDefaultMonospaceFont (sz, fconfig);
405
+ if (!skipMonospace) LoadDefaultMonospaceFont (sz, fconfig, autoScale );
403
406
#endif
404
407
#ifdef IM_RICHTEXT_TARGET_BLEND2D
405
408
if (!skipMonospace) LoadDefaultMonospaceFont (sz);
@@ -439,7 +442,8 @@ namespace ImFontManager
439
442
440
443
for (auto sz : sizes)
441
444
{
442
- LoadDefaultFonts (sz, names, !(flt & FLT_Proportional), !(flt & FLT_Monospace), glyphrange);
445
+ LoadDefaultFonts (sz, names, !(flt & FLT_Proportional), !(flt & FLT_Monospace),
446
+ flt & FLT_AutoScale, glyphrange);
443
447
}
444
448
445
449
#ifdef IM_RICHTEXT_TARGET_IMGUI
@@ -451,21 +455,22 @@ namespace ImFontManager
451
455
#ifndef IM_FONTMANAGER_STANDALONE
452
456
std::vector<float > GetFontSizes (const RenderConfig& config, uint64_t flt)
453
457
{
454
- std::unordered_set<float > sizes;
455
- sizes.insert (config.DefaultFontSize * config.FontScale );
456
-
457
- if (flt & FLT_HasSubscript) sizes.insert (config.DefaultFontSize * config.ScaleSubscript * config.FontScale );
458
- if (flt & FLT_HasSuperscript) sizes.insert (config.DefaultFontSize * config.ScaleSuperscript * config.FontScale );
459
- if (flt & FLT_HasSmall) sizes.insert (config.DefaultFontSize * 0 .8f * config.FontScale );
460
- if (flt & FLT_HasH1) sizes.insert (config.HFontSizes [0 ] * config.FontScale );
461
- if (flt & FLT_HasH2) sizes.insert (config.HFontSizes [1 ] * config.FontScale );
462
- if (flt & FLT_HasH3) sizes.insert (config.HFontSizes [2 ] * config.FontScale );
463
- if (flt & FLT_HasH4) sizes.insert (config.HFontSizes [3 ] * config.FontScale );
464
- if (flt & FLT_HasH5) sizes.insert (config.HFontSizes [4 ] * config.FontScale );
465
- if (flt & FLT_HasH6) sizes.insert (config.HFontSizes [5 ] * config.FontScale );
466
- if (flt & FLT_HasHeaders) for (auto sz : config.HFontSizes ) sizes.insert (sz * config.FontScale );
467
-
468
- return std::vector<float >{ sizes.begin (), sizes.end () };
458
+ std::vector<float > sizes;
459
+ sizes.push_back (config.DefaultFontSize * config.FontScale );
460
+
461
+ if (flt & FLT_HasSubscript) sizes.push_back (config.DefaultFontSize * config.ScaleSubscript * config.FontScale );
462
+ if (flt & FLT_HasSuperscript) sizes.push_back (config.DefaultFontSize * config.ScaleSuperscript * config.FontScale );
463
+ if (flt & FLT_HasSmall) sizes.push_back (config.DefaultFontSize * 0 .8f * config.FontScale );
464
+ if (flt & FLT_HasH1) sizes.push_back (config.HFontSizes [0 ] * config.FontScale );
465
+ if (flt & FLT_HasH2) sizes.push_back (config.HFontSizes [1 ] * config.FontScale );
466
+ if (flt & FLT_HasH3) sizes.push_back (config.HFontSizes [2 ] * config.FontScale );
467
+ if (flt & FLT_HasH4) sizes.push_back (config.HFontSizes [3 ] * config.FontScale );
468
+ if (flt & FLT_HasH5) sizes.push_back (config.HFontSizes [4 ] * config.FontScale );
469
+ if (flt & FLT_HasH6) sizes.push_back (config.HFontSizes [5 ] * config.FontScale );
470
+ if (flt & FLT_HasHeaders) for (auto sz : config.HFontSizes ) sizes.push_back (sz * config.FontScale );
471
+ std::sort (sizes.begin (), sizes.end ());
472
+
473
+ return (flt & FLT_AutoScale) ? std::vector<float >{ *(--sizes.end ()) } : sizes;
469
474
}
470
475
#endif
471
476
@@ -904,7 +909,7 @@ namespace ImFontManager
904
909
{
905
910
for (const auto & entry : std::filesystem::directory_iterator{ path })
906
911
{
907
- if (entry.is_regular_file () && entry.path ().extension () == " .TTF " )
912
+ if (entry.is_regular_file () && entry.path ().extension () == " .ttf " )
908
913
{
909
914
ProcessFileEntry (entry, false );
910
915
@@ -968,16 +973,23 @@ namespace ImFontManager
968
973
return famit;
969
974
}
970
975
971
- void * GetFont (std::string_view family, float size, FontType ft, void * )
976
+ void * GetFont (std::string_view family, float size, FontType ft)
972
977
{
973
978
auto famit = LookupFontFamily (family);
974
979
const auto & fonts = famit->second .FontPtrs [ft];
975
980
auto szit = fonts.find (size);
976
981
977
982
if (szit == fonts.end () && !fonts.empty ())
978
983
{
979
- szit = fonts.lower_bound (size);
980
- szit = szit == fonts.begin () ? szit : std::prev (szit);
984
+ if (famit->second .AutoScale )
985
+ {
986
+ return fonts.begin ()->second ;
987
+ }
988
+ else
989
+ {
990
+ szit = fonts.lower_bound (size);
991
+ szit = szit == fonts.begin () ? szit : std::prev (szit);
992
+ }
981
993
}
982
994
983
995
return szit->second ;
@@ -1004,7 +1016,7 @@ namespace ImFontManager
1004
1016
PreloadFontLookupInfoImpl (timeoutMs, nullptr , 0 );
1005
1017
}
1006
1018
1007
- void * GetFont (std::string_view family, float size, FontType type, FontExtraInfo extra, void * )
1019
+ void * GetFont (std::string_view family, float size, FontType type, FontExtraInfo extra)
1008
1020
{
1009
1021
auto famit = FontStore.find (family);
1010
1022
0 commit comments