Пример #1
0
/* BP - Begin Plot 
*/
static int
hpgl_BP(hpgl_args_t *pargs, hpgl_state_t *pgls)
{	
    hpgl_args_t args;
    int32 command = 0;
    int32 value = 0;
    bool more = true;


    while (more) {
        more = hpgl_arg_int(pgls->memory, pargs, &command);
	if (!more) 
	    break;
	if (command == 1) {
	    /* parse string */ 
	    const byte *p = pargs->source.ptr;
	    const byte *rlimit = pargs->source.limit;	    
	    while ( p < rlimit ) {
		switch ( *++p ) {
		case ' ':
		    /* Ignore spaces between command and opening ". */
		    continue;	
		case '"':
		    if ( !pargs->phase ) {
			/* begin string */
			pargs->phase = 1;
			continue;
		    }
		    else /* end string */
			break;
		default:
		    if ( !pargs->phase ) 
			break; 			/* ill formed command exit */
		    else
			continue;               /* character inside of string */
		}
		break;  /* error or trailing " exits */
	    }
	    pargs->source.ptr = p;
	} 
	else {
	    more = hpgl_arg_int(pgls->memory, pargs, &value);
	    /* BP command value pair is currently ignored */
	}
    }

    hpgl_args_setup(&args);
    hpgl_IN(&args, pgls);
    return 0;
}
Пример #2
0
/*
 * NP [n];
 */
int
hpgl_NP(hpgl_args_t * pargs, hpgl_state_t * pgls)
{
    int32 n = 8;

    if (pgls->personality == pcl5e)
        return 0;

    /* output any current path */
    hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector));

    if (hpgl_arg_int(pgls->memory, pargs, &n) && ((n < 2) || (n > 32768)))
        return e_Range;
    return pcl_palette_NP(pgls, n);
}
Пример #3
0
/*
 * PC [pen[,primary1,primary2,primary3];
 */
static int
hpgl_PC(hpgl_args_t * pargs, hpgl_state_t * pgls)
{
    int32 pen;
    int32 npen = pcl_palette_get_num_entries(pgls->ppalet);

    if (pgls->personality == pcl5e)
        return 0;

    /* output any current path */
    hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector));

    if (hpgl_arg_int(pgls->memory, pargs, &pen)) {
        hpgl_real_t primary[3];

        if ((pen < 0) || (pen >= npen))
            return e_Range;

        if (hpgl_arg_c_real(pgls->memory, pargs, &primary[0])) {
            float comps[3];

            if (!hpgl_arg_c_real(pgls->memory, pargs, &primary[1]) ||
                !hpgl_arg_c_real(pgls->memory, pargs, &primary[2]))
                return e_Range;
            comps[0] = primary[0];
            comps[1] = primary[1];
            comps[2] = primary[2];
            return pcl_palette_set_color(pgls, pen, comps);
        } else
            return pcl_palette_set_default_color(pgls, pen);
    } else {
        int i;
        int code;

        for (i = 0; i < npen; ++i) {
            if ((code = pcl_palette_set_default_color(pgls, i)) < 0)
                return code;
        }
    }

    return 0;
}
Пример #4
0
/* IP; */
int
hpgl_IP(hpgl_args_t *pargs, hpgl_state_t *pgls)
{	int32 ptxy[4];
	int i;
	gs_int_rect win;

	/* draw the current path */
	hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector));
	/* get the default picture frame coordinates */
	hpgl_call(hpgl_picture_frame_coords(pgls, &win));

	/* round the picture frame coordinates */
	ptxy[0] = win.p.x; ptxy[1] = win.p.y;
	ptxy[2] = win.q.x; ptxy[3] = win.q.y;
	for ( i = 0; i < 4 && hpgl_arg_int(pgls->memory, pargs, &ptxy[i]); ++i )
	  ;
	if ( i & 1 )
	  return e_Range;

	if ( i == 2 )
	  {
	    pgls->g.P2.x = (ptxy[0] - pgls->g.P1.x) +
	      pgls->g.P2.x;
	    pgls->g.P2.y = (ptxy[1] - pgls->g.P1.y) +
	      pgls->g.P2.y;
	    pgls->g.P1.x = ptxy[0];
	    pgls->g.P1.y = ptxy[1];
	  }
	else
	  {
	    pgls->g.P1.x = ptxy[0];
	    pgls->g.P1.y = ptxy[1];
	    pgls->g.P2.x = ptxy[2];
	    pgls->g.P2.y = ptxy[3];
	  }

	/* if either coordinate is equal it is incremented by 1 */
	if ( pgls->g.P1.x == pgls->g.P2.x ) pgls->g.P2.x++;
	if ( pgls->g.P1.y == pgls->g.P2.y ) pgls->g.P2.y++;
	
	return 0;
}
Пример #5
0
/*
 * CF [mode[,pen]];
 */
int
hpgl_CF(hpgl_args_t * pargs, hpgl_state_t * pgls)
{
    int mode = 0;
    int npen = pcl_palette_get_num_entries(pgls->ppalet);
    int32 pen = 0;

    if (hpgl_arg_c_int(pgls->memory, pargs, &mode)) {
        if ((mode & ~3) != 0)
            return e_Range;
        /* With only 1 argument, we "unset" the current pen.  This
           causes the drawing machinery to use the current pen when
           the stroke is rendered (i.e. a subsequent SP will change
           the character edge pen */
        if (hpgl_arg_int(pgls->memory, pargs, &pen)) {
            if ((pen < 0) || (pen >= npen))
                return e_Range;
        } else
            pen = CHAR_EDGE_PEN_UNSET;
    }
    pgls->g.character.fill_mode = mode;
    pgls->g.character.edge_pen = pen;
    return 0;
}
Пример #6
0
/* Define font parameters (AD, SD). */
static int
hpgl_font_definition(hpgl_args_t * pargs, hpgl_state_t * pgls, int index)
{
    /*
     * Since these commands take an arbitrary number of arguments, we
     * reset the argument bookkeeping after each group.  We reset
     * phase to 1, 2, or 3 after seeing the first pair, so we can tell
     * whether there were any arguments at all.  (1 means no parameter
     * changed, >1 means some parameter changed.)
     */

    pcl_font_selection_t *pfs = &pgls->g.font_selection[index];
#define pfp (&pfs->params)
    int kind;

    pfs->selected_id = (uint) - 1;
    for (; hpgl_arg_c_int(pgls->memory, pargs, &kind); pargs->phase |= 1)
        switch (kind) {
            case 1:            /* symbol set */
                {
                    int32 sset;

                    if (!hpgl_arg_int(pgls->memory, pargs, &sset))
                        return e_Range;
                    if (pfp->symbol_set != (uint) sset)
                        pfp->symbol_set = (uint) sset, pargs->phase |= 2;
                }
                break;
            case 2:            /* spacing */
                {
                    int spacing;

                    if (!hpgl_arg_c_int(pgls->memory, pargs, &spacing))
                        return e_Range;
                    if (((spacing == 1) || (spacing == 0))
                        && (pfp->proportional_spacing != spacing))
                        pfp->proportional_spacing = spacing, pargs->phase |=
                            2;
                }
                break;
            case 3:            /* pitch */
                {
                    hpgl_real_t pitch;

                    if (!hpgl_arg_c_real(pgls->memory, pargs, &pitch))
                        return e_Range;
                    if ((pl_fp_pitch_per_inch(pfp) != pitch) &&
                        (pitch >= 0) && (pitch < 32768.0)) {
                        pl_fp_set_pitch_per_inch(pfp,
                                                 pitch >
                                                 7200.0 ? 7200.0 : pitch);
                        pargs->phase |= 2;
                    }

                }
                break;
            case 4:            /* height */
                {
                    hpgl_real_t height;

                    if (!hpgl_arg_c_real(pgls->memory, pargs, &height))
                        return e_Range;
                    if ((pfp->height_4ths != (uint) (height * 4))
                        && (height >= 0)) {
                        /* minimum height for practical purposes is one
                           quarter point.  The HP Spec says 0 is legal
                           but does not specify what a height of zero
                           means.  The previous code truncated height,
                           it probably should be rounded as in pcl but
                           doing so would change a lot of files for no
                           compelling reason so for now truncate. */
                        uint trunc_height_4ths = (uint) (height * 4);

                        pfp->height_4ths =
                            (trunc_height_4ths == 0 ? 1 : trunc_height_4ths);
                        pargs->phase |= 2;
                    }
                }
                break;
            case 5:            /* posture */
                {
                    int posture;

                    if (!hpgl_arg_c_int(pgls->memory, pargs, &posture))
                        return e_Range;
                    if (pfp->style != posture)
                        pfp->style = posture, pargs->phase |= 2;

                }
                break;
            case 6:            /* stroke weight */
                {
                    int weight;

                    if (!hpgl_arg_c_int(pgls->memory, pargs, &weight))
                        return e_Range;
                    if (pfp->stroke_weight != weight)
                        if (((weight >= -7) && (weight <= 7))
                            || (weight == 9999))
                            pfp->stroke_weight = weight, pargs->phase |= 2;
                }
                break;
            case 7:            /* typeface */
                {
                    int32 face;

                    if (!hpgl_arg_int(pgls->memory, pargs, &face))
                        return e_Range;
                    if (pfp->typeface_family != (uint) face)
                        pfp->typeface_family = (uint) face, pargs->phase |= 2;
                }
                break;
            default:
                return e_Range;
        }
    /* If there were no arguments at all, default all values. */
    if (!pargs->phase)
        hpgl_default_font_params(pfs);
    if (pargs->phase != 1) {    /* A value changed, or we are defaulting.  Decache the font. */
        pfs->font = 0;
        if (index == pgls->g.font_selected)
            pgls->g.font = 0;
    }
    return 0;
}