From: JinWang An Date: Tue, 11 Jul 2023 04:57:16 +0000 (+0900) Subject: Add font size configuation file X-Git-Tag: submit/tizen_7.0/20230713.074933^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69ca31c9b90771c908dba594ca83f2cd7a22236b;p=platform%2Fcore%2Fapi%2Fsystem-settings.git Add font size configuation file 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 Change-Id: I4b5c80ef7a1da4672f5e4bfa5fd9b6c735706f85 Signed-off-by: JinWang An --- diff --git a/conf_example/font_scale.json b/conf_example/font_scale.json new file mode 100644 index 0000000..7e60c6f --- /dev/null +++ b/conf_example/font_scale.json @@ -0,0 +1,7 @@ +{ + "SMALL" : -80, + "NORMAL" : -100, + "LARGE" : -150, + "HUGE" : -190, + "GIANT" : -250 +} diff --git a/libutil/CMakeLists.txt b/libutil/CMakeLists.txt index d1a1572..1a46d3e 100644 --- a/libutil/CMakeLists.txt +++ b/libutil/CMakeLists.txt @@ -1,10 +1,11 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) SET(LIB_UTILS system-settings-util) +ADD_DEFINITIONS(-DSYSCONF_DIR=\"${SYSCONF_DIR}\") FILE(GLOB UTILS_SRCS *.c) -PKG_CHECK_MODULES(utils_pkgs REQUIRED dlog vconf fontconfig efl-extension) +PKG_CHECK_MODULES(utils_pkgs REQUIRED dlog vconf fontconfig efl-extension json-glib-1.0) INCLUDE_DIRECTORIES(${utils_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${utils_pkgs_LIBRARY_DIRS}) diff --git a/libutil/sstu.c b/libutil/sstu.c index b767fa6..9c6b974 100644 --- a/libutil/sstu.c +++ b/libutil/sstu.c @@ -19,9 +19,13 @@ #include #include #include +#include #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 @@ -45,6 +49,15 @@ #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; diff --git a/packaging/capi-system-system-settings.spec b/packaging/capi-system-system-settings.spec index 918ab90..3e3d404 100644 --- a/packaging/capi-system-system-settings.spec +++ b/packaging/capi-system-system-settings.spec @@ -106,6 +106,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -DTZ_SYS_ETC=%{TZ_SYS_ETC} \ -DTZ_SYS_RO_SHARE=%{TZ_SYS_RO_SHARE} \ -DTZ_SYS_SHARE=%{TZ_SYS_SHARE} \ + -DSYSCONF_DIR=%{_sysconfdir} \ -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} \ -DTEST_INSTALL_DIR:PATH=%{sys_setting_test_dir} \ -DSST_RES_DIR=%{TZ_SYS_GLOBALUSER_DATA}/settings \ @@ -138,6 +139,7 @@ test_main() { echo "test_main start" /usr/bin/sys-settings/sst-unit-test /usr/bin/sys-settings/sst-unit-test-err-interface + /usr/bin/sys-settings/sst-unit-test-err-font } teardown() { @@ -160,6 +162,7 @@ install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/ #bash tests/scripts/vconf_golden_master.sh LD_LIBRARY_PATH=.:tests:libutil tests/sst-unit-test-err-interface LD_LIBRARY_PATH=.:tests:libutil tests/sst-unit-test +LD_LIBRARY_PATH=.:tests:libutil tests/sst-unit-test-err-font %if 0%{?gcov:1} lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info genhtml %{name}.info -o out --legend --show-details diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4183ed9..fd52afc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,7 +13,7 @@ ADD_DEFINITIONS("-DSST_TEST") ADD_DEFINITIONS("-DN_THREADS=${N_THREADS}") ADD_DEFINITIONS(-DSYS_SETTINGS_TEST_DIR=\"${TEST_INSTALL_DIR}\") -pkg_check_modules(gtest_pkgs REQUIRED gmock json-glib-1.0) +pkg_check_modules(gtest_pkgs REQUIRED gmock) INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS}) @@ -35,4 +35,9 @@ ADD_EXECUTABLE(${SSTT_GTEST_INTERFACE} ${SSTT_COMMON_SRC} ${SSTT_GTEST_INTERFACE TARGET_LINK_LIBRARIES(${SSTT_GTEST_INTERFACE} ${MOCK_LIB} ${gtest_pkgs_LIBRARIES} ${pkgs_LIBRARIES} dl) INSTALL(TARGETS ${SSTT_GTEST_INTERFACE} DESTINATION ${TEST_INSTALL_DIR}) +SET(SSTT_GTEST_FONT_ERR "sst-unit-test-err-font") +SET(SSTT_GTEST_FONT_ERR_SRC sst_gtest_err_font.cpp) +ADD_EXECUTABLE(${SSTT_GTEST_FONT_ERR} ${SSTT_COMMON_SRC} ${SSTT_GTEST_FONT_ERR_SRC}) +TARGET_LINK_LIBRARIES(${SSTT_GTEST_FONT_ERR} ${MOCK_LIB} ${gtest_pkgs_LIBRARIES} ${pkgs_LIBRARIES} dl) +INSTALL(TARGETS ${SSTT_GTEST_FONT_ERR} DESTINATION ${TEST_INSTALL_DIR}) diff --git a/tests/res/font_scale_giant_error.json b/tests/res/font_scale_giant_error.json new file mode 100644 index 0000000..57ef590 --- /dev/null +++ b/tests/res/font_scale_giant_error.json @@ -0,0 +1,7 @@ +{ + "SMALL" : -80, + "NORMAL" : -100, + "LARGE" : -150, + "HUGE" : -190, + "GIANT" : "err_val" +} diff --git a/tests/res/font_scale_huge_error.json b/tests/res/font_scale_huge_error.json new file mode 100644 index 0000000..da49d6d --- /dev/null +++ b/tests/res/font_scale_huge_error.json @@ -0,0 +1,7 @@ +{ + "SMALL" : -80, + "NORMAL" : -100, + "LARGE" : -150, + "HUGE" : "err_val", + "GIANT" : -250 +} diff --git a/tests/res/font_scale_large_error.json b/tests/res/font_scale_large_error.json new file mode 100644 index 0000000..1126fbf --- /dev/null +++ b/tests/res/font_scale_large_error.json @@ -0,0 +1,7 @@ +{ + "SMALL" : -80, + "NORMAL" : -100, + "LARGE" : "err_val", + "HUGE" : -190, + "GIANT" : -250 +} diff --git a/tests/res/font_scale_normal_error.json b/tests/res/font_scale_normal_error.json new file mode 100644 index 0000000..6be665a --- /dev/null +++ b/tests/res/font_scale_normal_error.json @@ -0,0 +1,7 @@ +{ + "SMALL" : -80, + "NORMAL" : "err_val", + "LARGE" : -150, + "HUGE" : -190, + "GIANT" : -250 +} diff --git a/tests/res/font_scale_small_error.json b/tests/res/font_scale_small_error.json new file mode 100644 index 0000000..28e698b --- /dev/null +++ b/tests/res/font_scale_small_error.json @@ -0,0 +1,7 @@ +{ + "SMALL" : "err_val", + "NORMAL" : -100, + "LARGE" : -150, + "HUGE" : -190, + "GIANT" : -250 +} diff --git a/tests/sst_gtest_err_font.cpp b/tests/sst_gtest_err_font.cpp new file mode 100644 index 0000000..2b8249f --- /dev/null +++ b/tests/sst_gtest_err_font.cpp @@ -0,0 +1,256 @@ +/* + * 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 +#include +#include +#include +#include + +#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; +} + diff --git a/tests/sst_gtest_normal_font.cpp b/tests/sst_gtest_normal_font.cpp index a50ce68..8da5ea2 100644 --- a/tests/sst_gtest_normal_font.cpp +++ b/tests/sst_gtest_normal_font.cpp @@ -18,15 +18,25 @@ #include #include #include +#include #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) @@ -80,6 +90,45 @@ TEST(SstFontTest, setFontSizeERR) 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;