1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "print_margin.h"
17 #include "print_log.h"
18
19 namespace OHOS::Print {
PrintMargin()20 PrintMargin::PrintMargin() : hasTop_(false), top_(0), hasBottom_(false), bottom_(0), hasLeft_(false), left_(0),
21 hasRight_(false), right_(0) {
22 }
23
PrintMargin(const PrintMargin & right)24 PrintMargin::PrintMargin(const PrintMargin &right)
25 {
26 Set(right);
27 }
28
Set(const PrintMargin & right)29 void PrintMargin::Set(const PrintMargin &right)
30 {
31 hasTop_ = right.hasTop_;
32 top_ = right.top_;
33 hasBottom_ = right.hasBottom_;
34 bottom_ = right.bottom_;
35 hasLeft_ = right.hasLeft_;
36 left_ = right.left_;
37 hasRight_ = right.hasRight_;
38 right_ = right.right_;
39 }
40
operator =(const PrintMargin & right)41 PrintMargin &PrintMargin::operator=(const PrintMargin &right)
42 {
43 if (this != &right) {
44 Set(right);
45 }
46 return *this;
47 }
48
~PrintMargin()49 PrintMargin::~PrintMargin()
50 {
51 }
52
Reset()53 void PrintMargin::Reset()
54 {
55 hasTop_ = false;
56 top_ = 0;
57 hasBottom_ = false;
58 bottom_ = 0;
59 hasLeft_ = false;
60 left_ = 0;
61 hasRight_ = false;
62 right_ = 0;
63 }
64
SetTop(uint32_t top)65 void PrintMargin::SetTop(uint32_t top)
66 {
67 hasTop_ = true;
68 top_ = top;
69 }
70
SetBottom(uint32_t bottom)71 void PrintMargin::SetBottom(uint32_t bottom)
72 {
73 hasBottom_ = true;
74 bottom_ = bottom;
75 }
76
SetLeft(uint32_t left)77 void PrintMargin::SetLeft(uint32_t left)
78 {
79 hasLeft_ = true;
80 left_ = left;
81 }
82
SetRight(uint32_t right)83 void PrintMargin::SetRight(uint32_t right)
84 {
85 hasRight_ = true;
86 right_ = right;
87 }
88
HasTop() const89 bool PrintMargin::HasTop() const
90 {
91 return hasTop_;
92 }
93
GetTop() const94 uint32_t PrintMargin::GetTop() const
95 {
96 return top_;
97 }
98
HasBottom() const99 bool PrintMargin::HasBottom() const
100 {
101 return hasBottom_;
102 }
103
GetBottom() const104 uint32_t PrintMargin::GetBottom() const
105 {
106 return bottom_;
107 }
108
HasLeft() const109 bool PrintMargin::HasLeft() const
110 {
111 return hasLeft_;
112 }
113
GetLeft() const114 uint32_t PrintMargin::GetLeft() const
115 {
116 return left_;
117 }
118
HasRight() const119 bool PrintMargin::HasRight() const
120 {
121 return hasRight_;
122 }
123
GetRight() const124 uint32_t PrintMargin::GetRight() const
125 {
126 return right_;
127 }
128
ReadFromParcel(Parcel & parcel)129 void PrintMargin::ReadFromParcel(Parcel &parcel)
130 {
131 hasTop_ = parcel.ReadBool();
132 if (hasTop_) {
133 SetTop(parcel.ReadUint32());
134 }
135
136 hasBottom_ = parcel.ReadBool();
137 if (hasBottom_) {
138 SetBottom(parcel.ReadUint32());
139 }
140
141 hasLeft_ = parcel.ReadBool();
142 if (hasLeft_) {
143 SetLeft(parcel.ReadUint32());
144 }
145
146 hasRight_ = parcel.ReadBool();
147 if (hasRight_) {
148 SetRight(parcel.ReadUint32());
149 }
150 }
151
Marshalling(Parcel & parcel) const152 bool PrintMargin::Marshalling(Parcel &parcel) const
153 {
154 parcel.WriteBool(hasTop_);
155 if (hasTop_) {
156 parcel.WriteUint32(GetTop());
157 }
158
159 parcel.WriteBool(hasBottom_);
160 if (hasBottom_) {
161 parcel.WriteUint32(GetBottom());
162 }
163
164 parcel.WriteBool(hasLeft_);
165 if (hasLeft_) {
166 parcel.WriteUint32(GetLeft());
167 }
168
169 parcel.WriteBool(hasRight_);
170 if (hasRight_) {
171 parcel.WriteUint32(GetRight());
172 }
173 return true;
174 }
175
Unmarshalling(Parcel & parcel)176 std::shared_ptr<PrintMargin> PrintMargin::Unmarshalling(Parcel &parcel)
177 {
178 auto nativeObj = std::make_shared<PrintMargin>();
179 if (nativeObj != nullptr) {
180 nativeObj->ReadFromParcel(parcel);
181 }
182 return nativeObj;
183 }
184
Dump()185 void PrintMargin::Dump()
186 {
187 if (hasTop_) {
188 PRINT_HILOGD("top_ = %{public}d", top_);
189 }
190
191 if (hasBottom_) {
192 PRINT_HILOGD("bottom_ = %{public}d", bottom_);
193 }
194
195 if (hasLeft_) {
196 PRINT_HILOGD("left_ = %{public}d", left_);
197 }
198
199 if (hasRight_) {
200 PRINT_HILOGD("right_ = %{public}d", right_);
201 }
202 }
203 } // namespace OHOS::Print
204