author | prr |
Fri, 19 Sep 2014 09:41:05 -0700 | |
changeset 26751 | 70bac69b37c9 |
parent 26354 | jdk/src/java.desktop/unix/native/common/sun/awt/CUPSfuncs.c@2d04e6c7ed68 |
child 36470 | d5a6c81c5254 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <jni.h> |
|
27 |
#include <jni_util.h> |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
28 |
#include <jvm_md.h> |
2 | 29 |
#include <dlfcn.h> |
30 |
#include <cups/cups.h> |
|
31 |
#include <cups/ppd.h> |
|
32 |
||
33 |
//#define CUPS_DEBUG |
|
34 |
||
35 |
#ifdef CUPS_DEBUG |
|
36 |
#define DPRINTF(x, y) fprintf(stderr, x, y); |
|
37 |
#else |
|
38 |
#define DPRINTF(x, y) |
|
39 |
#endif |
|
40 |
||
41 |
typedef const char* (*fn_cupsServer)(void); |
|
42 |
typedef int (*fn_ippPort)(void); |
|
43 |
typedef http_t* (*fn_httpConnect)(const char *, int); |
|
44 |
typedef void (*fn_httpClose)(http_t *); |
|
45 |
typedef char* (*fn_cupsGetPPD)(const char *); |
|
46 |
typedef ppd_file_t* (*fn_ppdOpenFile)(const char *); |
|
47 |
typedef void (*fn_ppdClose)(ppd_file_t *); |
|
48 |
typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *); |
|
49 |
typedef ppd_size_t* (*fn_ppdPageSize)(ppd_file_t *, char *); |
|
50 |
||
51 |
fn_cupsServer j2d_cupsServer; |
|
52 |
fn_ippPort j2d_ippPort; |
|
53 |
fn_httpConnect j2d_httpConnect; |
|
54 |
fn_httpClose j2d_httpClose; |
|
55 |
fn_cupsGetPPD j2d_cupsGetPPD; |
|
56 |
fn_ppdOpenFile j2d_ppdOpenFile; |
|
57 |
fn_ppdClose j2d_ppdClose; |
|
58 |
fn_ppdFindOption j2d_ppdFindOption; |
|
59 |
fn_ppdPageSize j2d_ppdPageSize; |
|
60 |
||
61 |
||
62 |
/* |
|
63 |
* Initialize library functions. |
|
64 |
* // REMIND : move tab , add dlClose before return |
|
65 |
*/ |
|
66 |
JNIEXPORT jboolean JNICALL |
|
67 |
Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env, |
|
68 |
jobject printObj) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
69 |
void *handle = dlopen(VERSIONED_JNI_LIB_NAME("cups", "2"), |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
70 |
RTLD_LAZY | RTLD_GLOBAL); |
2 | 71 |
|
72 |
if (handle == NULL) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
73 |
handle = dlopen(JNI_LIB_NAME("cups"), RTLD_LAZY | RTLD_GLOBAL); |
2 | 74 |
if (handle == NULL) { |
75 |
return JNI_FALSE; |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
j2d_cupsServer = (fn_cupsServer)dlsym(handle, "cupsServer"); |
|
80 |
if (j2d_cupsServer == NULL) { |
|
81 |
dlclose(handle); |
|
82 |
return JNI_FALSE; |
|
83 |
} |
|
84 |
||
85 |
j2d_ippPort = (fn_ippPort)dlsym(handle, "ippPort"); |
|
86 |
if (j2d_ippPort == NULL) { |
|
87 |
dlclose(handle); |
|
88 |
return JNI_FALSE; |
|
89 |
} |
|
90 |
||
91 |
j2d_httpConnect = (fn_httpConnect)dlsym(handle, "httpConnect"); |
|
92 |
if (j2d_httpConnect == NULL) { |
|
93 |
dlclose(handle); |
|
94 |
return JNI_FALSE; |
|
95 |
} |
|
96 |
||
97 |
j2d_httpClose = (fn_httpClose)dlsym(handle, "httpClose"); |
|
98 |
if (j2d_httpClose == NULL) { |
|
99 |
dlclose(handle); |
|
100 |
return JNI_FALSE; |
|
101 |
} |
|
102 |
||
103 |
j2d_cupsGetPPD = (fn_cupsGetPPD)dlsym(handle, "cupsGetPPD"); |
|
104 |
if (j2d_cupsGetPPD == NULL) { |
|
105 |
dlclose(handle); |
|
106 |
return JNI_FALSE; |
|
107 |
} |
|
108 |
||
109 |
j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile"); |
|
110 |
if (j2d_ppdOpenFile == NULL) { |
|
111 |
dlclose(handle); |
|
112 |
return JNI_FALSE; |
|
113 |
||
114 |
} |
|
115 |
||
116 |
j2d_ppdClose = (fn_ppdClose)dlsym(handle, "ppdClose"); |
|
117 |
if (j2d_ppdClose == NULL) { |
|
118 |
dlclose(handle); |
|
119 |
return JNI_FALSE; |
|
120 |
||
121 |
} |
|
122 |
||
123 |
j2d_ppdFindOption = (fn_ppdFindOption)dlsym(handle, "ppdFindOption"); |
|
124 |
if (j2d_ppdFindOption == NULL) { |
|
125 |
dlclose(handle); |
|
126 |
return JNI_FALSE; |
|
127 |
} |
|
128 |
||
129 |
j2d_ppdPageSize = (fn_ppdPageSize)dlsym(handle, "ppdPageSize"); |
|
130 |
if (j2d_ppdPageSize == NULL) { |
|
131 |
dlclose(handle); |
|
132 |
return JNI_FALSE; |
|
133 |
} |
|
134 |
||
135 |
return JNI_TRUE; |
|
136 |
} |
|
137 |
||
138 |
/* |
|
139 |
* Gets CUPS server name. |
|
140 |
* |
|
141 |
*/ |
|
142 |
JNIEXPORT jstring JNICALL |
|
143 |
Java_sun_print_CUPSPrinter_getCupsServer(JNIEnv *env, |
|
144 |
jobject printObj) |
|
145 |
{ |
|
146 |
jstring cServer = NULL; |
|
147 |
const char* server = j2d_cupsServer(); |
|
148 |
if (server != NULL) { |
|
149 |
// Is this a local domain socket? |
|
150 |
if (strncmp(server, "/", 1) == 0) { |
|
151 |
cServer = JNU_NewStringPlatform(env, "localhost"); |
|
152 |
} else { |
|
153 |
cServer = JNU_NewStringPlatform(env, server); |
|
154 |
} |
|
155 |
} |
|
156 |
return cServer; |
|
157 |
} |
|
158 |
||
159 |
/* |
|
160 |
* Gets CUPS port name. |
|
161 |
* |
|
162 |
*/ |
|
163 |
JNIEXPORT jint JNICALL |
|
164 |
Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env, |
|
165 |
jobject printObj) |
|
166 |
{ |
|
167 |
int port = j2d_ippPort(); |
|
168 |
return (jint) port; |
|
169 |
} |
|
170 |
||
171 |
||
172 |
/* |
|
173 |
* Checks if connection can be made to the server. |
|
174 |
* |
|
175 |
*/ |
|
176 |
JNIEXPORT jboolean JNICALL |
|
177 |
Java_sun_print_CUPSPrinter_canConnect(JNIEnv *env, |
|
178 |
jobject printObj, |
|
179 |
jstring server, |
|
180 |
jint port) |
|
181 |
{ |
|
182 |
const char *serverName; |
|
183 |
serverName = (*env)->GetStringUTFChars(env, server, NULL); |
|
184 |
if (serverName != NULL) { |
|
185 |
http_t *http = j2d_httpConnect(serverName, (int)port); |
|
186 |
(*env)->ReleaseStringUTFChars(env, server, serverName); |
|
187 |
if (http != NULL) { |
|
188 |
j2d_httpClose(http); |
|
189 |
return JNI_TRUE; |
|
190 |
} |
|
191 |
} |
|
192 |
return JNI_FALSE; |
|
193 |
} |
|
194 |
||
195 |
||
196 |
/* |
|
197 |
* Returns list of media: pages + trays |
|
198 |
*/ |
|
199 |
JNIEXPORT jobjectArray JNICALL |
|
200 |
Java_sun_print_CUPSPrinter_getMedia(JNIEnv *env, |
|
201 |
jobject printObj, |
|
202 |
jstring printer) |
|
203 |
{ |
|
204 |
ppd_file_t *ppd; |
|
205 |
ppd_option_t *optionTray, *optionPage; |
|
206 |
ppd_choice_t *choice; |
|
207 |
const char *name; |
|
208 |
const char *filename; |
|
209 |
int i, nTrays=0, nPages=0, nTotal=0; |
|
210 |
jstring utf_str; |
|
211 |
jclass cls; |
|
212 |
jobjectArray nameArray = NULL; |
|
213 |
||
214 |
name = (*env)->GetStringUTFChars(env, printer, NULL); |
|
215 |
if (name == NULL) { |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
216 |
(*env)->ExceptionClear(env); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
217 |
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); |
2 | 218 |
return NULL; |
219 |
} |
|
220 |
||
221 |
// NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. |
|
222 |
// unlink() must be caled to remove the file when finished using it. |
|
223 |
filename = j2d_cupsGetPPD(name); |
|
224 |
(*env)->ReleaseStringUTFChars(env, printer, name); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
225 |
CHECK_NULL_RETURN(filename, NULL); |
2 | 226 |
|
227 |
cls = (*env)->FindClass(env, "java/lang/String"); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
228 |
CHECK_NULL_RETURN(cls, NULL); |
2 | 229 |
|
230 |
if ((ppd = j2d_ppdOpenFile(filename)) == NULL) { |
|
231 |
unlink(filename); |
|
232 |
DPRINTF("CUPSfuncs::unable to open PPD %s\n", filename); |
|
233 |
return NULL; |
|
234 |
} |
|
235 |
||
236 |
optionPage = j2d_ppdFindOption(ppd, "PageSize"); |
|
237 |
if (optionPage != NULL) { |
|
238 |
nPages = optionPage->num_choices; |
|
239 |
} |
|
240 |
||
241 |
optionTray = j2d_ppdFindOption(ppd, "InputSlot"); |
|
242 |
if (optionTray != NULL) { |
|
243 |
nTrays = optionTray->num_choices; |
|
244 |
} |
|
245 |
||
246 |
if ((nTotal = (nPages+nTrays) *2) > 0) { |
|
247 |
nameArray = (*env)->NewObjectArray(env, nTotal, cls, NULL); |
|
248 |
if (nameArray == NULL) { |
|
249 |
unlink(filename); |
|
250 |
j2d_ppdClose(ppd); |
|
251 |
DPRINTF("CUPSfuncs::bad alloc new array\n", "") |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
252 |
(*env)->ExceptionClear(env); |
2 | 253 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
254 |
return NULL; |
|
255 |
} |
|
256 |
||
257 |
for (i = 0; optionPage!=NULL && i<nPages; i++) { |
|
258 |
choice = (optionPage->choices)+i; |
|
259 |
utf_str = JNU_NewStringPlatform(env, choice->text); |
|
260 |
if (utf_str == NULL) { |
|
261 |
unlink(filename); |
|
262 |
j2d_ppdClose(ppd); |
|
263 |
DPRINTF("CUPSfuncs::bad alloc new string ->text\n", "") |
|
264 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
265 |
return NULL; |
|
266 |
} |
|
267 |
(*env)->SetObjectArrayElement(env, nameArray, i*2, utf_str); |
|
268 |
(*env)->DeleteLocalRef(env, utf_str); |
|
269 |
utf_str = JNU_NewStringPlatform(env, choice->choice); |
|
270 |
if (utf_str == NULL) { |
|
271 |
unlink(filename); |
|
272 |
j2d_ppdClose(ppd); |
|
273 |
DPRINTF("CUPSfuncs::bad alloc new string ->choice\n", "") |
|
274 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
275 |
return NULL; |
|
276 |
} |
|
277 |
(*env)->SetObjectArrayElement(env, nameArray, i*2+1, utf_str); |
|
278 |
(*env)->DeleteLocalRef(env, utf_str); |
|
279 |
} |
|
280 |
||
281 |
for (i = 0; optionTray!=NULL && i<nTrays; i++) { |
|
282 |
choice = (optionTray->choices)+i; |
|
283 |
utf_str = JNU_NewStringPlatform(env, choice->text); |
|
284 |
if (utf_str == NULL) { |
|
285 |
unlink(filename); |
|
286 |
j2d_ppdClose(ppd); |
|
287 |
DPRINTF("CUPSfuncs::bad alloc new string text\n", "") |
|
288 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
289 |
return NULL; |
|
290 |
} |
|
291 |
(*env)->SetObjectArrayElement(env, nameArray, |
|
292 |
(nPages+i)*2, utf_str); |
|
293 |
(*env)->DeleteLocalRef(env, utf_str); |
|
294 |
utf_str = JNU_NewStringPlatform(env, choice->choice); |
|
295 |
if (utf_str == NULL) { |
|
296 |
unlink(filename); |
|
297 |
j2d_ppdClose(ppd); |
|
298 |
DPRINTF("CUPSfuncs::bad alloc new string choice\n", "") |
|
299 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
300 |
return NULL; |
|
301 |
} |
|
302 |
(*env)->SetObjectArrayElement(env, nameArray, |
|
303 |
(nPages+i)*2+1, utf_str); |
|
304 |
(*env)->DeleteLocalRef(env, utf_str); |
|
305 |
} |
|
306 |
} |
|
307 |
j2d_ppdClose(ppd); |
|
308 |
unlink(filename); |
|
309 |
return nameArray; |
|
310 |
} |
|
311 |
||
312 |
||
313 |
/* |
|
314 |
* Returns list of page sizes and imageable area. |
|
315 |
*/ |
|
316 |
JNIEXPORT jfloatArray JNICALL |
|
317 |
Java_sun_print_CUPSPrinter_getPageSizes(JNIEnv *env, |
|
318 |
jobject printObj, |
|
319 |
jstring printer) |
|
320 |
{ |
|
321 |
ppd_file_t *ppd; |
|
322 |
ppd_option_t *option; |
|
323 |
ppd_choice_t *choice; |
|
324 |
ppd_size_t *size; |
|
325 |
||
326 |
const char *name = (*env)->GetStringUTFChars(env, printer, NULL); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
327 |
if (name == NULL) { |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
328 |
(*env)->ExceptionClear(env); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
329 |
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
330 |
return NULL; |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
331 |
} |
2 | 332 |
const char *filename; |
333 |
int i; |
|
334 |
jobjectArray sizeArray = NULL; |
|
335 |
jfloat *dims; |
|
336 |
||
337 |
// NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. |
|
338 |
// unlink() must be called to remove the file after using it. |
|
339 |
filename = j2d_cupsGetPPD(name); |
|
340 |
(*env)->ReleaseStringUTFChars(env, printer, name); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
341 |
CHECK_NULL_RETURN(filename, NULL); |
2 | 342 |
if ((ppd = j2d_ppdOpenFile(filename)) == NULL) { |
343 |
unlink(filename); |
|
344 |
DPRINTF("unable to open PPD %s\n", filename) |
|
345 |
return NULL; |
|
346 |
} |
|
347 |
option = j2d_ppdFindOption(ppd, "PageSize"); |
|
348 |
if (option != NULL && option->num_choices > 0) { |
|
349 |
// create array of dimensions - (num_choices * 6) |
|
350 |
//to cover length & height |
|
351 |
DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices) |
|
25555 | 352 |
// +1 is for storing the default media index |
353 |
sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1); |
|
2 | 354 |
if (sizeArray == NULL) { |
355 |
unlink(filename); |
|
356 |
j2d_ppdClose(ppd); |
|
357 |
DPRINTF("CUPSfuncs::bad alloc new float array\n", "") |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
358 |
(*env)->ExceptionClear(env); |
2 | 359 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
360 |
return NULL; |
|
361 |
} |
|
362 |
||
363 |
dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
364 |
if (dims == NULL) { |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
365 |
unlink(filename); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
366 |
j2d_ppdClose(ppd); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
367 |
(*env)->ExceptionClear(env); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
368 |
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
369 |
return NULL; |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
370 |
} |
2 | 371 |
for (i = 0; i<option->num_choices; i++) { |
372 |
choice = (option->choices)+i; |
|
25555 | 373 |
// get the index of the default page |
374 |
if (!strcmp(choice->choice, option->defchoice)) { |
|
375 |
dims[option->num_choices*6] = (float)i; |
|
376 |
} |
|
2 | 377 |
size = j2d_ppdPageSize(ppd, choice->choice); |
378 |
if (size != NULL) { |
|
379 |
// paper width and height |
|
380 |
dims[i*6] = size->width; |
|
381 |
dims[(i*6)+1] = size->length; |
|
382 |
// paper printable area |
|
383 |
dims[(i*6)+2] = size->left; |
|
384 |
dims[(i*6)+3] = size->top; |
|
385 |
dims[(i*6)+4] = size->right; |
|
386 |
dims[(i*6)+5] = size->bottom; |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
(*env)->ReleaseFloatArrayElements(env, sizeArray, dims, 0); |
|
391 |
} |
|
392 |
||
393 |
j2d_ppdClose(ppd); |
|
394 |
unlink(filename); |
|
395 |
return sizeArray; |
|
396 |
} |
|
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
397 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
398 |
/* |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
399 |
* Populates the supplied ArrayList<Integer> with resolutions. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
400 |
* The first pair of elements will be the default resolution. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
401 |
* If resolution isn't supported the list will be empty. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
402 |
* If needed we can add a 2nd ArrayList<String> which would |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
403 |
* be populated with the corresponding UI name. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
404 |
* PPD specifies the syntax for resolution as either "Ndpi" or "MxNdpi", |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
405 |
* eg 300dpi or 600x600dpi. The former is a shorthand where xres==yres. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
406 |
* We will always expand to the latter as we use a single array list. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
407 |
* Note: getMedia() and getPageSizes() both open the ppd file |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
408 |
* This is not going to scale forever so if we add anymore we |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
409 |
* should look to consolidate this. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
410 |
*/ |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
411 |
JNIEXPORT void JNICALL |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
412 |
Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env, |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
413 |
jobject printObj, |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
414 |
jstring printer, |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
415 |
jobject arrayList) |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
416 |
{ |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
417 |
ppd_file_t *ppd = NULL; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
418 |
ppd_option_t *resolution; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
419 |
int defx = 0, defy = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
420 |
int resx = 0, resy = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
421 |
jclass intCls, cls; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
422 |
jmethodID intCtr, arrListAddMID; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
423 |
int i; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
424 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
425 |
intCls = (*env)->FindClass(env, "java/lang/Integer"); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
426 |
CHECK_NULL(intCls); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
427 |
intCtr = (*env)->GetMethodID(env, intCls, "<init>", "(I)V"); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
428 |
CHECK_NULL(intCtr); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
429 |
cls = (*env)->FindClass(env, "java/util/ArrayList"); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
430 |
CHECK_NULL(cls); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
431 |
arrListAddMID = |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
432 |
(*env)->GetMethodID(env, cls, "add", "(Ljava/lang/Object;)Z"); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
433 |
CHECK_NULL(arrListAddMID); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
434 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
435 |
const char *name = (*env)->GetStringUTFChars(env, printer, NULL); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
436 |
if (name == NULL) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
437 |
(*env)->ExceptionClear(env); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
438 |
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); |
26354
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
439 |
return; |
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
440 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
441 |
const char *filename; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
442 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
443 |
// NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
444 |
// unlink() must be called to remove the file after using it. |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
445 |
filename = j2d_cupsGetPPD(name); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
446 |
(*env)->ReleaseStringUTFChars(env, printer, name); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
447 |
CHECK_NULL(filename); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
448 |
if ((ppd = j2d_ppdOpenFile(filename)) == NULL) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
449 |
unlink(filename); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
450 |
DPRINTF("unable to open PPD %s\n", filename) |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
451 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
452 |
resolution = j2d_ppdFindOption(ppd, "Resolution"); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
453 |
if (resolution != NULL) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
454 |
int matches = sscanf(resolution->defchoice, "%dx%ddpi", &defx, &defy); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
455 |
if (matches == 2) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
456 |
if (defx <= 0 || defy <= 0) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
457 |
defx = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
458 |
defy = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
459 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
460 |
} else { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
461 |
matches = sscanf(resolution->defchoice, "%ddpi", &defx); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
462 |
if (matches == 1) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
463 |
if (defx <= 0) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
464 |
defx = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
465 |
} else { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
466 |
defy = defx; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
467 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
468 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
469 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
470 |
if (defx > 0) { |
26354
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
471 |
jobject rxObj, ryObj; |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
472 |
rxObj = (*env)->NewObject(env, intCls, intCtr, defx); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
473 |
CHECK_NULL(rxObj); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
474 |
ryObj = (*env)->NewObject(env, intCls, intCtr, defy); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
475 |
CHECK_NULL(ryObj); |
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
476 |
(*env)->CallBooleanMethod(env, arrayList, arrListAddMID, rxObj); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
477 |
(*env)->CallBooleanMethod(env, arrayList, arrListAddMID, ryObj); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
478 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
479 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
480 |
for (i = 0; i < resolution->num_choices; i++) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
481 |
char *resStr = resolution->choices[i].choice; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
482 |
int matches = sscanf(resStr, "%dx%ddpi", &resx, &resy); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
483 |
if (matches == 2) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
484 |
if (resx <= 0 || resy <= 0) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
485 |
resx = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
486 |
resy = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
487 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
488 |
} else { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
489 |
matches = sscanf(resStr, "%ddpi", &resx); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
490 |
if (matches == 1) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
491 |
if (resx <= 0) { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
492 |
resx = 0; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
493 |
} else { |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
494 |
resy = resx; |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
495 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
496 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
497 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
498 |
if (resx > 0 && (resx != defx || resy != defy )) { |
26354
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
499 |
jobject rxObj, ryObj; |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
500 |
rxObj = (*env)->NewObject(env, intCls, intCtr, resx); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
501 |
CHECK_NULL(rxObj); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
502 |
ryObj = (*env)->NewObject(env, intCls, intCtr, resy); |
2d04e6c7ed68
8055201: JNI exception pending in jdk/src/solaris/native/sun/awt/CUPSfuncs.c
prr
parents:
25859
diff
changeset
|
503 |
CHECK_NULL(ryObj); |
25774
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
504 |
(*env)->CallBooleanMethod(env, arrayList, arrListAddMID, rxObj); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
505 |
(*env)->CallBooleanMethod(env, arrayList, arrListAddMID, ryObj); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
506 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
507 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
508 |
} |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
509 |
|
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
510 |
j2d_ppdClose(ppd); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
511 |
unlink(filename); |
21b78da4b2df
8048328: CUPS Printing does not report supported printer resolutions.
prr
parents:
25555
diff
changeset
|
512 |
} |