/* * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
name = (*env)->GetStringUTFChars(env, printer, NULL); if (name == NULL) {
(*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); return NULL;
}
// NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. // unlink() must be caled to remove the file when finished using it.
filename = j2d_cupsGetPPD(name);
(*env)->ReleaseStringUTFChars(env, printer, name);
CHECK_NULL_RETURN(filename, NULL);
// NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. // unlink() must be called to remove the file after using it.
filename = j2d_cupsGetPPD(name);
(*env)->ReleaseStringUTFChars(env, printer, name);
CHECK_NULL_RETURN(filename, NULL); if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
unlink(filename);
DPRINTF("unable to open PPD %s\n", filename) return NULL;
}
option = j2d_ppdFindOption(ppd, "PageSize"); if (option != NULL && option->num_choices > 0) { // create array of dimensions - (num_choices * 6) //to cover length & height
DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices) // +1 is for storing the default media index
sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1); if (sizeArray == NULL) {
unlink(filename);
j2d_ppdClose(ppd);
DPRINTF("CUPSfuncs::bad alloc new float array\n", "")
(*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL;
}
dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL); if (dims == NULL) {
unlink(filename);
j2d_ppdClose(ppd);
(*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); return NULL;
} for (i = 0; i<option->num_choices; i++) {
choice = (option->choices)+i; // get the index of the default page if (!strcmp(choice->choice, option->defchoice)) {
dims[option->num_choices*6] = (float)i;
}
size = j2d_ppdPageSize(ppd, choice->choice); if (size != NULL) { // paper width and height
dims[i*6] = size->width;
dims[(i*6)+1] = size->length; // paper printable area
dims[(i*6)+2] = size->left;
dims[(i*6)+3] = size->top;
dims[(i*6)+4] = size->right;
dims[(i*6)+5] = size->bottom;
}
}
/* * Populates the supplied ArrayList<Integer> with resolutions. * The first pair of elements will be the default resolution. * If resolution isn't supported the list will be empty. * If needed we can add a 2nd ArrayList<String> which would * be populated with the corresponding UI name. * PPD specifies the syntax for resolution as either "Ndpi" or "MxNdpi", * eg 300dpi or 600x600dpi. The former is a shorthand where xres==yres. * We will always expand to the latter as we use a single array list. * Note: getMedia() and getPageSizes() both open the ppd file * This is not going to scale forever so if we add anymore we * should look to consolidate this.
*/
JNIEXPORT void JNICALL
Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env,
jobject printObj,
jstring printer,
jobject arrayList)
{
ppd_file_t *ppd = NULL;
ppd_option_t *resolution; int defx = 0, defy = 0; int resx = 0, resy = 0;
jclass intCls, cls;
jmethodID intCtr, arrListAddMID; int i; constchar *name = NULL; constchar *filename = NULL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.