tizen 2.4 release
[framework/uifw/libscl-ui.git] / xml2binary / encode_modifier_decoration.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_modifier_decoration.h"
19 #include "xmlresource.h"
20 #include "resource_storage_impl.h"
21 #include "put_record.h"
22 #include "_auto_metadata.h"
23 #include <dlog.h>
24
25 using namespace xmlresource;
26 static void
27 encode_modifier_decoration_record(ResourceStorage& storage, const PSclModifierDecoration cur, const Modifier_decoration_width& record_width) {
28     storage.put<sint_t>(cur->extract_background, record_width.extract_background);
29     storage.encode_string(cur->name, record_width.name);
30     for (int i = 0; i < DISPLAYMODE_MAX; ++i) {
31         for (int j = 0; j < KEY_MODIFIER_MAX; ++j) {
32             storage.encode_string(cur->bg_image_path[i][j], record_width.bg_image_path);
33         }
34     }
35 }
36
37 int
38 encode_modifier_decoration_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
39
40     int init_size = storage.get_size();
41
42     XMLResource *xmlresource = XMLResource::get_instance();
43     PSclModifierDecoration modifierDecorationTable = xmlresource->get_modifier_decoration_table();
44     if (modifierDecorationTable == NULL) {
45         LOGW("Error. modifier decoration table is NULL");
46         return 0;
47     }
48
49 #ifdef __SCL_TXT_DEBUG
50     put_modifier_decoration(ENCODE, modifierDecorationTable);
51
52 #endif
53     Modifier_decoration_width record_width;
54     set_modifier_decoration_width(md_helper, record_width);
55
56     storage.reserve(8);
57
58     storage.put<sint_t>(MAX_SCL_MODIFIER_DECORATION_NUM, 4);
59     PSclModifierDecoration cur = modifierDecorationTable;
60     for (int i = 0; i < MAX_SCL_MODIFIER_DECORATION_NUM; ++i) {
61         encode_modifier_decoration_record(storage, cur, record_width);
62         cur++;
63     }
64
65     int advance_size = storage.get_size() - init_size;
66     storage.random_put<sint_t>(advance_size, 8, init_size);
67
68     return storage.get_size();
69 }
70
71 int
72 encode_modifier_decoration_file(const char* file, IMetaData_Helper& md_helper) {
73     if (!file) return 0;
74
75     ResourceStorage storage;
76
77     encode_modifier_decoration_file(storage, md_helper);
78     storage.toFile(file);
79
80     return storage.get_size();
81 }
82
83 int
84 encode_modifier_decoration_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
85     if (!file) return 0;
86
87     ResourceStorage storage;
88
89     encode_modifier_decoration_file(storage, md_helper);
90     storage.toFile(file, offset);
91
92     return storage.get_size();
93 }