9db7bb031c8918e903f2ea3d4a293811f5092c1a
[platform/core/uifw/libscl-ui-nui.git] / scl / label_properties_bin_parser.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 "label_properties_bin_parser.h"
19 #include "simple_debug.h"
20 #include "put_record.h"
21
22 BinLabelPropertyParser::BinLabelPropertyParser() {
23     m_size = 0;
24     memset(m_label_properties_frame, 0, sizeof(SclLabelProperties) * MAX_SCL_LABEL_PROPERTIES * MAX_SIZE_OF_LABEL_FOR_ONE);
25     parser_info_provider = NULL;
26 }
27
28 BinLabelPropertyParser::~BinLabelPropertyParser() {
29     m_size = 0;
30 }
31
32 BinLabelPropertyParser* BinLabelPropertyParser::get_instance() {
33     static BinLabelPropertyParser instance;
34     return &instance;
35 }
36 void BinLabelPropertyParser::init(const FileStorage& storage, int offset, int size, IParserInfo_Provider* provider) {
37     m_storage.set_str_provider(parser_info_provider);
38     m_storage.get_storage(storage, offset, size);
39     this->parser_info_provider = provider;
40     parsing_label_properties_frame();
41 }
42 int
43 BinLabelPropertyParser::get_size() {
44     return m_size;
45 }
46
47 //recompute_layout will change the table
48 PSclLabelPropertiesTable BinLabelPropertyParser::get_label_properties_frame() {
49     return m_label_properties_frame;
50 }
51
52 void BinLabelPropertyParser::parsing_label_properties_frame() {
53     // skip data_size
54     m_storage.advance(8);
55
56     m_size = m_storage.get<sint_t>(4);
57     int maxj = m_storage.get<sint_t>(4);
58
59     if (parser_info_provider == NULL) {
60         SCLLOG(SclLog::ERROR, "Error parser_info_provider is NULL\n");
61         return;
62     }
63
64     Label_properties_record_width record_width;
65     set_label_properties_record_width(*parser_info_provider, record_width);
66     for (int i = 0; i < m_size; ++i) {
67         for (int j = 0; j < maxj; ++j) {
68             SclLabelProperties &cur = m_label_properties_frame[i][j];
69             decode_label_properties_record(&cur, record_width);
70         }
71     }
72 #ifdef __SCL_TXT_DEBUG
73     put_label_properties_frame(DECODE, m_label_properties_frame);
74 #endif
75 }
76
77 void
78 BinLabelPropertyParser::decode_color(SclColor& color, int width) {
79     if (width <= 0) return;
80
81     color.r = m_storage.get<sint_t>(width);
82     color.g = m_storage.get<sint_t>(width);
83     color.b = m_storage.get<sint_t>(width);
84     color.a = m_storage.get<sint_t>(width);
85 }
86 void
87 BinLabelPropertyParser::decode_label_properties_record(const PSclLabelProperties cur, const Label_properties_record_width& record_width) {
88     cur->valid = (sclboolean)true;
89
90     //label_name
91     m_storage.get_str(&(cur->label_type), record_width.label_type, m_string_collector);
92     //font_name
93     m_storage.get_str(&(cur->font_name), record_width.font_name, m_string_collector);
94
95     //font_size
96     cur->font_size = m_storage.get<sint_t>(record_width.font_size);
97     //font color
98         for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
99             for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
100                 decode_color(cur->font_color[i][j], record_width.font_color);
101             }
102         }
103
104     //alignment
105     cur->alignment = (SCLLabelAlignment)m_storage.get<sint_t>(record_width.alignment);
106
107     //padding_x
108     cur->padding_x = m_storage.get<sint_t>(record_width.padding_x);
109
110     //padding_y
111     cur->padding_y = m_storage.get<sint_t>(record_width.padding_y);
112
113     //inner_width
114     cur->inner_width = m_storage.get<sint_t>(record_width.inner_width);
115
116     //inner_height
117     cur->inner_height = m_storage.get<sint_t>(record_width.inner_height);
118
119     //shadow_distance
120     cur->shadow_distance = m_storage.get<sint_t>(record_width.shadow_distance);
121
122     //shadow_direction
123     cur->shadow_direction = (SCLShadowDirection)m_storage.get<sint_t>(record_width.shadow_direction);
124
125     //shadow_color
126         for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
127             for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
128                 decode_color(cur->shadow_color[i][j], record_width.shadow_color);
129             }
130         }
131 }