static void stpui_spin_changed(GtkWidget *w,gpointer *ud) { stpui_Slider *s=STPUI_SLIDER(ud); double value; switch(s->type) { case STP_PARAMETER_TYPE_DOUBLE: value=gtk_spin_button_get_value(GTK_SPIN_BUTTON(s->spin)); stp_set_float_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_INT: value=gtk_spin_button_get_value(GTK_SPIN_BUTTON(s->spin)); stp_set_int_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_DIMENSION: value=dimension_get_pt(DIMENSION(s->spin)); stp_set_dimension_parameter(s->vars,s->optionname,value); break; default: break; } stpui_slider_refresh(s); // g_signal_emit(G_OBJECT (s), // stpui_slider_signals[CHANGED_SIGNAL], 0); }
static void stpui_slider_changed(GtkWidget *w,gpointer *ud) { stpui_Slider *s=STPUI_SLIDER(ud); double value; if(s->checkbutton) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s->checkbutton),TRUE); switch(s->type) { case STP_PARAMETER_TYPE_DOUBLE: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_float_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_INT: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_int_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_DIMENSION: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_dimension_parameter(s->vars,s->optionname,value); break; default: break; } stpui_slider_refresh(s); // g_signal_emit(G_OBJECT (s), // stpui_slider_signals[CHANGED_SIGNAL], 0); }
static gboolean stpui_slider_released(GtkWidget *w,GdkEventButton *e,gpointer ud) { stpui_Slider *s=STPUI_SLIDER(ud); double value; switch(s->type) { case STP_PARAMETER_TYPE_DOUBLE: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_float_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_INT: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_int_parameter(s->vars,s->optionname,value); break; case STP_PARAMETER_TYPE_DIMENSION: value=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_dimension_parameter(s->vars,s->optionname,value); break; default: break; } stpui_slider_refresh(s); g_signal_emit(G_OBJECT (s), stpui_slider_signals[CHANGED_SIGNAL], 0); return(FALSE); }
static void stpui_toggle_changed(GtkWidget *w,gpointer *ud) { stpui_Slider *s=STPUI_SLIDER(ud); gboolean enabled=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s->checkbutton)); if(enabled) { stp_parameter_t desc; stp_describe_parameter(s->vars,s->optionname,&desc); switch(desc.p_type) { case STP_PARAMETER_TYPE_DOUBLE: { double val=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_float_parameter(s->vars,s->optionname,val); } break; case STP_PARAMETER_TYPE_INT: { double val=gtk_range_get_value(GTK_RANGE(s->scale)); stp_set_int_parameter(s->vars,s->optionname,val); } break; case STP_PARAMETER_TYPE_DIMENSION: { double val=gtk_range_get_value(GTK_RANGE(s->scale)); // Convert to correct unit here stp_set_dimension_parameter(s->vars,s->optionname,val); } break; default: break; } } else { stp_parameter_t desc; stp_describe_parameter(s->vars,s->optionname,&desc); switch(desc.p_type) { case STP_PARAMETER_TYPE_DOUBLE: stp_clear_float_parameter(s->vars,s->optionname); break; case STP_PARAMETER_TYPE_INT: stp_clear_int_parameter(s->vars,s->optionname); break; case STP_PARAMETER_TYPE_DIMENSION: stp_clear_dimension_parameter(s->vars,s->optionname); break; default: break; } } stpui_slider_refresh(s); }
void guten_set_user_parameters(struct stp_vars* gvars, char **params, unsigned int params_num) { int i; for(i=0; i<params_num; i++) { stp_parameter_t pardesc; char* name = params[2*i]; char* value = params[2*i +1]; stp_describe_parameter(gvars, name, &pardesc); switch(pardesc.p_type) { case STP_PARAMETER_TYPE_STRING_LIST: { stp_set_string_parameter(gvars, pardesc.name, value); break; } case STP_PARAMETER_TYPE_INT: { int ival; if(sscanf(value, "%d", &ival)) { stp_set_int_parameter(gvars, pardesc.name, ival); } else { printf("Cannot parse gutenprint int parameter %s=%s - skipping\n", name, value); } break; } case STP_PARAMETER_TYPE_BOOLEAN: { boolean bval; boolean correct = FALSE; if(strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0 || strcmp(value, "1") == 0) { bval = TRUE; correct = TRUE; } else if(strcasecmp(value, "false") == 0 || strcasecmp(value, "no") == 0 || strcmp(value, "0") == 0) { bval = FALSE; correct = TRUE; } if(correct) { stp_set_boolean_parameter(gvars, pardesc.name, bval); } else { printf("Cannot parse gutenprint boolean parameter %s=%s - skipping\n", name, value); } break; } case STP_PARAMETER_TYPE_DOUBLE: { double dval; if(sscanf(value, "%lf", &dval)) { stp_set_float_parameter(gvars, pardesc.name, dval); } else { printf("Cannot parse gutenprint double parameter %s=%s - skipping\n", name, value); } break; } case STP_PARAMETER_TYPE_CURVE: { printf("Gutenprint curve parameter %s - skipping, freel free to write a curve parser for this tool\n", name); break; } case STP_PARAMETER_TYPE_FILE: { stp_set_file_parameter(gvars, pardesc.name, value); break; } case STP_PARAMETER_TYPE_RAW: { printf("Gutenprint raw parameter %s - skipping, freel free to write an implementation to support raw parameter in this tool\n", name); break; } case STP_PARAMETER_TYPE_ARRAY: { printf("Gutenprint array parameter %s - skipping, freel free to write an implementation to support arra parameter in this tool\n", name); break; } case STP_PARAMETER_TYPE_DIMENSION: { int ival; if(sscanf(value, "%d", &ival)) { stp_set_dimension_parameter(gvars, pardesc.name, ival); } else { printf("Cannot parse gutenprint dimension parameter %s=%s - skipping\n", name, value); } break; } default: { printf("Gutenprint parameter %s has unknown type - skippig\n", name); } } } }
struct stp_vars *guten_prepare_printer(const stp_printer_t *printer) { const struct stp_vars *gvars_defaults; struct stp_vars *gvars; gvars_defaults = stp_printer_get_defaults(printer); gvars = stp_vars_create_copy(gvars_defaults); stp_set_outdata(gvars, stdout); stp_set_outfunc(gvars, gfunc_print); stp_set_errdata(gvars, stderr); stp_set_errfunc(gvars, gfunc_error); stp_parameter_list_t *list = stp_get_parameter_list(gvars); size_t count = stp_parameter_list_count(list); int i; for(i=0; i<count; i++) { const stp_parameter_t *par = stp_parameter_list_param(list, i); stp_parameter_t pardesc; stp_describe_parameter(gvars, par->name, &pardesc); if(pardesc.is_mandatory) { switch(pardesc.p_type) { case STP_PARAMETER_TYPE_STRING_LIST: { stp_set_string_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } case STP_PARAMETER_TYPE_INT: { stp_set_int_parameter(gvars, pardesc.name, pardesc.deflt.integer); break; } case STP_PARAMETER_TYPE_BOOLEAN: { stp_set_boolean_parameter(gvars, pardesc.name, pardesc.deflt.boolean); break; } case STP_PARAMETER_TYPE_DOUBLE: { stp_set_float_parameter(gvars, pardesc.name, pardesc.deflt.dbl); break; } case STP_PARAMETER_TYPE_CURVE: { stp_set_curve_parameter(gvars, pardesc.name, pardesc.deflt.curve); break; } case STP_PARAMETER_TYPE_FILE: { stp_set_file_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } /* case STP_PARAMETER_TYPE_RAW: { stp_set_raw_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } */ case STP_PARAMETER_TYPE_ARRAY: { stp_set_array_parameter(gvars, pardesc.name, pardesc.deflt.array); break; } case STP_PARAMETER_TYPE_DIMENSION: { stp_set_dimension_parameter(gvars, pardesc.name, pardesc.deflt.dimension); break; } default: {} } } } stp_parameter_list_destroy(list); return gvars; }
static int do_print(void) { int status = 0; stp_vars_t *v; const stp_printer_t *the_printer; int left, right, top, bottom; int x, y; int width, height; int retval; stp_parameter_list_t params; int count; int i; char tmp[32]; initialize_global_parameters(); global_vars = stp_vars_create(); stp_set_outfunc(global_vars, writefunc); stp_set_errfunc(global_vars, writefunc); stp_set_outdata(global_vars, stdout); stp_set_errdata(global_vars, stderr); setlocale(LC_ALL, "C"); retval = yyparse(); setlocale(LC_ALL, ""); if (retval) return retval + 1; if (!global_did_something) return 1; v = stp_vars_create(); the_printer = stp_get_printer_by_driver(global_printer); if (!the_printer) { int j; fprintf(stderr, "Unknown printer %s\nValid printers are:\n", global_printer); for (j = 0; j < stp_printer_model_count(); j++) { the_printer = stp_get_printer_by_index(j); fprintf(stderr, "%-16s%s\n", stp_printer_get_driver(the_printer), stp_printer_get_long_name(the_printer)); } return 2; } bytes_written = 0; if (global_output) { if (strcmp(global_output, "-") == 0) output = stdout; else if (strcmp(global_output, "") == 0) output = NULL; else if (global_output[0] == '|') { close_output(); write_to_process = 1; output = popen(global_output+1, "w"); if (! output) { fprintf(stderr, "popen '%s' failed: %s\n", global_output, strerror(errno)); output = NULL; } free(global_output); global_output = NULL; } else { close_output(); output = fopen(global_output, "wb"); if (! output) { fprintf(stderr, "Create %s failed: %s\n", global_output, strerror(errno)); output = NULL; } free(global_output); global_output = NULL; } } stp_set_printer_defaults(v, the_printer); stp_set_outfunc(v, writefunc); stp_set_errfunc(v, writefunc); stp_set_outdata(v, output); stp_set_errdata(v, stderr); stp_set_string_parameter(v, "InputImageType", global_image_type); sprintf(tmp, "%d", global_bit_depth); stp_set_string_parameter(v, "ChannelBitDepth", tmp); if (strcmp(global_image_type, "Raw") == 0) { sprintf(tmp, "%d", global_channel_depth); stp_set_string_parameter(v, "RawChannels", tmp); } stp_set_float_parameter(v, "Density", global_density); stp_set_string_parameter(v, "Quality", "None"); stp_set_string_parameter(v, "ImageType", "None"); params = stp_get_parameter_list(v); count = stp_parameter_list_count(params); for (i = 0; i < count; i++) { const stp_parameter_t *p = stp_parameter_list_param(params, i); if (p->p_type == STP_PARAMETER_TYPE_STRING_LIST) { const char *val = stp_get_string_parameter(global_vars, p->name); if (val && strlen(val) > 0) { stp_set_string_parameter(v, p->name, val); } } else if (p->p_type == STP_PARAMETER_TYPE_INT && stp_check_int_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { int val = stp_get_int_parameter(global_vars, p->name); stp_set_int_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_BOOLEAN && stp_check_boolean_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { int val = stp_get_boolean_parameter(global_vars, p->name); stp_set_boolean_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_CURVE && stp_check_curve_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { const stp_curve_t *val = stp_get_curve_parameter(global_vars, p->name); stp_set_curve_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_DOUBLE && stp_check_float_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { double val = stp_get_float_parameter(global_vars, p->name); stp_set_float_parameter(v, p->name, val); } } stp_set_page_width(v, stp_get_page_width(global_vars)); stp_set_page_height(v, stp_get_page_height(global_vars)); stp_parameter_list_destroy(params); if (stp_check_string_parameter(v, "PageSize", STP_PARAMETER_ACTIVE) && !strcmp(stp_get_string_parameter(v, "PageSize"), "Auto")) { stp_parameter_t desc; stp_describe_parameter(v, "PageSize", &desc); if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST) stp_set_string_parameter(v, "PageSize", desc.deflt.str); stp_parameter_description_destroy(&desc); } stp_set_printer_defaults_soft(v, the_printer); stp_get_imageable_area(v, &left, &right, &bottom, &top); stp_describe_resolution(v, &x, &y); if (x < 0) x = 300; if (y < 0) y = 300; width = right - left; height = bottom - top; switch (global_size_mode) { case SIZE_PT: top += (int) (global_xtop + .5); left += (int) (global_xleft + .5); width = (int) (global_hsize + .5); height = (int) (global_vsize + .5); break; case SIZE_IN: top += (int) ((global_xtop * 72) + .5); left += (int) ((global_xleft * 72) + .5); width = (int) ((global_hsize * 72) + .5); height = (int) ((global_vsize * 72) + .5); break; case SIZE_MM: top += (int) ((global_xtop * 72 / 25.4) + .5); left += (int) ((global_xleft * 72 / 25.4) + .5); width = (int) ((global_hsize * 72 / 25.4) + .5); height = (int) ((global_vsize * 72 / 25.4) + .5); break; case SIZE_RELATIVE: default: top += height * global_xtop; left += width * global_xleft; width *= global_hsize; height *= global_vsize; break; } stp_set_width(v, width); stp_set_height(v, height); #if 0 width = (width / global_steps) * global_steps; height = (height / global_n_testpatterns) * global_n_testpatterns; #endif if (global_steps > width) global_steps = width; global_printer_width = width * x / 72; global_printer_height = height * y / 72; global_band_height = global_printer_height / global_n_testpatterns; if (global_band_height == 0) global_band_height = 1; stp_set_left(v, left); stp_set_top(v, top); stp_merge_printvars(v, stp_printer_get_defaults(the_printer)); if (stp_verify(v)) { bytes_written = 0; if (start_job) { stp_start_job(v, &theImage); start_job = 0; } if (stp_print(v, &theImage) != 1) { if (!global_quiet) fputs("FAILED", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else if (bytes_written == 0) { if (!global_quiet) fputs("FAILED: No output", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else passes++; if (end_job) { stp_end_job(v, &theImage); end_job = 0; } } else { if (! global_fail_verify_ok) { if (!global_quiet) fputs("FAILED", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else { if (!global_quiet) fputs("(skipped)", stderr); skipped++; } } if (!global_quiet) fputc('\n', stderr); stp_vars_destroy(v); stp_free(static_testpatterns); static_testpatterns = NULL; return status; }