File: a_color.c

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (123 lines) | stat: -rw-r--r-- 3,847 bytes parent folder | download | duplicates (3)
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
/* We call these routines, which set the Illustrator pen and fill colors,
   lazily i.e. only when needed (just before an object is written to the
   output buffer). */

#include "sys-defines.h"
#include "extern.h"

void
#ifdef _HAVE_PROTOS
_a_set_pen_color(S___(Plotter *_plotter))
#else
_a_set_pen_color(S___(_plotter))
     S___(Plotter *_plotter;)
#endif
{
  double red, green, blue;
  double cyan, magenta, yellow, black, temp;

  /* convert from RGB to CMYK */
  red = ((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
  green = ((double)((_plotter->drawstate->fgcolor).green))/0xFFFF;
  blue = ((double)((_plotter->drawstate->fgcolor).blue))/0xFFFF;
  cyan = 1.0 - red;
  magenta = 1.0 - green;
  yellow = 1.0 - blue;
  temp = magenta < yellow ? magenta : yellow;
  black = cyan < temp ? cyan : temp;
  cyan -= black;
  magenta -= black;
  yellow -= black;

  if ((_plotter->ai_pen_cyan != cyan)
      || (_plotter->ai_pen_magenta != magenta)
      || (_plotter->ai_pen_yellow != yellow)
      || (_plotter->ai_pen_black != black))
    /* need to change pen CMYK */
    {
      sprintf (_plotter->data->page->point, "%.4f %.4f %.4f %.4f K\n",
	       cyan, magenta, yellow, black);
      _update_buffer (_plotter->data->page);
      _plotter->ai_pen_cyan = cyan;
      _plotter->ai_pen_magenta = magenta;  
      _plotter->ai_pen_yellow = yellow;
      _plotter->ai_pen_black = black;
    }
  
  /* keep track of which colors AI uses */
  if (_plotter->ai_pen_cyan > 0.0)
    _plotter->ai_cyan_used = true;
  if (_plotter->ai_pen_magenta > 0.0)
    _plotter->ai_magenta_used = true;
  if (_plotter->ai_pen_yellow > 0.0)
    _plotter->ai_yellow_used = true;
  if (_plotter->ai_pen_black > 0.0)
    _plotter->ai_black_used = true;
}

void
#ifdef _HAVE_PROTOS
_a_set_fill_color(R___(Plotter *_plotter) bool force_pen_color)
#else
_a_set_fill_color(R___(_plotter) force_pen_color)
     S___(Plotter *_plotter;)
     bool force_pen_color;
#endif
{
  double red, green, blue;
  double cyan, magenta, yellow, black, temp;

  if (force_pen_color == false && _plotter->drawstate->fill_type == 0) 
    /* won't be doing filling, so punt */
    return;

  /* get color; if force_pen_color is set, get pen color instead
     of fill color */
  if (force_pen_color)
    {
      red = ((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
      green = ((double)((_plotter->drawstate->fgcolor).green))/0xFFFF;
      blue = ((double)((_plotter->drawstate->fgcolor).blue))/0xFFFF;
    }
  else
    {
      red = ((double)((_plotter->drawstate->fillcolor).red))/0xFFFF;
      green = ((double)((_plotter->drawstate->fillcolor).green))/0xFFFF;
      blue = ((double)((_plotter->drawstate->fillcolor).blue))/0xFFFF;
    }

  /* convert from RGB to CMYK */
  cyan = 1.0 - red;
  magenta = 1.0 - green;
  yellow = 1.0 - blue;
  temp = magenta < yellow ? magenta : yellow;
  black = cyan < temp ? cyan : temp;
  cyan -= black;
  magenta -= black;
  yellow -= black;

  if ((_plotter->ai_fill_cyan != cyan)
      || (_plotter->ai_fill_magenta != magenta)
      || (_plotter->ai_fill_yellow != yellow)
      || (_plotter->ai_fill_black != black))
    /* need to change AI fill CMYK */
    {
      sprintf (_plotter->data->page->point, "%.4f %.4f %.4f %.4f k\n",
	       cyan, magenta, yellow, black);
      _update_buffer (_plotter->data->page);
      _plotter->ai_fill_cyan = cyan;
      _plotter->ai_fill_magenta = magenta;  
      _plotter->ai_fill_yellow = yellow;
      _plotter->ai_fill_black = black;
    }
  
  /* keep track of which colors AI uses */
  if (_plotter->ai_fill_cyan > 0.0)
    _plotter->ai_cyan_used = true;
  if (_plotter->ai_fill_magenta > 0.0)
    _plotter->ai_magenta_used = true;
  if (_plotter->ai_fill_yellow > 0.0)
    _plotter->ai_yellow_used = true;
  if (_plotter->ai_fill_black > 0.0)
    _plotter->ai_black_used = true;
}