UI: disable new text hinting from D3201 by default for now.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 14 Aug 2018 15:53:27 +0000 (17:53 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 21 Aug 2018 17:07:04 +0000 (19:07 +0200)
This changes the text hinting setting to be an enum with options
Auto / None / Slight / Full. The default is Auto which currently disables
hinting.

The hinting was tested with a new FreeType version, but this is not what
is used on the buildbots an official release environment, and the fonts
look quite bad because of that. Once FreeType has been upgraded we can
change the default.

Even then the results are not ideal, perhaps due to missing subpixel
positioning and linear color blending support in BLF.

release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf_glyph.c
source/blender/editors/interface/interface_style.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c

index e0902dd86362c4b630849866f02888096f057b39..26facd251748f163c1ebb57b9fbce95fe7ff2ac0 100644 (file)
@@ -538,9 +538,10 @@ class USERPREF_PT_system(Panel):
         col.separator()
 
         col.label(text="Text Draw Options:")
-        col.prop(system, "use_text_antialiasing")
-        if system.use_text_antialiasing:
-            col.prop(system, "use_text_hinting")
+        col.prop(system, "use_text_antialiasing", text="Anti-aliasing")
+        sub = col.column()
+        sub.active = system.use_text_antialiasing
+        sub.prop(system, "text_hinting", text="Hinting")
 
         col.separator()
 
index 9bb3dd39aa627abcc396afed75c01d170cd3bf87..0a4212ff2337dae3afcf4e81d215a82c44850823 100644 (file)
@@ -218,9 +218,11 @@ void BLF_state_print(int fontid);
 #define BLF_KERNING_DEFAULT  (1 << 3)
 #define BLF_MATRIX           (1 << 4)
 #define BLF_ASPECT           (1 << 5)
-#define BLF_HINTING          (1 << 6)
-#define BLF_WORD_WRAP        (1 << 7)
-#define BLF_MONOCHROME       (1 << 8)  /* no-AA */
+#define BLF_WORD_WRAP        (1 << 6)
+#define BLF_MONOCHROME       (1 << 7)  /* no-AA */
+#define BLF_HINTING_NONE     (1 << 8)
+#define BLF_HINTING_SLIGHT   (1 << 9)
+#define BLF_HINTING_FULL     (1 << 10)
 
 #define BLF_DRAW_STR_DUMMY_MAX 1024
 
index f1301d38ab6f68656d08a0501c3e6dcf11ac5f8e..c19c85282325dfcb2bc3ea28e2437fca73e75d81 100644 (file)
@@ -221,7 +221,6 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
        GlyphBLF *g;
        FT_Error err;
        FT_Bitmap bitmap, tempbitmap;
-       int flags = FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
        FT_BBox bbox;
        unsigned int key;
 
@@ -242,13 +241,27 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
                return g;
        }
 
-       if (font->flags & BLF_HINTING)
-               flags &= ~FT_LOAD_NO_HINTING;
-
        if (font->flags & BLF_MONOCHROME) {
                err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO);
        }
        else {
+               int flags = FT_LOAD_NO_BITMAP;
+
+               if (font->flags & BLF_HINTING_NONE) {
+                       flags |= FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING;
+               }
+               else if (font->flags & BLF_HINTING_SLIGHT) {
+                       flags |= FT_LOAD_TARGET_LIGHT;
+               }
+               else if (font->flags & BLF_HINTING_FULL) {
+                       flags |= FT_LOAD_TARGET_NORMAL;
+               }
+               else {
+                       /* Default, hinting disabled until FreeType has been upgraded
+                        * to give good results on all platforms. */
+                       flags |= FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING;
+               }
+
                err = FT_Load_Glyph(font->face, (FT_UInt)index, flags);
        }
 
index 0257fb0d428aab2cffaeff16c061b888555c48f1..c7ecc37b0bf29b21132de202a44285713b35bfd7 100644 (file)
@@ -523,30 +523,35 @@ void uiStyleInit(void)
 
        /* Set default flags based on UI preferences (not render fonts) */
        {
-               int flag_enable = 0, flag_disable = 0;
-               if ((U.text_render & USER_TEXT_DISABLE_HINTING) == 0) {
-                       flag_enable |= BLF_HINTING;
+               int flag_disable = BLF_MONOCHROME |
+                                  BLF_HINTING_NONE |
+                                  BLF_HINTING_SLIGHT |
+                                  BLF_HINTING_FULL;
+               int flag_enable = 0;
+
+               if (U.text_render & USER_TEXT_HINTING_NONE) {
+                       flag_enable |= BLF_HINTING_NONE;
                }
-               else {
-                       flag_disable |= BLF_HINTING;
+               else if (U.text_render & USER_TEXT_HINTING_SLIGHT) {
+                       flag_enable |= BLF_HINTING_SLIGHT;
+               }
+               else if (U.text_render & USER_TEXT_HINTING_FULL) {
+                       flag_enable |= BLF_HINTING_FULL;
                }
 
                if (U.text_render & USER_TEXT_DISABLE_AA) {
                        flag_enable |= BLF_MONOCHROME;
                }
-               else {
-                       flag_disable |= BLF_MONOCHROME;
-               }
 
                for (font = U.uifonts.first; font; font = font->next) {
                        if (font->blf_id != -1) {
-                               BLF_enable(font->blf_id, flag_enable);
                                BLF_disable(font->blf_id, flag_disable);
+                               BLF_enable(font->blf_id, flag_enable);
                        }
                }
                if (blf_mono_font != -1) {
-                       BLF_enable(blf_mono_font, flag_enable);
                        BLF_disable(blf_mono_font, flag_disable);
+                       BLF_enable(blf_mono_font, flag_enable);
                }
        }
 
index 6f0f97261eea250c4379e36c4e74341990b3d616..f78b48b2d25db7a958ad626ebc54ee33acd13fe5 100644 (file)
@@ -67,7 +67,7 @@ typedef struct uiFont {
        short blf_id;           /* from blfont lib */
        short uifont_id;        /* own id (eUIFont_ID) */
        short r_to_l;           /* fonts that read from left to right */
-       short hinting;
+       short pad;
 } uiFont;
 
 /* this state defines appearance of text */
@@ -805,7 +805,10 @@ typedef enum eWM_DrawMethod {
  * UserDef.text_render */
 typedef enum eText_Draw_Options {
        USER_TEXT_DISABLE_AA      = (1 << 0),
-       USER_TEXT_DISABLE_HINTING = (1 << 1),
+
+       USER_TEXT_HINTING_NONE    = (1 << 1),
+       USER_TEXT_HINTING_SLIGHT  = (1 << 2),
+       USER_TEXT_HINTING_FULL    = (1 << 3),
 } eText_Draw_Options;
 
 /* tw_flag (transform widget) */
index 315ac26c1d2708e33eee37567b8b73d3eb4d7de5..c3e30de10af8b6b31ce626dcd2804ab38ab5fcb6 100644 (file)
@@ -3973,6 +3973,14 @@ static void rna_def_userdef_system(BlenderRNA *brna)
            {0, NULL, 0, NULL, NULL}
        };
 
+       static const EnumPropertyItem text_hinting_items[] = {
+           {0, "AUTO", 0, "Auto", ""},
+           {USER_TEXT_HINTING_NONE, "NONE", 0, "None", ""},
+           {USER_TEXT_HINTING_SLIGHT, "SLIGHT", 0, "Slight", ""},
+           {USER_TEXT_HINTING_FULL, "FULL", 0, "Full", ""},
+           {0, NULL, 0, NULL, NULL}
+       };
+
        srna = RNA_def_struct(brna, "UserPreferencesSystem", NULL);
        RNA_def_struct_sdna(srna, "UserDef");
        RNA_def_struct_nested(brna, srna, "UserPreferences");
@@ -4207,9 +4215,10 @@ static void rna_def_userdef_system(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Text Anti-aliasing", "Draw user interface text anti-aliased");
        RNA_def_property_update(prop, 0, "rna_userdef_text_update");
 
-       prop = RNA_def_property(srna, "use_text_hinting", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "text_render", USER_TEXT_DISABLE_HINTING);
-       RNA_def_property_ui_text(prop, "Text Hinting", "Draw user interface text with hinting");
+       prop = RNA_def_property(srna, "text_hinting", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_bitflag_sdna(prop, NULL, "text_render");
+       RNA_def_property_enum_items(prop, text_hinting_items);
+       RNA_def_property_ui_text(prop, "Text Hinting", "Method for making user interface text render sharp");
        RNA_def_property_update(prop, 0, "rna_userdef_text_update");
 
        prop = RNA_def_property(srna, "select_method", PROP_ENUM, PROP_NONE);