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.
18 #include <libxml/tree.h>
21 #include "sst_utils_wrapper.h"
23 int sst_font_set_size(sst_interface *iface, void *value)
26 vconf_value = *(int **)value;
28 RETVM_IF(*vconf_value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < *vconf_value,
29 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid value(%d)", *vconf_value);
31 if (vconf_set_int(iface->vconf_key, *vconf_value)) {
32 ERR("vconf_set_int(%s) Fail", iface->vconf_key);
33 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
37 return SYSTEM_SETTINGS_ERROR_NONE;
40 static void* font_conf_doc_parse(char *doc_name, char *font_name)
43 xmlNodePtr cur = NULL;
44 xmlNodePtr cur2 = NULL;
45 xmlNodePtr cur3 = NULL;
48 doc = xmlParseFile(doc_name);
50 cur = xmlDocGetRootElement(doc);
58 if (xmlStrcmp(cur->name, (const xmlChar*)"fontconfig")) {
64 cur = cur->xmlChildrenNode;
66 bool is_changed = false;
68 if ((!xmlStrcmp(cur->name, (const xmlChar*)"match"))) {
69 cur2 = cur->xmlChildrenNode;
70 while (cur2 != NULL) {
71 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"edit"))) {
72 xmlChar *name = xmlGetProp(cur2, (const xmlChar*)"name");
73 /* if name is not 'family', break */
74 if (xmlStrcmp(name, (const xmlChar*)"family")) {
82 cur3 = cur2->xmlChildrenNode;
83 while (cur3 != NULL) {
84 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"string"))) {
85 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
86 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
96 } else if ((!xmlStrcmp(cur->name, (const xmlChar*)"alias"))) {
97 cur2 = cur->xmlChildrenNode;
98 while (cur2 != NULL) {
99 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"family"))) {
100 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar*)font_name);
101 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
105 } else if ((!xmlStrcmp(cur2->name, (const xmlChar*)"prefer"))) {
106 cur3 = cur2->xmlChildrenNode;
107 while (cur3 != NULL) {
108 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"family"))) {
109 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
110 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
135 int sst_font_set_type(sst_interface *iface, void *value)
137 char *font_name = NULL;
138 font_name = (char*)value;
140 /* get current font list */
141 int is_found = sstu_is_available_font(font_name);
143 DBG("found font : %s ", font_name);
145 ERR(" NOT found font : %s ", font_name);
146 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
149 bool bsave = sstu_set_font_config(font_name);
151 ERR("sstu_set_font_config() Fail");
152 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
155 xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
157 xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
162 sstu_font_config_set_notification();
165 vconf_value = (char*)value;
166 if (vconf_set_str(iface->vconf_key, vconf_value)) {
167 ERR("vconf_set_str(%s) Fail", iface->vconf_key);
168 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
171 return SYSTEM_SETTINGS_ERROR_NONE;
174 int sst_font_get_default_type(sst_interface *iface, void **value)
176 char *font_name = sstu_get_default_font();
177 if (NULL == font_name) {
178 ERR("sstu_get_default_font() Fail");
179 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
182 *value = (void*)font_name;
183 return SYSTEM_SETTINGS_ERROR_NONE;