font: update font logic 35/219235/3
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 3 Dec 2019 12:48:23 +0000 (13:48 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 3 Dec 2019 15:17:36 +0000 (16:17 +0100)
1. Read information about default font from system settings instead
   of manually parsing system config file.
2. Fix issue with not checked current font. Out-of-the box the
   value of SYSTEM_SETTINGS_KEY_FONT_TYPE is set to "Default" string,
   which was not matched with any installed font.
3. Always display "Default" in Settings / Display when default font
   is used.

Change-Id: I9129c3655079153f0c2c19118b6d165153b58f82

setting-common/include/setting-common-data-type.h
setting-common/include/setting-common-general-func.h
setting-common/src/setting-common-general-func.c
setting-display/src/setting-display-main.c
setting-font/src/setting-font-main.c

index d5cac7b019c740c0b18f706e4a2586f0c4755ab9..007318e56a6c1476f133f37f62afffcdc9c8ba62 100755 (executable)
@@ -70,8 +70,6 @@
 
 
 #define PROGRESSBAR_STYLE "process_medium"
-#define SETTING_DEFAULT_FONT_CONF_FILE _TZ_SYS_DATA\
-       "/etc/fonts/conf.avail/99-slp.conf"
 
 /**
 * @brief slider, button, and etc.
index 0a43fb898116be58b53ea1c6d3b3c71818d539c5..4b065f3cbb8b08173d64dd098b3201e26bf4f439 100755 (executable)
@@ -61,6 +61,7 @@ extern int get_popup_btn_response_type(Evas_Object *obj);
 extern char *cur_font_get();
 extern void font_size_set();
 extern char *_get_default_font();
+extern char *cur_font_family_get();
 
 extern int app_launcher(const char *pkg_name, app_control_reply_cb callback,
                void *user_data);
index 147721ab0724eb1fb01a2c533e7ad551f409d7d8..3c5b95dc103a7439e757b14c527fda14d680373a 100755 (executable)
@@ -22,7 +22,6 @@
 #include "setting-common-general-func.h"
 #include "setting-common-data-slp-setting.h"
 
-#include <libxml/parser.h>
 #include <system_info.h>
 #include <system_settings.h>
 #include "setting-cfg.h"
@@ -677,6 +676,17 @@ char *cur_font_get()
        return font_name;
 }
 
+EXPORT_PUBLIC
+char *cur_font_family_get()
+{
+       char *ret = cur_font_get();
+       if (ret && !safeStrCmp(ret, "Default")) {
+               free(ret);
+               return _get_default_font();
+       }
+       return ret;
+}
+
 /**
  * [API] system-settings
  * @see font_size_set()
@@ -715,83 +725,13 @@ static int __font_size_get()
 
 EXPORT_PUBLIC char *_get_default_font()
 {
-       xmlDocPtr doc = NULL;
-       xmlNodePtr cur = NULL;
-       xmlNodePtr cur2 = NULL;
-       xmlNodePtr cur3 = NULL;
-       xmlChar *key = NULL;
-       struct _xmlAttr *properties = NULL;
-       char *default_font_name = NULL;
-
-       doc = xmlParseFile(SETTING_DEFAULT_FONT_CONF_FILE);
-
-       cur = xmlDocGetRootElement(doc);
-
-       if (cur == NULL) {
-               xmlFreeDoc(doc);
-               doc = NULL;
+       char *ret = NULL;
+       int err = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, &ret);
+       if (err != TIZEN_ERROR_NONE) {
+               SETTING_TRACE_ERROR("system_settings_get_value_string failed for SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE: %s", get_error_message(err));
                return NULL;
        }
-
-       if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
-               xmlFreeDoc(doc);
-               doc = NULL;
-               return NULL;
-       }
-
-       cur = cur->xmlChildrenNode;
-
-       while (cur != NULL) {
-               if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
-                       cur2 = cur->xmlChildrenNode;
-                       while (cur2 != NULL) {
-                               if ((!xmlStrcmp(cur2->name,
-                                               (const xmlChar *)"edit"))) {
-                                       properties = cur2->properties;
-                                       /*find the "name" property*/
-                                       while (NULL != properties) {
-                                               if (!xmlStrcmp(properties->name,
-                                                               (const xmlChar *)"name")) {
-                                                       break;
-                                               }
-                                               properties = properties->next;
-                                       }
-
-                                       /*If the value of "name" property is "family", then get the child node string,
-                                        it shall be the default font type*/
-                                       if (NULL != properties && !xmlStrcmp(
-                                                       properties->children->content,
-                                                       (const xmlChar *)"family")) {
-                                               cur3 = cur2->xmlChildrenNode;
-                                               while (cur3 != NULL) {
-                                                       if ((!xmlStrcmp(
-                                                                       cur3->name,
-                                                                       (const xmlChar *)"string"))) {
-                                                               key = xmlNodeListGetString(
-                                                                               doc,
-                                                                               cur3->xmlChildrenNode,
-                                                                               1);
-                                                               default_font_name = strndup(
-                                                                               (char *)key, PATH_MAX);
-                                                               xmlFree(key);
-                                                               key = NULL;
-                                                               xmlFreeDoc(doc);
-                                                               doc = NULL;
-                                                               return default_font_name;
-                                                       }
-                                                       cur3 = cur3->next;
-                                               }
-                                       }
-                               }
-                               cur2 = cur2->next;
-                       }
-               }
-               cur = cur->next;
-       }
-
-       xmlFreeDoc(doc);
-       doc = NULL;
-       return NULL;
+       return ret;
 }
 
 /**
index 57ccd545b185e1c648debdaf6dc238719fc9a7f9..2680096c63959d183f1755497d2833b92814a0b5 100755 (executable)
@@ -555,18 +555,27 @@ static void _get_font_name_string(char *buff, int len_max)
 {
        int value = 0;
        char *current_font_type_str = NULL;
+       char *default_font_name = NULL;
        const char *current_font_size_str = NULL;
 
        if (!buff)
                return;
 
-       current_font_type_str = cur_font_get();
+       current_font_type_str = cur_font_family_get();
+       default_font_name = _get_default_font();
        (void)system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE,
                        &value);
        current_font_size_str = get_font_size_str(value);
-       snprintf(buff, NAME_MAX, "%s, %s", _(current_font_size_str),
-                       current_font_type_str);
+       if (current_font_type_str && default_font_name &&
+                       !safeStrCmp(current_font_type_str, default_font_name)) {
+               snprintf(buff, NAME_MAX, "%s, %s", _(current_font_size_str),
+                               _("IDS_ST_BODY_CALLERID_DEFAULT"));
+       } else {
+               snprintf(buff, NAME_MAX, "%s, %s", _(current_font_size_str),
+                               current_font_type_str);
+       }
        free(current_font_type_str);
+       free(default_font_name);
 }
 
 static bool _get_battery_lvl_less_than_low(void)
index 41b73889b20afe4f6c7007dea269f8379d233279..88a28155dab222717ff49bb5b9a1ad0bc3a53f8a 100755 (executable)
@@ -900,14 +900,9 @@ static int setting_font_main_create(void *cb)
                        __gl_realized_cb, ad);
 
        G_FREE(ad->font_type_str);
-       ret = system_settings_get_value_string(
-                       SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
-       if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
-               SETTING_TRACE_ERROR(
-                               "Failed to call system_settings_get_value_string with error code %d",
-                               ret);
+       font_name = cur_font_family_get();
+       if (!font_name)
                font_name = _get_default_font();
-       }
        __setting_get_font_type_str(ad, font_name);
 
        ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE,
@@ -978,16 +973,9 @@ static int setting_font_main_create(void *cb)
                        "IDS_ST_BODY_TYPE", NULL);
 
        FREE(ad->font_name);
-       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE,
-                       &(ad->font_name));
-       if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
-               SETTING_TRACE_ERROR(
-                               "Failed to call system_settings_get_value_string with error code %d",
-                               ret);
+       ad->font_name = cur_font_family_get();
+       if (!ad->font_name)
                ad->font_name = _get_default_font();
-       } else{
-               SETTING_TRACE_DEBUG("ad->font_name dfrom vconf :%s", ad->font_name);
-       }
 
        rgd = elm_radio_add(ad->md.genlist);
        elm_radio_value_set(rgd, -1);