Exemple #1
0
static gboolean stpui_slider_update(stpui_Slider *c)
{
	stp_parameter_t desc;
	gboolean result;

	gboolean enabled=TRUE;

	if(c->checkbutton)
		enabled=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->checkbutton));

	stp_describe_parameter(c->vars,c->optionname,&desc);
	if(desc.is_active)
	{
		switch(desc.p_type)
		{
			case STP_PARAMETER_TYPE_DOUBLE:
				{
					double min,max,current;
					min=desc.bounds.dbl.lower;
					max=desc.bounds.dbl.upper;
					current=stp_get_float_parameter(c->vars,c->optionname);
					gtk_range_set_range(GTK_RANGE(c->scale),min,max);
					gtk_range_set_value(GTK_RANGE(c->scale),current);
					gtk_spin_button_set_range(GTK_SPIN_BUTTON(c->spin),min,max);
					gtk_spin_button_set_value(GTK_SPIN_BUTTON(c->spin),current);
					break;
				}
			case STP_PARAMETER_TYPE_INT:
				{
					int min,max,current;
					min=desc.bounds.integer.lower;
					max=desc.bounds.integer.upper;
					current=stp_get_int_parameter(c->vars,c->optionname);
					gtk_range_set_range(GTK_RANGE(c->scale),min,max);
					gtk_range_set_value(GTK_RANGE(c->scale),current);
					gtk_spin_button_set_range(GTK_SPIN_BUTTON(c->spin),min,max);
					gtk_spin_button_set_value(GTK_SPIN_BUTTON(c->spin),current);
					break;
				}
			case STP_PARAMETER_TYPE_DIMENSION:
				{
					int min,max,current;
					min=desc.bounds.integer.lower;
					max=desc.bounds.integer.upper;
					current=stp_get_dimension_parameter(c->vars,c->optionname);
					// Convert to correct unit here...
					gtk_range_set_range(GTK_RANGE(c->scale),min,max);
					gtk_range_set_value(GTK_RANGE(c->scale),current);
					dimension_set_range_pt(DIMENSION(c->spin),min,max);
					dimension_set_pt(DIMENSION(c->spin),current);
					break;
				}
			default:
				break;
		}
	}
	if(desc.is_active)
	{
		gtk_widget_show(GTK_WIDGET(c));
		if(c->checkbutton)
			gtk_widget_show(GTK_WIDGET(c->checkbutton));
		if(c->label)
			gtk_widget_show(GTK_WIDGET(c->label));
	}
	else
	{
		gtk_widget_hide(GTK_WIDGET(c));
		if(c->checkbutton)
			gtk_widget_hide(GTK_WIDGET(c->checkbutton));
		if(c->label)
			gtk_widget_hide(GTK_WIDGET(c->label));
	}
	gtk_widget_set_sensitive(GTK_WIDGET(c->scale),desc.is_active);
	gtk_widget_set_sensitive(GTK_WIDGET(c->spin),desc.is_active & enabled);
	if(c->checkbutton)
		gtk_widget_set_sensitive(GTK_WIDGET(c->checkbutton),desc.is_active);
	result=desc.is_active;
	return(result);
}
Exemple #2
0
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;
}