Exemplo n.º 1
0
/*
  HPGL command LA (Line Attributes)
*/
int hpgs_reader_do_LA(hpgs_reader *reader)
{
  int    kind;
  int    ivalue;
  double rvalue;

  static hpgs_line_cap caps[5] =
    { hpgs_cap_butt,
      hpgs_cap_butt,
      hpgs_cap_square,
      hpgs_cap_round,
      hpgs_cap_round    };

  static hpgs_line_join joins[7] =
    { hpgs_join_miter,
      hpgs_join_miter,
      hpgs_join_miter,
      hpgs_join_miter,
      hpgs_join_round,
      hpgs_join_bevel,
      hpgs_join_miter };

  while (!reader->eoc)
    {
      if (hpgs_reader_read_int(reader,&kind)) return -1;
      if (reader->eoc) return -1;
      
      switch (kind)
	{
	case 3:
	  if (hpgs_reader_read_double(reader,&rvalue)) return -1;
	  if (hpgs_setmiterlimit(reader->device,rvalue)) return -1;
	  break;
	case 1:
	  if (hpgs_reader_read_int(reader,&ivalue)) return -1;
	  if (ivalue >= 0 && ivalue < 5 &&
	      hpgs_setlinecap(reader->device,caps[ivalue])) return -1;
	  break;
	case 2:
	  if (hpgs_reader_read_int(reader,&ivalue)) return -1;
	  if (ivalue >= 0 && ivalue < 7 &&
	      hpgs_setlinejoin(reader->device,joins[ivalue])) return -1;
	  break;
	default:
	  return -1;
	}
    }
  return 0;
}
Exemplo n.º 2
0
/* 
  HPGL command WU (Width Unit selection)
*/
int hpgs_reader_do_WU (hpgs_reader *reader)
{
  reader->pen_width_relative=0;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&reader->pen_width_relative)) return -1;
  return 0;
}
Exemplo n.º 3
0
/* 
  HPGL command SP (Set Pen)
*/
int hpgs_reader_do_SP (hpgs_reader *reader)
{
  int pen=0;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&pen)) return -1;

  return hpgs_reader_do_setpen(reader,pen);
}
Exemplo n.º 4
0
/*
  HPGL command LT (Line Type)
*/
int hpgs_reader_do_LT(hpgs_reader *reader)
{
  float dashes[20];
  int i,ndash;
  int linetype=0;
  double patlen = 4.0;
  int    mode = 0;

  if (hpgs_reader_checkpath(reader)) return -1;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&linetype)) return -1;

  if (!reader->eoc &&
      hpgs_reader_read_double(reader,&patlen)) return -1;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&mode)) return -1;

  if (linetype < -8 || linetype > 8)
    {
      if (reader->verbosity)
	hpgs_log(hpgs_i18n("LT: Illegal linetype %d.\n"),linetype);
      return 0;
    }

  // line type are store as percentages.
  patlen *= 0.01;

  if (mode)
    patlen *= MM_TO_PT;
  else
    patlen *= hypot(reader->P2.x-reader->P1.x,
		    reader->P2.y-reader->P1.y ) * 0.01 * HP_TO_PT;

  ndash = reader->linetype_nsegs[linetype+8];
  if (ndash > 20) ndash = 20;

  for (i=0;i<ndash;++i)
    dashes[i] = reader->linetype_segs[linetype+8][i] * patlen;
  
  return hpgs_setdash(reader->device,
		      dashes,ndash,0.0);
}
Exemplo n.º 5
0
/* 
  HPGL command NP (Number of Pens)
*/
int hpgs_reader_do_NP (hpgs_reader *reader)
{
  int npens=8;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&npens)) return -1;

  if (npens <= reader->npens) return 0;

  return hpgs_reader_set_number_of_pens(reader,npens);
}
Exemplo n.º 6
0
/* 
  HPGL command SC (SCale)
*/
int hpgs_reader_do_SC (hpgs_reader *reader)
{
  double xmin,xmax,ymin,ymax,left=50.0,bottom=50.0;
  int type=0;

  if (reader->eoc)
    {
      reader->sc_type = -1;
      hpgs_reader_set_default_transformation(reader);
      return 0;
    }

  if (hpgs_reader_read_double(reader,&xmin)) return -1;
  if (reader->eoc) return -1;
  if (hpgs_reader_read_double(reader,&xmax)) return -1;
  if (reader->eoc) return -1;

  if (xmin == xmax)
    return hpgs_set_error(hpgs_i18n("Empty x range."));

  if (hpgs_reader_read_double(reader,&ymin)) return -1;
  if (reader->eoc) return -1;
  if (hpgs_reader_read_double(reader,&ymax)) return -1;

  if (ymin == ymax)
    return hpgs_set_error(hpgs_i18n("Empty y range."));

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&type)) return -1;

  if (type == 1 && !reader->eoc)
    {
      if (hpgs_reader_read_double(reader,&left)) return -1;
      if (reader->eoc) return -1;
      if (hpgs_reader_read_double(reader,&bottom)) return -1;
    }

  reader->sc_type = type;
  reader->sc_xmin = xmin;
  reader->sc_xmax = xmax;
  reader->sc_ymin = ymin;
  reader->sc_ymax = ymax;
  reader->sc_bottom = bottom;
  reader->sc_left = left;

  hpgs_reader_set_default_transformation(reader);
  return 0;
}
Exemplo n.º 7
0
/* 
  HPGL command RO (ROtate)
*/
int hpgs_reader_do_RO (hpgs_reader *reader)
{
  int rot=0;
  hpgs_point p1,p2;
  double dx,dy;

  if (!reader->eoc &&
      hpgs_reader_read_int(reader,&rot)) return -1;

  switch ((rot - reader->rotation) % 360)
    {
    case 90:
      p1.x = -reader->P1.y;
      p1.y =  reader->P1.x;
      p2.x = -reader->P2.y;
      p2.y =  reader->P2.x;
      break;
    case 180:
      p1.x = -reader->P1.x;
      p1.y = -reader->P1.y;
      p2.x = -reader->P2.x;
      p2.y = -reader->P2.y;
      break;
    case 270:
      p1.x =  reader->P1.y;
      p1.y = -reader->P1.x;
      p2.x =  reader->P2.y;
      p2.y = -reader->P2.x;
      break;
    default: /* 0,360 */
      p1.x = reader->P1.x;
      p1.y = reader->P1.y;
      p2.x = reader->P2.x;
      p2.y = reader->P2.y;
      break;
    }
  
  dx = p1.x < p2.x ? p1.x : p2.x;
  dy = p1.y < p2.y ? p1.y : p2.y;

#ifdef HPGS_DEBUG_XFORM
  hpgs_log("RO: rot_old,rot = %d,%d.\n",reader->rotation,rot);
  hpgs_log("RO: P1 = %g,%g.\n",reader->P1.x,reader->P1.y);
  hpgs_log("RO: P2 = %g,%g.\n",reader->P2.x,reader->P2.y);
#endif

  reader->P1.x = p1.x-dx;
  reader->P1.y = p1.y-dy;
  reader->P2.x = p2.x-dx;
  reader->P2.y = p2.y-dy;

#ifdef HPGS_DEBUG_XFORM
  hpgs_log("RO: P1 = %g,%g.\n",reader->P1.x,reader->P1.y);
  hpgs_log("RO: P2 = %g,%g.\n",reader->P2.x,reader->P2.y);
#endif

  reader->rotation = rot;

  hpgs_reader_set_default_transformation(reader);

  return 0;
}
Exemplo n.º 8
0
/* 
  HPGL command PW (Pen Width)
*/
int hpgs_reader_do_PW (hpgs_reader *reader)
{
  int pen=-1;
  double width=1.0;

  if (!reader->eoc)
    if (hpgs_reader_read_double(reader,&width)) return -1;
  if (!reader->eoc)
    {
      if (hpgs_reader_read_int(reader,&pen)) return -1;

      if (pen < 0 || pen >= reader->npens)
        {
          if (pen >= reader->npens && pen < 256)
            {
              if (hpgs_reader_set_number_of_pens(reader,pen+1))
                return -1;
            }
          else
            {
              if (reader->verbosity)
                hpgs_log(hpgs_i18n("PW: Illegal pen number %d.\n"),pen);
              
              return 0;
            }
        }
    }

  if (reader->verbosity >= 2)
    hpgs_log("PW: pen,width,rel = %d,%g,%d.\n",pen,width,reader->pen_width_relative);

  if (reader->pen_width_relative)
    width *= 10.0;
  else
    width *= MM_TO_PT;

  if (pen < 0)
    {
      int i;
      for (i=0;i<reader->npens;++i)
	reader->pen_widths[i] = width;
    }
  else
    reader->pen_widths[pen] = width;

  if (pen < 0 || pen == reader->current_pen)
    {
      if (hpgs_reader_checkpath(reader)) return -1;

      if (reader->pen_width_relative)
        width *= hypot(reader->P2.x-reader->P1.x,
                       reader->P2.y-reader->P1.y ) * 0.001 * HP_TO_PT;
      else
        width *= HP_TO_PT / reader->world_scale;

      width *= reader->page_scale;

      if (hpgs_setlinewidth(reader->device,width*reader->lw_factor))
	return -1;
    }

  return 0;
}
Exemplo n.º 9
0
/* 
  HPGL command PC (Pen Color)
*/
int hpgs_reader_do_PC (hpgs_reader *reader)
{
  int pen=-1;
  double r=-1.0e20,g=-1.0e20,b=-1.0e20;

  if (!reader->eoc && hpgs_reader_read_int(reader,&pen)) return -1;
  if (!reader->eoc && hpgs_reader_read_double(reader,&r)) return -1;
  if (!reader->eoc && hpgs_reader_read_double(reader,&g)) return -1;
  if (!reader->eoc && hpgs_reader_read_double(reader,&b)) return -1;

  if (pen >= reader->npens)
    {
      if (pen < 256)
        {
          if (hpgs_reader_set_number_of_pens(reader,pen+1))
            return -1;
        }
      else
        {
          if (reader->verbosity)
            hpgs_log(hpgs_i18n("PC: Illegal pen number %d.\n"),pen);

          return 0;
        }
    }

  if (pen < 0)
    {
      hpgs_reader_set_std_pen_colors(reader,0,reader->npens);
      pen = reader->current_pen;
    }
  else
    {
      if (r==-1.0e20 || g==-1.0e20 || b==-1.0e20)
        {
          hpgs_reader_set_std_pen_colors(reader,pen,1);
        }
      else
        {
          reader->pen_colors[pen].r =
            (r - reader->min_color.r) / (reader->max_color.r - reader->min_color.r);
          if (reader->pen_colors[pen].r < 0.0) reader->pen_colors[pen].r = 0.0;
          if (reader->pen_colors[pen].r > 1.0) reader->pen_colors[pen].r = 1.0;

          reader->pen_colors[pen].g =
            (g - reader->min_color.g) / (reader->max_color.g - reader->min_color.g);
          if (reader->pen_colors[pen].g < 0.0) reader->pen_colors[pen].g = 0.0;
          if (reader->pen_colors[pen].g > 1.0) reader->pen_colors[pen].g = 1.0;

          reader->pen_colors[pen].b =
            (b - reader->min_color.b) / (reader->max_color.b - reader->min_color.b);
          if (reader->pen_colors[pen].b < 0.0) reader->pen_colors[pen].b = 0.0;
          if (reader->pen_colors[pen].b > 1.0) reader->pen_colors[pen].b = 1.0;
        }
    }

  if (pen == reader->current_pen)
    if (hpgs_setrgbcolor(reader->device,
			 &reader->pen_colors[pen]))
      return -1;

  return 0;
}