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);
78 FcPatternGetString(set->fonts[0], FC_FAMILY, 0, &family);
80 ret = strdup((char*)family);
82 FcFontSetDestroy(set);
85 FcPatternDestroy(pat);
86 FcConfigDestroy(font_config);
91 API bool sstu_is_valid_image(const char *path)
96 if (0 == ecore_evas_init()) {
97 ERR("ecore_evas_init() Fail");
101 ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
102 evas = ecore_evas_get(ee);
104 void *img = evas_object_image_add(evas);
105 evas_object_image_file_set(img, path, NULL);
106 int ret = evas_object_image_load_error_get(img);
112 ERR("Invalid(%s)", path);
116 ecore_evas_shutdown();
120 API void sstu_font_config_set_notification()
124 API int sstu_is_available_font(const char *font_name)
129 FcConfig *font_config;
132 RETV_IF(NULL == font_name, -1);
134 font_config = FcInitLoadConfigAndFonts();
135 if (NULL == font_config)
136 ERR("FcInitLoadConfigAndFonts() Fail");
138 char *locale = setlocale(0, NULL);
139 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, NULL);
141 ERR("FcObjectSetBuild() Fail");
142 FcConfigDestroy(font_config);
146 pat = FcPatternCreate();
148 ERR("FcPatternCreate() Fail");
149 FcObjectSetDestroy(os);
150 FcConfigDestroy(font_config);
154 fs = FcFontList(font_config, pat, os);
155 FcPatternDestroy(pat);
156 FcObjectSetDestroy(os);
158 ERR("FcFontList() Fail");
159 FcConfigDestroy(font_config);
163 INFO("fs->nfont = %d", fs->nfont);
166 for (i = 0; i < fs->nfont; i++) {
167 FcChar8 *file = NULL;
168 FcChar8 *family = NULL;
171 result = FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file);
172 if (FcResultMatch != result || NULL == file) {
173 ERR("FcPatternGetString() Fail(%d)", result);
174 FcFontSetDestroy(fs);
175 FcConfigDestroy(font_config);
178 const char *preloaded = SETTING_FONT_PRELOAD_FONT_PATH;
179 const char *downloaded = SETTING_FONT_DOWNLOADED_FONT_PATH;
180 int preload_len = sizeof(SETTING_FONT_PRELOAD_FONT_PATH) - 1;
181 int download_len = sizeof(SETTING_FONT_DOWNLOADED_FONT_PATH) - 1;
183 if (SST_EQUAL == strncmp((char*)file, preloaded, preload_len)
184 || SST_EQUAL == strncmp((char*)file, downloaded, download_len)) {
185 char *family_result = NULL;
186 FcChar8 *lang = NULL;
188 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, id, &family) != FcResultMatch)
190 if (FcPatternGetString(fs->fonts[i], FC_FAMILYLANG, id, &lang) != FcResultMatch)
192 family_result = (char*)family;
194 /* Find proper family name for current locale. */
195 while (locale && family && lang) {
196 if (SST_EQUAL == strncmp(locale, (char*)lang, strlen((char*)lang))) {
197 family_result = (char*)family;
201 /* I will set english as default family language. */
202 /* If there is no proper family language for current locale, */
203 /* we have to show the english family name. */
204 if (SST_EQUAL == strcmp((char*)lang, "en"))
205 family_result = (char*)family;
208 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, id, &family) != FcResultMatch)
210 if (FcPatternGetString(fs->fonts[i], FC_FAMILYLANG, id, &lang) != FcResultMatch)
215 DBG("family = %s", family_result);
216 if (strcmp(family_result, font_name) == 0) {
223 FcFontSetDestroy(fs);
224 FcConfigDestroy(font_config);
228 API char* sstu_get_default_font()
230 return _get_main_font_family(SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS);
233 static int _get_font_size()
237 int vconf_value = -1;
238 if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
239 ERR("vconf_get_int() Fail");
243 switch (vconf_value) {
244 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
245 font_size = SMALL_FONT_DPI;
247 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
248 font_size = MIDDLE_FONT_DPI;
250 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
251 font_size = LARGE_FONT_DPI;
253 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
254 font_size = HUGE_FONT_DPI;
256 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
257 font_size = GIANT_FONT_DPI;
260 font_size = MIDDLE_FONT_DPI;
266 API bool sstu_set_font_config(const char *font_name)
268 int font_size = _get_font_size();
269 return eext_config_font_set((char*)font_name, font_size);
272 API void sstu_set_font_size()
274 int font_size = _get_font_size();
275 char *font_name = NULL;
276 font_name = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
277 eext_config_font_set(font_name, font_size);