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 #ifndef PRINT_PAGESIZE_H 17 #define PRINT_PAGESIZE_H 18 19 #include <map> 20 #include <mutex> 21 #include "parcel.h" 22 23 namespace OHOS::Print { 24 using DiscreteId = std::string; 25 using DiscretePageName = std::string; 26 using PAGE_SIZE_ID = std::string; 27 28 class PrintPageSize final : public Parcelable { 29 public: 30 static void BuildPageSizeMap(); 31 static PAGE_SIZE_ID MatchPageSize(const std::string& pageString); 32 static bool FindPageSizeById(const PAGE_SIZE_ID &id, PrintPageSize& pageSize); 33 34 explicit PrintPageSize(); 35 36 PrintPageSize(PAGE_SIZE_ID id, DiscretePageName name, uint32_t width, uint32_t height); 37 38 PrintPageSize(const PrintPageSize &right); 39 40 PrintPageSize &operator=(const PrintPageSize &right); 41 42 bool operator==(const PrintPageSize &right); 43 44 virtual ~PrintPageSize(); 45 46 void Reset(); 47 48 [[nodiscard]] const std::string &GetId() const; 49 50 [[nodiscard]] const std::string &GetName() const; 51 52 [[nodiscard]] uint32_t GetWidth() const; 53 54 [[nodiscard]] uint32_t GetHeight() const; 55 56 void SetId(const std::string &id); 57 58 void SetName(const std::string &name); 59 60 void SetWidth(uint32_t width); 61 62 void SetHeight(uint32_t height); 63 64 virtual bool Marshalling(Parcel &parcel) const override; 65 66 static std::shared_ptr<PrintPageSize> Unmarshalling(Parcel &parcel); 67 68 void Dump(); 69 70 private: 71 void ReadFromParcel(Parcel &parcel); 72 73 private: 74 std::string id_; 75 std::string name_; 76 uint32_t width_; 77 uint32_t height_; 78 static std::map<PAGE_SIZE_ID, std::shared_ptr<PrintPageSize>> pageSize_; 79 static std::mutex pageSizeMapMutex; 80 }; 81 } // namespace OHOS::Print 82 #endif // PRINT_PAGESIZE_H 83