jaehyun pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=f391c03be0e0ca9d202e2a584e181125af0d129e

commit f391c03be0e0ca9d202e2a584e181125af0d129e
Author: Jaehyun Cho <jae_hyun_...@naver.com>
Date:   Sat Feb 20 12:58:12 2016 +0900

    text_setting: Show monospaced fonts.
    
    Monospaced fonts are identified by fontconfig APIs.
    (i.e. Monospaced fonts have a spacing value with 100.)
    Therefore, showing monospaced fonts are available only if fontconfig is
    installed.
---
 configure.ac               |   7 ++
 src/bin/config_data.c      |  24 +++++
 src/bin/setting.c          |   2 +-
 src/bin/text_setting.c     | 249 +++++++++++++++++++++++++++++++++++++++------
 src/include/common.h       |   9 +-
 src/include/config_data.h  |   2 +
 src/include/text_setting.h |   4 +
 7 files changed, 264 insertions(+), 33 deletions(-)

diff --git a/configure.ac b/configure.ac
index 95ef54e..57df76a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,13 @@ edje >= ${efl_version} \
 eio >= ${efl_version} \
 efreet >= ${efl_version}"
 
+# Check fontconfig
+PKG_CHECK_EXISTS([fontconfig >= 2.5.0],
+                 [
+                 AC_DEFINE(HAVE_FONTCONFIG, 1, [have fontconfig searching 
capabilities])
+                 requirement_enventor="fontconfig >= 2.5.0 
${requirement_enventor}"
+                 ])
+
 AC_SUBST(requirement_enventor)
 
 PKG_CHECK_MODULES([ENVENTOR], [${requirement_enventor}])
diff --git a/src/bin/config_data.c b/src/bin/config_data.c
index 6c7e0f5..5e675fc 100644
--- a/src/bin/config_data.c
+++ b/src/bin/config_data.c
@@ -1,3 +1,6 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include "common.h"
 
 typedef struct config_s
@@ -39,6 +42,7 @@ typedef struct config_s
    Eina_Bool auto_complete;
    Eina_Bool smart_undo_redo;
    Eina_Bool edc_navigator;
+   Eina_Bool monospace_font;
 } config_data;
 
 static config_data *g_cd = NULL;
@@ -182,6 +186,10 @@ config_load(void)
         cd->version = ENVENTOR_CONFIG_VERSION;
         cd->smart_undo_redo = EINA_FALSE;
         cd->edc_navigator = EINA_TRUE;
+#ifdef HAVE_FONTCONFIG
+        //Check Monospace Font is disabled if fontconfig is not installed.
+        cd->monospace_font = EINA_TRUE;
+#endif
      }
 
    g_cd = cd;
@@ -299,6 +307,8 @@ eddc_init(void)
                                     smart_undo_redo, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC(edd_base, config_data, "edc_navigator",
                                     edc_navigator, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_base, config_data, "monospace_font",
+                                    monospace_font, EET_T_UCHAR);
 }
 
 void
@@ -901,3 +911,17 @@ config_edc_navigator_get(void)
    config_data *cd = g_cd;
    return cd->edc_navigator;
 }
+
+void
+config_monospace_font_set(Eina_Bool monospace_font)
+{
+   config_data *cd = g_cd;
+   cd->monospace_font = monospace_font;
+}
+
+Eina_Bool
+config_monospace_font_get(void)
+{
+   config_data *cd = g_cd;
+   return cd->monospace_font;
+}
diff --git a/src/bin/setting.c b/src/bin/setting.c
index 3e1a667..161e969 100644
--- a/src/bin/setting.c
+++ b/src/bin/setting.c
@@ -185,7 +185,7 @@ setting_reset_btn_cb(void *data EINA_UNUSED, Evas_Object 
*obj EINA_UNUSED,
    text_setting_linenumber_set(config_linenumber_get());
    text_setting_auto_indent_set(config_auto_indent_get());
    text_setting_auto_complete_set(config_auto_complete_get());
-
+   text_setting_monospace_font_set(config_monospace_font_get());
    text_setting_syntax_color_reset();
 }
 
diff --git a/src/bin/text_setting.c b/src/bin/text_setting.c
index 886a37b..a15b9c2 100644
--- a/src/bin/text_setting.c
+++ b/src/bin/text_setting.c
@@ -11,6 +11,10 @@
 #define SYNTAX_TEMPLATE_FONT_SIZE 10
 #define SYNTAX_COLOR_LEN 7
 
+#ifdef HAVE_FONTCONFIG
+static FcConfig *fc_config = NULL;
+#endif
+
 static char 
unsupported_font_list[UNSUPPORTED_FONT_CNT][UNSUPPORTED_FONT_MAX_LEN] =
 {
    "Dingbats", "KacstArt", "KacstBook", "KacstDecorative", "KacstDigital",
@@ -620,24 +624,69 @@ font_name_selected_cb(void *data, Evas_Object *obj,
    elm_list_clear(list_font_style);
 
    //Append Items of Font Style List
-   Elm_Font_Properties *efp;
-   Eina_List *font_list;
+   Eina_List *font_list = NULL;
    Eina_List *l, *ll;
    char *font, *style;
+
+#ifdef HAVE_FONTCONFIG
+   if (!fc_config)
+     fc_config = FcInitLoadConfigAndFonts();
+
+   FcPattern *p = FcPatternCreate();
+   FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_SPACING, NULL);
+   FcFontSet *set = NULL;
+
+   if (p && os) set = FcFontList(fc_config, p, os);
+
+   if (p) FcPatternDestroy(p);
+   if (os) FcObjectSetDestroy(os);
+
+   if (set)
+     {
+        int i;
+        for (i = 0; i < set->nfont; i++)
+          {
+             char *font = (char *)FcNameUnparse(set->fonts[i]);
+             font_list = eina_list_append(font_list,
+                                          eina_stringshare_add(font));
+             free(font);
+          }
+        FcFontSetDestroy(set);
+     }
+#else
    font_list = evas_font_available_list(evas_object_evas_get(obj));
+#endif
+   if (!font_list) return;
+
    font_list = eina_list_sort(font_list, eina_list_count(font_list),
                               font_cmp_cb);
    EINA_LIST_FOREACH(font_list, l, font)
      {
-        efp = elm_font_properties_get(font);
+        Elm_Font_Properties *efp = elm_font_properties_get(font);
         if (efp)
           {
              if (!strcmp(font_name, efp->name))
                {
                   EINA_LIST_FOREACH(efp->styles, ll, style)
                     {
-                       elm_list_item_append(list_font_style, style, NULL, NULL,
-                                            font_style_selected_cb, obj);
+#ifdef HAVE_FONTCONFIG
+                       char *spacing = strstr(style, ":spacing=");
+                       if (spacing)
+                         {
+                            const char *style_only = NULL;
+                            int style_len = spacing - style;
+                            style_only = eina_stringshare_add_length(style,
+                                                                     
style_len);
+                            elm_list_item_append(list_font_style, style_only,
+                                                 NULL, NULL,
+                                                 font_style_selected_cb, obj);
+                            eina_stringshare_del(style_only);
+                         }
+                       else
+#endif
+                         elm_list_item_append(list_font_style, style, NULL,
+                                              NULL, font_style_selected_cb,
+                                              obj);
                     }
                }
              elm_font_properties_free(efp);
@@ -663,6 +712,77 @@ is_supported_font(const char *font_name)
    return EINA_TRUE;
 }
 
+//Check Monospace Font is disabled if fontconfig is not installed.
+#ifdef HAVE_FONTCONFIG
+static void
+monospace_font_check_changed_cb(void *data, Evas_Object *obj,
+                                void *event_info EINA_UNUSED)
+{
+   text_setting_data *tsd = data;
+   Eina_List *font_list = NULL;
+   Eina_List *l;
+   char *font;
+   char prev_font[128] = {0};
+
+   //Reset Font Name List and Font Style List
+   elm_list_clear(tsd->list_font_name);
+   elm_list_clear(tsd->list_font_style);
+
+   if (!fc_config)
+     fc_config = FcInitLoadConfigAndFonts();
+
+   FcPattern *p = FcPatternCreate();
+   FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_SPACING, NULL);
+   FcFontSet *set = NULL;
+
+   if (p && os) set = FcFontList(fc_config, p, os);
+
+   if (p) FcPatternDestroy(p);
+   if (os) FcObjectSetDestroy(os);
+
+   if (set)
+     {
+        int i;
+        for (i = 0; i < set->nfont; i++)
+          {
+             char *font = (char *)FcNameUnparse(set->fonts[i]);
+             font_list = eina_list_append(font_list,
+                                          eina_stringshare_add(font));
+             free(font);
+          }
+        FcFontSetDestroy(set);
+     }
+
+   font_list = eina_list_sort(font_list, eina_list_count(font_list),
+                              font_cmp_cb);
+   EINA_LIST_FOREACH(font_list, l, font)
+     {
+        Elm_Font_Properties *efp = elm_font_properties_get(font);
+        if (efp)
+          {
+             if (elm_check_state_get(obj))
+               {
+                  char *style = eina_list_data_get(efp->styles);
+                  if (!strstr(style, ":spacing=100"))
+                    {
+                       elm_font_properties_free(efp);
+                       continue;
+                    }
+               }
+             if (strcmp(prev_font, efp->name) && is_supported_font(efp->name))
+               {
+                  elm_list_item_append(tsd->list_font_name, efp->name, NULL,
+                                       NULL, font_name_selected_cb,
+                                       tsd->list_font_style);
+                  snprintf(prev_font, sizeof(prev_font), "%s", efp->name);
+               }
+             elm_font_properties_free(efp);
+          }
+     }
+   elm_list_go(tsd->list_font_name);
+}
+#endif
+
 Evas_Object *
 text_setting_layout_create(Evas_Object *parent)
 {
@@ -759,78 +879,134 @@ text_setting_layout_create(Evas_Object *parent)
                                                 config_smart_undo_redo_get());
    elm_box_pack_end(box, toggle_smart_undo_redo);
 
-   //Font Name and Style (Box)
+   //Font Name and Style and Check Monospace Font (Box)
    box = elm_box_add(layout);
-   elm_box_horizontal_set(box, EINA_TRUE);
    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_object_part_content_set(layout, "elm.swallow.font", box);
 
-   //Font Name (Box)
+   //Font Name and Style (Box2)
    box2 = elm_box_add(box);
+   elm_box_horizontal_set(box2, EINA_TRUE);
    evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_show(box2);
-
    elm_box_pack_end(box, box2);
 
-   //Font Name (Label)
+   //Font Name (Box3)
+   Evas_Object *box3 = elm_box_add(box2);
+   evas_object_size_hint_weight_set(box3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(box3, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(box3);
+   elm_box_pack_end(box2, box3);
 
+   //Font Name (Label)
    /* This layout is intended to put the label aligned to left side
       far from 3 pixels. */
-   Evas_Object *layout_padding3 = elm_layout_add(box2);
+   Evas_Object *layout_padding3 = elm_layout_add(box3);
    elm_layout_file_set(layout_padding3, EDJE_PATH, "padding3_layout");
    evas_object_show(layout_padding3);
-
-   elm_box_pack_end(box2, layout_padding3);
+   elm_box_pack_end(box3, layout_padding3);
 
    Evas_Object *label_font_name = label_create(layout_padding3, _("Font 
Name"));
    elm_object_part_content_set(layout_padding3, "elm.swallow.content",
                                label_font_name);
 
    //Font Name (List)
-   Evas_Object *list_font_name = list_create(box2);
-   elm_box_pack_end(box2, list_font_name);
+   Evas_Object *list_font_name = list_create(box3);
+   elm_box_pack_end(box3, list_font_name);
 
-   //Font Style (Box)
-   box2 = elm_box_add(box);
-   evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-   evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   evas_object_show(box2);
-
-   elm_box_pack_end(box, box2);
+   //Font Style (Box3)
+   box3 = elm_box_add(box2);
+   evas_object_size_hint_weight_set(box3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(box3, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(box3);
+   elm_box_pack_end(box2, box3);
 
    //Font Style (Label)
-
    /* This layout is intended to put the label aligned to left side
       far from 3 pixels. */
-   layout_padding3 = elm_layout_add(box2);
+   layout_padding3 = elm_layout_add(box3);
    elm_layout_file_set(layout_padding3, EDJE_PATH, "padding3_layout");
    evas_object_show(layout_padding3);
-
-   elm_box_pack_end(box2, layout_padding3);
+   elm_box_pack_end(box3, layout_padding3);
 
    Evas_Object *label_font_style = label_create(layout_padding3, _("Font 
Style"));
    elm_object_part_content_set(layout_padding3, "elm.swallow.content",
                                label_font_style);
 
    //Font Style (List)
-   Evas_Object *list_font_style = list_create(box2);
-   elm_box_pack_end(box2, list_font_style);
+   Evas_Object *list_font_style = list_create(box3);
+   elm_box_pack_end(box3, list_font_style);
+
+   //Check (Monospace Font)
+   Evas_Object *check_monospace_font = elm_check_add(box);
+   evas_object_size_hint_weight_set(check_monospace_font, EVAS_HINT_EXPAND, 0);
+   evas_object_size_hint_align_set(check_monospace_font, EVAS_HINT_FILL, 0);
+   elm_object_text_set(check_monospace_font, _("Monospaced Fonts"));
+#ifdef HAVE_FONTCONFIG
+   elm_check_state_set(check_monospace_font, config_monospace_font_get());
+   evas_object_smart_callback_add(check_monospace_font, "changed",
+                                  monospace_font_check_changed_cb, tsd);
+#else
+   elm_check_state_set(check_monospace_font, EINA_FALSE);
+   elm_object_disabled_set(check_monospace_font, EINA_TRUE);
+#endif
+   evas_object_show(check_monospace_font);
+   elm_box_pack_end(box, check_monospace_font);
 
    //Append Items of Font Name List
-   Elm_Font_Properties *efp;
-   Eina_List *font_list;
+   Eina_List *font_list = NULL;
    Eina_List *l;
    char *font;
    char prev_font[128] = {0};
+
+#ifdef HAVE_FONTCONFIG
+   if (!fc_config)
+     fc_config = FcInitLoadConfigAndFonts();
+
+   FcPattern *p = FcPatternCreate();
+   FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_SPACING, NULL);
+   FcFontSet *set = NULL;
+
+   if (p && os) set = FcFontList(fc_config, p, os);
+
+   if (p) FcPatternDestroy(p);
+   if (os) FcObjectSetDestroy(os);
+
+   if (set)
+     {
+        int i;
+        for (i = 0; i < set->nfont; i++)
+          {
+             char *font = (char *)FcNameUnparse(set->fonts[i]);
+             font_list = eina_list_append(font_list,
+                                          eina_stringshare_add(font));
+             free(font);
+          }
+        FcFontSetDestroy(set);
+     }
+#else
    font_list = evas_font_available_list(evas_object_evas_get(parent));
+#endif
+
    font_list = eina_list_sort(font_list, eina_list_count(font_list),
                               font_cmp_cb);
    EINA_LIST_FOREACH(font_list, l, font)
      {
-        efp = elm_font_properties_get(font);
+        Elm_Font_Properties *efp = elm_font_properties_get(font);
         if (efp)
           {
+#ifdef HAVE_FONTCONFIG
+             if (elm_check_state_get(check_monospace_font))
+               {
+                  char *style = eina_list_data_get(efp->styles);
+                  if (!strstr(style, ":spacing=100"))
+                    {
+                       elm_font_properties_free(efp);
+                       continue;
+                    }
+               }
+#endif
              if (strcmp(prev_font, efp->name) && is_supported_font(efp->name))
                {
                   elm_list_item_append(list_font_name, efp->name, NULL, NULL,
@@ -849,6 +1025,9 @@ text_setting_layout_create(Evas_Object *parent)
    tsd->toggle_indent = toggle_indent;
    tsd->toggle_autocomp = toggle_autocomp;
    tsd->toggle_smart_undo_redo = toggle_smart_undo_redo;
+   tsd->check_monospace_font = check_monospace_font;
+   tsd->list_font_name = list_font_name;
+   tsd->list_font_style = list_font_style;
    return layout;
 }
 
@@ -895,6 +1074,7 @@ text_setting_config_set(void)
    config_auto_indent_set(elm_check_state_get(tsd->toggle_indent));
    config_auto_complete_set(elm_check_state_get(tsd->toggle_autocomp));
    
config_smart_undo_redo_set(elm_check_state_get(tsd->toggle_smart_undo_redo));
+   config_monospace_font_set(elm_check_state_get(tsd->check_monospace_font));
 }
 
 static void
@@ -962,6 +1142,13 @@ text_setting_smart_undo_redo_set(Eina_Bool enabled)
 }
 
 void
+text_setting_monospace_font_set(Eina_Bool enabled)
+{
+   text_setting_data *tsd = g_tsd;
+   elm_check_state_set(tsd->check_monospace_font, enabled);
+}
+
+void
 text_setting_init(void)
 {
    text_setting_data *tsd = g_tsd;
diff --git a/src/include/common.h b/src/include/common.h
index e0ddecb..81f89bb 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -57,7 +57,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
 
 #define ROUNDING(x, dig) (floor((x) * pow(10, dig) + 0.5) / pow(10, dig))
 
-#define ENVENTOR_CONFIG_VERSION 5
+#define ENVENTOR_CONFIG_VERSION 6
 
 #define EVENT_KEY_MODIFIER_CHECK(NAME, MASK) \
   ((MASK & ECORE_EVENT_MODIFIER_##NAME) && \
@@ -96,4 +96,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
 #endif /* localization */
 
 
+/* fontconfig */
+#ifdef HAVE_FONTCONFIG
+   #include <fontconfig/fontconfig.h>
+   #include <fontconfig/fcfreetype.h>
+#endif /* fontconfig */
+
+
 #endif
diff --git a/src/include/config_data.h b/src/include/config_data.h
index 0b2c06d..b86e609 100644
--- a/src/include/config_data.h
+++ b/src/include/config_data.h
@@ -60,3 +60,5 @@ void config_smart_undo_redo_set(Eina_Bool smart_undo_redo);
 Eina_Bool config_smart_undo_redo_get(void);
 void config_edc_navigator_set(Eina_Bool enabled);
 Eina_Bool config_edc_navigator_get(void);
+void config_monospace_font_set(Eina_Bool monospace_font);
+Eina_Bool config_monospace_font_get(void);
diff --git a/src/include/text_setting.h b/src/include/text_setting.h
index 55a1306..3e2946c 100644
--- a/src/include/text_setting.h
+++ b/src/include/text_setting.h
@@ -16,6 +16,9 @@ struct text_setting_s
    Evas_Object *toggle_indent;
    Evas_Object *toggle_autocomp;
    Evas_Object *toggle_smart_undo_redo;
+   Evas_Object *check_monospace_font;
+   Evas_Object *list_font_name;
+   Evas_Object *list_font_style;
 
    color_keyword *color_keyword_list;
    char *syntax_template_format;
@@ -39,5 +42,6 @@ void text_setting_linenumber_set(Eina_Bool enabled);
 void text_setting_auto_indent_set(Eina_Bool enabled);
 void text_setting_auto_complete_set(Eina_Bool enabled);
 void text_setting_smart_undo_redo_set(Eina_Bool enabled);
+void text_setting_monospace_font_set(Eina_Bool enabled);
 void text_setting_term(void);
 void text_setting_init(void);

-- 


Reply via email to