File: hpgl-attr.c

package info (click to toggle)
cups 1.4.4-7+squeeze10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 25,548 kB
  • ctags: 9,583
  • sloc: ansic: 138,214; sh: 37,926; cpp: 25,469; makefile: 3,285; perl: 190; python: 127; php: 28
file content (479 lines) | stat: -rw-r--r-- 11,673 bytes parent folder | download | duplicates (2)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/*
 * "$Id: hpgl-attr.c 8123 2008-11-13 06:31:30Z mike $"
 *
 *   HP-GL/2 attribute processing for the Common UNIX Printing System (CUPS).
 *
 *   Copyright 2007-2008 by Apple Inc.
 *   Copyright 1993-2007 by Easy Software Products.
 *
 *   These coded instructions, statements, and computer programs are the
 *   property of Apple Inc. and are protected by Federal copyright
 *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
 *   which should have been included with this file.  If this file is
 *   file is missing or damaged, see the license at "http://www.cups.org/".
 *
 *   This file is subject to the Apple OS-Developed Software exception.
 *
 * Contents:
 *
 *   CR_color_range()     - Set the range for color values.
 *   AC_anchor_corner()   - Set the anchor corner.
 *   FT_fill_type()       - Set the fill type or pattern.
 *   LA_line_attributes() - Set the line drawing attributes.
 *   LT_line_type()       - Set the line type (style)...
 *   NP_number_pens()     - Set the number of pens to be used.
 *   PC_pen_color()       - Set the pen color...
 *   PW_pen_width()       - Set the pen width.
 *   RF_raster_fill()     - Set the raster fill pattern.
 *   SM_symbol_mode()     - Set where symbols are drawn.
 *   SP_select_pen()      - Select a pen for drawing.
 *   UL_user_line_type()  - Set a user-defined line type.
 *   WU_width_units()     - Set the units used for pen widths.
 */

/*
 * Include necessary headers...
 */

#include "hpgltops.h"


/*
 * 'CR_color_range()' - Set the range for color values.
 */

void
CR_color_range(int     num_params,	/* I - Number of parameters */
               param_t *params)		/* I - Parameters */
{
  if (num_params == 0)
  {
   /*
    * Default to 0 to 255 for all color values.
    */

    ColorRange[0][0] = 0.0;
    ColorRange[0][1] = 255.0;
    ColorRange[1][0] = 0.0;
    ColorRange[1][1] = 255.0;
    ColorRange[2][0] = 0.0;
    ColorRange[2][1] = 255.0;
  }
  else if (num_params == 6)
  {
   /*
    * Set the range based on the parameters...
    */

    ColorRange[0][0] = params[0].value.number;
    ColorRange[0][1] = params[1].value.number - params[0].value.number;
    ColorRange[1][0] = params[2].value.number;
    ColorRange[1][1] = params[3].value.number - params[2].value.number;
    ColorRange[2][0] = params[4].value.number;
    ColorRange[2][1] = params[5].value.number - params[4].value.number;
  }
  else
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'CR\' command with invalid number of "
	    "parameters (%d)!\n", num_params);
}


/*
 * 'AC_anchor_corner()' - Set the anchor corner.
 */

void
AC_anchor_corner(int     num_params,	/* I - Number of parameters */
                 param_t *params)	/* I - Parameters */
{
  (void)num_params;
  (void)params;
}


/*
 * 'FT_fill_type()' - Set the fill type or pattern.
 *
 * Note:
 *
 *   This needs to be updated to support non-solid fill.
 */

void
FT_fill_type(int     num_params,	/* I - Number of parameters */
             param_t *params)		/* I - Parameters */
{
  if (num_params == 0 ||
      params[0].value.number == 1 ||
      params[0].value.number == 2)
  {
    /**** SOLID PATTERN ****/
  }
}


/*
 * 'LA_line_attributes()' - Set the line drawing attributes.
 */

void
LA_line_attributes(int     num_params,	/* I - Number of parameters */
                   param_t *params)	/* I - Parameters */
{
  int	i;				/* Looping var */


  if (num_params == 0)
  {
    MiterLimit = 3.0f;
    LineCap    = 0;
    LineJoin   = 0;
  }
  else for (i = 0; i < (num_params - 1); i += 2)
    switch ((int)params[i].value.number)
    {
      case 1 :
          LineCap = params[i + 1].value.number == 1 ? 0 :
                    params[i + 1].value.number == 4 ? 1 : 2;
          break;
      case 2 :
          switch ((int)params[i + 1].value.number)
          {
            case 1 :
            case 2 :
            case 3 :
                LineJoin = 0;
                break;
            case 5 :
                LineJoin = 2;
                break;
            default :
                LineJoin = 1;
                break;
          }
          break;
      case 3 :
          MiterLimit = 1.0 + 0.5 * (params[i + 1].value.number - 1.0);
          break;
    }

  if (PageDirty)
  {
    printf("%.1f setmiterlimit\n", MiterLimit);
    printf("%d setlinecap\n", LineCap);
    printf("%d setlinejoin\n", LineJoin);
  }
}


/*
 * 'LT_line_type()' - Set the line type (style)...
 *
 * Note:
 *
 *   This needs to be updated to support line types.
 */

void
LT_line_type(int     num_params,	/* I - Number of parameters */
             param_t *params)		/* I - Parameters */
{
  (void)num_params;
  (void)params;
}


/*
 * 'NP_number_pens()' - Set the number of pens to be used.
 */

void
NP_number_pens(int     num_params,	/* I - Number of parameters */
               param_t *params)		/* I - Parameters */
{
  int	i;				/* Looping var */


  if (num_params == 0)
    PenCount = 8;
  else if (num_params == 1)
  {
    if (params[0].value.number < 1 || params[0].value.number > MAX_PENS)
    {
      fprintf(stderr,
	      "DEBUG: HP-GL/2 \'NP\' command with invalid number of "
	      "pens (%d)!\n", (int)params[0].value.number);
      PenCount = 8;
    }
    else
      PenCount = (int)params[0].value.number;
  }
  else
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'NP\' command with invalid number of "
	    "parameters (%d)!\n", num_params);

  for (i = 0; i < PenCount; i ++)
    Pens[i].width = PenWidth;

  PC_pen_color(0, NULL);
}


/*
 * 'PC_pen_color()' - Set the pen color...
 */

void
PC_pen_color(int     num_params,	/* I - Number of parameters */
             param_t *params)		/* I - Parameters */
{
  int		i;			/* Looping var */
  static float	standard_colors[8][3] =	/* Standard colors for first 8 pens */
		{
		  { 0.0, 0.0, 0.0 },	/* Black */
		  { 1.0, 0.0, 0.0 },	/* Red */
		  { 0.0, 1.0, 0.0 },	/* Green */
		  { 1.0, 1.0, 0.0 },	/* Yellow */
		  { 0.0, 0.0, 1.0 },	/* Blue */
		  { 1.0, 0.0, 1.0 },	/* Magenta */
		  { 0.0, 1.0, 1.0 },	/* Cyan */
		  { 1.0, 1.0, 1.0 }	/* White */
		};


  if (num_params == 0)
  {
    for (i = 0; i < PenCount; i ++)
      if (i < 8)
      {
        Pens[i].rgb[0] = standard_colors[i][0];
        Pens[i].rgb[1] = standard_colors[i][1];
        Pens[i].rgb[2] = standard_colors[i][2];
      }
      else
      {
        Pens[i].rgb[0] = 0.0f;
        Pens[i].rgb[1] = 0.0f;
        Pens[i].rgb[2] = 0.0f;
      }

    if (PageDirty)
      printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
	     Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
	     Pens[PenNumber].width * PenScaling);
  }
  else if (num_params == 1 || num_params == 4)
  {
    i = (int)params[0].value.number - 1;

    if (i < 0 || i >= PenCount)
    {
      fprintf(stderr,
              "DEBUG: HP-GL/2 \'PC\' command with invalid pen (%d)!\n", i + 1);
      return;
    }

    if (num_params == 1)
    {
      Pens[i].rgb[0] = standard_colors[i & 7][0];
      Pens[i].rgb[1] = standard_colors[i & 7][1];
      Pens[i].rgb[2] = standard_colors[i & 7][2];
    }
    else
    {
      Pens[i].rgb[0] = (params[1].value.number - ColorRange[0][0]) /
                       (ColorRange[0][1] - ColorRange[0][0]);
      Pens[i].rgb[1] = (params[2].value.number - ColorRange[1][0]) /
                       (ColorRange[1][1] - ColorRange[1][0]);
      Pens[i].rgb[2] = (params[3].value.number - ColorRange[2][0]) /
                       (ColorRange[2][1] - ColorRange[2][0]);

      fprintf(stderr, "DEBUG: Pen %d %.0f %.0f %.0f = %.3f %.3f %.3f\n",
	      i, params[1].value.number, params[2].value.number,
	      params[3].value.number, Pens[i].rgb[0], Pens[i].rgb[1],
	      Pens[i].rgb[2]);
    }

    if (PageDirty && i == PenNumber)
      printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
	     Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
	     Pens[PenNumber].width * PenScaling);
  }
  else
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'PC\' command with invalid number of "
	    "parameters (%d)!\n", num_params);
}


/*
 * 'PW_pen_width()' - Set the pen width.
 */

void
PW_pen_width(int     num_params,	/* I - Number of parameters */
             param_t *params)		/* I - Parameters */
{
  int	pen;				/* Pen number */
  float	w;				/* Width value */


  if (WidthUnits == 0)
  {
   /*
    * Metric...
    */

    if (num_params == 0)
      w = 0.35f / 25.4f * 72.0f;
    else
      w = params[0].value.number / 25.4f * 72.0f;
  }
  else
  {
   /*
    * Relative...
    */

    w = (float)hypot(PlotSize[0], PlotSize[1]) / 1016.0f * 72.0f;

    if (num_params == 0)
      w *= 0.01f;
    else
      w *= params[0].value.number;
  }

  if (num_params == 2)
  {
    pen = (int)params[1].value.number - 1;

    if (pen < 0 || pen >= PenCount)
    {
      fprintf(stderr,
              "DEBUG: HP-GL/2 \'PW\' command with invalid pen (%d)!\n",
	      pen + 1);
      return;
    }

    Pens[pen].width = w;

    if (PageDirty && pen == PenNumber)
      printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
	     Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
	     Pens[PenNumber].width * PenScaling);
  }
  else if (num_params < 2)
  {
   /*
    * Set width for all pens...
    */

    for (pen = 0; pen < PenCount; pen ++)
      Pens[pen].width = w;

    if (PageDirty)
      printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
	     Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
	     Pens[PenNumber].width * PenScaling);
  }
  else
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'PW\' command with invalid number of "
	    "parameters (%d)!\n", num_params);
}


/*
 * 'RF_raster_fill()' - Set the raster fill pattern.
 *
 * Note:
 *
 *   This needs to be implemented.
 */

void
RF_raster_fill(int     num_params,	/* I - Number of parameters */
               param_t *params)		/* I - Parameters */
{
  (void)num_params;
  (void)params;
}


/*
 * 'SM_symbol_mode()' - Set where symbols are drawn.
 */

void
SM_symbol_mode(int     num_params,	/* I - Number of parameters */
               param_t *params)		/* I - Parameters */
{
  (void)num_params;
  (void)params;
}


/*
 * 'SP_select_pen()' - Select a pen for drawing.
 */

void
SP_select_pen(int     num_params,	/* I - Number of parameters */
              param_t *params)		/* I - Parameters */
{
  if (num_params == 0)
    PenNumber = 0;
  else if (num_params > 1)
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'SP\' command with invalid number of parameters "
	    "(%d)!\n", num_params);
  else if (params[0].value.number <= 0 || params[0].value.number >= PenCount)
    fprintf(stderr, "DEBUG: HP-GL/2 \'SP\' command with invalid pen (%d)!\n",
	    (int)params[0].value.number);
  else
    PenNumber = (int)params[0].value.number - 1;

  if (PageDirty)
    printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
	   Pens[PenNumber].rgb[1], Pens[PenNumber].rgb[2],
	   Pens[PenNumber].width * PenScaling);
}


/*
 * 'UL_user_line_type()' - Set a user-defined line type.
 */

void
UL_user_line_type(int     num_params,	/* I - Number of parameters */
                  param_t *params)	/* I - Parameters */
{
  (void)num_params;
  (void)params;
}


/*
 * 'WU_width_units()' - Set the units used for pen widths.
 */

void
WU_width_units(int     num_params,	/* I - Number of parameters */
               param_t *params)		/* I - Parameters */
{
  if (num_params == 0)
    WidthUnits = 0;
  else if (num_params == 1)
    WidthUnits = (int)params[0].value.number;
  else
    fprintf(stderr,
            "DEBUG: HP-GL/2 \'WU\' command with invalid number of "
	    "parameters (%d)!\n", num_params);
}


/*
 * End of "$Id: hpgl-attr.c 8123 2008-11-13 06:31:30Z mike $".
 */