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_resolution.h"
17 #include "print_log.h"
18
19 namespace OHOS::Print {
PrintResolution()20 PrintResolution::PrintResolution() : id_(""), horizontalDpi_(0), verticalDpi_(0) {
21 }
22
PrintResolution(const PrintResolution & right)23 PrintResolution::PrintResolution(const PrintResolution &right)
24 {
25 SetId(right.id_);
26 SetHorizontalDpi(right.horizontalDpi_);
27 SetVerticalDpi(right.verticalDpi_);
28 }
29
operator =(const PrintResolution & right)30 PrintResolution &PrintResolution::operator=(const PrintResolution &right)
31 {
32 if (this != &right) {
33 SetId(right.id_);
34 SetHorizontalDpi(right.horizontalDpi_);
35 SetVerticalDpi(right.verticalDpi_);
36 }
37 return *this;
38 }
39
~PrintResolution()40 PrintResolution::~PrintResolution()
41 {
42 }
43
Reset()44 void PrintResolution::Reset()
45 {
46 SetId("");
47 SetHorizontalDpi(0);
48 SetVerticalDpi(0);
49 }
50
GetId() const51 const std::string &PrintResolution::GetId() const
52 {
53 return id_;
54 }
55
GetHorizontalDpi() const56 uint32_t PrintResolution::GetHorizontalDpi() const
57 {
58 return horizontalDpi_;
59 }
60
GetVerticalDpi() const61 uint32_t PrintResolution::GetVerticalDpi() const
62 {
63 return verticalDpi_;
64 }
65
SetId(const std::string & id)66 void PrintResolution::SetId(const std::string &id)
67 {
68 id_ = id;
69 }
70
SetHorizontalDpi(uint32_t horizontalDpi)71 void PrintResolution::SetHorizontalDpi(uint32_t horizontalDpi)
72 {
73 horizontalDpi_ = horizontalDpi;
74 }
75
SetVerticalDpi(uint32_t verticalDpi)76 void PrintResolution::SetVerticalDpi(uint32_t verticalDpi)
77 {
78 verticalDpi_ = verticalDpi;
79 }
80
ReadFromParcel(Parcel & parcel)81 void PrintResolution::ReadFromParcel(Parcel &parcel)
82 {
83 SetId(parcel.ReadString());
84 SetHorizontalDpi(parcel.ReadUint32());
85 SetVerticalDpi(parcel.ReadUint32());
86 }
87
Marshalling(Parcel & parcel) const88 bool PrintResolution::Marshalling(Parcel &parcel) const
89 {
90 parcel.WriteString(GetId());
91 parcel.WriteUint32(GetHorizontalDpi());
92 parcel.WriteUint32(GetVerticalDpi());
93 return true;
94 }
95
Unmarshalling(Parcel & parcel)96 std::shared_ptr<PrintResolution> PrintResolution::Unmarshalling(Parcel &parcel)
97 {
98 auto nativeObj = std::make_shared<PrintResolution>();
99 if (nativeObj != nullptr) {
100 nativeObj->ReadFromParcel(parcel);
101 }
102 return nativeObj;
103 }
104
Dump()105 void PrintResolution::Dump()
106 {
107 PRINT_HILOGD("id_ = %{public}s", id_.c_str());
108 PRINT_HILOGD("horizontalDpi_ = %{public}d", horizontalDpi_);
109 PRINT_HILOGD("verticalDpi_ = %{public}d", verticalDpi_);
110 }
111 } // namespace OHOS::Print
112