@esslassi/electron-printer 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -318
- package/binding.gyp +57 -57
- package/lib/electronPrinter.js +17 -18
- package/lib/native.d.ts +2 -0
- package/lib/native.js +12 -0
- package/package.json +10 -3
- package/src/linux_printer.cpp +370 -370
- package/src/linux_printer.h +30 -30
- package/src/mac_printer.cpp +372 -372
- package/src/mac_printer.h +30 -30
- package/src/main.cpp +50 -50
- package/src/print.cpp +352 -352
- package/src/printer_factory.cpp +19 -19
- package/src/printer_factory.h +12 -12
- package/src/printer_interface.h +66 -66
- package/src/windows_printer.cpp +346 -346
- package/src/windows_printer.h +63 -63
- package/test.js +0 -120
package/src/printer_factory.cpp
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
#include "printer_factory.h"
|
|
2
|
-
|
|
3
|
-
#ifdef _WIN32
|
|
4
|
-
#include "windows_printer.h"
|
|
5
|
-
#elif defined(__APPLE__)
|
|
6
|
-
#include "mac_printer.h"
|
|
7
|
-
#else
|
|
8
|
-
#include "linux_printer.h"
|
|
9
|
-
#endif
|
|
10
|
-
|
|
11
|
-
std::unique_ptr<PrinterInterface> PrinterFactory::Create()
|
|
12
|
-
{
|
|
13
|
-
#ifdef _WIN32
|
|
14
|
-
return std::make_unique<WindowsPrinter>();
|
|
15
|
-
#elif defined(__APPLE__)
|
|
16
|
-
return std::make_unique<MacPrinter>();
|
|
17
|
-
#else
|
|
18
|
-
return std::make_unique<LinuxPrinter>();
|
|
19
|
-
#endif
|
|
1
|
+
#include "printer_factory.h"
|
|
2
|
+
|
|
3
|
+
#ifdef _WIN32
|
|
4
|
+
#include "windows_printer.h"
|
|
5
|
+
#elif defined(__APPLE__)
|
|
6
|
+
#include "mac_printer.h"
|
|
7
|
+
#else
|
|
8
|
+
#include "linux_printer.h"
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
std::unique_ptr<PrinterInterface> PrinterFactory::Create()
|
|
12
|
+
{
|
|
13
|
+
#ifdef _WIN32
|
|
14
|
+
return std::make_unique<WindowsPrinter>();
|
|
15
|
+
#elif defined(__APPLE__)
|
|
16
|
+
return std::make_unique<MacPrinter>();
|
|
17
|
+
#else
|
|
18
|
+
return std::make_unique<LinuxPrinter>();
|
|
19
|
+
#endif
|
|
20
20
|
}
|
package/src/printer_factory.h
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#ifndef PRINTER_FACTORY_H
|
|
2
|
-
#define PRINTER_FACTORY_H
|
|
3
|
-
|
|
4
|
-
#include "printer_interface.h"
|
|
5
|
-
#include <memory>
|
|
6
|
-
|
|
7
|
-
class PrinterFactory
|
|
8
|
-
{
|
|
9
|
-
public:
|
|
10
|
-
static std::unique_ptr<PrinterInterface> Create();
|
|
11
|
-
};
|
|
12
|
-
|
|
1
|
+
#ifndef PRINTER_FACTORY_H
|
|
2
|
+
#define PRINTER_FACTORY_H
|
|
3
|
+
|
|
4
|
+
#include "printer_interface.h"
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
class PrinterFactory
|
|
8
|
+
{
|
|
9
|
+
public:
|
|
10
|
+
static std::unique_ptr<PrinterInterface> Create();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
13
|
#endif
|
package/src/printer_interface.h
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
#ifndef PRINTER_INTERFACE_H
|
|
2
|
-
#define PRINTER_INTERFACE_H
|
|
3
|
-
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <vector>
|
|
6
|
-
#include <map>
|
|
7
|
-
#include <cstdint>
|
|
8
|
-
#include <ctime>
|
|
9
|
-
|
|
10
|
-
using StringMap = std::map<std::string, std::string>;
|
|
11
|
-
using DriverOptions = std::map<std::string, std::map<std::string, bool>>;
|
|
12
|
-
|
|
13
|
-
struct PrinterDetailsNative {
|
|
14
|
-
std::string name;
|
|
15
|
-
bool isDefault = false;
|
|
16
|
-
StringMap options; // matches TS: options: { [k:string]: string }
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
struct JobDetailsNative {
|
|
20
|
-
int id = 0;
|
|
21
|
-
std::string name;
|
|
22
|
-
std::string printerName;
|
|
23
|
-
std::string user;
|
|
24
|
-
std::string format;
|
|
25
|
-
int priority = 0;
|
|
26
|
-
int size = 0;
|
|
27
|
-
|
|
28
|
-
std::vector<std::string> status; // TS: JobStatus[]
|
|
29
|
-
std::time_t completedTime = 0;
|
|
30
|
-
std::time_t creationTime = 0;
|
|
31
|
-
std::time_t processingTime = 0;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
class PrinterInterface
|
|
35
|
-
{
|
|
36
|
-
public:
|
|
37
|
-
virtual ~PrinterInterface() = default;
|
|
38
|
-
|
|
39
|
-
// Printers
|
|
40
|
-
virtual std::vector<PrinterDetailsNative> GetPrinters() = 0;
|
|
41
|
-
virtual PrinterDetailsNative GetPrinter(const std::string &printerName) = 0;
|
|
42
|
-
virtual std::string GetDefaultPrinterName() = 0;
|
|
43
|
-
|
|
44
|
-
// Driver options & paper
|
|
45
|
-
virtual DriverOptions GetPrinterDriverOptions(const std::string &printerName) = 0;
|
|
46
|
-
virtual std::string GetSelectedPaperSize(const std::string &printerName) = 0;
|
|
47
|
-
|
|
48
|
-
// Printing
|
|
49
|
-
// return jobId (>0) or 0 on failure
|
|
50
|
-
virtual int PrintDirect(const std::string &printerName,
|
|
51
|
-
const std::vector<uint8_t> &data,
|
|
52
|
-
const std::string &type,
|
|
53
|
-
const StringMap &options) = 0;
|
|
54
|
-
|
|
55
|
-
virtual int PrintFile(const std::string &printerName,
|
|
56
|
-
const std::string &filename) = 0;
|
|
57
|
-
|
|
58
|
-
// Capabilities
|
|
59
|
-
virtual std::vector<std::string> GetSupportedPrintFormats() = 0;
|
|
60
|
-
|
|
61
|
-
// Jobs
|
|
62
|
-
virtual JobDetailsNative GetJob(const std::string &printerName, int jobId) = 0;
|
|
63
|
-
virtual void SetJob(const std::string &printerName, int jobId, const std::string &command) = 0;
|
|
64
|
-
virtual std::vector<std::string> GetSupportedJobCommands() = 0;
|
|
65
|
-
};
|
|
66
|
-
|
|
1
|
+
#ifndef PRINTER_INTERFACE_H
|
|
2
|
+
#define PRINTER_INTERFACE_H
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <ctime>
|
|
9
|
+
|
|
10
|
+
using StringMap = std::map<std::string, std::string>;
|
|
11
|
+
using DriverOptions = std::map<std::string, std::map<std::string, bool>>;
|
|
12
|
+
|
|
13
|
+
struct PrinterDetailsNative {
|
|
14
|
+
std::string name;
|
|
15
|
+
bool isDefault = false;
|
|
16
|
+
StringMap options; // matches TS: options: { [k:string]: string }
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
struct JobDetailsNative {
|
|
20
|
+
int id = 0;
|
|
21
|
+
std::string name;
|
|
22
|
+
std::string printerName;
|
|
23
|
+
std::string user;
|
|
24
|
+
std::string format;
|
|
25
|
+
int priority = 0;
|
|
26
|
+
int size = 0;
|
|
27
|
+
|
|
28
|
+
std::vector<std::string> status; // TS: JobStatus[]
|
|
29
|
+
std::time_t completedTime = 0;
|
|
30
|
+
std::time_t creationTime = 0;
|
|
31
|
+
std::time_t processingTime = 0;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class PrinterInterface
|
|
35
|
+
{
|
|
36
|
+
public:
|
|
37
|
+
virtual ~PrinterInterface() = default;
|
|
38
|
+
|
|
39
|
+
// Printers
|
|
40
|
+
virtual std::vector<PrinterDetailsNative> GetPrinters() = 0;
|
|
41
|
+
virtual PrinterDetailsNative GetPrinter(const std::string &printerName) = 0;
|
|
42
|
+
virtual std::string GetDefaultPrinterName() = 0;
|
|
43
|
+
|
|
44
|
+
// Driver options & paper
|
|
45
|
+
virtual DriverOptions GetPrinterDriverOptions(const std::string &printerName) = 0;
|
|
46
|
+
virtual std::string GetSelectedPaperSize(const std::string &printerName) = 0;
|
|
47
|
+
|
|
48
|
+
// Printing
|
|
49
|
+
// return jobId (>0) or 0 on failure
|
|
50
|
+
virtual int PrintDirect(const std::string &printerName,
|
|
51
|
+
const std::vector<uint8_t> &data,
|
|
52
|
+
const std::string &type,
|
|
53
|
+
const StringMap &options) = 0;
|
|
54
|
+
|
|
55
|
+
virtual int PrintFile(const std::string &printerName,
|
|
56
|
+
const std::string &filename) = 0;
|
|
57
|
+
|
|
58
|
+
// Capabilities
|
|
59
|
+
virtual std::vector<std::string> GetSupportedPrintFormats() = 0;
|
|
60
|
+
|
|
61
|
+
// Jobs
|
|
62
|
+
virtual JobDetailsNative GetJob(const std::string &printerName, int jobId) = 0;
|
|
63
|
+
virtual void SetJob(const std::string &printerName, int jobId, const std::string &command) = 0;
|
|
64
|
+
virtual std::vector<std::string> GetSupportedJobCommands() = 0;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
67
|
#endif
|