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