2 * Copyright (c) 2011-2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "sst_utils_wrapper.h"
20 #include <fontconfig/fontconfig.h>
21 #include <Ecore_Evas.h>
22 #include <efl_extension.h>
23 #include "system_settings.h"
27 #define SMALL_FONT_DPI (-90)
29 #define SMALL_FONT_DPI (-80)
32 #define MIDDLE_FONT_DPI (-100)
35 #define LARGE_FONT_DPI (-110)
37 #define LARGE_FONT_DPI (-150)
40 #define HUGE_FONT_DPI (-190)
41 #define GIANT_FONT_DPI (-250)
43 #define SETTING_FONT_PRELOAD_FONT_PATH _TZ_SYS_RO_SHARE"/fonts"
44 #define SETTING_FONT_DOWNLOADED_FONT_PATH _TZ_SYS_SHARE"/fonts"
46 #define SETTING_FONT_TIZEN_FONT_ALIAS "Tizen"
47 #define SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS "TizenDefaultFont"
49 static char* _get_main_font_family(char *alias)
53 FcConfig *font_config = NULL;
54 FcChar8 *family = NULL;
58 font_config = FcInitLoadConfigAndFonts();
59 if (NULL == font_config) {
60 ERR("FcInitLoadConfigAndFonts() Fail");
64 pat = FcPatternBuild(0, FC_FAMILY, FcTypeString, alias, NULL);
66 ERR("FcPatternBuild() Fail");
67 FcConfigDestroy(font_config);
71 FcConfigSubstitute(font_config, pat, FcMatchPattern);
72 FcDefaultSubstitute(pat);
75 set = FcFontSort(font_config, pat, FcTrue, NULL, &res);
77 if (set && 0 < set->nfont) {
78 int result = FcPatternGetString(set->fonts[0], FC_FAMILY, 0, &family);
79 if (FcResultMatch != result) {
80 ERR("FcPatternGetString() Fail(%d)", result);
85 ret = strdup((char*)family);
90 FcFontSetDestroy(set);
92 FcPatternDestroy(pat);
93 FcConfigDestroy(font_config);
98 API bool sstu_is_valid_image(const char *path)
103 if (0 == ecore_evas_init()) {
104 ERR("ecore_evas_init() Fail");
108 ee = ecore_evas_buffer_new(100, 100);
109 evas = ecore_evas_get(ee);
111 void *img = evas_object_image_add(evas);
112 evas_object_image_file_set(img, path, NULL);
113 int ret = evas_object_image_load_error_get(img);
119 ERR("Invalid(%s)", path);
123 ecore_evas_shutdown();
127 API void sstu_font_config_set_notification()
131 API int sstu_is_available_font(const char *font_name)
136 FcConfig *font_config;
139 RETV_IF(NULL == font_name, -1);
141 font_config = FcInitLoadConfigAndFonts();
142 if (NULL == font_config)
143 ERR("FcInitLoadConfigAndFonts() Fail");
145 char *locale = setlocale(0, NULL);
146 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, NULL);
148 ERR("FcObjectSetBuild() Fail");
149 FcConfigDestroy(font_config);
153 pat = FcPatternCreate();
155 ERR("FcPatternCreate() Fail");
156 FcObjectSetDestroy(os);
157 FcConfigDestroy(font_config);
161 fs = FcFontList(font_config, pat, os);
162 FcPatternDestroy(pat);
163 FcObjectSetDestroy(os);
165 ERR("FcFontList() Fail");
166 FcConfigDestroy(font_config);
170 INFO("fs->nfont = %d", fs->nfont);
173 for (i = 0; i < fs->nfont; i++) {
174 FcChar8 *file = NULL;
175 FcChar8 *family = NULL;
178 result = FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file);
179 if (FcResultMatch != result || NULL == file) {
180 ERR("FcPatternGetString() Fail(%d)", result);
181 FcFontSetDestroy(fs);
182 FcConfigDestroy(font_config);
185 const char *preloaded = SETTING_FONT_PRELOAD_FONT_PATH;
186 const char *downloaded = SETTING_FONT_DOWNLOADED_FONT_PATH;
187 int preload_len = sizeof(SETTING_FONT_PRELOAD_FONT_PATH) - 1;
188 int download_len = sizeof(SETTING_FONT_DOWNLOADED_FONT_PATH) - 1;
190 if (SST_EQUAL == strncmp((char*)file, preloaded, preload_len)
191 || SST_EQUAL == strncmp((char*)file, downloaded, download_len)) {
192 char *family_result = NULL;
193 FcChar8 *lang = NULL;
195 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, id, &family) != FcResultMatch)
197 if (FcPatternGetString(fs->fonts[i], FC_FAMILYLANG, id, &lang) != FcResultMatch)
199 family_result = (char*)family;
201 /* Find proper family name for current locale. */
202 while (locale && family && lang) {
203 if (SST_EQUAL == strncmp(locale, (char*)lang, strlen((char*)lang))) {
204 family_result = (char*)family;
208 /* I will set english as default family language. */
209 /* If there is no proper family language for current locale, */
210 /* we have to show the english family name. */
211 if (SST_EQUAL == strcmp((char*)lang, "en"))
212 family_result = (char*)family;
215 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, id, &family) != FcResultMatch)
217 if (FcPatternGetString(fs->fonts[i], FC_FAMILYLANG, id, &lang) != FcResultMatch)
222 DBG("family = %s", family_result);
223 if (strcmp(family_result, font_name) == 0) {
230 FcFontSetDestroy(fs);
231 FcConfigDestroy(font_config);
235 API char* sstu_get_default_font()
237 return _get_main_font_family(SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS);
240 static int _get_font_size()
244 int vconf_value = -1;
245 if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
246 ERR("vconf_get_int() Fail");
250 switch (vconf_value) {
251 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
252 font_size = SMALL_FONT_DPI;
254 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
255 font_size = MIDDLE_FONT_DPI;
257 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
258 font_size = LARGE_FONT_DPI;
260 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
261 font_size = HUGE_FONT_DPI;
263 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
264 font_size = GIANT_FONT_DPI;
267 font_size = MIDDLE_FONT_DPI;
273 API bool sstu_set_font_config(const char *font_name)
275 int font_size = _get_font_size();
276 return eext_config_font_set((char*)font_name, font_size);
279 API void sstu_set_font_size()
281 int font_size = _get_font_size();
282 char *font_name = NULL;
283 font_name = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
284 eext_config_font_set(font_name, font_size);