print_job.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef PRINTING_PLUGIN_PRINT_JOB_H_
  17. #define PRINTING_PLUGIN_PRINT_JOB_H_
  18. #include <flutter/standard_method_codec.h>
  19. #include <windows.h>
  20. #include <map>
  21. #include <memory>
  22. #include <sstream>
  23. #include <vector>
  24. namespace nfet {
  25. class Printing;
  26. struct Printer {
  27. const std::string name;
  28. const std::string url;
  29. const std::string model;
  30. const std::string location;
  31. const std::string comment;
  32. const bool default;
  33. const bool available;
  34. Printer(const std::string& name,
  35. const std::string& url,
  36. const std::string& model,
  37. const std::string& location,
  38. const std::string& comment,
  39. bool default,
  40. bool available)
  41. : name(name),
  42. url(url),
  43. model(model),
  44. location(location),
  45. comment(comment),
  46. default(default),
  47. available(available) {}
  48. };
  49. class PrintJob {
  50. private:
  51. Printing* printing;
  52. int index;
  53. HGLOBAL hDevMode = nullptr;
  54. HGLOBAL hDevNames = nullptr;
  55. HDC hDC = nullptr;
  56. std::string documentName;
  57. public:
  58. PrintJob(Printing* printing, int index);
  59. int id() { return index; }
  60. std::vector<Printer> listPrinters();
  61. bool printPdf(const std::string& name,
  62. std::string printer,
  63. double width,
  64. double height,
  65. bool usePrinterSettings);
  66. void writeJob(std::vector<uint8_t> data);
  67. void cancelJob(const std::string& error);
  68. bool sharePdf(std::vector<uint8_t> data, const std::string& name);
  69. void pickPrinter(void* result);
  70. void rasterPdf(std::vector<uint8_t> data,
  71. std::vector<int> pages,
  72. double scale);
  73. std::map<std::string, bool> printingInfo();
  74. };
  75. } // namespace nfet
  76. #endif // PRINTING_PLUGIN_PRINT_JOB_H_