コード例 #1
0
ファイル: hpgsreader.c プロジェクト: AmirAbrams/haiku
/*!
   Sets a vector drawing device to a HPGL reader an resets the input
   stream.

   The function return 0 in any case.
*/
int  hpgs_reader_imbue(hpgs_reader *reader, hpgs_device *dev)
{
  if (reader->device)
    {
      // overtake a plotsize device for transferring individual plot sizes
      // for each page.
      if (hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_PLOTSIZE)
        {
          if (reader->plotsize_device)
            hpgs_device_destroy(reader->plotsize_device);

          reader->plotsize_device = reader->device;
        }
      else
        hpgs_device_destroy(reader->device);
    }

  reader->device = dev;

  if (reader->current_page <= 0)
    reader->current_page = -1;
  else
    reader->current_page = 1;

  hpgs_reader_set_defaults (reader);

  return hpgs_istream_seek(reader->in,0);
}
コード例 #2
0
ファイル: hpgs.c プロジェクト: OS2World/APP-GRAPHICS-HPGS
int main(int argc, const char *argv[])
{
  const char *dev_name="eps";
  int dev_name_len = 3;
  const char *out_fn=0;
  const char *stamp=0;
  const char *stamp_enc=0;
  const char *png_dump_fn=0;
  int ifile;
  char *aux_path;
  double x_dpi=72.0;
  double y_dpi=72.0;
  hpgs_bbox bbox= { 0.0, 0.0, 0.0, 0.0 };
  double paper_angle = 0.0;
  double paper_border = 0.0;
  double paper_width = 0.0;
  double paper_height = 0.0;
  double lw_factor=-1.0;
  double thin_alpha=0.25;
  double stamp_size=500.0;
  int x_px_size=0;
  int y_px_size=0;
  hpgs_bool multipage=HPGS_FALSE;
  hpgs_bool ignore_ps=HPGS_FALSE;
  hpgs_bool do_linewidth=HPGS_TRUE;
  hpgs_bool do_rop3=HPGS_TRUE;
  int verbosity=1;
  int compression=6;
  hpgs_bool antialias=HPGS_FALSE;
  int image_interpolation=0;
  hpgs_device *size_dev = 0;
  hpgs_device *plot_dev = 0;
  hpgs_istream *in = 0;
  hpgs_reader  *reader = 0;
  hpgs_png_image *image = 0;
  const char *plugin_argv[HPGS_MAX_PLUGIN_ARGS];
  int plugin_argc = 0;
  int ret = 1;

#ifdef LC_MESSAGES
  setlocale(LC_MESSAGES,"");
#endif
  setlocale(LC_CTYPE,"");

  aux_path = get_aux_path();

  if (!aux_path)
    {
      fprintf(stderr,hpgs_i18n("Error getting installation path: %s.\n"),
	      strerror(errno));
      return 1;
    }
  
  hpgs_init(aux_path);
  free(aux_path);

  memset(plugin_argv,0,sizeof(plugin_argv));

  ++argv;
  --argc;

  while (argc>0)
    {
      int narg = 1;
      const char *value;

      if (strcmp(argv[0],"--") == 0)
	{
	  ++argv;
	  --argc;
	  break;
	}
      else       if (strcmp(argv[0],"-v") == 0)
	{
	  ++verbosity;
	}
      else if (strcmp(argv[0],"-q") == 0 || strcmp(argv[0],"-dQUIET") == 0)
	{
	  --verbosity;
	}
      else if (strcmp(argv[0],"-i") == 0)
	{
	  ignore_ps=HPGS_TRUE;
	}
      else if (strcmp(argv[0],"-m") == 0)
	{
	  multipage=HPGS_TRUE;
	}
      else if (hpgs_get_arg_value("-d",argv,&value,&narg))
	{
	  dev_name = value;
          dev_name_len = strlen(dev_name);

          if (plugin_argc)
	    {
	      fprintf(stderr,hpgs_i18n("Error: Device options specified before -d argument.\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("--stamp=",argv,&value,&narg))
	{
	  stamp = value;
	}
      else if (hpgs_get_arg_value("--stamp-encoding=",argv,&value,&narg))
	{
	  stamp_enc = value;
	}
      else if (hpgs_get_arg_value("--stamp-size=",argv,&value,&narg))
	{
          if (hpgs_parse_length(value,&stamp_size))
	    {
	      fprintf(stderr,hpgs_i18n("Error: --stamp-size= must be followed by a valid length.\n"));
	      return usage();
	    }

	  if (stamp_size < 20.0 || stamp_size > 2000.0)
	    {
	      fprintf(stderr,hpgs_i18n("Error: stamp-size must lie in the interval [20,2000]pt.\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("--dump-png=",argv,&value,&narg))
	{
          png_dump_fn = value;
	}
       else if (hpgs_get_arg_value("-o",argv,&value,&narg))
	{
	  out_fn = value;
	}
      else if (strcmp(argv[0],"-a") == 0)
	{
          antialias = HPGS_TRUE;
	}
      else if (hpgs_get_arg_value("-I",argv,&value,&narg))
	{
	  if (get_int_arg(value,&image_interpolation))
	    {
	      if (narg == 1)
		{
		  fprintf(stderr,hpgs_i18n("Error: -I must be followed by an integer number.\n"));
		  return usage();
		}
	      else
		{
		  image_interpolation= 1;
		  narg = 1;
		}
	    }

	  if (image_interpolation < 0 || image_interpolation > 1)
	    {
	      fprintf(stderr,hpgs_i18n("Error: The argument to -I must be 0 or 1.\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("-c",argv,&value,&narg))
	{
	  if (get_int_arg(value,&compression))
	    {
	      fprintf(stderr,hpgs_i18n("Error: -c must be followed by an integer number.\n"));
	      return usage();
	    }
	  
	  if (compression < 1 || compression > 9)
	    {
	      fprintf(stderr,hpgs_i18n("Error: compression factor must lie in the interval [1,9].\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("-w",argv,&value,&narg))
	{
	  if (get_double_arg(value,&lw_factor))
	    {
	      fprintf(stderr,hpgs_i18n("Error: -w must be followed by a floating point number.\n"));
	      return usage();
	    }
	  
	  if (lw_factor < 0.0 || lw_factor > 10.0)
	    {
	      fprintf(stderr,hpgs_i18n("Error: Linewidth factor must lie in the interval [0.0,10.0].\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("--thin-alpha=",argv,&value,&narg))
	{
	  if (get_double_arg(value,&thin_alpha))
	    {
	      fprintf(stderr,hpgs_i18n("Error: --thin-alpha= must be followed by a floating point number.\n"));
	      return usage();
	    }
	  
	  if (thin_alpha < 0.01 || thin_alpha > 10.0)
	    {
	      fprintf(stderr,hpgs_i18n("Error: Thin alpha must lie in the interval [0.01,10.0].\n"));
	      return usage();
	    }
	}
      else if (hpgs_get_arg_value("-r",argv,&value,&narg))
	{
	  if (get_double_pair(value,&x_dpi,&y_dpi))
	    {
	      fprintf(stderr,hpgs_i18n("Error: -r must be followed by <res> or <xres>x<yres>.\n"));
	      return usage();
            }

          if (x_dpi < 5.0 || y_dpi < 5.0)
            {
              fprintf(stderr,hpgs_i18n("Error: Resolutions must be at least 5 dpi.\n"));
              return usage();
            }
	}
      else if (hpgs_get_arg_value("-p",argv,&value,&narg))
	{
	  if (get_int_pair(value,&x_px_size,&y_px_size))
	    {
	      fprintf(stderr,hpgs_i18n("Error: -p must be followed by <sz> or <xsz>x<ysz>.\n"));
	      return usage();
            }

          if (y_px_size < 20 ||  x_px_size < 20)
            {
              fprintf(stderr,hpgs_i18n("Error: Pixel sizes must be at least 20px.\n"));
              return usage();
            }
	}
      else if (hpgs_get_arg_value("-s",argv,&value,&narg))
	{
          double x_size,y_size;

          if (hpgs_parse_papersize(value,&x_size, &y_size)<0)
            {
	      fprintf(stderr,hpgs_i18n("Error: -s must be followed by a valid paper size.\n"));
	      return usage();
            }

          if (x_size < 72.0 || y_size < 72.0)
            {
              fprintf(stderr,hpgs_i18n("Error: The plot size must be at least 72 pt.\n"));
              return usage();
            }

          bbox.urx = bbox.llx + x_size;
          bbox.ury = bbox.lly + y_size;
	}
      else if (hpgs_get_arg_value("--origin=",argv,&value,&narg))
	{
          double xo,yo;

          if (hpgs_parse_papersize(value,&xo, &yo)<0)
            {
	      fprintf(stderr,hpgs_i18n("Error: --origin= must be followed by a valid pair of length specification.\n"));
	      return usage();
            }

          

          bbox.urx = (bbox.urx - bbox.llx) + xo;
          bbox.ury = (bbox.ury - bbox.lly) + yo;
          bbox.llx = xo;
          bbox.lly = yo;
	}
      else if (hpgs_get_arg_value("--paper=",argv,&value,&narg))
	{
          if (hpgs_parse_papersize(value,&paper_width,&paper_height)<0)
            {
	      fprintf(stderr,hpgs_i18n("Error: --paper= must be followed by a valid paper size.\n"));
	      return usage();
            }

          if (paper_width < 72.0 || paper_height < 72.0)
            {
              fprintf(stderr,hpgs_i18n("Error: The paper size must be at least 72 pt.\n"));
              return usage();
            }
	}
      else if (hpgs_get_arg_value("--border=",argv,&value,&narg) ||
               // Allow old device-specific border parameters.
               get_dev_arg_value(dev_name,dev_name_len,"-border=",argv,&value,&narg)     )
	{
          if (hpgs_parse_length(value,&paper_border)<0)
            {
	      fprintf(stderr,hpgs_i18n("Error: --border= must be followed by a valid length.\n"));
	      return usage();
            }

          if (paper_border < 0.0 || paper_border > 144.0)
            {
              fprintf(stderr,hpgs_i18n("Error: The page border must lie in the interval [0,144] pt.\n"));
              return usage();
            }
	}
      else if (hpgs_get_arg_value("--rotation=",argv,&value,&narg) ||
               // Allow old device-specific rotation parameters.
               get_dev_arg_value(dev_name,dev_name_len,"-rotation=",argv,&value,&narg)       )
	{
          if (hpgs_parse_length(value,&paper_angle)<0)
            {
	      fprintf(stderr,hpgs_i18n("Error: --angle= must be followed by a valid angle.\n"));
	      return usage();
            }
	}
      else if (strcmp(argv[0],"--linewidth-size") == 0)
	{
	  do_linewidth = HPGS_TRUE;
	}
      else if (strcmp(argv[0],"--no-linewidth-size") == 0)
  	{
	  do_linewidth = HPGS_FALSE;
	}
      else if (strcmp(argv[0],"--rop3") == 0)
	{
	  do_rop3 = HPGS_TRUE;
	}
      else if (strcmp(argv[0],"--no-rop3") == 0)
	{
	  do_rop3 = HPGS_FALSE;
	}
      else if (strcmp(argv[0],"--help") == 0)
	{
	  return help();
	}
      else if (strcmp(argv[0],"--version") == 0)
	{
	  usage();
	  return 0;
	}
      else if (strncmp(argv[0],"--",2) == 0 &&
               strncmp(argv[0]+2,dev_name,dev_name_len) == 0 &&
               argv[0][dev_name_len+2] == '-')
	{
          int l=strlen(argv[0]);

          if (plugin_argc >= HPGS_MAX_PLUGIN_ARGS-1)
	    {
	      fprintf(stderr,hpgs_i18n("Error: Number of plugin-args exceeds maximum of %d.\n"),
                      HPGS_MAX_PLUGIN_ARGS-1);
	      return usage();
	    }

          plugin_argv[plugin_argc] = argv[0]+dev_name_len+2;
          ++plugin_argc;

          if (argv[0][l-1] == '=')
            {
              if (plugin_argc >= HPGS_MAX_PLUGIN_ARGS-1)
                {
                  fprintf(stderr,hpgs_i18n("Error: Number of plugin-args exceed maximum of %d.\n"),
                          HPGS_MAX_PLUGIN_ARGS-1);
                  usage();
                }

              plugin_argv[plugin_argc] = argv[2];
              ++plugin_argc;

              narg=2;
            }
	}
      else
	{
	  if (argv[0][0] == '-')
	    {
	      fprintf(stderr,hpgs_i18n("Error: Unknown option %s given.\n"),argv[0]);
	      return usage();
	    }

          break;
	}

      argv+=narg;
      argc-=narg;
    }
  
  if (argc < 1)
    {
      fprintf(stderr,hpgs_i18n("Error: No input file given.\n"));
      return usage();
    }

  if (argc > 1 && !multipage)
    {
      multipage = HPGS_TRUE;
    }

  // adjust default linewidth factor.
  if (lw_factor < 0.0)
    {
      // This is the best choice for our basic, non-antialiased renderer,
      // which rounds up pixel line widths.
      if (antialias == 0 && strncmp(dev_name,"png_",4) == 0)
        lw_factor = 0.5;
      else
        lw_factor = 1.0;
    }

  size_dev = (hpgs_device*)hpgs_new_plotsize_device(ignore_ps,do_linewidth);

  if (!size_dev)
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot create plotsize device.\n"));
      goto cleanup;
    }

  in = hpgs_new_file_istream(argv[0]);

  if (!in)
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"),
	      argv[0],strerror(errno));
      hpgs_device_destroy((hpgs_device*)size_dev);
      goto cleanup;
    }

  reader = hpgs_new_reader(in,size_dev,
			   multipage,verbosity);

  if (!reader)
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot create hpgl reader: %s\n"),strerror(errno));
      goto cleanup;
    }
 
  hpgs_reader_set_lw_factor(reader,lw_factor);

  // determine plot size, if not specified on the cmd line
  if (bbox.urx-bbox.llx < 72.0 || bbox.ury-bbox.lly < 72.0)
    {
      // read in multiple pages.
      for (ifile = 1; ifile < argc; ++ifile)
        {
          if (hpgs_read(reader,HPGS_FALSE))
            {
              fprintf(stderr,hpgs_i18n("Error: Cannot determine plot size of file %s: %s\n"),
                      argv[ifile-1],hpgs_get_error());
              goto cleanup;
            }

          in = hpgs_new_file_istream(argv[ifile]);

          if (!in)
            {
              fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"),
                      argv[ifile],strerror(errno));
              goto cleanup;
            }

          hpgs_reader_attach(reader,in);
        }
      
      if (hpgs_read(reader,HPGS_TRUE))
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot determine plot size of file %s: %s\n"),
		  argv[ifile-1],hpgs_get_error());
	  goto cleanup;
	}

      // get bounding box of first page.
      // (will return overall boundingbox, if in singlepage mode.)
      if (hpgs_getplotsize(size_dev,1,&bbox)<0)
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot determine plotsize: %s\n"),
		  hpgs_get_error());
	  goto cleanup;
	}

      if (hpgs_bbox_isempty(&bbox))
	{
	  fprintf(stderr,hpgs_i18n("Error: Empty bounding:  %g %g %g %g.\n"),
		  bbox.llx,bbox.lly,bbox.urx,bbox.ury);
	  goto cleanup;
	}

      if (verbosity >= 1)
	fprintf(stderr,"BoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury);
    }

  // set the appropriate page placement.
  if (paper_width > 0.0 && paper_height > 0.0)
    {
      hpgs_reader_set_fixed_page(reader,&bbox,
                                 paper_width,paper_height,
                                 paper_border,paper_angle );
    }
  else
    {
      paper_width = 200.0 * 72.0;
      paper_height = 200.0 * 72.0;

      hpgs_reader_set_dynamic_page(reader,&bbox,
                                   paper_width,paper_height,
                                   paper_border,paper_angle );
    }

  if (strcmp(dev_name,"bbox") == 0)
    {
      int i;
      FILE *out = out_fn ? fopen(out_fn,"wb") : stdout;

      if (!out)
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot open output file <%s>.\n"),out_fn);
	  goto cleanup;
	}

      for (i=0;i<10000;++i)
        {
          int r = hpgs_getplotsize(size_dev,i,&bbox);

          if (r < 0)
            {
              fprintf(stderr,hpgs_i18n("Error: Cannot determine plotsize: %s\n"),
                      hpgs_get_error());
              fclose(out);
              goto cleanup;
            }

          if (r) break;

          if (i>0)
            {
              fprintf(out,"%%%%Page: %d %d.\n",i,i);
              fprintf(out,"%%%%PageBoundingBox: %d %d %d %d.\n",
                      (int)floor(bbox.llx),(int)floor(bbox.lly),
                      (int)ceil(bbox.urx),(int)ceil(bbox.ury));
              fprintf(out,"%%%%PageHiResBoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury);
            }
          else
            {
              fprintf(out,"%%%%BoundingBox: %d %d %d %d.\n",
                      (int)floor(bbox.llx),(int)floor(bbox.lly),
                      (int)ceil(bbox.urx),(int)ceil(bbox.ury));
              fprintf(out,"%%%%HiResBoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury);
            }
        }

      if (out != stdout) fclose(out);

      ret=0;
      goto cleanup;
    }
  else if (strcmp(dev_name,"eps") == 0)
    {
      plot_dev =
	(hpgs_device*)hpgs_new_eps_device(out_fn,&bbox,do_rop3);

      if (!plot_dev)
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot create eps device.\n"));
	  goto cleanup;
	}
    }
  else if (strcmp(dev_name,"ps") == 0)
    {
      plot_dev =
	(hpgs_device*)hpgs_new_ps_device(out_fn,&bbox,do_rop3);

      if (!plot_dev)
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot create postscript device.\n"));
	  goto cleanup;
	}
    }
  else if (strncmp(dev_name,"png_",4) == 0)
    {
      int depth = 8;
      int palette = 0;
      hpgs_paint_device *pdv;

      if (strcmp(dev_name+4,"gray") == 0)
	depth = 8;
      else if (strcmp(dev_name+4,"gray_alpha") == 0)
	depth = 16;
      else if (strcmp(dev_name+4,"rgb") == 0)
	depth = 24;
      else if (strcmp(dev_name+4,"rgb_alpha") == 0)
	depth = 32;
      else if (strcmp(dev_name+4,"256") == 0)
	palette = 1;
      else
	{
	  fprintf(stderr,hpgs_i18n("Error: png device %s in not supported.\n"),
		  dev_name);
	  goto cleanup;
	}

      if (x_px_size >= 20 && y_px_size >= 20)
	{
          // get overall bounding box, if pixel size is specified.
          // This way no page image exceeds the given size and
          // all images have the same resolution.
          hpgs_bbox bb;

          if (hpgs_getplotsize(size_dev,0,&bb)<0)
            {
              fprintf(stderr,hpgs_i18n("Error: Cannot determine overall plotsize: %s\n"),
                      hpgs_get_error());
              goto cleanup;
            }

	  x_dpi = 72.0 * x_px_size / (bb.urx-bb.llx);
	  y_dpi = 72.0 * y_px_size / (bb.ury-bb.lly);

	  if (x_dpi > y_dpi)
	    {
	      x_dpi = y_dpi;
	      x_px_size = x_dpi * (bb.urx-bb.llx) / 72.0;
	    }
	  else
	    {
	      y_dpi = x_dpi;
	      y_px_size = y_dpi * (bb.ury-bb.lly) / 72.0;
	    }
	}
      else
	{
          // initialize the pixel size from the first page.
	  x_px_size = x_dpi * (bbox.urx-bbox.llx) / 72.0;
	  y_px_size = y_dpi * (bbox.ury-bbox.lly) / 72.0;
	}

      image = hpgs_new_png_image(x_px_size,y_px_size,depth,palette,do_rop3);
	
      if (!image)
	{
	  fprintf(stderr,hpgs_i18n("Error creating %dx%dx%d sized png image: %s.\n"),
		  x_px_size,y_px_size,depth,strerror(errno));
	  goto cleanup;
	}

      hpgs_png_image_set_compression(image,compression);

      pdv = hpgs_new_paint_device((hpgs_image*)image,
                                  out_fn,&bbox,
                                  antialias);
      if (!pdv)
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot create paint device.\n"));
	  goto cleanup;
	}

      hpgs_paint_device_set_image_interpolation(pdv,image_interpolation);
      hpgs_paint_device_set_thin_alpha(pdv,thin_alpha);
      // set the resolution of the image, although
      // hpgs_new_paint_device has done this before.
      // The reason is, that we know the resolution with more precision
      // than hpgs_new_paint_device.
      hpgs_image_set_resolution((hpgs_image*)image,x_dpi,y_dpi);

      plot_dev = (hpgs_device *)pdv;
    }
  else
    {
      if (x_px_size >= 20 && y_px_size >= 20)
	{
          // calculate resolution from overall bounding box,
          // if pixel size is specified.
          // This way no page image exceeds the given size and
          // all images have the same resolution.
          hpgs_bbox bb;

          if (hpgs_getplotsize(size_dev,0,&bb)<0)
            {
              fprintf(stderr,hpgs_i18n("Error: Cannot determine overall plotsize: %s\n"),
                      hpgs_get_error());
              goto cleanup;
            }

	  x_dpi = 72.0 * x_px_size / (bb.urx-bb.llx);
	  y_dpi = 72.0 * y_px_size / (bb.ury-bb.lly);

	  if (x_dpi > y_dpi)
	    x_dpi = y_dpi;
	  else
	    y_dpi = x_dpi;
	}

      void *page_asset_ctxt = 0;
      hpgs_reader_asset_func_t page_asset_func = 0;
      void *frame_asset_ctxt = 0;
      hpgs_reader_asset_func_t frame_asset_func = 0;

      if (hpgs_new_plugin_device(&plot_dev,
                                 &page_asset_ctxt,
                                 &page_asset_func,
                                 &frame_asset_ctxt,
                                 &frame_asset_func,
                                 dev_name,out_fn,&bbox,
                                 x_dpi,y_dpi,do_rop3,
                                 plugin_argc,plugin_argv))
	{
	  fprintf(stderr,hpgs_i18n("Error: Cannot create plugin device: %s\n"),
                  hpgs_get_error());
	  goto cleanup;
	}

      if (page_asset_func)
        hpgs_reader_set_page_asset_func(reader,page_asset_ctxt,page_asset_func);

      if (frame_asset_func)
        hpgs_reader_set_frame_asset_func(reader,frame_asset_ctxt,frame_asset_func);
    }

  if (!plot_dev)
    {
      fprintf (stderr,hpgs_i18n("Error: invalid plot device name %s specified.\n"),dev_name);
      goto cleanup;
    }

  if (png_dump_fn && hpgs_reader_set_png_dump(reader,png_dump_fn))
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot set png_dump filename to reader: %s\n"),
	      hpgs_get_error());
      goto cleanup;
    }

  if (stamp && hpgs_device_stamp(plot_dev,&bbox,stamp,stamp_enc,stamp_size))
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot stamp plot: %s\n"),
	      hpgs_get_error());
      goto cleanup;
    }

  if (hpgs_reader_imbue(reader,plot_dev))
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot imbue plot device to reader: %s\n"),
	      hpgs_get_error());
      goto cleanup;
    }

  // re-open first file, if we have more than one input file.
  if (argc > 1)
    {
      in = hpgs_new_file_istream(argv[0]);

      if (!in)
        {
          fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"),
                  argv[0],strerror(errno));
          goto cleanup;
        }
      hpgs_reader_attach(reader,in);
    }

  // read in multiple pages.
  for (ifile = 1; ifile < argc; ++ifile)
    {
      if (hpgs_read(reader,HPGS_FALSE))
        {
          fprintf(stderr,hpgs_i18n("Error: Cannot process plot file %s: %s\n"),
                  argv[ifile-1],hpgs_get_error());
          goto cleanup;
        }
      
      in = hpgs_new_file_istream(argv[ifile]);

      if (!in)
        {
          fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"),
                  argv[ifile],strerror(errno));
          goto cleanup;
        }
      
      hpgs_reader_attach(reader,in);
    }

  if (hpgs_read(reader,HPGS_TRUE))
    {
      fprintf(stderr,hpgs_i18n("Error: Cannot process plot file %s: %s\n"),
	      argv[ifile-1],hpgs_get_error());
      goto cleanup;
    }

  if (verbosity >= 2)
    fprintf(stderr,hpgs_i18n("Success.\n"));

  ret = 0;

 cleanup:
  if (reader)
    hpgs_destroy_reader(reader);

  hpgs_cleanup();

  return ret;
}
コード例 #3
0
ファイル: hpgsreader.c プロジェクト: AmirAbrams/haiku
/*!
   Contructs a HPGL reader on the heap using the given input device
   \c in and the given output vector drawing device \c dev.

   The argument \c multipage specifies, whether the reader processes more than
   one page.
   
   The argument \c v specifies the verbosity of the HPGL reader.
   A value of 0 forces the reader to not report anything to \c hpgs_log().
   Value of 1 or 2 give diagnostics output to \c hpgs_log() with increasing
   volume.
   
   You do not have to call neither \c hpgs_close on \c in nor
   \c hpgs_destroy on \c dev.

   In the case of an error, a null pointer is returned. This only happens,
   if the system is out of memory.
*/
hpgs_reader *hpgs_new_reader(hpgs_istream *in, hpgs_device *dev,
                             hpgs_bool multipage, int v)
{
  int i;
  hpgs_reader *ret = (hpgs_reader *)malloc(sizeof(hpgs_reader));

  if (!ret)
    {
      hpgs_istream_close(in);
      if (dev)
	hpgs_device_destroy(dev);
      return 0;
    }

  ret->in        = in;
  ret->device    = dev;
  ret->verbosity = v;
  ret->lw_factor = 1.0; 

  ret->plotsize_device = 0;
  ret->current_page = multipage ? 1 : -1;

  hpgs_matrix_set_identity(&ret->page_matrix);
  ret->page_scale = 1.0;

  ret->page_bbox.llx = 0.0;
  ret->page_bbox.lly = 0.0;

  ret->page_bbox.urx = 33600.0 * HP_TO_PT;
  ret->page_bbox.ury = 47520.0 * HP_TO_PT;

  ret->content_bbox = ret->page_bbox;
  ret->page_asset_ctxt = 0;
  ret->page_asset_func = 0;
  ret->frame_asset_ctxt = 0;
  ret->frame_asset_func = 0;

  ret->page_mode=0;

  ret->page_width  = 0.0;
  ret->page_height = 0.0;
  ret->page_angle  = 0.0;
  ret->page_border = 0.0;

  ret->pen_widths = NULL;
  ret->pen_colors = NULL;
  ret->poly_buffer = NULL;

  for (i=0;i<8;++i)
    ret->pcl_raster_data[i] = 0;

  ret->pcl_image=0;
  ret->png_dump_filename=0;
  ret->png_dump_count=0;
  ret->pcl_i_palette=-1;
  
  ret->interrupted = HPGS_FALSE;

  hpgs_reader_set_defaults (ret);

  return ret;
}