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 const char* const sst_utils_library = SETTING_UTILS_SO_FILE_PATH;
25 static int dl_is_available_font(char *str)
30 int (*check_available_font)(char *font_name);
32 handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
34 ERR("dlopen(%s) Fail", sst_utils_library);
38 check_available_font = dlsym(handle, "sstu_is_available_font");
39 if ((error = dlerror()) != NULL) {
40 ERR("dlsym(sstu_is_available_font) Fail(%s)", error);
44 ret = check_available_font(str);
49 static void dl_font_size_set()
53 void(*set_font_size)();
55 handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
57 ERR("dlopen(%s) Fail", sst_utils_library);
61 set_font_size = dlsym(handle, "sstu_set_font_size");
62 if ((error = dlerror()) != NULL) {
63 ERR("dlsym(sstu_set_font_size) Fail(%s)", error);
72 static void dl_font_config_set_notification()
76 void (*set_font_nodification)();
78 handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
80 ERR("dlopen(%s) Fail", sst_utils_library);
84 set_font_nodification = dlsym(handle, "sstu_font_config_set_notification");
85 if ((error = dlerror()) != NULL) {
86 ERR("dlsym(sstu_font_config_set_notification) Fail(%s)", error);
90 set_font_nodification();
95 static bool dl_font_config_set(char *font_name)
100 bool (*check_font_type)(char *font_name);
102 handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
103 if (NULL == handle) {
104 ERR("dlopen(%s) Fail", sst_utils_library);
108 check_font_type = dlsym(handle, "sstu_set_font_config");
109 if ((error = dlerror()) != NULL) {
110 ERR("dlsym(sstu_set_font_config) Fail(%s)", error);
114 ret = check_font_type(font_name);
119 static char *dl_get_default_font_info()
124 char *(*get_font_info)();
126 handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
127 if (NULL == handle) {
128 ERR("dlopen(%s) Fail", sst_utils_library);
132 get_font_info = dlsym(handle, "sstu_get_default_font");
133 if ((error = dlerror()) != NULL) {
134 ERR("dlsym(sstu_get_default_font) Fail(%s)", error);
138 ret = get_font_info();
143 int sst_font_set_size(sst_interface *iface, void *value)
146 vconf_value = *(int **)value;
148 RETVM_IF(*vconf_value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < *vconf_value,
149 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid value(%d)", *vconf_value);
151 if (vconf_set_int(iface->vconf_key, *vconf_value)) {
152 ERR("vconf_set_int(%s) Fail", iface->vconf_key);
153 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
157 return SYSTEM_SETTINGS_ERROR_NONE;
160 static void* font_conf_doc_parse(char *doc_name, char *font_name)
162 xmlDocPtr doc = NULL;
163 xmlNodePtr cur = NULL;
164 xmlNodePtr cur2 = NULL;
165 xmlNodePtr cur3 = NULL;
168 doc = xmlParseFile(doc_name);
170 cur = xmlDocGetRootElement(doc);
178 if (xmlStrcmp(cur->name, (const xmlChar*)"fontconfig")) {
184 cur = cur->xmlChildrenNode;
186 bool is_changed = false;
187 while (cur != NULL) {
188 if ((!xmlStrcmp(cur->name, (const xmlChar*)"match"))) {
189 cur2 = cur->xmlChildrenNode;
190 while (cur2 != NULL) {
191 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"edit"))) {
192 xmlChar *name = xmlGetProp(cur2, (const xmlChar*)"name");
193 /* if name is not 'family', break */
194 if (xmlStrcmp(name, (const xmlChar*)"family")) {
202 cur3 = cur2->xmlChildrenNode;
203 while (cur3 != NULL) {
204 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"string"))) {
205 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
206 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
216 } else if ((!xmlStrcmp(cur->name, (const xmlChar*)"alias"))) {
217 cur2 = cur->xmlChildrenNode;
218 while (cur2 != NULL) {
219 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"family"))) {
220 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar*)font_name);
221 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
225 } else if ((!xmlStrcmp(cur2->name, (const xmlChar*)"prefer"))) {
226 cur3 = cur2->xmlChildrenNode;
227 while (cur3 != NULL) {
228 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"family"))) {
229 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
230 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
255 int sst_font_set_type(sst_interface *iface, void *value)
257 char *font_name = NULL;
258 font_name = (char*)value;
260 /* get current font list */
261 int is_found = dl_is_available_font(font_name);
263 DBG("found font : %s ", font_name);
265 ERR(" NOT found font : %s ", font_name);
266 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
269 bool bsave = dl_font_config_set(font_name);
271 ERR("dl_font_config_set() Fail");
272 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
275 xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
277 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
282 dl_font_config_set_notification();
285 vconf_value = (char*)value;
286 if (vconf_set_str(iface->vconf_key, vconf_value)) {
287 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
288 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
291 return SYSTEM_SETTINGS_ERROR_NONE;
294 int sst_font_get_default_type(sst_interface *iface, void **value)
296 char *font_name = dl_get_default_font_info();
297 if (NULL == font_name) {
298 ERR("dl_get_default_font_info() Fail");
299 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
302 *value = (void*)font_name;
303 return SYSTEM_SETTINGS_ERROR_NONE;