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>
22 #include "sst_utils_wrapper.h"
24 int sst_font_set_size(sst_interface *iface, int value)
26 RETVM_IF(value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < value,
27 SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid size(%d)", value);
29 if (vconf_set_int(iface->vconf_key, value)) {
30 ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value);
31 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
35 return SYSTEM_SETTINGS_ERROR_NONE;
38 static void* font_conf_doc_parse(const char *doc_name, const char *font_name)
41 xmlNodePtr cur = NULL;
42 xmlNodePtr cur2 = NULL;
43 xmlNodePtr cur3 = NULL;
46 doc = xmlParseFile(doc_name);
47 cur = xmlDocGetRootElement(doc);
54 if (xmlStrcmp(cur->name, (const xmlChar*)"fontconfig")) {
60 cur = cur->xmlChildrenNode;
62 bool is_changed = false;
64 if ((!xmlStrcmp(cur->name, (const xmlChar*)"match"))) {
65 cur2 = cur->xmlChildrenNode;
66 while (cur2 != NULL) {
67 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"edit"))) {
68 xmlChar *name = xmlGetProp(cur2, (const xmlChar*)"name");
69 /* if name is not 'family', break */
70 if (xmlStrcmp(name, (const xmlChar*)"family")) {
78 cur3 = cur2->xmlChildrenNode;
79 while (cur3 != NULL) {
80 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"string"))) {
81 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
82 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
92 } else if ((!xmlStrcmp(cur->name, (const xmlChar*)"alias"))) {
93 cur2 = cur->xmlChildrenNode;
94 while (cur2 != NULL) {
95 if ((!xmlStrcmp(cur2->name, (const xmlChar*)"family"))) {
96 xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar*)font_name);
97 key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
101 } else if ((!xmlStrcmp(cur2->name, (const xmlChar*)"prefer"))) {
102 cur3 = cur2->xmlChildrenNode;
103 while (cur3 != NULL) {
104 if ((!xmlStrcmp(cur3->name, (const xmlChar*)"family"))) {
105 xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar*)font_name);
106 key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
131 int sst_font_set_type(sst_interface *iface, const char *font_name)
133 /* get current font list */
134 int is_found = sstu_is_available_font(font_name);
135 if (FALSE == is_found) {
136 ERR("NO font(%s)", font_name);
137 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
140 bool bsave = sstu_set_font_config(font_name);
142 ERR("sstu_set_font_config() Fail");
143 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
146 xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
148 int ret = xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
151 ERR("xmlSaveFormatFile() Fail");
152 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
156 sstu_font_config_set_notification();
158 if (vconf_set_str(iface->vconf_key, font_name)) {
159 ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, font_name);
160 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
163 return SYSTEM_SETTINGS_ERROR_NONE;
166 int sst_font_get_type(sst_interface *iface, char **value)
168 RETV_IF(NULL == iface, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
169 RETV_IF(NULL == iface->vconf_key, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
171 char *result = vconf_get_str(iface->vconf_key);
172 if (NULL == result) {
173 ERR("vconf_get_str(%s) Fail(NULL)", iface->vconf_key);
174 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
177 if (SST_EQUAL == strcmp(result, "Default")) {
179 return sst_font_get_default_type(iface, value);
184 return SYSTEM_SETTINGS_ERROR_NONE;
187 int sst_font_get_default_type(sst_interface *iface, char **value)
189 char *font_name = sstu_get_default_font();
190 if (NULL == font_name) {
191 ERR("sstu_get_default_font() Fail");
192 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
196 return SYSTEM_SETTINGS_ERROR_NONE;