580905eeac13b91bc04c159669bbea78f731f875
[platform/core/uifw/libscl-ui-nui.git] / xml2binary / encode_label_properties_frame.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 "resource_storage_impl.h"
19 #include "encode_label_properties_frame.h"
20 #include <string>
21 #include "xmlresource.h"
22 #include "put_record.h"
23 #include "_auto_metadata.h"
24 using namespace xmlresource;
25 using namespace std;
26 static void _encode_color(ResourceStorage& storage, const SclColor& color, int width) {
27     if (width <= 0) return;
28     storage.put<sint_t>(color.r, width);
29     storage.put<sint_t>(color.g, width);
30     storage.put<sint_t>(color.b, width);
31     storage.put<sint_t>(color.a, width);
32 }
33
34 static void
35 encode_label_properties_record(ResourceStorage& storage, const PSclLabelProperties cur, const Label_properties_record_width& record_width) {
36     if (cur == NULL) return;
37
38     //label_name
39     storage.encode_string(cur->label_type, record_width.label_type);
40
41     //font_name
42     storage.encode_string(cur->font_name, record_width.font_name);
43
44     //font_size
45     storage.put<sint_t>(cur->font_size, record_width.font_size);
46
47     //font color
48     for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
49         for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
50             _encode_color(storage, cur->font_color[i][j], record_width.font_color);
51         }
52     }
53
54     //alignment
55     storage.put<sint_t>(cur->alignment, record_width.alignment);
56
57     //padding_x
58     storage.put<sint_t>(cur->padding_x, record_width.padding_x);
59
60     //padding_y
61     storage.put<sint_t>(cur->padding_y, record_width.padding_y);
62
63     //inner_width
64     storage.put<sint_t>(cur->inner_width, record_width.inner_width);
65
66     //inner_height
67     storage.put<sint_t>(cur->inner_height, record_width.inner_height);
68
69     //shadow_distance
70     storage.put<sint_t>(cur->shadow_distance, record_width.shadow_distance);
71
72     //shadow_direction
73     storage.put<sint_t>(cur->shadow_direction, record_width.shadow_direction);
74
75     //shadow_color
76     for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
77         for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
78             _encode_color(storage, cur->shadow_color[i][j], record_width.shadow_color);
79         }
80     }
81 }
82
83 int
84 encode_label_properties_frame_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
85     int init_size = storage.get_size();
86
87     /*size 4bytes*/
88     const int _SIZE_WIDTH = 4;
89
90     XMLResource *xmlresource = XMLResource::get_instance();
91     PSclLabelPropertiesTable labelPropertiesFrame = xmlresource->get_label_properties_frame();
92
93 #ifdef __SCL_TXT_DEBUG
94     put_label_properties_frame(ENCODE, labelPropertiesFrame);
95
96 #endif
97     int size = xmlresource->get_labelproperty_size();
98     int maxj = MAX_SIZE_OF_LABEL_FOR_ONE;
99
100     storage.reserve(8);
101
102     storage.put<sint_t>(size, _SIZE_WIDTH);
103     storage.put<sint_t>(maxj, _SIZE_WIDTH);
104
105     Label_properties_record_width record_width;
106     set_label_properties_record_width(md_helper, record_width);
107     for ( int i = 0; i < size; ++i ) {
108         for ( int j = 0; j < maxj; ++j ) {
109             SclLabelProperties cur = labelPropertiesFrame[i][j];
110             encode_label_properties_record(storage, &cur, record_width);
111         }
112     }
113
114     int advance_size = storage.get_size() - init_size;
115     storage.random_put<sint_t>(advance_size, 8, init_size);
116
117     return storage.get_size();
118 }
119
120 int
121 encode_label_properties_frame_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
122     if (!file) return 0;
123
124
125     ResourceStorage storage;
126     encode_label_properties_frame_file(storage, md_helper);
127     storage.toFile(file, offset);
128
129     return storage.get_size();
130 }
131
132 int
133 encode_label_properties_frame_file(const char* file, IMetaData_Helper& md_helper) {
134     if (!file) return 0;
135
136
137     ResourceStorage storage;
138     encode_label_properties_frame_file(storage, md_helper);
139     storage.toFile(file);
140
141     return storage.get_size();
142 }