-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathCefPrintSettings_N.cpp
492 lines (446 loc) · 19.1 KB
/
CefPrintSettings_N.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "CefPrintSettings_N.h"
#include "include/cef_print_handler.h"
#include "jni_scoped_helpers.h"
#include "jni_util.h"
namespace {
const char kCefClassName[] = "CefPrintSettings";
CefRefPtr<CefPrintSettings> GetSelf(jlong self) {
return reinterpret_cast<CefPrintSettings*>(self);
}
// Retrieve the CefPageRange equivalent of a org.cef.misc.CefPageRange
CefRange GetJNIPageRange(JNIEnv* env, jobject obj) {
CefRange range;
ScopedJNIClass cls(env, "org/cef/misc/CefPageRange");
if (!cls)
return range;
int from, to;
if (GetJNIFieldInt(env, cls, obj, "from", &from) &&
GetJNIFieldInt(env, cls, obj, "to", &to)) {
range.Set(from, to);
}
return range;
}
// Create a new org.cef.misc.CefPageRange
jobject NewJNIPageRange(JNIEnv* env, const CefRange& range) {
ScopedJNIClass cls(env, "org/cef/misc/CefPageRange");
if (!cls)
return nullptr;
ScopedJNIObjectLocal obj(env, NewJNIObject(env, cls));
if (!obj)
return nullptr;
if (SetJNIFieldInt(env, cls, obj, "from", range.from) &&
SetJNIFieldInt(env, cls, obj, "to", range.to)) {
return obj.Release();
}
return nullptr;
}
} // namespace
JNIEXPORT jobject JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1Create(JNIEnv* env, jclass cls) {
CefRefPtr<CefPrintSettings> settings = CefPrintSettings::Create();
ScopedJNIPrintSettings jsettings(env, settings);
return jsettings.Release();
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1Dispose(JNIEnv* env,
jobject obj,
jlong self) {
SetCefForJNIObject<CefPrintSettings>(env, obj, nullptr, kCefClassName);
}
JNIEXPORT jboolean JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1IsValid(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return JNI_FALSE;
return settings->IsValid() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1IsReadOnly(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return JNI_FALSE;
return settings->IsReadOnly() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetOrientation(JNIEnv* env,
jobject obj,
jlong self,
jboolean jlandscape) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetOrientation(jlandscape != JNI_FALSE);
}
JNIEXPORT jboolean JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1IsLandscape(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return JNI_FALSE;
return settings->IsLandscape() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetPrinterPrintableArea(
JNIEnv* env,
jobject obj,
jlong self,
jobject jphysical_size_device_units,
jobject jprintable_area_device_units,
jboolean jlandscape_needs_flip) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
CefSize physical_size = GetJNISize(env, jphysical_size_device_units);
CefRect printable_area = GetJNIRect(env, jprintable_area_device_units);
bool needs_flip = jlandscape_needs_flip != JNI_FALSE;
settings->SetPrinterPrintableArea(physical_size, printable_area, needs_flip);
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetDeviceName(JNIEnv* env,
jobject obj,
jlong self,
jstring jname) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetDeviceName(GetJNIString(env, jname));
}
JNIEXPORT jstring JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetDeviceName(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return nullptr;
return NewJNIString(env, settings->GetDeviceName());
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetDPI(JNIEnv* env,
jobject obj,
jlong self,
jint jdpi) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetDPI((int)jdpi);
}
JNIEXPORT jint JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetDPI(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return 0;
return (jint)settings->GetDPI();
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetPageRanges(JNIEnv* env,
jobject obj,
jlong self,
jobject jrangeVector) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings || !jrangeVector)
return;
CefPrintSettings::PageRangeList rangeList;
jint jsize = 0;
JNI_CALL_METHOD(env, jrangeVector, "size", "()I", Int, jsize);
for (jint index = 0; index < jsize; index++) {
ScopedJNIObjectResult jresult(env);
JNI_CALL_METHOD(env, jrangeVector, "get", "(I)Ljava/lang/Object;", Object,
jresult, index);
if (!jresult)
continue;
rangeList.push_back(GetJNIPageRange(env, jresult));
}
settings->SetPageRanges(rangeList);
}
JNIEXPORT jint JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetPageRangesCount(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return 0;
return (jint)settings->GetPageRangesCount();
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetPageRanges(JNIEnv* env,
jobject obj,
jlong self,
jobject jrangeVector) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings || !jrangeVector)
return;
CefPrintSettings::PageRangeList rangeList;
settings->GetPageRanges(rangeList);
CefPrintSettings::PageRangeList::size_type i = 0;
for (i = 0; i < rangeList.size(); ++i) {
ScopedJNIObjectLocal jrange(env, NewJNIPageRange(env, rangeList.at(i)));
JNI_CALL_VOID_METHOD(env, jrangeVector, "addElement",
"(Ljava/lang/Object;)V", jrange.get());
}
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetSelectionOnly(
JNIEnv* env,
jobject obj,
jlong self,
jboolean jselection_only) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetSelectionOnly(jselection_only != JNI_FALSE);
}
JNIEXPORT jboolean JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1IsSelectionOnly(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return JNI_FALSE;
return settings->IsSelectionOnly() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetCollate(JNIEnv* env,
jobject obj,
jlong self,
jboolean jcollate) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetCollate(jcollate != JNI_FALSE);
}
JNIEXPORT jboolean JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1WillCollate(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return JNI_FALSE;
return settings->WillCollate() ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetColorModel(JNIEnv* env,
jobject obj,
jlong self,
jobject jcolor_model) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
CefPrintSettings::ColorModel mode;
if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_GRAY")) {
mode = COLOR_MODEL_GRAY;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_COLOR")) {
mode = COLOR_MODEL_COLOR;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_CMYK")) {
mode = COLOR_MODEL_CMYK;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_CMY")) {
mode = COLOR_MODEL_CMY;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_KCMY")) {
mode = COLOR_MODEL_KCMY;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_CMY_K")) {
mode = COLOR_MODEL_CMY_K;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_BLACK")) {
mode = COLOR_MODEL_BLACK;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_GRAYSCALE")) {
mode = COLOR_MODEL_GRAYSCALE;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_RGB")) {
mode = COLOR_MODEL_RGB;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_RGB16")) {
mode = COLOR_MODEL_RGB16;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_RGBA")) {
mode = COLOR_MODEL_RGBA;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_COLORMODE_COLOR")) {
mode = COLOR_MODEL_COLORMODE_COLOR;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_COLORMODE_MONOCHROME")) {
mode = COLOR_MODEL_COLORMODE_MONOCHROME;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_HP_COLOR_COLOR")) {
mode = COLOR_MODEL_HP_COLOR_COLOR;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_HP_COLOR_BLACK")) {
mode = COLOR_MODEL_HP_COLOR_BLACK;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_PRINTOUTMODE_NORMAL")) {
mode = COLOR_MODEL_PRINTOUTMODE_NORMAL;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_PRINTOUTMODE_NORMAL_GRAY")) {
mode = COLOR_MODEL_PRINTOUTMODE_NORMAL_GRAY;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_PROCESSCOLORMODEL_CMYK")) {
mode = COLOR_MODEL_PROCESSCOLORMODEL_CMYK;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_PROCESSCOLORMODEL_GREYSCALE")) {
mode = COLOR_MODEL_PROCESSCOLORMODEL_GREYSCALE;
} else if (IsJNIEnumValue(env, jcolor_model,
"org/cef/misc/CefPrintSettings$ColorModel",
"COLOR_MODEL_PROCESSCOLORMODEL_RGB")) {
mode = COLOR_MODEL_PROCESSCOLORMODEL_RGB;
} else {
mode = COLOR_MODEL_UNKNOWN;
}
settings->SetColorModel(mode);
}
JNIEXPORT jobject JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetColorModel(JNIEnv* env,
jobject obj,
jlong self) {
jobject result = GetJNIEnumValue(
env, "org/cef/misc/CefPrintSettings$ColorModel", "COLOR_MODEL_UNKNOWN");
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return result;
switch (settings->GetColorModel()) {
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_GRAY,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_COLOR,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_CMYK,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_CMY,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_KCMY,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_CMY_K,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_BLACK,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_GRAYSCALE, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_RGB,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_RGB16,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel", COLOR_MODEL_RGBA,
result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_COLORMODE_COLOR, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_COLORMODE_MONOCHROME, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_HP_COLOR_COLOR, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_HP_COLOR_BLACK, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_PRINTOUTMODE_NORMAL, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_PRINTOUTMODE_NORMAL_GRAY, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_PROCESSCOLORMODEL_CMYK, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_PROCESSCOLORMODEL_GREYSCALE, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_PROCESSCOLORMODEL_RGB, result);
default:
JNI_CASE(env, "org/cef/misc/CefPrintSettings$ColorModel",
COLOR_MODEL_UNKNOWN, result);
}
return result;
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetCopies(JNIEnv* env,
jobject obj,
jlong self,
jint jcopies) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
settings->SetCopies((int)jcopies);
}
JNIEXPORT jint JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetCopies(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return 0;
return (jint)settings->GetCopies();
}
JNIEXPORT void JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1SetDuplexMode(JNIEnv* env,
jobject obj,
jlong self,
jobject jduplex_mode) {
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return;
CefPrintSettings::DuplexMode mode;
if (IsJNIEnumValue(env, jduplex_mode,
"org/cef/misc/CefPrintSettings$DuplexMode",
"DUPLEX_MODE_SIMPLEX")) {
mode = DUPLEX_MODE_SIMPLEX;
} else if (IsJNIEnumValue(env, jduplex_mode,
"org/cef/misc/CefPrintSettings$DuplexMode",
"DUPLEX_MODE_LONG_EDGE")) {
mode = DUPLEX_MODE_LONG_EDGE;
} else if (IsJNIEnumValue(env, jduplex_mode,
"org/cef/misc/CefPrintSettings$DuplexMode",
"DUPLEX_MODE_SHORT_EDGE")) {
mode = DUPLEX_MODE_SHORT_EDGE;
} else {
mode = DUPLEX_MODE_UNKNOWN;
}
settings->SetDuplexMode(mode);
}
JNIEXPORT jobject JNICALL
Java_org_cef_misc_CefPrintSettings_1N_N_1GetDuplexMode(JNIEnv* env,
jobject obj,
jlong self) {
jobject result = GetJNIEnumValue(
env, "org/cef/misc/CefPrintSettings$DuplexMode", "DUPLEX_MODE_UNKNOWN");
CefRefPtr<CefPrintSettings> settings = GetSelf(self);
if (!settings)
return result;
switch (settings->GetDuplexMode()) {
JNI_CASE(env, "org/cef/misc/CefPrintSettings$DuplexMode",
DUPLEX_MODE_SIMPLEX, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$DuplexMode",
DUPLEX_MODE_LONG_EDGE, result);
JNI_CASE(env, "org/cef/misc/CefPrintSettings$DuplexMode",
DUPLEX_MODE_SHORT_EDGE, result);
default:
JNI_CASE(env, "org/cef/misc/CefPrintSettings$DuplexMode",
DUPLEX_MODE_UNKNOWN, result);
}
return result;
}