Do not change the size of font for class "tizen"
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 29 Apr 2013 07:29:36 +0000 (16:29 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 29 Apr 2013 07:29:36 +0000 (16:29 +0900)
Change-Id: Ifb74e34566b9ce12198fe84a1548099ee58cb6cf

src/script_port.c

index 4e98bf6..da52f0f 100644 (file)
@@ -40,6 +40,7 @@
 #include "script_port.h"
 
 #define TEXT_CLASS     "tizen"
+#define DEFAULT_FONT_SIZE      -100
 #define BASE_WIDTH     720.0f
 
 #define PUBLIC __attribute__((visibility("default")))
@@ -86,7 +87,7 @@ static struct {
        int font_size;
 } s_info = {
        .font_name = NULL,
-       .font_size = 1,
+       .font_size = -100,
 };
 
 static inline double scale_get(void)
@@ -1314,32 +1315,34 @@ static void access_cb(keynode_t *node, void *user_data)
 
 static void update_font_cb(void *data)
 {
-       elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, s_info.font_size);
-       DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, s_info.font_size);
+       elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
+       DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
 }
 
-static void font_changed_cb(system_settings_key_e key, void *user_data)
+static void font_changed_cb(keynode_t *node, void *user_data)
 {
-       int ret;
        char *font_name;
 
-       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
-       if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name)
+       font_name = vconf_get_str("db/setting/accessibility/font_name");
+       if (!font_name) {
+               ErrPrint("Invalid font name (NULL)\n");
                return;
+       }
 
        if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
-               DbgPrint("Font is not changed\n");
+               DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
                free(font_name);
                return;
        }
 
        if (s_info.font_name) {
+               DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
                free(s_info.font_name);
                s_info.font_name = NULL;
        }
 
        s_info.font_name = font_name;
-       DbgPrint("Font name is changed to %s\n", s_info.font_name);
+       DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
 
        /*!
         * \NOTE
@@ -1348,6 +1351,33 @@ static void font_changed_cb(system_settings_key_e key, void *user_data)
        update_font_cb(NULL);
 }
 
+static inline int convert_font_size(int size)
+{
+       switch (size) {
+       case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
+               size = -80;
+               break;
+       case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
+               size = -100;
+               break;
+       case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
+               size = -150;
+               break;
+       case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
+               size = -190;
+               break;
+       case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
+               size = -250;
+               break;
+       default:
+               size = -100;
+               break;
+       }
+
+       DbgPrint("Return size: %d\n", size);
+       return size;
+}
+
 static void font_size_cb(system_settings_key_e key, void *user_data)
 {
        int size;
@@ -1355,6 +1385,8 @@ static void font_size_cb(system_settings_key_e key, void *user_data)
        if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
                return;
 
+       size = convert_font_size(size);
+
        if (size == s_info.font_size) {
                DbgPrint("Font size is not changed\n");
                return;
@@ -1369,6 +1401,7 @@ static void font_size_cb(system_settings_key_e key, void *user_data)
 PUBLIC int script_init(void)
 {
        int ret;
+       int size = DEFAULT_FONT_SIZE;
        char *argv[] = {
                "livebox.edje",
                NULL,
@@ -1383,19 +1416,18 @@ PUBLIC int script_init(void)
 
        access_cb(NULL, NULL);
 
-       ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE, font_changed_cb, NULL);
+       ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
        DbgPrint("System font is changed: %d\n", ret);
        
        ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
        DbgPrint("System font size is changed: %d\n", ret);
 
-       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &s_info.font_name);
-       if (ret == SYSTEM_SETTINGS_ERROR_NONE)
-               DbgPrint("Current font: %s\n", s_info.font_name);
+       s_info.font_name = vconf_get_str("db/setting/accessibility/font_name");
+       DbgPrint("Current font: %s\n", s_info.font_name);
 
-       ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &s_info.font_size);
-       if (ret == SYSTEM_SETTINGS_ERROR_NONE)
-               DbgPrint("Current size: %d\n", s_info.font_size);
+       ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size);
+       s_info.font_size = convert_font_size(size);
+       DbgPrint("Current size: %d\n", s_info.font_size);
 
        return LB_STATUS_SUCCESS;
 }