2 * Copyright 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 "resource_storage_impl.h"
19 #include "encode_layout.h"
21 #include <libxml/parser.h>
23 #include "xmlresource.h"
24 #include "put_record.h"
25 #include "_auto_metadata.h"
27 using namespace xmlresource;
28 extern IString_Encoder& string_encoder;
30 static void _encode_color(ResourceStorage& storage, const SclColor& color, int width) {
31 if (width <= 0) return;
33 storage.put<sint_t>(color.r, width);
34 storage.put<sint_t>(color.g, width);
35 storage.put<sint_t>(color.b, width);
36 storage.put<sint_t>(color.a, width);
40 encode_layout_record(ResourceStorage& storage, PSclLayout cur, const Layout_width& record_width) {
42 storage.encode_string((const char*)cur->name, record_width.name);
44 storage.put<sint_t>(cur->display_mode, record_width.display_mode);
47 storage.put<sint_t>(cur->style, record_width.style);
50 storage.put<sint_t>(cur->width, record_width.width);
53 storage.put<sint_t>(cur->height, record_width.height);
56 storage.put<sint_t>(cur->use_sw_button, record_width.use_sw_button);
58 //use_magnifier_window
59 storage.put<sint_t>(cur->use_magnifier_window, record_width.use_magnifier_window);
62 storage.put<sint_t>(cur->extract_background, record_width.extract_background);
65 storage.put<sint_t>(cur->key_width, record_width.key_width);
68 storage.put<sint_t>(cur->key_height, record_width.key_height);
70 storage.put<sint_t>(cur->key_spacing, record_width.key_spacing);
72 storage.put<sint_t>(cur->row_spacing, record_width.row_spacing);
75 storage.put<sint_t>(cur->use_sw_background, record_width.use_sw_background);
77 _encode_color(storage, cur->bg_color, record_width.bg_color);
80 storage.put<float_t>(cur->bg_line_width, record_width.bg_line_width);
82 _encode_color(storage, cur->bg_line_color, record_width.bg_line_color);
85 storage.put<sint_t>(cur->add_grab_left, record_width.add_grab_left);
88 storage.put<sint_t>(cur->add_grab_right, record_width.add_grab_right);
91 storage.put<sint_t>(cur->add_grab_top, record_width.add_grab_top);
94 storage.put<sint_t>(cur->add_grab_bottom, record_width.add_grab_bottom);
97 for (int i = 0; i < SCL_BUTTON_STATE_MAX; ++i) {
98 storage.encode_string(cur->image_path[i], record_width.image_path);
101 //key_background_image
102 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
103 for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
104 storage.encode_string(cur->key_background_image[i][j], record_width.key_background_image);
109 storage.encode_string(cur->sound_style, record_width.sound_style);
111 storage.encode_string(cur->vibe_style, record_width.vibe_style);
113 storage.encode_string(cur->label_type, record_width.label_type);
115 storage.encode_string(cur->modifier_decorator, record_width.modifier_decorator);
119 encode_layout_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
120 // 4 byte (range[0-4,294,967,295))
121 const int DATA_SIZE_BYTES = 4;
122 // 1 byte (range[0-128))
123 const int REC_NUM_BYTES = 1;
124 // 2 byte (range[0-65536))
125 const int LAYOUT_REC_DATA_SIZE_BYTES = 2;
127 const int init_size = storage.size();
129 XMLResource *xmlresource = XMLResource::get_instance();
130 PSclLayout layoutTable = xmlresource->get_layout_table();
132 int size = xmlresource->get_layout_size();
134 #ifdef __SCL_TXT_DEBUG
135 put_layout_table(ENCODE, layoutTable);
138 PSclLayout cur = layoutTable;
141 storage.reserve(DATA_SIZE_BYTES);
144 storage.put<sint_t>(size, REC_NUM_BYTES);
147 storage.reserve(LAYOUT_REC_DATA_SIZE_BYTES);
149 Layout_width record_width;
150 set_layout_width(md_helper, record_width);
152 int layout_rec_data_size = 0;
153 for ( int i = 0; i < size; ++i) {
154 int pre_size = storage.size();
155 encode_layout_record(storage, cur, record_width);
157 int aft_size = storage.size();
158 if (layout_rec_data_size == 0) {
159 layout_rec_data_size = aft_size - pre_size;
161 assert(layout_rec_data_size == aft_size - pre_size);
166 // back write data size
167 int advance_size = storage.size() - init_size;
169 // random put advance_size
170 int data_size_offset = init_size;
171 storage.random_put<sint_t>(advance_size, DATA_SIZE_BYTES, data_size_offset);
173 // random put layout_rec size
174 int layout_rec_data_offset = init_size + DATA_SIZE_BYTES + REC_NUM_BYTES;
175 storage.random_put<sint_t>(layout_rec_data_size, LAYOUT_REC_DATA_SIZE_BYTES, layout_rec_data_offset);
177 return storage.size();
181 encode_layout_file(const char* file, IMetaData_Helper& md_helper) {
184 ResourceStorage storage;
185 encode_layout_file(storage, md_helper);
187 storage.toFile(file);
189 return storage.size();
193 encode_layout_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
196 ResourceStorage storage;
197 encode_layout_file(storage, md_helper);
199 storage.toFile(file, offset);
201 return storage.size();