From 82bfc41d0c84453443c3f079b94809d862cf4777 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 29 Sep 2023 19:02:25 +0200 Subject: [PATCH] UI: Allow Separate Configuration of Subpixel Antialiasing Separate user configuration of subpixel antialiasing from the hinting options. For example, this allows turning this on while hinting is "None", or off when hinting is "Full". Pull Request: https://projects.blender.org/blender/blender/pulls/113027 --- scripts/startup/bl_ui/space_userpref.py | 1 + source/blender/blenfont/BLF_api.h | 2 ++ source/blender/blenfont/intern/blf_glyph.cc | 4 ++-- source/blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenloader/intern/versioning_userdef.cc | 4 ++++ source/blender/editors/interface/interface_style.cc | 5 ++++- source/blender/makesdna/DNA_userdef_types.h | 2 ++ source/blender/makesrna/intern/rna_userdef.cc | 6 ++++++ 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/startup/bl_ui/space_userpref.py b/scripts/startup/bl_ui/space_userpref.py index aa924c3dadf..c4c5c91a983 100644 --- a/scripts/startup/bl_ui/space_userpref.py +++ b/scripts/startup/bl_ui/space_userpref.py @@ -235,6 +235,7 @@ class USERPREF_PT_interface_text(InterfacePanel, CenterAlignMixIn, Panel): flow.prop(view, "use_text_antialiasing", text="Anti-Aliasing") sub = flow.column() sub.active = view.use_text_antialiasing + sub.prop(view, "use_text_render_subpixelaa", text="Subpixel Anti-Aliasing") sub.prop(view, "text_hinting", text="Hinting") flow.prop(view, "font_path_ui") diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 3d7dc246a68..639a78ac3e6 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -349,6 +349,8 @@ enum { BLF_BAD_FONT = 1 << 16, /** This font is managed by the FreeType cache subsystem. */ BLF_CACHED = 1 << 17, + /** At small sizes glyphs are rendered at multiple subpixel positions. */ + BLF_RENDER_SUBPIXELAA = 1 << 18, }; #define BLF_DRAW_STR_DUMMY_MAX 1024 diff --git a/source/blender/blenfont/intern/blf_glyph.cc b/source/blender/blenfont/intern/blf_glyph.cc index 2b15213ae96..b3741b09356 100644 --- a/source/blender/blenfont/intern/blf_glyph.cc +++ b/source/blender/blenfont/intern/blf_glyph.cc @@ -1121,8 +1121,8 @@ GlyphBLF *blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, const uint charcode #ifdef BLF_SUBPIXEL_AA GlyphBLF *blf_glyph_ensure_subpixel(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int32_t pen_x) { - if ((font->flags & (BLF_HINTING_NONE | BLF_MONOCHROME)) != 0) { - /* Not if we are in mono mode (aliased) or if not hinting. */ + if (!(font->flags & BLF_RENDER_SUBPIXELAA) || (font->flags & BLF_MONOCHROME)) { + /* Not if we are in mono mode (aliased) or the feature is turned off. */ return g; } diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 43ad961a726..de9050a1c95 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -29,7 +29,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 31 +#define BLENDER_FILE_SUBVERSION 32 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenloader/intern/versioning_userdef.cc b/source/blender/blenloader/intern/versioning_userdef.cc index a22b3de7970..7e785184212 100644 --- a/source/blender/blenloader/intern/versioning_userdef.cc +++ b/source/blender/blenloader/intern/versioning_userdef.cc @@ -881,6 +881,10 @@ void blo_do_versions_userdef(UserDef *userdef) userdef->animation_flag |= USER_ANIM_SHOW_CHANNEL_GROUP_COLORS; } + if (!USER_VERSION_ATLEAST(400, 32)) { + userdef->text_render |= USER_TEXT_RENDER_SUBPIXELAA; + } + /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc index 13905b15438..1b0bf8bb5ac 100644 --- a/source/blender/editors/interface/interface_style.cc +++ b/source/blender/editors/interface/interface_style.cc @@ -440,7 +440,7 @@ void uiStyleInit() /* Set default flags based on UI preferences (not render fonts) */ { const int flag_disable = (BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT | - BLF_HINTING_FULL); + BLF_HINTING_FULL | BLF_RENDER_SUBPIXELAA); int flag_enable = 0; if (U.text_render & USER_TEXT_HINTING_NONE) { @@ -456,6 +456,9 @@ void uiStyleInit() if (U.text_render & USER_TEXT_DISABLE_AA) { flag_enable |= BLF_MONOCHROME; } + if (U.text_render & USER_TEXT_RENDER_SUBPIXELAA) { + flag_enable |= BLF_RENDER_SUBPIXELAA; + } LISTBASE_FOREACH (uiFont *, font, &U.uifonts) { if (font->blf_id != -1) { diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index de62076126d..416e6168132 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -1338,6 +1338,8 @@ typedef enum eText_Draw_Options { USER_TEXT_HINTING_NONE = (1 << 1), USER_TEXT_HINTING_SLIGHT = (1 << 2), USER_TEXT_HINTING_FULL = (1 << 3), + + USER_TEXT_RENDER_SUBPIXELAA = (1 << 4), } eText_Draw_Options; /** diff --git a/source/blender/makesrna/intern/rna_userdef.cc b/source/blender/makesrna/intern/rna_userdef.cc index 34c38f874db..032449edca7 100644 --- a/source/blender/makesrna/intern/rna_userdef.cc +++ b/source/blender/makesrna/intern/rna_userdef.cc @@ -5180,6 +5180,12 @@ static void rna_def_userdef_view(BlenderRNA *brna) prop, "Text Anti-Aliasing", "Smooth jagged edges of user interface text"); RNA_def_property_update(prop, 0, "rna_userdef_text_update"); + prop = RNA_def_property(srna, "use_text_render_subpixelaa", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "text_render", USER_TEXT_RENDER_SUBPIXELAA); + RNA_def_property_ui_text( + prop, "Text Subpixel Anti-Aliasing", "Render text for optimal horizontal placement"); + RNA_def_property_update(prop, 0, "rna_userdef_text_update"); + prop = RNA_def_property(srna, "text_hinting", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, nullptr, "text_render"); RNA_def_property_enum_items(prop, text_hinting_items);