Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/windows/classes/sun/print/Win32PrintJob.java
41152 views
1
/*
2
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.print;
27
28
import java.net.URI;
29
import java.io.BufferedInputStream;
30
import java.io.File;
31
import java.io.InputStream;
32
import java.io.IOException;
33
import java.io.Reader;
34
import java.net.URL;
35
import java.nio.file.Files;
36
import java.nio.file.Path;
37
import java.nio.file.StandardCopyOption;
38
import java.util.Vector;
39
40
import javax.print.CancelablePrintJob;
41
import javax.print.Doc;
42
import javax.print.DocFlavor;
43
import javax.print.PrintService;
44
import javax.print.PrintException;
45
import javax.print.event.PrintJobEvent;
46
import javax.print.event.PrintJobListener;
47
import javax.print.event.PrintJobAttributeListener;
48
49
import javax.print.attribute.Attribute;
50
import javax.print.attribute.AttributeSetUtilities;
51
import javax.print.attribute.DocAttributeSet;
52
import javax.print.attribute.HashPrintJobAttributeSet;
53
import javax.print.attribute.HashPrintRequestAttributeSet;
54
import javax.print.attribute.PrintJobAttribute;
55
import javax.print.attribute.PrintJobAttributeSet;
56
import javax.print.attribute.PrintRequestAttribute;
57
import javax.print.attribute.PrintRequestAttributeSet;
58
import javax.print.attribute.standard.Copies;
59
import javax.print.attribute.standard.DocumentName;
60
import javax.print.attribute.standard.Fidelity;
61
import javax.print.attribute.standard.JobName;
62
import javax.print.attribute.standard.JobOriginatingUserName;
63
import javax.print.attribute.standard.Media;
64
import javax.print.attribute.standard.MediaSize;
65
import javax.print.attribute.standard.MediaSizeName;
66
import javax.print.attribute.standard.OrientationRequested;
67
import javax.print.attribute.standard.RequestingUserName;
68
import javax.print.attribute.standard.Destination;
69
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
70
import javax.print.attribute.standard.PrinterState;
71
import javax.print.attribute.standard.PrinterStateReason;
72
import javax.print.attribute.standard.PrinterStateReasons;
73
74
import java.awt.print.*;
75
76
public class Win32PrintJob implements CancelablePrintJob {
77
78
private transient Vector<PrintJobListener> jobListeners;
79
private transient Vector<PrintJobAttributeListener> attrListeners;
80
private transient Vector<PrintJobAttributeSet> listenedAttributeSets;
81
82
private Win32PrintService service;
83
private boolean fidelity;
84
private boolean printing = false;
85
private boolean printReturned = false;
86
private PrintRequestAttributeSet reqAttrSet = null;
87
private PrintJobAttributeSet jobAttrSet = null;
88
private PrinterJob job;
89
private Doc doc;
90
private String mDestination = null;
91
92
/* these variables used globally to store reference to the print
93
* data retrieved as a stream. On completion these are always closed
94
* if non-null.
95
*/
96
private InputStream instream = null;
97
private Reader reader = null;
98
99
/* default values overridden by those extracted from the attributes */
100
private String jobName = "Java Printing";
101
private int copies = 0;
102
private MediaSizeName mediaName = null;
103
private MediaSize mediaSize = null;
104
private OrientationRequested orient = null;
105
106
/* print job handle used by native code */
107
private long hPrintJob;
108
109
/* buffer length for printing raw data */
110
private static final int PRINTBUFFERLEN = 8192;
111
112
Win32PrintJob(Win32PrintService service) {
113
this.service = service;
114
}
115
116
public PrintService getPrintService() {
117
return service;
118
}
119
120
public PrintJobAttributeSet getAttributes() {
121
synchronized (this) {
122
if (jobAttrSet == null) {
123
/* just return an empty set until the job is submitted */
124
PrintJobAttributeSet jobSet = new HashPrintJobAttributeSet();
125
return AttributeSetUtilities.unmodifiableView(jobSet);
126
} else {
127
return jobAttrSet;
128
}
129
}
130
}
131
132
public void addPrintJobListener(PrintJobListener listener) {
133
synchronized (this) {
134
if (listener == null) {
135
return;
136
}
137
if (jobListeners == null) {
138
jobListeners = new Vector<>();
139
}
140
jobListeners.add(listener);
141
}
142
}
143
144
public void removePrintJobListener(PrintJobListener listener) {
145
synchronized (this) {
146
if (listener == null || jobListeners == null ) {
147
return;
148
}
149
jobListeners.remove(listener);
150
if (jobListeners.isEmpty()) {
151
jobListeners = null;
152
}
153
}
154
}
155
156
157
/* Closes any stream already retrieved for the data.
158
* We want to avoid unnecessarily asking the Doc to create a stream only
159
* to get a reference in order to close it because the job failed.
160
* If the representation class is itself a "stream", this
161
* closes that stream too.
162
*/
163
private void closeDataStreams() {
164
165
if (doc == null) {
166
return;
167
}
168
169
Object data = null;
170
171
try {
172
data = doc.getPrintData();
173
} catch (IOException e) {
174
return;
175
}
176
177
if (instream != null) {
178
try {
179
instream.close();
180
} catch (IOException e) {
181
} finally {
182
instream = null;
183
}
184
}
185
else if (reader != null) {
186
try {
187
reader.close();
188
} catch (IOException e) {
189
} finally {
190
reader = null;
191
}
192
}
193
else if (data instanceof InputStream) {
194
try {
195
((InputStream)data).close();
196
} catch (IOException e) {
197
}
198
}
199
else if (data instanceof Reader) {
200
try {
201
((Reader)data).close();
202
} catch (IOException e) {
203
}
204
}
205
}
206
207
private void notifyEvent(int reason) {
208
209
/* since this method should always get called, here's where
210
* we will perform the clean up of any data stream supplied.
211
*/
212
switch (reason) {
213
case PrintJobEvent.DATA_TRANSFER_COMPLETE:
214
case PrintJobEvent.JOB_CANCELED :
215
case PrintJobEvent.JOB_FAILED :
216
case PrintJobEvent.NO_MORE_EVENTS :
217
case PrintJobEvent.JOB_COMPLETE :
218
closeDataStreams();
219
}
220
221
synchronized (this) {
222
if (jobListeners != null) {
223
PrintJobListener listener;
224
PrintJobEvent event = new PrintJobEvent(this, reason);
225
for (int i = 0; i < jobListeners.size(); i++) {
226
listener = jobListeners.elementAt(i);
227
switch (reason) {
228
229
case PrintJobEvent.JOB_COMPLETE :
230
listener.printJobCompleted(event);
231
break;
232
233
case PrintJobEvent.JOB_CANCELED :
234
listener.printJobCanceled(event);
235
break;
236
237
case PrintJobEvent.JOB_FAILED :
238
listener.printJobFailed(event);
239
break;
240
241
case PrintJobEvent.DATA_TRANSFER_COMPLETE :
242
listener.printDataTransferCompleted(event);
243
break;
244
245
case PrintJobEvent.NO_MORE_EVENTS :
246
listener.printJobNoMoreEvents(event);
247
break;
248
249
default:
250
break;
251
}
252
}
253
}
254
}
255
}
256
257
public void addPrintJobAttributeListener(
258
PrintJobAttributeListener listener,
259
PrintJobAttributeSet attributes) {
260
synchronized (this) {
261
if (listener == null) {
262
return;
263
}
264
if (attrListeners == null) {
265
attrListeners = new Vector<>();
266
listenedAttributeSets = new Vector<>();
267
}
268
attrListeners.add(listener);
269
if (attributes == null) {
270
attributes = new HashPrintJobAttributeSet();
271
}
272
listenedAttributeSets.add(attributes);
273
}
274
}
275
276
public void removePrintJobAttributeListener(
277
PrintJobAttributeListener listener) {
278
synchronized (this) {
279
if (listener == null || attrListeners == null ) {
280
return;
281
}
282
int index = attrListeners.indexOf(listener);
283
if (index == -1) {
284
return;
285
} else {
286
attrListeners.remove(index);
287
listenedAttributeSets.remove(index);
288
if (attrListeners.isEmpty()) {
289
attrListeners = null;
290
listenedAttributeSets = null;
291
}
292
}
293
}
294
}
295
296
public void print(Doc doc, PrintRequestAttributeSet attributes)
297
throws PrintException {
298
299
synchronized (this) {
300
if (printing) {
301
throw new PrintException("already printing");
302
} else {
303
printing = true;
304
}
305
}
306
307
PrinterState prnState = service.getAttribute(PrinterState.class);
308
if (prnState == PrinterState.STOPPED) {
309
PrinterStateReasons prnStateReasons =
310
service.getAttribute(PrinterStateReasons.class);
311
if ((prnStateReasons != null) &&
312
(prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
313
{
314
throw new PrintException("PrintService is no longer available.");
315
}
316
}
317
318
if (service.getAttribute(PrinterIsAcceptingJobs.class) ==
319
PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
320
throw new PrintException("Printer is not accepting job.");
321
}
322
323
324
this.doc = doc;
325
/* check if the parameters are valid before doing much processing */
326
DocFlavor flavor = doc.getDocFlavor();
327
Object data;
328
329
try {
330
data = doc.getPrintData();
331
} catch (IOException e) {
332
notifyEvent(PrintJobEvent.JOB_FAILED);
333
throw new PrintException("can't get print data: " + e.toString());
334
}
335
336
if (data == null) {
337
throw new PrintException("Null print data.");
338
}
339
340
if (flavor == null || (!service.isDocFlavorSupported(flavor))) {
341
notifyEvent(PrintJobEvent.JOB_FAILED);
342
throw new PrintJobFlavorException("invalid flavor", flavor);
343
}
344
345
initializeAttributeSets(doc, attributes);
346
347
getAttributeValues(flavor);
348
349
String repClassName = flavor.getRepresentationClassName();
350
351
if (flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
352
flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
353
flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
354
flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
355
flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
356
flavor.equals(DocFlavor.BYTE_ARRAY.PNG)) {
357
try {
358
instream = doc.getStreamForBytes();
359
if (instream == null) {
360
notifyEvent(PrintJobEvent.JOB_FAILED);
361
throw new PrintException("No stream for data");
362
}
363
printableJob(new ImagePrinter(instream));
364
service.wakeNotifier();
365
return;
366
} catch (ClassCastException cce) {
367
notifyEvent(PrintJobEvent.JOB_FAILED);
368
throw new PrintException(cce);
369
} catch (IOException ioe) {
370
notifyEvent(PrintJobEvent.JOB_FAILED);
371
throw new PrintException(ioe);
372
}
373
} else if (flavor.equals(DocFlavor.URL.GIF) ||
374
flavor.equals(DocFlavor.URL.JPEG) ||
375
flavor.equals(DocFlavor.URL.PNG)) {
376
try {
377
printableJob(new ImagePrinter((URL)data));
378
service.wakeNotifier();
379
return;
380
} catch (ClassCastException cce) {
381
notifyEvent(PrintJobEvent.JOB_FAILED);
382
throw new PrintException(cce);
383
}
384
} else if (repClassName.equals("java.awt.print.Pageable")) {
385
try {
386
pageableJob((Pageable)doc.getPrintData());
387
service.wakeNotifier();
388
return;
389
} catch (ClassCastException cce) {
390
notifyEvent(PrintJobEvent.JOB_FAILED);
391
throw new PrintException(cce);
392
} catch (IOException ioe) {
393
notifyEvent(PrintJobEvent.JOB_FAILED);
394
throw new PrintException(ioe);
395
}
396
} else if (repClassName.equals("java.awt.print.Printable")) {
397
try {
398
printableJob((Printable)doc.getPrintData());
399
service.wakeNotifier();
400
return;
401
} catch (ClassCastException cce) {
402
notifyEvent(PrintJobEvent.JOB_FAILED);
403
throw new PrintException(cce);
404
} catch (IOException ioe) {
405
notifyEvent(PrintJobEvent.JOB_FAILED);
406
throw new PrintException(ioe);
407
}
408
} else if (repClassName.equals("[B") ||
409
repClassName.equals("java.io.InputStream") ||
410
repClassName.equals("java.net.URL")) {
411
412
if (repClassName.equals("java.net.URL")) {
413
URL url = (URL)data;
414
try {
415
instream = url.openStream();
416
} catch (IOException e) {
417
notifyEvent(PrintJobEvent.JOB_FAILED);
418
throw new PrintException(e.toString());
419
}
420
} else {
421
try {
422
instream = doc.getStreamForBytes();
423
} catch (IOException ioe) {
424
notifyEvent(PrintJobEvent.JOB_FAILED);
425
throw new PrintException(ioe.toString());
426
}
427
}
428
429
if (instream == null) {
430
notifyEvent(PrintJobEvent.JOB_FAILED);
431
throw new PrintException("No stream for data");
432
}
433
434
if (mDestination != null) { // if destination attribute is set
435
try {
436
Files.copy(instream, Path.of(mDestination), StandardCopyOption.REPLACE_EXISTING);
437
} catch (IOException ioe) {
438
notifyEvent(PrintJobEvent.JOB_FAILED);
439
throw new PrintException(ioe.toString());
440
}
441
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
442
notifyEvent(PrintJobEvent.JOB_COMPLETE);
443
service.wakeNotifier();
444
return;
445
}
446
447
if (!startPrintRawData(service.getName(), jobName)) {
448
notifyEvent(PrintJobEvent.JOB_FAILED);
449
throw new PrintException("Print job failed to start.");
450
}
451
BufferedInputStream bin = new BufferedInputStream(instream);
452
int bread = 0;
453
try {
454
byte[] buffer = new byte[PRINTBUFFERLEN];
455
456
while ((bread = bin.read(buffer, 0, PRINTBUFFERLEN)) >=0) {
457
if (!printRawData(buffer, bread)) {
458
bin.close();
459
notifyEvent(PrintJobEvent.JOB_FAILED);
460
throw new PrintException ("Problem while spooling data");
461
}
462
}
463
bin.close();
464
if (!endPrintRawData()) {
465
notifyEvent(PrintJobEvent.JOB_FAILED);
466
throw new PrintException("Print job failed to close properly.");
467
}
468
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
469
} catch (IOException e) {
470
notifyEvent(PrintJobEvent.JOB_FAILED);
471
throw new PrintException (e.toString());
472
} finally {
473
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
474
}
475
} else {
476
notifyEvent(PrintJobEvent.JOB_FAILED);
477
throw new PrintException("unrecognized class: "+repClassName);
478
}
479
service.wakeNotifier();
480
}
481
482
public void printableJob(Printable printable) throws PrintException {
483
try {
484
synchronized(this) {
485
if (job != null) { // shouldn't happen
486
throw new PrintException("already printing");
487
} else {
488
job = new sun.awt.windows.WPrinterJob();
489
}
490
}
491
PrintService svc = getPrintService();
492
job.setPrintService(svc);
493
if (copies == 0) {
494
Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
495
copies = c.getValue();
496
}
497
498
if (mediaName == null) {
499
Object media = svc.getDefaultAttributeValue(Media.class);
500
if (media instanceof MediaSizeName) {
501
mediaName = (MediaSizeName) media;
502
mediaSize = MediaSize.getMediaSizeForName(mediaName);
503
}
504
}
505
506
if (orient == null) {
507
orient =
508
(OrientationRequested)svc.getDefaultAttributeValue(OrientationRequested.class);
509
}
510
511
job.setCopies(copies);
512
job.setJobName(jobName);
513
PageFormat pf = new PageFormat();
514
if (mediaSize != null) {
515
Paper p = new Paper();
516
p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
517
mediaSize.getY(MediaSize.INCH)*72.0);
518
p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
519
p.getHeight()-144.0);
520
pf.setPaper(p);
521
}
522
if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
523
pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
524
} else if (orient == OrientationRequested.LANDSCAPE) {
525
pf.setOrientation(PageFormat.LANDSCAPE);
526
}
527
job.setPrintable(printable, pf);
528
job.print(reqAttrSet);
529
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
530
return;
531
} catch (PrinterException pe) {
532
notifyEvent(PrintJobEvent.JOB_FAILED);
533
throw new PrintException(pe);
534
} finally {
535
printReturned = true;
536
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
537
}
538
}
539
540
public void pageableJob(Pageable pageable) throws PrintException {
541
try {
542
synchronized(this) {
543
if (job != null) { // shouldn't happen
544
throw new PrintException("already printing");
545
} else {
546
job = new sun.awt.windows.WPrinterJob();
547
}
548
}
549
PrintService svc = getPrintService();
550
job.setPrintService(svc);
551
if (copies == 0) {
552
Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
553
copies = c.getValue();
554
}
555
job.setCopies(copies);
556
job.setJobName(jobName);
557
job.setPageable(pageable);
558
job.print(reqAttrSet);
559
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
560
return;
561
} catch (PrinterException pe) {
562
notifyEvent(PrintJobEvent.JOB_FAILED);
563
throw new PrintException(pe);
564
} finally {
565
printReturned = true;
566
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
567
}
568
}
569
570
/* There's some inefficiency here as the job set is created even though
571
* it may never be requested.
572
*/
573
private synchronized void
574
initializeAttributeSets(Doc doc, PrintRequestAttributeSet reqSet) {
575
576
reqAttrSet = new HashPrintRequestAttributeSet();
577
jobAttrSet = new HashPrintJobAttributeSet();
578
579
Attribute[] attrs;
580
if (reqSet != null) {
581
reqAttrSet.addAll(reqSet);
582
attrs = reqSet.toArray();
583
for (int i=0; i<attrs.length; i++) {
584
if (attrs[i] instanceof PrintJobAttribute) {
585
jobAttrSet.add(attrs[i]);
586
}
587
}
588
}
589
590
DocAttributeSet docSet = doc.getAttributes();
591
if (docSet != null) {
592
attrs = docSet.toArray();
593
for (int i=0; i<attrs.length; i++) {
594
if (attrs[i] instanceof PrintRequestAttribute) {
595
reqAttrSet.add(attrs[i]);
596
}
597
if (attrs[i] instanceof PrintJobAttribute) {
598
jobAttrSet.add(attrs[i]);
599
}
600
}
601
}
602
603
/* add the user name to the job */
604
String userName = "";
605
try {
606
userName = System.getProperty("user.name");
607
} catch (SecurityException se) {
608
}
609
610
if (userName == null || userName.isEmpty()) {
611
RequestingUserName ruName =
612
(RequestingUserName)reqSet.get(RequestingUserName.class);
613
if (ruName != null) {
614
jobAttrSet.add(
615
new JobOriginatingUserName(ruName.getValue(),
616
ruName.getLocale()));
617
} else {
618
jobAttrSet.add(new JobOriginatingUserName("", null));
619
}
620
} else {
621
jobAttrSet.add(new JobOriginatingUserName(userName, null));
622
}
623
624
/* if no job name supplied use doc name (if supplied), if none and
625
* its a URL use that, else finally anything .. */
626
if (jobAttrSet.get(JobName.class) == null) {
627
JobName jobName;
628
if (docSet != null && docSet.get(DocumentName.class) != null) {
629
DocumentName docName =
630
(DocumentName)docSet.get(DocumentName.class);
631
jobName = new JobName(docName.getValue(), docName.getLocale());
632
jobAttrSet.add(jobName);
633
} else {
634
String str = "JPS Job:" + doc;
635
try {
636
Object printData = doc.getPrintData();
637
if (printData instanceof URL) {
638
str = ((URL)(doc.getPrintData())).toString();
639
}
640
} catch (IOException e) {
641
}
642
jobName = new JobName(str, null);
643
jobAttrSet.add(jobName);
644
}
645
}
646
647
jobAttrSet = AttributeSetUtilities.unmodifiableView(jobAttrSet);
648
}
649
650
private void getAttributeValues(DocFlavor flavor) throws PrintException {
651
652
if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
653
fidelity = true;
654
} else {
655
fidelity = false;
656
}
657
658
Class<? extends Attribute> category;
659
Attribute [] attrs = reqAttrSet.toArray();
660
for (int i=0; i<attrs.length; i++) {
661
Attribute attr = attrs[i];
662
category = attr.getCategory();
663
if (fidelity == true) {
664
if (!service.isAttributeCategorySupported(category)) {
665
notifyEvent(PrintJobEvent.JOB_FAILED);
666
throw new PrintJobAttributeException(
667
"unsupported category: " + category, category, null);
668
} else if
669
(!service.isAttributeValueSupported(attr, flavor, null)) {
670
notifyEvent(PrintJobEvent.JOB_FAILED);
671
throw new PrintJobAttributeException(
672
"unsupported attribute: " + attr, null, attr);
673
}
674
}
675
if (category == Destination.class) {
676
URI uri = ((Destination)attr).getURI();
677
if (!"file".equals(uri.getScheme())) {
678
notifyEvent(PrintJobEvent.JOB_FAILED);
679
throw new PrintException("Not a file: URI");
680
} else {
681
try {
682
mDestination = (new File(uri)).getPath();
683
} catch (Exception e) {
684
throw new PrintException(e);
685
}
686
// check write access
687
@SuppressWarnings("removal")
688
SecurityManager security = System.getSecurityManager();
689
if (security != null) {
690
try {
691
security.checkWrite(mDestination);
692
} catch (SecurityException se) {
693
notifyEvent(PrintJobEvent.JOB_FAILED);
694
throw new PrintException(se);
695
}
696
}
697
}
698
} else if (category == JobName.class) {
699
jobName = ((JobName)attr).getValue();
700
} else if (category == Copies.class) {
701
copies = ((Copies)attr).getValue();
702
} else if (category == Media.class) {
703
if (attr instanceof MediaSizeName) {
704
mediaName = (MediaSizeName)attr;
705
// If requested MediaSizeName is not supported,
706
// get the corresponding media size - this will
707
// be used to create a new PageFormat.
708
if (!service.isAttributeValueSupported(attr, null, null)) {
709
mediaSize = MediaSize.getMediaSizeForName(mediaName);
710
}
711
}
712
} else if (category == OrientationRequested.class) {
713
orient = (OrientationRequested)attr;
714
}
715
}
716
}
717
718
private native boolean startPrintRawData(String printerName,
719
String jobName);
720
private native boolean printRawData(byte[] data, int count);
721
private native boolean endPrintRawData();
722
723
/* Cancel PrinterJob jobs that haven't yet completed. */
724
public void cancel() throws PrintException {
725
synchronized (this) {
726
if (!printing) {
727
throw new PrintException("Job is not yet submitted.");
728
} else if (job != null && !printReturned) {
729
job.cancel();
730
notifyEvent(PrintJobEvent.JOB_CANCELED);
731
return;
732
} else {
733
throw new PrintException("Job could not be cancelled.");
734
}
735
}
736
}
737
}
738
739