int GetPrinterSettings( cups_option_t *p_cups_opt, int num_opt, ParamList **p_list, int *listNum ) { char *p_ppd_name = getenv("PPD"); ppd_file_t *p_ppd; ppd_choice_t *p_choice; int result = -1; PpdToOptKey *p_opt_key_table = alloc_opt_key_table(p_ppd_name); PpdToOptKey *p_table = p_opt_key_table; int numCnt = 0; char choice[BUF_SIZE]; ParamList *local_p_list = NULL; static const char *libpath; if ( (p_cups_opt == NULL) || (listNum == NULL) ) goto onErr; *listNum = 0; DEBUG_PRINT2( "DEBUG:[rastertocanonij] PPD Path(%s)\n", p_ppd_name ); if ( (p_ppd = ppdOpenFile( p_ppd_name )) == NULL ) goto onErr; ppdMarkDefaults(p_ppd); cupsMarkOptions(p_ppd, num_opt, p_cups_opt); /* add libpath */ libpath = GetExecProgPath(); if ( libpath != NULL ){ param_list_add( &local_p_list, "--filterpath", libpath, strlen(libpath) + 1 ); } while( p_table->ppd_key != NULL ){ p_choice = ppdFindMarkedChoice( p_ppd, p_table->ppd_key ); if ( p_choice ) { DEBUG_PRINT3( "DEBUG:[rastertocanonij] OPTION(%s) / VALUE(%s)\n", p_table->ppd_key, p_choice->choice ); } else { DEBUG_PRINT2( "DEBUG:[rastertocanonij] OPTION(%s) / VALUE(novalue)\n", p_table->ppd_key ); } if ( p_choice != NULL ){ strcpy( choice, p_choice->choice ); //to_lower_except_size_X(choice); param_list_add( &local_p_list, p_table->opt_key, choice, strlen(choice) + 1 ); numCnt++; } p_table++; } *listNum = numCnt; *p_list = local_p_list; result = 0; onErr: return result; }
static char* make_cmd_param(cups_option_t *p_cups_opt, int num_opt, ParamList *p_param, char *p_product, int len) { #ifdef DEBUG_PPD char *p_ppd_name = "debug.ppd"; #else char *p_ppd_name = getenv("PPD"); #endif ppd_file_t *p_ppd; char *cmd_buf = NULL; ppd_choice_t *p_choice; ppd_size_t *p_size; ppd_size_t *p_default_size; int reso; char gs_exec_buf[256]; char gs_cmd_buf[1024]; char *flt_cmd_buf = NULL; //For InkJet long minw_mm, maxw_mm; long minl_mm, maxl_mm; PpdToOptKey *p_opt_key_table = alloc_opt_key_table(p_ppd_name); PpdToOptKey *p_table = p_opt_key_table; ParamList *p_list = NULL; if( (p_ppd = ppdOpenFile(p_ppd_name)) == NULL ) return NULL; if( p_opt_key_table == NULL) return NULL; ppdMarkDefaults(p_ppd); // Obtain default page size setting. p_choice = ppdFindMarkedChoice(p_ppd, "PageSize"); p_default_size = ppdPageSize(p_ppd, p_choice->choice); mark_ps_param_options(p_ppd, p_param); cupsMarkOptions(p_ppd, num_opt, p_cups_opt); // Obtain page size setting. p_choice = ppdFindMarkedChoice(p_ppd, "PageSize"); p_size = ppdPageSize(p_ppd, p_choice->choice); if (!p_size || ((int)(p_size->width == 0)) || ((int)(p_size->length == 0))) { p_size = p_default_size; } // Obtain resolution setting. p_choice = ppdFindMarkedChoice(p_ppd, "Resolution"); reso = atoi(p_choice->choice); //Obtain product name. parse_product_name(p_ppd->product, p_product, len); get_min_max_width_length(p_opt_key_table, p_cups_opt, num_opt, &minw_mm, &maxw_mm, &minl_mm, &maxl_mm); // gs command strncpy(gs_exec_buf, GS_PATH, 256); strncat(gs_exec_buf, "/", 1); strncat(gs_exec_buf, GS_BIN, strlen(GS_BIN)); snprintf(gs_cmd_buf, 1023, "%s -r%d -g%dx%d -q -dNOPROMPT -dSAFER -sDEVICE=ppmraw -sOutputFile=- -| ", gs_exec_buf, reso, (int)(p_size->width * (float)reso / 72.0), (int)(p_size->length * (float)reso / 72.0)); // For InkJet bjfilter Command while( p_table->ppd_key != NULL ) { p_choice = ppdFindMarkedChoice(p_ppd, p_table->ppd_key); if( p_choice != NULL ) { char choice[256]; strncpy(choice, p_choice->choice, 256); if( !strcmp(p_table->ppd_key, "PageSize") && !strcmp(choice, "Custom") ) { char pw[256]; char pl[256]; long pw_mm, pl_mm; pw_mm = (long)((double)p_size->width * 2540.0 / 72.0); pl_mm = (long)((double)p_size->length * 2540.0 / 72.0); if( minw_mm != -1 && pw_mm < minw_mm ) pw_mm = minw_mm; if( maxw_mm != -1 && pw_mm > maxw_mm ) pw_mm = maxw_mm; if( minl_mm != -1 && pl_mm < minl_mm ) pl_mm = minl_mm; if( maxl_mm != -1 && pl_mm > maxl_mm ) pl_mm = maxw_mm; snprintf(pw, 255, "%ld", pw_mm); snprintf(pl, 255, "%ld", pl_mm); param_list_add(&p_list, p_table->opt_key, "user", 5); param_list_add(&p_list, "--paperwidth", pw, strlen(pw) + 1); param_list_add(&p_list, "--paperheight", pl, strlen(pl) + 1); } else { if( !strcmp(p_table->ppd_key, "PageSize") && is_borderless(choice) ) { param_list_add(&p_list, "--borderless", "", 1); } param_list_add(&p_list, p_table->opt_key, choice, strlen(choice) + 1); } } p_table++; } while( num_opt-- > 0 ) { char *opt_key = ppd_to_opt_key(p_opt_key_table, p_cups_opt->name); if( opt_key != NULL ) { char *value = p_cups_opt->value; param_list_add(&p_list, opt_key, value, strlen(value) + 1); } p_cups_opt++; } { char bbox_buf[256]; float dd = 1.0 - 36.0 / (float)reso; int left = (int)p_size->left; int top = (int)(p_size->top + dd); int right = left + (int)(p_size->right - p_size->left + dd); int bottom = top - (int)(p_size->top - p_size->bottom + dd); snprintf(bbox_buf, 255, "%-d,%-d,%-d,%-d", left, bottom, right, top); param_list_add(&p_list, "--bbox", bbox_buf, strlen(bbox_buf) + 1); } flt_cmd_buf = make_filter_param_line(p_product, reso, p_list); if( p_list != NULL ){ param_list_free(p_list); free_opt_key_table(p_opt_key_table); } ppdClose(p_ppd); if( flt_cmd_buf ) { int buf_len; buf_len = strlen(gs_cmd_buf) + strlen(flt_cmd_buf) + 1; if( (cmd_buf = (char*)malloc(buf_len)) != NULL ) { strcpy(cmd_buf, gs_cmd_buf); strcat(cmd_buf, flt_cmd_buf); } free(flt_cmd_buf); fprintf(stderr, "pstocanonbj: %s\n", cmd_buf); return cmd_buf; } else return NULL; }