Reload xml files when resolution gets changed
[platform/core/uifw/libscl-ui.git] / xml2binary / encode_nine_patch.cpp
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include "encode_nine_patch.h"
19 #include <string>
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"
25 #include <dlog.h>
26
27 using namespace std;
28 using namespace xmlresource;
29 static void
30 encode_nine_patch_info(ResourceStorage& storage, const SclNinePatchInfo* cur, const Nine_patch_width& record_width) {
31     assert(cur != NULL);
32     storage.encode_string(cur->image_path, record_width.image_path);
33     //left
34     storage.put<sint_t>(cur->left, record_width.left);
35     //right
36     storage.put<sint_t>(cur->right, record_width.right);
37     //top
38     storage.put<sint_t>(cur->top, record_width.top);
39     //bottom
40     storage.put<sint_t>(cur->bottom, record_width.bottom);
41 }
42
43 int
44 encode_nine_patch_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
45     int init_size = storage.get_size();
46
47     XMLResource *xmlresource = XMLResource::get_instance();
48     if (xmlresource == NULL) {
49         LOGW("Error: failed to get xmlresource instance.\n");
50         return 0;
51     }
52     SclNinePatchInfo* ninePatchInfoTable = xmlresource->get_nine_patch_list();
53     if (ninePatchInfoTable == NULL) {
54         LOGW("Warning: nine patch list is null\n");
55         return 0;
56     }
57 #ifdef __SCL_TXT_DEBUG
58     put_nine_patch_info(ENCODE, ninePatchInfoTable);
59
60 #endif
61     storage.reserve(8);
62     storage.put<sint_t>(MAX_NINE_PATCH_FILE_LIST, 4);
63
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);
69         cur++;
70     }
71
72     int size = storage.get_size() - init_size;
73     storage.random_put<sint_t>(size, 8, init_size);
74
75     return storage.get_size();
76 }
77
78 int
79 encode_nine_patch_file(const char* file, IMetaData_Helper& md_helper) {
80     if (!file) return 0;
81
82     ResourceStorage storage;
83     encode_nine_patch_file(storage, md_helper);
84     storage.toFile(file);
85
86     return storage.get_size();
87 }
88
89 int
90 encode_nine_patch_file(const char* file, int& offset,  IMetaData_Helper& md_helper) {
91     if (!file) return 0;
92
93     ResourceStorage storage;
94     encode_nine_patch_file(storage, md_helper);
95     storage.toFile(file, offset);
96
97     return storage.get_size();
98 }