2 * Copyright (c) 2012 - 2014 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 "nine_patch_file_list_bin_parser.h"
21 #include "put_record.h"
23 BinNinePatchFileParser::BinNinePatchFileParser() {
25 memset(m_nine_patch_file_list, 0x00, sizeof(SclNinePatchInfo) * MAX_NINE_PATCH_FILE_LIST);
26 parser_info_provider = NULL;
29 BinNinePatchFileParser::~BinNinePatchFileParser() {
32 BinNinePatchFileParser* BinNinePatchFileParser::get_instance() {
33 static BinNinePatchFileParser instance;
36 void BinNinePatchFileParser::init(const FileStorage& storage, int offset, int size, IParserInfo_Provider* provider) {
37 m_storage.set_str_provider(provider);
38 m_storage.get_storage(storage, offset, size);
39 this->parser_info_provider = provider;
41 parsing_nine_patch_file_list();
44 void BinNinePatchFileParser::parsing_nine_patch_file_list() {
45 Nine_patch_width record_width;
46 set_nine_patch_width(*parser_info_provider, record_width);
51 SclNinePatchInfo* cur = m_nine_patch_file_list;
52 m_size = m_storage.get<sint_t>(4);
53 for (int i = 0; i < m_size; ++i) {
55 m_storage.get_str(&(temp), record_width.image_path, m_string_collector);
56 cur->image_path = (char*)temp;
58 cur->left = m_storage.get<sint_t>(record_width.left);
59 cur->right = m_storage.get<sint_t>(record_width.right);
60 cur->top = m_storage.get<sint_t>(record_width.top);
61 cur->bottom = m_storage.get<sint_t>(record_width.bottom);
64 #ifdef __SCL_TXT_DEBUG
65 put_nine_patch_info(DECODE, m_nine_patch_file_list);
70 BinNinePatchFileParser::get_nine_patch_list() {
71 return m_nine_patch_file_list;
74 BinNinePatchFileParser::get_nine_patch_info(const char* filename, SclNinePatchInfo *info) {
75 if (filename == NULL) return false;
77 for (int i = 0; i < MAX_NINE_PATCH_FILE_LIST && i < m_size; ++i) {
78 if ( m_nine_patch_file_list[i].image_path != NULL &&
79 0 == strcmp(m_nine_patch_file_list[i].image_path, filename) ) {
81 *info = m_nine_patch_file_list[i];