#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;
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)) {
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;
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <glib.h>
+#include <gtest/gtest.h>
+#include <vconf.h>
+#include <dlfcn.h>
+
+#include "system_settings.h"
+#include "mocks/sstt_mock.h"
+
+extern "C" {
+#include "sst.h"
+#include "sst_font.h"
+#include "sst_vconf.h"
+#include "sst_interface.h"
+
+typedef struct __font_size_info {
+ int small;
+ int normal;
+ int large;
+ int huge;
+ int giant;
+} font_size_info;
+}
+
+
+static void* _utils_load_lib()
+{
+ const char* const path = SETTING_UTILS_SO_FILE_PATH;
+ void *handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
+ if (NULL == handle)
+ ERR("dlopen(%s) Fail", path);
+
+ return handle;
+}
+
+TEST(SstFontTest,loadFontSizeInfoPathERR)
+{
+ static font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "/error/asdlfajsdf.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoInputERR)
+{
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(NULL, "/error/asdlfajsdf.json");
+ EXPECT_NE(0, ret);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoSmallERR)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "tests/res/font_scale_small_error.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoNormalERR)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "tests/res/font_scale_normal_error.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoLargeERR)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "tests/res/font_scale_large_error.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoHugeERR)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "tests/res/font_scale_huge_error.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
+TEST(SstFontTest,loadFontSizeInfoGiantERR)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, "tests/res/font_scale_giant_error.json");
+ EXPECT_EQ(0, ret);
+
+#ifdef TIZEN_WEARABLE
+ EXPECT_EQ(-90, info.small);
+ EXPECT_EQ(-110, info.large);
+#else
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+#endif
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+}
+
#include <glib.h>
#include <gtest/gtest.h>
#include <vconf.h>
+#include <dlfcn.h>
#include "system_settings.h"
#include "mocks/sstt_mock.h"
+#define FONT_SCALE_CONF_PATH "conf_example/font_scale.json"
extern "C" {
#include "sst.h"
#include "sst_font.h"
#include "sst_vconf.h"
#include "sst_interface.h"
+
+typedef struct __font_size_info {
+ int small;
+ int normal;
+ int large;
+ int huge;
+ int giant;
+} font_size_info;
}
TEST(SstFontTest, getDefaultfontERR)
ret = sst_font_set_size(iface, SYSTEM_SETTINGS_FONT_SIZE_NORMAL);
EXPECT_EQ(SYSTEM_SETTINGS_ERROR_IO_ERROR, ret);
}
+
+
+static void* _utils_load_lib()
+{
+ const char* const path = SETTING_UTILS_SO_FILE_PATH;
+ void *handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
+ if (NULL == handle)
+ ERR("dlopen(%s) Fail", path);
+
+ return handle;
+}
+
+TEST(SstFontTest,loadFontSizeInfo)
+{
+ font_size_info info;
+ void *handle = _utils_load_lib();
+ EXPECT_NE((void*)NULL, handle);
+
+ typedef int (*fn_impl)(font_size_info *info, const char *path);
+ fn_impl load_font_size_info = NULL;
+
+ load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
+ char *error = dlerror();
+ EXPECT_EQ(0, error);
+
+ int ret = load_font_size_info(&info, FONT_SCALE_CONF_PATH);
+ EXPECT_EQ(0, ret);
+
+ EXPECT_EQ(-80, info.small);
+ EXPECT_EQ(-150, info.large);
+ EXPECT_EQ(-100, info.normal);
+ EXPECT_EQ(-190, info.huge);
+ EXPECT_EQ(-250, info.giant);
+
+ dlclose(handle);
+ handle = NULL;
+
+}
+
TEST(SstFontTest, getDefaultfont)
{
char *val = NULL;