forked from tojocky/node-printer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_printer.cc
More file actions
37 lines (32 loc) · 1.25 KB
/
Copy pathnode_printer.cc
File metadata and controls
37 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "node_printer.hpp"
#include <node_buffer.h>
void initNode(v8::Handle<v8::Object> exports) {
// only for node
NODE_SET_METHOD(exports, "getPrinters", getPrinters);
NODE_SET_METHOD(exports, "getDefaultPrinterName", getDefaultPrinterName);
NODE_SET_METHOD(exports, "getPrinter", getPrinter);
NODE_SET_METHOD(exports, "getPrinterDriverOptions", getPrinterDriverOptions);
NODE_SET_METHOD(exports, "getJob", getJob);
NODE_SET_METHOD(exports, "setJob", setJob);
NODE_SET_METHOD(exports, "printDirect", PrintDirect);
NODE_SET_METHOD(exports, "printFile", PrintFile);
NODE_SET_METHOD(exports, "getSupportedPrintFormats", getSupportedPrintFormats);
NODE_SET_METHOD(exports, "getSupportedJobCommands", getSupportedJobCommands);
}
NODE_MODULE(node_printer, initNode);
// Helpers
bool getStringOrBufferFromV8Value(v8::Handle<v8::Value> iV8Value, std::string &oData)
{
if(iV8Value->IsString())
{
v8::String::Utf8Value data_str_v8(iV8Value->ToString());
oData.assign(*data_str_v8, data_str_v8.length());
return true;
}
if(iV8Value->IsObject() && node::Buffer::HasInstance(iV8Value))
{
oData.assign(node::Buffer::Data(iV8Value), node::Buffer::Length(iV8Value));
return true;
}
return false;
}