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, int value)
25 RETVM_IF(value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < value,
26 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid size(%d)", value);
28 if (vconf_set_int(iface->vconf_key, value)) {
29 ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value);
30 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
34 return SYSTEM_SETTINGS_ERROR_NONE;
37 static void* font_conf_doc_parse(const char *doc_name, const char *font_name)
40 xmlNodePtr cur = NULL;
41 xmlNodePtr cur2 = NULL;
42 xmlNodePtr cur3 = NULL;
45 doc = xmlParseFile(doc_name);
46 cur = xmlDocGetRootElement(doc);
53 if (xmlStrcmp(cur->name, (const xmlChar*)"fontconfig")) {
59 cur = cur->xmlChildrenNode;
61 bool is_changed = false;
63 if ((!xmlStrcmp(cur->name, (const xmlChar*)"match"))) {
64 cur2 = cur->xmlChildrenNode;
65 while (cur2 != NULL) {
66 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"edit"))) {
67 xmlChar *name = xmlGetProp(cur2, (const xmlChar*)"name");
68 /* if name is not 'family', break */
69 if (xmlStrcmp(name, (const xmlChar*)"family")) {
77 cur3 = cur2->xmlChildrenNode;
78 while (cur3 != NULL) {
79 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"string"))) {
80 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
81 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
91 } else if ((!xmlStrcmp(cur->name, (const xmlChar*)"alias"))) {
92 cur2 = cur->xmlChildrenNode;
93 while (cur2 != NULL) {
94 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"family"))) {
95 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar*)font_name);
96 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
100 } else if ((!xmlStrcmp(cur2->name, (const xmlChar*)"prefer"))) {
101 cur3 = cur2->xmlChildrenNode;
102 while (cur3 != NULL) {
103 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"family"))) {
104 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
105 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
130 int sst_font_set_type(sst_interface *iface, const char *font_name)
132 /* get current font list */
133 int is_found = sstu_is_available_font(font_name);
134 if (FALSE == is_found) {
135 ERR("NO font(%s)", font_name);
136 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
139 bool bsave = sstu_set_font_config(font_name);
141 ERR("sstu_set_font_config() Fail");
142 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
145 xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
147 int ret = xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
150 ERR("xmlSaveFormatFile() Fail");
151 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
155 sstu_font_config_set_notification();
157 if (vconf_set_str(iface->vconf_key, font_name)) {
158 ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, font_name);
159 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
162 return SYSTEM_SETTINGS_ERROR_NONE;
165 int sst_font_get_type(sst_interface *iface, char **value)
167 RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
168 RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
170 char *result = vconf_get_str(iface->vconf_key);
171 if (NULL == result) {
172 ERR("vconf_get_str(%s) Fail(NULL)", iface->vconf_key);
173 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
176 if (SST_EQUAL == strcmp(result, "Default")) {
178 return sst_font_get_default_type(iface, value);
183 return SYSTEM_SETTINGS_ERROR_NONE;
186 int sst_font_get_default_type(sst_interface *iface, char **value)
188 char *font_name = sstu_get_default_font();
189 if (NULL == font_name) {
190 ERR("sstu_get_default_font() Fail");
191 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
195 return SYSTEM_SETTINGS_ERROR_NONE;