< prev index next >

src/java.desktop/unix/native/common/awt/CUPSfuncs.c

Print this page




 354         }
 355     }
 356     j2d_ppdClose(ppd);
 357     unlink(filename);
 358     return nameArray;
 359 }
 360 
 361 
 362 /*
 363  * Returns list of page sizes and imageable area.
 364  */
 365 JNIEXPORT jfloatArray JNICALL
 366 Java_sun_print_CUPSPrinter_getPageSizes(JNIEnv *env,
 367                                          jobject printObj,
 368                                          jstring printer)
 369 {
 370     ppd_file_t *ppd;
 371     ppd_option_t *option;
 372     ppd_choice_t *choice;
 373     ppd_size_t *size;




 374 
 375     const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
 376     if (name == NULL) {
 377         (*env)->ExceptionClear(env);
 378         JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
 379         return NULL;
 380     }
 381     const char *filename;
 382     int i;
 383     jobjectArray sizeArray = NULL;
 384     jfloat *dims;
 385 
 386     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
 387     // unlink() must be called to remove the file after using it.
 388     filename = j2d_cupsGetPPD(name);
 389     (*env)->ReleaseStringUTFChars(env, printer, name);
 390     CHECK_NULL_RETURN(filename, NULL);
 391     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
 392         unlink(filename);
 393         DPRINTF("unable to open PPD  %s\n", filename)
 394         return NULL;
 395     }
 396     option = j2d_ppdFindOption(ppd, "PageSize");
 397     if (option != NULL && option->num_choices > 0) {
 398         // create array of dimensions - (num_choices * 6)
 399         //to cover length & height
 400         DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices)
 401         // +1 is for storing the default media index
 402         sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1);
 403         if (sizeArray == NULL) {
 404             unlink(filename);


 453  * PPD specifies the syntax for resolution as either "Ndpi" or "MxNdpi",
 454  * eg 300dpi or 600x600dpi. The former is a shorthand where xres==yres.
 455  * We will always expand to the latter as we use a single array list.
 456  * Note: getMedia() and getPageSizes() both open the ppd file
 457  * This is not going to scale forever so if we add anymore we
 458  * should look to consolidate this.
 459  */
 460 JNIEXPORT void JNICALL
 461 Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env,
 462                                           jobject printObj,
 463                                           jstring printer,
 464                                           jobject arrayList)
 465 {
 466     ppd_file_t *ppd = NULL;
 467     ppd_option_t *resolution;
 468     int defx = 0, defy = 0;
 469     int resx = 0, resy = 0;
 470     jclass intCls, cls;
 471     jmethodID intCtr, arrListAddMID;
 472     int i;


 473 
 474     intCls = (*env)->FindClass(env, "java/lang/Integer");
 475     CHECK_NULL(intCls);
 476     intCtr = (*env)->GetMethodID(env, intCls, "<init>", "(I)V");
 477     CHECK_NULL(intCtr);
 478     cls = (*env)->FindClass(env, "java/util/ArrayList");
 479     CHECK_NULL(cls);
 480     arrListAddMID =
 481         (*env)->GetMethodID(env, cls, "add", "(Ljava/lang/Object;)Z");
 482     CHECK_NULL(arrListAddMID);
 483 
 484     const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
 485     if (name == NULL) {
 486         (*env)->ExceptionClear(env);
 487         JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
 488         return;
 489     }
 490     const char *filename;
 491 
 492     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
 493     // unlink() must be called to remove the file after using it.
 494     filename = j2d_cupsGetPPD(name);
 495     (*env)->ReleaseStringUTFChars(env, printer, name);
 496     CHECK_NULL(filename);
 497     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
 498         unlink(filename);
 499         DPRINTF("unable to open PPD  %s\n", filename)
 500     }
 501     resolution = j2d_ppdFindOption(ppd, "Resolution");
 502     if (resolution != NULL) {
 503         int matches = sscanf(resolution->defchoice, "%dx%ddpi", &defx, &defy);
 504         if (matches == 2) {
 505            if (defx <= 0 || defy <= 0) {
 506               defx = 0;
 507               defy = 0;
 508            }
 509         } else {
 510             matches = sscanf(resolution->defchoice, "%ddpi", &defx);




 354         }
 355     }
 356     j2d_ppdClose(ppd);
 357     unlink(filename);
 358     return nameArray;
 359 }
 360 
 361 
 362 /*
 363  * Returns list of page sizes and imageable area.
 364  */
 365 JNIEXPORT jfloatArray JNICALL
 366 Java_sun_print_CUPSPrinter_getPageSizes(JNIEnv *env,
 367                                          jobject printObj,
 368                                          jstring printer)
 369 {
 370     ppd_file_t *ppd;
 371     ppd_option_t *option;
 372     ppd_choice_t *choice;
 373     ppd_size_t *size;
 374     const char *filename = NULL;
 375     int i;
 376     jobjectArray sizeArray = NULL;
 377     jfloat *dims;
 378 
 379     const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
 380     if (name == NULL) {
 381         (*env)->ExceptionClear(env);
 382         JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
 383         return NULL;
 384     }




 385 
 386     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
 387     // unlink() must be called to remove the file after using it.
 388     filename = j2d_cupsGetPPD(name);
 389     (*env)->ReleaseStringUTFChars(env, printer, name);
 390     CHECK_NULL_RETURN(filename, NULL);
 391     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
 392         unlink(filename);
 393         DPRINTF("unable to open PPD  %s\n", filename)
 394         return NULL;
 395     }
 396     option = j2d_ppdFindOption(ppd, "PageSize");
 397     if (option != NULL && option->num_choices > 0) {
 398         // create array of dimensions - (num_choices * 6)
 399         //to cover length & height
 400         DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices)
 401         // +1 is for storing the default media index
 402         sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1);
 403         if (sizeArray == NULL) {
 404             unlink(filename);


 453  * PPD specifies the syntax for resolution as either "Ndpi" or "MxNdpi",
 454  * eg 300dpi or 600x600dpi. The former is a shorthand where xres==yres.
 455  * We will always expand to the latter as we use a single array list.
 456  * Note: getMedia() and getPageSizes() both open the ppd file
 457  * This is not going to scale forever so if we add anymore we
 458  * should look to consolidate this.
 459  */
 460 JNIEXPORT void JNICALL
 461 Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env,
 462                                           jobject printObj,
 463                                           jstring printer,
 464                                           jobject arrayList)
 465 {
 466     ppd_file_t *ppd = NULL;
 467     ppd_option_t *resolution;
 468     int defx = 0, defy = 0;
 469     int resx = 0, resy = 0;
 470     jclass intCls, cls;
 471     jmethodID intCtr, arrListAddMID;
 472     int i;
 473     const char *name = NULL;
 474     const char *filename = NULL;
 475 
 476     intCls = (*env)->FindClass(env, "java/lang/Integer");
 477     CHECK_NULL(intCls);
 478     intCtr = (*env)->GetMethodID(env, intCls, "<init>", "(I)V");
 479     CHECK_NULL(intCtr);
 480     cls = (*env)->FindClass(env, "java/util/ArrayList");
 481     CHECK_NULL(cls);
 482     arrListAddMID =
 483         (*env)->GetMethodID(env, cls, "add", "(Ljava/lang/Object;)Z");
 484     CHECK_NULL(arrListAddMID);
 485 
 486     name = (*env)->GetStringUTFChars(env, printer, NULL);
 487     if (name == NULL) {
 488         (*env)->ExceptionClear(env);
 489         JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
 490         return;
 491     }
 492     
 493 
 494     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
 495     // unlink() must be called to remove the file after using it.
 496     filename = j2d_cupsGetPPD(name);
 497     (*env)->ReleaseStringUTFChars(env, printer, name);
 498     CHECK_NULL(filename);
 499     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
 500         unlink(filename);
 501         DPRINTF("unable to open PPD  %s\n", filename)
 502     }
 503     resolution = j2d_ppdFindOption(ppd, "Resolution");
 504     if (resolution != NULL) {
 505         int matches = sscanf(resolution->defchoice, "%dx%ddpi", &defx, &defy);
 506         if (matches == 2) {
 507            if (defx <= 0 || defy <= 0) {
 508               defx = 0;
 509               defy = 0;
 510            }
 511         } else {
 512             matches = sscanf(resolution->defchoice, "%ddpi", &defx);


< prev index next >