ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=f4c48d4ca90277e52cac59a36e937c46022116fb

commit f4c48d4ca90277e52cac59a36e937c46022116fb
Author: Andy Williams <a...@andywilliams.me>
Date:   Sun May 24 18:39:57 2015 +0100

    elm_code: support setting custom fonts
    
    For EDI create the config that would allow this to be altered.
    Actual setting widget to follow...
---
 elm_code/src/bin/elm_code_test_main.c             | 12 +++++------
 elm_code/src/lib/elm_code_diff_widget.c           |  6 +++---
 elm_code/src/lib/elm_code_diff_widget.h           |  2 +-
 elm_code/src/lib/widget/elm_code_widget.c         | 26 +++++++++++++++++------
 elm_code/src/lib/widget/elm_code_widget.eo        | 11 ++++++----
 elm_code/src/lib/widget/elm_code_widget_private.h |  1 +
 src/bin/edi_config.c                              | 12 +++++++----
 src/bin/edi_config.h                              |  3 ++-
 src/bin/edi_consolepanel.c                        |  8 +++----
 src/bin/edi_content_provider.c                    |  2 +-
 src/bin/edi_logpanel.c                            |  4 ++--
 src/bin/editor/edi_editor.c                       |  2 +-
 12 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/elm_code/src/bin/elm_code_test_main.c 
b/elm_code/src/bin/elm_code_test_main.c
index 1522cbc..ebca4d4 100644
--- a/elm_code/src/bin/elm_code_test_main.c
+++ b/elm_code/src/bin/elm_code_test_main.c
@@ -71,7 +71,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent)
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(12),
+         elm_code_widget_font_set(NULL, 12),
          eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, 
_elm_code_test_line_done_cb, NULL);
          eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, 
_elm_code_test_line_clicked_cb, code));
 
@@ -101,7 +101,7 @@ _elm_code_test_editor_setup(Evas_Object *parent)
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(14),
+         elm_code_widget_font_set(NULL, 14),
          elm_code_widget_editable_set(EINA_TRUE),
          elm_code_widget_show_whitespace_set(EINA_TRUE),
          elm_code_widget_line_numbers_set(EINA_TRUE));
@@ -123,14 +123,14 @@ _elm_code_test_editor_setup(Evas_Object *parent)
 }
 
 static Evas_Object *
-_elm_code_test_mirror_setup(Elm_Code *code, Evas_Object *parent)
+_elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object 
*parent)
 {
    Elm_Code_Widget *widget;
 
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(11),
+         elm_code_widget_font_set(font_name, 11),
          elm_code_widget_line_numbers_set(EINA_TRUE));
 
    evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, 
EVAS_HINT_EXPAND);
@@ -212,8 +212,8 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object 
*obj EINA_UNUSED, void
          code = elm_code_widget_code_get());
    elm_box_pack_end(screen, widget);
 
-   elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen));
-   elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen));
+   elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, 
"Mono:style=Oblique", screen));
+   elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Nimbus Mono", 
screen));
 
    evas_object_show(screen);
    elm_naviframe_item_push(naviframe, "Mirrored editor",
diff --git a/elm_code/src/lib/elm_code_diff_widget.c 
b/elm_code/src/lib/elm_code_diff_widget.c
index 3688724..eba3b37 100644
--- a/elm_code/src/lib/elm_code_diff_widget.c
+++ b/elm_code/src/lib/elm_code_diff_widget.c
@@ -121,13 +121,13 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code 
*code)
 }
 
 EAPI void
-elm_code_diff_widget_font_size_set(Evas_Object *widget, int size)
+elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size)
 {
    Elm_Code_Widget *child;
 
    child = (Elm_Code_Widget *) evas_object_data_get(widget, 
_ELM_CODE_DIFF_WIDGET_LEFT);
-   eo_do(child, elm_code_widget_font_size_set(size));
+   eo_do(child, elm_code_widget_font_set(name, size));
    child = (Elm_Code_Widget *) evas_object_data_get(widget, 
_ELM_CODE_DIFF_WIDGET_RIGHT);
-   eo_do(child, elm_code_widget_font_size_set(size));
+   eo_do(child, elm_code_widget_font_set(name, size));
 }
 
diff --git a/elm_code/src/lib/elm_code_diff_widget.h 
b/elm_code/src/lib/elm_code_diff_widget.h
index b6605bb..895dd55 100644
--- a/elm_code/src/lib/elm_code_diff_widget.h
+++ b/elm_code/src/lib/elm_code_diff_widget.h
@@ -23,7 +23,7 @@ extern "C" {
 
 EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code 
*code);
 
-EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size);
+EAPI void elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int 
size);
 
 /**
  * @}
diff --git a/elm_code/src/lib/widget/elm_code_widget.c 
b/elm_code/src/lib/widget/elm_code_widget.c
index 341f034..7ae845c 100644
--- a/elm_code/src/lib/widget/elm_code_widget.c
+++ b/elm_code/src/lib/widget/elm_code_widget.c
@@ -1277,16 +1277,28 @@ _elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, 
Elm_Code_Widget_Data *pd
 }
 
 EOLIAN static void
-_elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, 
Evas_Font_Size font_size)
+_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char 
*name,
+                          Evas_Font_Size size)
 {
-   evas_object_textgrid_font_set(pd->grid, "Mono", font_size * 
elm_config_scale_get());
-   pd->font_size = font_size;
+   char *face = name;
+   if (!face)
+     face = "Mono";
+
+   evas_object_textgrid_font_set(pd->grid, face, size * 
elm_config_scale_get());
+   if (pd->font_name)
+     free((char *)pd->font_name);
+   pd->font_name = strdup(face);
+   pd->font_size = size;
 }
 
-EOLIAN static Evas_Font_Size
-_elm_code_widget_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd)
+EOLIAN static void
+_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char 
**name,
+                          Evas_Font_Size *size)
 {
-   return pd->font_size;
+   if (name)
+     *name = strdup((const char *)pd->font_name);
+   if (size)
+     *size = pd->font_size;
 }
 
 EOLIAN static void
@@ -1517,7 +1529,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, 
Elm_Code_Widget_Data *pd)
          eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, 
_elm_code_widget_selection_cb, obj),
          eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, 
_elm_code_widget_selection_cb, obj));
 
-   _elm_code_widget_font_size_set(obj, pd, 10);
+   _elm_code_widget_font_set(obj, pd, NULL, 10);
 }
 
 #include "elm_code_widget_text.c"
diff --git a/elm_code/src/lib/widget/elm_code_widget.eo 
b/elm_code/src/lib/widget/elm_code_widget.eo
index b9fad3b..583d8c8 100644
--- a/elm_code/src/lib/widget/elm_code_widget.eo
+++ b/elm_code/src/lib/widget/elm_code_widget.eo
@@ -21,21 +21,24 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text)
             code: Elm_Code *; /*@ Our underlying Elm_Code object */
          }
       }
-      @property font_size {
+      @property font {
          set {
             /*@
-            Set the font size that this widget uses, the font will always be a 
system monospaced font
+            Set the font that this widget uses, the font should be a 
monospaced scalable font.
+            Passing NULL will load the default system monospaced font.
 
             @ingroup Style */
          }
          get {
             /*@
-            Get the font size currently in use
+            Get the font currently in use.
+            The font name is a copy ad should be freed once it is no longer 
needed
 
             @ingroup Style */
          }
          values {
-            font_size: Evas_Font_Size; /*@ The font size of the widgget */
+            name: char *; /*@ The name of the font to load */
+            size: Evas_Font_Size; /*@ The font size for the widget */
          }
       }
       @property gravity {
diff --git a/elm_code/src/lib/widget/elm_code_widget_private.h 
b/elm_code/src/lib/widget/elm_code_widget_private.h
index 0f758c7..a1dc7b1 100644
--- a/elm_code/src/lib/widget/elm_code_widget_private.h
+++ b/elm_code/src/lib/widget/elm_code_widget_private.h
@@ -15,6 +15,7 @@ typedef struct
    Elm_Code *code;
    Evas_Object *grid, *scroller;
 
+   const char *font_name;
    Evas_Font_Size font_size;
    double gravity_x, gravity_y;
 
diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c
index 5f17e91..9d330f7 100644
--- a/src/bin/edi_config.c
+++ b/src/bin/edi_config.c
@@ -38,7 +38,7 @@
 #  define EDI_CONFIG_FILE_VERSION \
    ((EDI_CONFIG_FILE_EPOCH << 16) | EDI_CONFIG_FILE_GENERATION)
 
-#  define EDI_PROJECT_CONFIG_FILE_EPOCH 0x0001
+#  define EDI_PROJECT_CONFIG_FILE_EPOCH 0x0002
 #  define EDI_PROJECT_CONFIG_FILE_GENERATION 0x0001
 #  define EDI_PROJECT_CONFIG_FILE_VERSION \
    ((EDI_PROJECT_CONFIG_FILE_EPOCH << 16) | EDI_PROJECT_CONFIG_FILE_GENERATION)
@@ -235,6 +235,7 @@ _edi_config_init(void)
    #define T Edi_Project_Config
    #define D _edi_proj_cfg_edd
    EDI_CONFIG_VAL(D, T, version, EET_T_INT);
+   EDI_CONFIG_VAL(D, T, font.name, EET_T_STRING);
    EDI_CONFIG_VAL(D, T, font.size, EET_T_INT);
    EDI_CONFIG_VAL(D, T, gui.translucent, EET_T_UCHAR);
    EDI_CONFIG_VAL(D, T, gui.width, EET_T_INT);
@@ -435,8 +436,6 @@ _edi_project_config_load()
 
    /* setup defaults */
    IFPCFG(0x0001);
-
-   _edi_project_config->font.size = 12;
    _edi_project_config->gui.translucent = EINA_TRUE;
    _edi_project_config->gui.width = 640;
    _edi_project_config->gui.height = 480;
@@ -453,8 +452,13 @@ _edi_project_config_load()
    _edi_project_config->tabs = NULL;
    IFPCFGEND;
 
+   IFPCFG(0x0002);
+   _edi_project_config->font.name = "Mono";
+   _edi_project_config->font.size = 12;
+   IFPCFGEND;
+
    /* limit config values so they are sane */
-   EDI_CONFIG_LIMIT(_edi_project_config->font.size, 8, 96);
+   EDI_CONFIG_LIMIT(_edi_project_config->font.size, 6, 96);
    EDI_CONFIG_LIMIT(_edi_project_config->gui.width, 150, 10000);
    EDI_CONFIG_LIMIT(_edi_project_config->gui.height, 100, 8000);
    EDI_CONFIG_LIMIT(_edi_project_config->gui.leftsize, 0.0, 1.0);
diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h
index a03a0e4..c8c2c42 100644
--- a/src/bin/edi_config.h
+++ b/src/bin/edi_config.h
@@ -50,8 +50,9 @@ struct _Edi_Project_Config
 {
    int version;
 
-   struct 
+   struct
      {
+        char *name;
         int size;
      } font;
 
diff --git a/src/bin/edi_consolepanel.c b/src/bin/edi_consolepanel.c
index d80fdf4..2da1a3b 100644
--- a/src/bin/edi_consolepanel.c
+++ b/src/bin/edi_consolepanel.c
@@ -319,13 +319,13 @@ _edi_consolepanel_config_changed(void *data EINA_UNUSED, 
int type EINA_UNUSED, v
    EINA_LIST_FOREACH(_edi_console_code->widgets, item, widget)
      {
         eo_do(widget,
-              elm_code_widget_font_size_set(_edi_project_config->font.size));
+              elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size));
      }
 
    EINA_LIST_FOREACH(_edi_test_code->widgets, item, widget)
      {
         eo_do(widget,
-              elm_code_widget_font_size_set(_edi_project_config->font.size));
+              elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size));
      }
 
    return ECORE_CALLBACK_RENEW;
@@ -342,7 +342,7 @@ void edi_consolepanel_add(Evas_Object *parent)
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(_edi_project_config->font.size),
+         elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size),
          elm_code_widget_gravity_set(0.0, 1.0),
          eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, 
_edi_consolepanel_line_cb, NULL),
          eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, 
_edi_consolepanel_clicked_cb, code));
@@ -369,7 +369,7 @@ void edi_testpanel_add(Evas_Object *parent)
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(_edi_project_config->font.size),
+         elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size),
          elm_code_widget_gravity_set(0.0, 1.0),
          eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, 
_edi_testpanel_line_cb, NULL),
          eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, 
_edi_consolepanel_clicked_cb, code));
diff --git a/src/bin/edi_content_provider.c b/src/bin/edi_content_provider.c
index c147628..7e4ddd0 100644
--- a/src/bin/edi_content_provider.c
+++ b/src/bin/edi_content_provider.c
@@ -42,7 +42,7 @@ _edi_content_provider_diff_add(Evas_Object *parent, 
Edi_Mainview_Item *item)
    code = elm_code_create();
    elm_code_file_open(code, item->path);
    diff = elm_code_diff_widget_add(parent, code);
-   elm_code_diff_widget_font_size_set(diff, 12);
+   elm_code_diff_widget_font_set(diff, NULL, 12);
 
    return diff;
 }
diff --git a/src/bin/edi_logpanel.c b/src/bin/edi_logpanel.c
index c12d7c5..d4625a8 100644
--- a/src/bin/edi_logpanel.c
+++ b/src/bin/edi_logpanel.c
@@ -50,7 +50,7 @@ static Eina_Bool
 _edi_logpanel_config_changed(void *data EINA_UNUSED, int type EINA_UNUSED, 
void *event EINA_UNUSED)
 {
    eo_do(_info_widget,
-         elm_code_widget_font_size_set(_edi_project_config->font.size));
+         elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size));
 
    return ECORE_CALLBACK_RENEW;
 }
@@ -64,7 +64,7 @@ void edi_logpanel_add(Evas_Object *parent)
    widget = eo_add(ELM_CODE_WIDGET_CLASS, parent,
                    elm_code_widget_code_set(code));
    eo_do(widget,
-         elm_code_widget_font_size_set(_edi_project_config->font.size),
+         elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size),
          elm_code_widget_gravity_set(0.0, 1.0),
          eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, 
_edi_logpanel_line_cb, NULL));
    evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, 
EVAS_HINT_EXPAND);
diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c
index 0e17ea9..ba34d23 100644
--- a/src/bin/editor/edi_editor.c
+++ b/src/bin/editor/edi_editor.c
@@ -578,7 +578,7 @@ _edi_editor_config_changed(void *data, int type 
EINA_UNUSED, void *event EINA_UN
 
    widget = (Elm_Code_Widget *) data;
    eo_do(widget,
-         elm_code_widget_font_size_set(_edi_project_config->font.size),
+         elm_code_widget_font_set(_edi_project_config->font.name, 
_edi_project_config->font.size),
          
elm_code_widget_show_whitespace_set(_edi_project_config->gui.show_whitespace),
          
elm_code_widget_line_width_marker_set(_edi_project_config->gui.width_marker),
          elm_code_widget_tabstop_set(_edi_project_config->gui.tabstop));

-- 


Reply via email to