18 #include <libxml/xmlmemory.h>
19 #include <libxml/parser.h>
21 #include <fontconfig/fontconfig.h>
23 #include <Elementary.h>
25 #include <Ecore_Evas.h>
27 #include <pkgmgr-info.h>
29 #include <system_settings.h>
30 #include <system_settings_private.h>
32 #include <tzplatform_config.h>
33 #include <system_settings_util.h>
36 #define SMALL_FONT_DPI (-90)
39 #define SMALL_FONT_DPI (-80)
41 #define MIDDLE_FONT_DPI (-100)
43 #define LARGE_FONT_DPI (-110)
46 #define LARGE_FONT_DPI (-150)
48 #define HUGE_FONT_DPI (-190)
49 #define GIANT_FONT_DPI (-250)
51 #define SETTING_FONT_PRELOAD_FONT_PATH _TZ_SYS_RO_SHARE"/fonts"
52 #define SETTING_FONT_DOWNLOADED_FONT_PATH _TZ_SYS_RO_SHARE"/fonts"
54 #define SETTING_FONT_CONF_FILE _TZ_SYS_ETC"/fonts/conf.avail/99-tizen.conf"
55 #define SETTING_DEFAULT_FONT_CONF_FILE _TZ_SYS_ETC"/fonts/conf.avail/99-tizen.conf"
58 bool font_config_set(char *font_name);
59 int __is_available_font(char *font_name);
60 char *_get_default_font();
61 char *_get_cur_font();
63 int __font_size_get();
64 void __font_size_set();
66 bool __is_supported_image_type_load(char *path)
74 ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
75 evas = ecore_evas_get(ee);
77 Evas_Object *img = evas_object_image_add(evas);
78 evas_object_image_file_set(img, path, NULL);
79 Evas_Load_Error ret = evas_object_image_load_error_get(img);
82 if (ret == EVAS_LOAD_ERROR_NONE) {
83 SETTING_TRACE("%s - OK", path);
86 SETTING_TRACE("%s - NO", path);
94 bool __is_supported_image_type(char *path)
100 if (evas_object_image_extension_can_load_get(path))
110 char *_get_cur_font()
113 xmlDocPtr doc = NULL;
114 xmlNodePtr cur = NULL;
115 xmlNodePtr cur2 = NULL;
116 xmlNodePtr cur3 = NULL;
119 char *font_name = NULL;
121 doc = xmlParseFile(SETTING_FONT_CONF_FILE);
123 cur = xmlDocGetRootElement(doc);
131 if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
137 cur = cur->xmlChildrenNode;
139 while (cur != NULL) {
140 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
141 cur2 = cur->xmlChildrenNode;
142 while (cur2 != NULL) {
143 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
144 cur3 = cur2->xmlChildrenNode;
145 while (cur3 != NULL) {
146 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
147 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
149 font_name = g_strdup((char *)key);
170 void font_config_set_notification()
175 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
176 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
177 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
181 int __is_available_font(char *font_name)
184 FcObjectSet *os = NULL;
185 FcFontSet *fs = NULL;
186 FcPattern *pat = NULL;
187 FcConfig *font_config = NULL;
191 if (font_name == NULL)
194 font_config = FcInitLoadConfigAndFonts();
196 /*setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts"); */
198 char *locale = setlocale(0, NULL);
200 pat = FcPatternCreate();
202 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, (char *) 0);
205 fs = FcFontList(font_config, pat, os);
206 FcObjectSetDestroy(os);
211 FcPatternDestroy(pat);
217 SETTING_TRACE("fs->nfont = %d", fs->nfont);
219 for (j = 0; j < fs->nfont; j++) {
220 FcChar8 *family = NULL;
221 FcChar8 *file = NULL;
223 if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
224 int preload_path_len = strlen(SETTING_FONT_PRELOAD_FONT_PATH);
225 int download_path_len = strlen(SETTING_FONT_DOWNLOADED_FONT_PATH);
227 if (file && (!strncmp((const char *)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len)
228 || !strncmp((const char *)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len))) {
229 char *family_result = NULL;
230 FcChar8 *lang = NULL;
232 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
235 if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
238 family_result = (char *)family;
240 /* Find proper family name for current locale. */
241 while (locale && family && lang) {
242 if (!strncmp(locale, (char *)lang, strlen((char *)lang))) {
243 family_result = (char *)family;
247 /* I will set english as default family language. */
248 /* If there is no proper family language for current locale, */
249 /* we have to show the english family name. */
250 if (!strcmp((char *)lang, (char *)"en")) {
251 family_result = (char *)family;
254 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
257 if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
263 SETTING_TRACE("-------- FONT - family_result = %s", (char *)family_result);
264 if (strcmp(family_result, font_name) == 0) {
272 FcFontSetDestroy(fs);
275 FcConfigDestroy(font_config);
281 char *_get_default_font()
284 xmlDocPtr doc = NULL;
285 xmlNodePtr cur = NULL;
286 xmlNodePtr cur2 = NULL;
287 xmlNodePtr cur3 = NULL;
289 struct _xmlAttr *properties = NULL;
290 char *default_font_name = NULL;
292 doc = xmlParseFile(SETTING_DEFAULT_FONT_CONF_FILE);
294 cur = xmlDocGetRootElement(doc);
302 if (xmlStrcmp(cur->name, (const xmlChar *)"fontconfig")) {
308 cur = cur->xmlChildrenNode;
310 while (cur != NULL) {
311 if ((!xmlStrcmp(cur->name, (const xmlChar *)"match"))) {
312 cur2 = cur->xmlChildrenNode;
313 while (cur2 != NULL) {
314 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"edit"))) {
315 properties = cur2->properties;
316 /*find the "name" property*/
317 while (NULL != properties) {
318 if (!xmlStrcmp(properties->name, (const xmlChar *)"name")) {
321 properties = properties->next;
324 /*If the value of "name" property is "family", then get the child node string,
325 it shall be the default font type*/
326 if (NULL != properties && !xmlStrcmp(properties->children->content, (const xmlChar *)"family")) {
327 cur3 = cur2->xmlChildrenNode;
328 while (cur3 != NULL) {
329 if ((!xmlStrcmp(cur3->name, (const xmlChar *)"string"))) {
330 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
331 default_font_name = g_strdup((char *)key);
336 return default_font_name;
353 bool font_config_set(char *font_name)
356 Eina_List *text_classes = NULL;
357 Elm_Text_Class *etc = NULL;
358 const Eina_List *l = NULL;
359 Eina_List *fo_list = NULL;
360 Elm_Font_Overlay *efo = NULL;
362 int font_size = __font_size_get();
365 text_classes = elm_config_text_classes_list_get();
367 fo_list = (Eina_List *)elm_config_font_overlay_list_get();
369 Eina_List *ll = NULL;
370 Eina_List *l_next = NULL;
372 Eina_Bool slp_medium_exist = EINA_FALSE;
373 Eina_Bool slp_roman_exist = EINA_FALSE;
374 Eina_Bool slp_bold_exist = EINA_FALSE;
375 Eina_Bool slp_regular_exist = EINA_FALSE;
378 Eina_Bool tizen_exist = EINA_FALSE;
380 EINA_LIST_FOREACH_SAFE(fo_list, ll, l_next, efo) {
381 if (!strcmp(efo->text_class, "tizen_medium")) {
382 elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
383 slp_medium_exist = EINA_TRUE;
384 } else if (!strcmp(efo->text_class, "tizen_roman")) {
385 elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
386 slp_roman_exist = EINA_TRUE;
387 } else if (!strcmp(efo->text_class, "tizen_bold")) {
388 elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
389 slp_bold_exist = EINA_TRUE;
390 } else if (!strcmp(efo->text_class, "tizen_regular")) {
391 elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
392 slp_regular_exist = EINA_TRUE;
396 if (!strcmp(efo->text_class, "tizen")) {
397 elm_config_font_overlay_set(efo->text_class, (const char *)font_name, efo->size);
398 tizen_exist = EINA_TRUE;
403 /* if slp_XX do not exist, need to set them, font size is -100(100%) */
404 if (slp_medium_exist == EINA_FALSE) {
405 elm_config_font_overlay_set("tizen_medium", (const char *)font_name, MIDDLE_FONT_DPI);
407 if (slp_roman_exist == EINA_FALSE) {
408 elm_config_font_overlay_set("tizen_roman", (const char *)font_name, MIDDLE_FONT_DPI);
410 if (slp_bold_exist == EINA_FALSE) {
411 elm_config_font_overlay_set("tizen_bold", (const char *)font_name, MIDDLE_FONT_DPI);
413 if (slp_regular_exist == EINA_FALSE) {
414 elm_config_font_overlay_set("tizen_regular", (const char *)font_name, MIDDLE_FONT_DPI);
418 if (tizen_exist == EINA_FALSE) {
419 elm_config_font_overlay_set("tizen", (const char *)font_name, MIDDLE_FONT_DPI);
422 elm_config_font_overlay_set("tizen", (const char *)font_name, MIDDLE_FONT_DPI);
425 elm_config_font_overlay_set("tizen", (const char *)font_name, MIDDLE_FONT_DPI);
427 EINA_LIST_FOREACH(text_classes, l, etc) {
431 EINA_LIST_FOREACH(fo_list, ll, efo) {
432 if (!strcmp(etc->name, efo->text_class)) {
436 elm_config_font_overlay_set(etc->name, (const char *)font_name, size);
438 elm_config_text_classes_list_free(text_classes);
441 /* add new function */
442 #ifdef USE_EFL_ASSIST
443 ea_theme_system_font_set(font_name, font_size);
444 ea_theme_system_fonts_apply();
447 elm_config_font_overlay_apply();
448 elm_config_all_flush();
453 void __font_size_set()
456 Eina_List *text_classes = NULL;
457 Elm_Text_Class *etc = NULL;
458 const Eina_List *l = NULL;
459 int font_size = __font_size_get();
460 char *font_name = _get_cur_font();
462 if (font_size == -1) {
466 text_classes = elm_config_text_classes_list_get();
468 EINA_LIST_FOREACH(text_classes, l, etc) {
469 elm_config_font_overlay_set(etc->name, font_name, font_size);
472 elm_config_text_classes_list_free(text_classes);
474 #ifdef USE_EFL_ASSIST
475 ea_theme_system_font_set(font_name, font_size);
476 ea_theme_system_fonts_apply();
479 elm_config_font_overlay_apply();
480 elm_config_all_flush();
487 int __font_size_get()
492 int vconf_value = -1;
493 if (system_setting_vconf_get_value_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
497 switch (vconf_value) {
498 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
499 font_size = SMALL_FONT_DPI;
501 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
502 font_size = MIDDLE_FONT_DPI;
504 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
505 font_size = LARGE_FONT_DPI;
507 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
508 font_size = HUGE_FONT_DPI;
510 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
511 font_size = GIANT_FONT_DPI;
514 font_size = MIDDLE_FONT_DPI;