• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_MANAGER_ADAPTER_H
17 #define PRINT_MANAGER_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS::NWeb {
24 
25 struct PrintRangeAdapter {
26     uint32_t startPage;
27     uint32_t endPage;
28     std::vector<uint32_t> pages;
29 };
30 
31 struct PrintPageSizeAdapter {
32     uint32_t width;
33     uint32_t height;
34 };
35 
36 struct PrintMarginAdapter {
37     uint32_t top;
38     uint32_t bottom;
39     uint32_t left;
40     uint32_t right;
41 };
42 
43 struct PrintAttributesAdapter {
44     uint32_t copyNumber;
45     PrintRangeAdapter pageRange;
46     bool isSequential;
47     PrintPageSizeAdapter pageSize;
48     bool isLandscape;
49     uint32_t colorMode;
50     uint32_t duplexMode;
51     PrintMarginAdapter margin;
52     bool hasOption;
53     std::string option;
54 };
55 
56 /*[clang::lto_visibility_public]:Prevent this class from being optimized away at compile time*/
57 class [[clang::lto_visibility_public]] PrintWriteResultCallbackAdapter {
58 public:
59     PrintWriteResultCallbackAdapter() = default;
60     virtual ~PrintWriteResultCallbackAdapter() = default;
61 
62     virtual void WriteResultCallback(std::string jobId, uint32_t code) = 0;
63 };
64 
65 class PrintDocumentAdapterAdapter {
66 public:
67     PrintDocumentAdapterAdapter() = default;
68     virtual ~PrintDocumentAdapterAdapter() = default;
69 
70     virtual void OnStartLayoutWrite(const std::string& jobId, const PrintAttributesAdapter& oldAttrs,
71         const PrintAttributesAdapter& newAttrs, uint32_t fd,
72         std::shared_ptr<PrintWriteResultCallbackAdapter> callback) = 0;
73 
74     virtual void OnJobStateChanged(const std::string& jobId, uint32_t state) = 0;
75 };
76 
77 class PrintManagerAdapter {
78 public:
79     PrintManagerAdapter() = default;
80 
81     virtual ~PrintManagerAdapter() = default;
82 
83     virtual int32_t StartPrint(
84         const std::vector<std::string>& fileList, const std::vector<uint32_t>& fdList, std::string& taskId) = 0;
85 
86     virtual int32_t Print(const std::string& printJobName, const std::shared_ptr<PrintDocumentAdapterAdapter> listener,
87         const PrintAttributesAdapter& printAttributes) = 0;
88 
89     virtual int32_t Print(const std::string& printJobName, const std::shared_ptr<PrintDocumentAdapterAdapter> listener,
90         const PrintAttributesAdapter& printAttributes, void* contextToken) = 0;
91 };
92 
93 } // namespace OHOS::NWeb
94 
95 #endif // PRINT_MANAGER_ADAPTER_H
96