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.
19 #include <libxml/tree.h>
23 static int dl_is_available_font(char *str)
28 int (*check_available_font)(char *font_name);
30 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY);
32 SST_SECURE_TRACE("ERROR!! canNOT find libsystem-settings-util.so");
36 check_available_font = dlsym(handle, "__is_available_font");
37 if ((error = dlerror()) != NULL) {
38 SST_SECURE_TRACE("ERROR!! canNOT find __is_available_font function at libsystem-settings-util.so");
43 ret = check_available_font(str);
49 static void dl_font_size_set()
53 void(*set_font_size)();
55 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY);
57 SST_SECURE_TRACE("ERROR!! canNOT find libsystem-settings-util.so");
61 set_font_size = dlsym(handle, "__font_size_set");
62 if ((error = dlerror()) != NULL) {
63 SST_SECURE_TRACE("ERROR!! canNOT find __font_size_set function at libsystem-settings-util.so");
74 static void dl_font_config_set_notification()
78 void (*set_font_nodification)();
80 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY);
82 SST_SECURE_TRACE("ERROR!! canNOT find libsystem-settings-util.so");
86 set_font_nodification = dlsym(handle, "font_config_set_notification");
87 if ((error = dlerror()) != NULL) {
88 SST_SECURE_TRACE("ERROR!! canNOT find font_config_set_notification function at libsystem-settings-util.so");
93 set_font_nodification();
99 static bool dl_font_config_set(char *font_name)
104 bool (*check_font_type)(char *font_name);
106 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY);
108 SST_SECURE_TRACE("ERROR!! canNOT find libsystem-settings-util.so");
112 check_font_type = dlsym(handle, "font_config_set");
113 if ((error = dlerror()) != NULL) {
114 SST_SECURE_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so");
119 ret = check_font_type(font_name);
125 static char *dl_get_default_font_info()
130 char *(*get_font_info)();
132 handle = dlopen(SETTING_UTILS_SO_FILE_PATH, RTLD_LAZY);
134 SST_SECURE_TRACE("ERROR!! canNOT find libsystem-settings-util.so");
138 get_font_info = dlsym(handle, "_get_default_font");
140 if ((error = dlerror()) != NULL) {
141 SST_SECURE_TRACE("ERROR!! canNOT find _get_default_font function at libsystem-settings-util.so");
146 ret = get_font_info();
152 int system_setting_set_font_size(system_setting_h item, void *value)
155 vconf_value = *(int **)value;
157 if (*vconf_value < 0 || *vconf_value > SYSTEM_SETTINGS_FONT_SIZE_GIANT)
158 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
160 if (vconf_set_int(item->vconf_key, *vconf_value))
161 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
164 return SYSTEM_SETTINGS_ERROR_NONE;
167 static void* font_conf_doc_parse(char *doc_name, char *font_name)
169 xmlDocPtr doc = NULL;
170 xmlNodePtr cur = NULL;
171 xmlNodePtr cur2 = NULL;
172 xmlNodePtr cur3 = NULL;
175 doc = xmlParseFile(doc_name);
177 cur = xmlDocGetRootElement(doc);
185 if (xmlStrcmp(cur->name, (const xmlChar*)"fontconfig")) {
191 cur = cur->xmlChildrenNode;
193 bool is_changed = false;
194 while (cur != NULL) {
195 if ((!xmlStrcmp(cur->name, (const xmlChar*)"match"))) {
196 cur2 = cur->xmlChildrenNode;
197 while (cur2 != NULL) {
198 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"edit"))) {
199 xmlChar *name = xmlGetProp(cur2, (const xmlChar*)"name");
200 /* if name is not 'family', break */
201 if (xmlStrcmp(name, (const xmlChar*)"family")) {
209 cur3 = cur2->xmlChildrenNode;
210 while (cur3 != NULL) {
211 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"string"))) {
212 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
213 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
223 } else if ((!xmlStrcmp(cur->name, (const xmlChar*)"alias"))) {
224 cur2 = cur->xmlChildrenNode;
225 while (cur2 != NULL) {
226 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"family"))) {
227 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar*)font_name);
228 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
232 } else if ((!xmlStrcmp(cur2->name, (const xmlChar*)"prefer"))) {
233 cur3 = cur2->xmlChildrenNode;
234 while (cur3 != NULL) {
235 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"family"))) {
236 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
237 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
262 int system_setting_set_font_type(system_setting_h item, void *value)
264 char *font_name = NULL;
265 font_name = (char*)value;
267 /* get current font list */
268 int is_found = dl_is_available_font(font_name);
271 SST_SECURE_TRACE("found font : %s ", font_name);
273 SST_SECURE_TRACE(" NOT found font : %s ", font_name);
274 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
277 bool bsave = dl_font_config_set(font_name);
280 SST_SECURE_TRACE(" font type save error by font_config_set() ");
281 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
283 SST_SECURE_TRACE(" save OK - font_config_set() ");
286 xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
288 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
293 dl_font_config_set_notification();
296 vconf_value = (char*)value;
298 if (vconf_set_str(item->vconf_key, vconf_value))
299 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
301 return SYSTEM_SETTINGS_ERROR_NONE;
304 int system_setting_get_default_font_type(system_setting_h item, void **value)
306 char *font_name = dl_get_default_font_info();
308 *value = (void*)font_name;
309 return SYSTEM_SETTINGS_ERROR_NONE;
311 return SYSTEM_SETTINGS_ERROR_IO_ERROR;