summaryrefslogtreecommitdiff
path: root/pcl/pgcolor.c
blob: a8f32932a509f90c3b7021e6d3037f2c910cb3f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Portions Copyright (C) 2001 artofcode LLC.
   Portions Copyright (C) 1996, 2001 Artifex Software Inc.
   Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
   This software is based in part on the work of the Independent JPEG Group.
   All Rights Reserved.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/ or
   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
   San Rafael, CA  94903, (415)492-9861, for further information. */
/*$Id$ */

/* pgcolor.c - HP-GL/2 color vector graphics commands */

#include "std.h"
#include "pcparse.h"
#include "pgmand.h"
#include "pginit.h"
#include "pgmisc.h"
#include "pgdraw.h"
#include "gsstate.h"		/* for gs_setfilladjust */
#include "pcpalet.h"

/* ------ Commands ------ */

/*
 * PC [pen[,primary1,primary2,primary3];
 */
  private 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;
}

/*
 * 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);
}

/*
 * Initialization. There is no reset or copy command, as those operations are
 * carried out by the palette mechanism.
 */
  private int
pgcolor_do_registration(
    pcl_parser_state_t *pcl_parser_state,
    gs_memory_t *mem
)
{
    /* Register commands */
    DEFINE_HPGL_COMMANDS(mem)
    HPGL_COMMAND('N', 'P', hpgl_NP, hpgl_cdf_pcl_rtl_both),
    HPGL_COMMAND('P', 'C', hpgl_PC, hpgl_cdf_pcl_rtl_both),
    END_HPGL_COMMANDS
    return 0;
}

const pcl_init_t    pgcolor_init = { pgcolor_do_registration, 0, 0 };