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_page_size.h"
17 #include "print_log.h"
18
19 namespace OHOS::Print {
20 std::map<PAGE_SIZE_ID, std::shared_ptr<PrintPageSize>> PrintPageSize::pageSize_;
BuildPageSizeMap()21 void PrintPageSize::BuildPageSizeMap()
22 {
23 PRINT_HILOGD("");
24 }
25
PrintPageSize()26 PrintPageSize::PrintPageSize() : id_(""), name_("PrintPageSize"), width_(0), height_(0) {}
27
PrintPageSize(PAGE_SIZE_ID id,DiscretePageName name,uint32_t width,uint32_t height)28 PrintPageSize::PrintPageSize(PAGE_SIZE_ID id, DiscretePageName name, uint32_t width, uint32_t height)
29 {
30 id_ = id;
31 name_ = name;
32 width_ = width;
33 height_ = height;
34 }
35
GetPageSize(PageSizeId id)36 PrintPageSize PrintPageSize::GetPageSize(PageSizeId id)
37 {
38 uint32_t pageSizeId = (uint32_t)id;
39 if (pageSizeId < (uint32_t)sizeof(PAGE_SIZE_TABLE)) {
40 auto iter = pageSize_.find(PAGE_SIZE_TABLE[pageSizeId]);
41 if (iter != pageSize_.end()) {
42 return *(iter->second);
43 }
44 }
45 PrintPageSize printPageSize;
46 return printPageSize;
47 }
48
PrintPageSize(const PrintPageSize & right)49 PrintPageSize::PrintPageSize(const PrintPageSize &right)
50 {
51 id_ = right.id_;
52 name_ = right.name_;
53 width_ = right.width_;
54 height_ = right.height_;
55 }
56
operator =(const PrintPageSize & right)57 PrintPageSize &PrintPageSize::operator=(const PrintPageSize &right)
58 {
59 if (this != &right) {
60 id_ = right.id_;
61 name_ = right.name_;
62 width_ = right.width_;
63 height_ = right.height_;
64 }
65 return *this;
66 }
67
~PrintPageSize()68 PrintPageSize::~PrintPageSize()
69 {
70 }
71
Reset()72 void PrintPageSize::Reset()
73 {
74 SetId("");
75 SetName("");
76 SetWidth(0);
77 SetHeight(0);
78 }
79
SetId(const std::string & id)80 void PrintPageSize::SetId(const std::string &id)
81 {
82 id_ = id;
83 }
84
SetName(const std::string & name)85 void PrintPageSize::SetName(const std::string &name)
86 {
87 name_ = name;
88 }
89
SetWidth(uint32_t width)90 void PrintPageSize::SetWidth(uint32_t width)
91 {
92 width_ = width;
93 }
94
SetHeight(uint32_t height)95 void PrintPageSize::SetHeight(uint32_t height)
96 {
97 height_ = height;
98 }
99
GetId() const100 const std::string &PrintPageSize::GetId() const
101 {
102 return id_;
103 }
104
GetName() const105 const std::string &PrintPageSize::GetName() const
106 {
107 return name_;
108 }
109
GetWidth() const110 uint32_t PrintPageSize::GetWidth() const
111 {
112 return width_;
113 }
114
GetHeight() const115 uint32_t PrintPageSize::GetHeight() const
116 {
117 return height_;
118 }
119
ReadFromParcel(Parcel & parcel)120 void PrintPageSize::ReadFromParcel(Parcel &parcel)
121 {
122 SetId(parcel.ReadString());
123 SetName(parcel.ReadString());
124 SetWidth(parcel.ReadUint32());
125 SetHeight(parcel.ReadUint32());
126 }
127
Marshalling(Parcel & parcel) const128 bool PrintPageSize::Marshalling(Parcel &parcel) const
129 {
130 parcel.WriteString(GetId());
131 parcel.WriteString(GetName());
132 parcel.WriteUint32(GetWidth());
133 parcel.WriteUint32(GetHeight());
134 return true;
135 }
136
Unmarshalling(Parcel & parcel)137 std::shared_ptr<PrintPageSize> PrintPageSize::Unmarshalling(Parcel &parcel)
138 {
139 auto nativeObj = std::make_shared<PrintPageSize>();
140 if (nativeObj != nullptr) {
141 nativeObj->ReadFromParcel(parcel);
142 }
143 return nativeObj;
144 }
145
Dump()146 void PrintPageSize::Dump()
147 {
148 PRINT_HILOGD("id_ = %{public}s", id_.c_str());
149 PRINT_HILOGD("name_ = %{public}s", name_.c_str());
150 PRINT_HILOGD("width_ = %{public}d", width_);
151 PRINT_HILOGD("height_ = %{public}d", height_);
152 }
153 } // namespace OHOS::Print
154