Add font size configuation file
[platform/core/api/system-settings.git] / libutil / sstu.c
index b767fa6..9c6b974 100644 (file)
 #include <vconf.h>
 #include <fontconfig/fontconfig.h>
 #include <efl_extension.h>
+#include <json-glib/json-glib.h>
 #include "system_settings.h"
 #include "sst.h"
 
+#define FONT_SCALE_CONF_PATH SYSCONF_DIR"/font_scale.json"
+#define INTERNAL_API __attribute__((visibility("default")))
+
 #ifdef TIZEN_WEARABLE
 #define SMALL_FONT_DPI                                         (-90)
 #else
 #define SETTING_FONT_TIZEN_FONT_ALIAS "Tizen"
 #define SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS "TizenDefaultFont"
 
+
+typedef struct __font_size_info {
+       int small;
+       int normal;
+       int large;
+       int huge;
+       int giant;
+} font_size_info;
+
 static char* _get_main_font_family(char *alias)
 {
        FcFontSet *set;
@@ -207,9 +220,89 @@ API char* sstu_get_default_font()
        return _get_main_font_family(SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS);
 }
 
+/*
+To support different variable product, font_scale.json is added.
+With %config option in .spec file, the font_scale.json can be
+uploaded only when there is no the font_scale.json in /etc.
+
+In font_scale.json, there are 5 grade of font size, below.
+
+$ cat /etc/font_scale.json
+{
+        "SMALL"  : -80,
+        "NORMAL" : -100,
+        "LARGE"  : -150,
+        "HUGE"   : -190,
+        "GIANT"  : -250
+}
+
+-80 means that 80% font scale of each application font size.
+Each grade is mapping, below.
+
+SYSTEM_SETTINGS_FONT_SIZE_SMALL == "SMALL" in font_scale.json value
+SYSTEM_SETTINGS_FONT_SIZE_NORMAL == "NORMAL" in font_scale.json value
+SYSTEM_SETTINGS_FONT_SIZE_LARGE == "LARGE" in font_scale.json value
+SYSTEM_SETTINGS_FONT_SIZE_HUGE == "HUGE" in font_scale.json value
+SYSTEM_SETTINGS_FONT_SIZE_GIANT == "GIANT" in font_scale.json value
+*/
+
+static int get_int_from_object(JsonObject *obj, const char *key, int *data)
+{
+       JsonNode *tmp = json_object_get_member(obj, key);
+
+       if (tmp == NULL){
+               ERR("json_object_object_get_ex(key:%s) error", key);
+               return -EINVAL;
+       }
+
+       int tmp_int = json_node_get_int(tmp);
+       if (tmp_int < 0) {
+               *data = tmp_int;
+       } else {
+               ERR("%s key Wrong value : %d ", key, tmp_int);
+       }
+
+       return 0;
+}
+
+INTERNAL_API int load_font_size_info(font_size_info *info, const gchar *path)
+{
+       GError *error = NULL;
+
+       if (info == NULL)
+           return -EINVAL;
+
+       info->small = SMALL_FONT_DPI;
+       info->normal = MIDDLE_FONT_DPI;
+       info->large = LARGE_FONT_DPI;
+       info->huge = HUGE_FONT_DPI;
+       info->giant = GIANT_FONT_DPI;
+
+       JsonParser *parser  = json_parser_new();
+       json_parser_load_from_file (parser, path, &error);
+       /* Parse configuration file */
+       if (error) {
+               INFO("There is no json_object file(%s), loaded default font size values", path);
+               return 0;
+       }
+
+       JsonObject *obj = json_node_get_object(json_parser_get_root (parser));
+       INFO("json_object file(%s) OPENED! Try to load font size values from the file.", path);
+       get_int_from_object(obj, "SMALL", &info->small);
+       get_int_from_object(obj, "NORMAL", &info->normal);
+       get_int_from_object(obj, "LARGE", &info->large);
+       get_int_from_object(obj, "HUGE", &info->huge);
+       get_int_from_object(obj, "GIANT", &info->giant);
+
+       g_object_unref(parser);
+
+       return 0;
+}
+
 static int _get_font_size()
 {
        int font_size = -1;
+       font_size_info info;
 
        int vconf_value = -1;
        if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
@@ -217,24 +310,26 @@ static int _get_font_size()
                return -1;
        }
 
+       load_font_size_info(&info, FONT_SCALE_CONF_PATH);
+
        switch (vconf_value) {
        case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
-               font_size = SMALL_FONT_DPI;
+               font_size = info.small;
                break;
        case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
-               font_size = MIDDLE_FONT_DPI;
+               font_size = info.normal;
                break;
        case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
-               font_size = LARGE_FONT_DPI;
+               font_size = info.large;
                break;
        case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
-               font_size = HUGE_FONT_DPI;
+               font_size = info.huge;
                break;
        case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
-               font_size = GIANT_FONT_DPI;
+               font_size = info.giant;
                break;
        default:
-               font_size = MIDDLE_FONT_DPI;
+               font_size = info.normal;
                break;
        }
        return font_size;