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