Skip to content

Commit d33b79a

Browse files
fix: nk_font_config oversampling 3x horizontaly by default
See linked issue for very detailed explanation. According to the commit that intoroduced this, it was suppoused to: "oversample the default font to make it look better" but it was oversampling every single font, potentially making it blurry. This fix preserves old behavior for code that may still expect it, but nk_font_config will now use oversample_h=1 by default. Some demos achieve sharp font by scalling their pixel_size and in this case there won't be any difference, but if someone used badly bahaving font and didn't notice it only worked because of oversampling, that font may now appear differently (this is unlikely but still possible). Fixes: #855 Refs: 1d7f024
1 parent e634a0d commit d33b79a

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

nuklear.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17713,7 +17713,7 @@ nk_font_config(float pixel_height)
1771317713
cfg.ttf_size = 0;
1771417714
cfg.ttf_data_owned_by_atlas = 0;
1771517715
cfg.size = pixel_height;
17716-
cfg.oversample_h = 3;
17716+
cfg.oversample_h = 1;
1771717717
cfg.oversample_v = 1;
1771817718
cfg.pixel_snap = 0;
1771917719
cfg.coord_type = NK_COORD_UV;
@@ -18021,9 +18021,21 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
1802118021

1802218022
#ifdef NK_INCLUDE_DEFAULT_FONT
1802318023
/* no font added so just use default font */
18024-
if (!atlas->font_num)
18025-
atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0);
18024+
/* FIXME(sleeptightAnsiC): This "fallback" exists for compatibility
18025+
* with code that creates empty atlas and immediately bakes it.
18026+
* Several demos do this, but it doesn't make sense for API to allow it.
18027+
* It was never documented anywhere and it's more of a hack than feature.
18028+
* App/backend should call nk_font_atlas_add_default() on it's own
18029+
* with whatever config it wants, and treat it like any other font.
18030+
* Worth to consider this for removal during next major release... */
18031+
if (!atlas->font_num) {
18032+
struct nk_font_config config;
18033+
config = nk_font_config(0);
18034+
config.oversample_h = 3;
18035+
atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, &config);
18036+
}
1802618037
#endif
18038+
1802718039
NK_ASSERT(atlas->font_num);
1802818040
if (!atlas->font_num) return 0;
1802918041

src/nuklear_font.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ nk_font_config(float pixel_height)
865865
cfg.ttf_size = 0;
866866
cfg.ttf_data_owned_by_atlas = 0;
867867
cfg.size = pixel_height;
868-
cfg.oversample_h = 3;
868+
cfg.oversample_h = 1;
869869
cfg.oversample_v = 1;
870870
cfg.pixel_snap = 0;
871871
cfg.coord_type = NK_COORD_UV;
@@ -1173,9 +1173,21 @@ nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height,
11731173

11741174
#ifdef NK_INCLUDE_DEFAULT_FONT
11751175
/* no font added so just use default font */
1176-
if (!atlas->font_num)
1177-
atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0);
1176+
/* FIXME(sleeptightAnsiC): This "fallback" exists for compatibility
1177+
* with code that creates empty atlas and immediately bakes it.
1178+
* Several demos do this, but it doesn't make sense for API to allow it.
1179+
* It was never documented anywhere and it's more of a hack than feature.
1180+
* App/backend should call nk_font_atlas_add_default() on it's own
1181+
* with whatever config it wants, and treat it like any other font.
1182+
* Worth to consider this for removal during next major release... */
1183+
if (!atlas->font_num) {
1184+
struct nk_font_config config;
1185+
config = nk_font_config(0);
1186+
config.oversample_h = 3;
1187+
atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, &config);
1188+
}
11781189
#endif
1190+
11791191
NK_ASSERT(atlas->font_num);
11801192
if (!atlas->font_num) return 0;
11811193

0 commit comments

Comments
 (0)