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 "encode_nine_patch.h"
20 #include "xmlresource.h"
21 #include "imetadata_helper.h"
22 #include "resource_storage_impl.h"
23 #include "put_record.h"
24 #include "_auto_metadata.h"
28 using namespace xmlresource;
30 encode_nine_patch_info(ResourceStorage& storage, const SclNinePatchInfo* cur, const Nine_patch_width& record_width) {
32 storage.encode_string(cur->image_path, record_width.image_path);
34 storage.put<sint_t>(cur->left, record_width.left);
36 storage.put<sint_t>(cur->right, record_width.right);
38 storage.put<sint_t>(cur->top, record_width.top);
40 storage.put<sint_t>(cur->bottom, record_width.bottom);
44 encode_nine_patch_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
45 int init_size = storage.get_size();
47 XMLResource *xmlresource = XMLResource::get_instance();
48 if (xmlresource == NULL) {
49 LOGW("Error: failed to get xmlresource instance.\n");
52 SclNinePatchInfo* ninePatchInfoTable = xmlresource->get_nine_patch_list();
53 if (ninePatchInfoTable == NULL) {
54 LOGW("Warning: nine patch list is null\n");
57 #ifdef __SCL_TXT_DEBUG
58 put_nine_patch_info(ENCODE, ninePatchInfoTable);
62 storage.put<sint_t>(MAX_NINE_PATCH_FILE_LIST, 4);
64 Nine_patch_width record_width;
65 set_nine_patch_width(md_helper, record_width);
66 SclNinePatchInfo* cur = ninePatchInfoTable;
67 for (int i = 0; i < MAX_NINE_PATCH_FILE_LIST; ++i) {
68 encode_nine_patch_info(storage, cur, record_width);
72 int size = storage.get_size() - init_size;
73 storage.random_put<sint_t>(size, 8, init_size);
75 return storage.get_size();
79 encode_nine_patch_file(const char* file, IMetaData_Helper& md_helper) {
82 ResourceStorage storage;
83 encode_nine_patch_file(storage, md_helper);
86 return storage.get_size();
90 encode_nine_patch_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
93 ResourceStorage storage;
94 encode_nine_patch_file(storage, md_helper);
95 storage.toFile(file, offset);
97 return storage.get_size();