2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 "tizen-font-configuration-parser.h"
21 #include <libxml/xmlmemory.h>
22 #include <libxml/parser.h>
24 #include <dali/integration-api/debug.h>
29 namespace TizenPlatform
32 namespace FontConfigurationParser
35 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TIZEN_FONT_CONFIGURATION_PARSER");
42 void Parse(std::string confFile, std::string& fontFamily, std::string& fontStyle)
44 bool familyParsed(false);
45 bool styleParsed(false);
47 if ( !confFile.empty() )
49 xmlDocPtr doc = xmlParseFile(confFile.c_str());
52 DALI_LOG_ERROR("Document %s not parsed successfully.\n", confFile.c_str());
56 xmlNodePtr cur = xmlDocGetRootElement(doc);
59 DALI_LOG_ERROR("%s is Empty\n", confFile.c_str());
64 if(xmlStrcmp(cur->name, (const xmlChar *)"fontconfig"))
66 DALI_LOG_ERROR("Document %s is of the wrong type, root node != fontconfig\n", confFile.c_str());
71 cur = cur->xmlChildrenNode;
73 while(cur != NULL && !(familyParsed && styleParsed))
75 if((!xmlStrcmp(cur->name, (const xmlChar *)"match")))
77 xmlNodePtr cur2 = cur->xmlChildrenNode;
78 while(cur2 != NULL && !(familyParsed && styleParsed))
80 if((!xmlStrcmp(cur2->name, (const xmlChar *)"edit")))
82 xmlChar* xmlValue = xmlGetProp( cur2, (const xmlChar *)"name" );
83 if((!xmlStrcmp(xmlValue, (const xmlChar *)"family")))
85 xmlNodePtr cur3 = cur2->xmlChildrenNode;
86 while(cur3 != NULL && !(familyParsed && styleParsed))
88 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
90 xmlChar* key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
91 DALI_LOG_INFO(gLogFilter,Debug::Concise, "Document %s uses the following font family as default: %s\n", confFile.c_str(), key);
92 std::stringstream str;
94 fontFamily = str.str();
102 else if((!xmlStrcmp(xmlValue, (const xmlChar *)"style")))
104 xmlNodePtr cur3 = cur2->xmlChildrenNode;
105 while(cur3 != NULL && !(familyParsed && styleParsed))
107 if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
109 xmlChar* key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
110 DALI_LOG_INFO(gLogFilter,Debug::Concise, "Document %s uses the following font style as default: %s\n", confFile.c_str(), key);
111 std::stringstream str;
113 fontStyle = str.str();
133 } // namespace FontConfParser
135 } // namespace TizenPlatform