1 /* This file is part of the GNU plotutils package. Copyright (C) 1995,
2 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
3
4 The GNU plotutils package is free software. You may redistribute it
5 and/or modify it under the terms of the GNU General Public License as
6 published by the Free Software foundation; either version 2, or (at your
7 option) any later version.
8
9 The GNU plotutils package is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with the GNU plotutils package; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17 Boston, MA 02110-1301, USA. */
18
19 /* We call these routines, which set the Illustrator pen and fill colors,
20 lazily i.e. only when needed (just before an object is written to the
21 output buffer). */
22
23 #include "sys-defines.h"
24 #include "extern.h"
25
26 void
_pl_a_set_pen_color(S___ (Plotter * _plotter))27 _pl_a_set_pen_color(S___(Plotter *_plotter))
28 {
29 double red, green, blue;
30 double cyan, magenta, yellow, black, temp;
31
32 /* convert from RGB to CMYK */
33 red = ((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
34 green = ((double)((_plotter->drawstate->fgcolor).green))/0xFFFF;
35 blue = ((double)((_plotter->drawstate->fgcolor).blue))/0xFFFF;
36 cyan = 1.0 - red;
37 magenta = 1.0 - green;
38 yellow = 1.0 - blue;
39 temp = magenta < yellow ? magenta : yellow;
40 black = cyan < temp ? cyan : temp;
41 cyan -= black;
42 magenta -= black;
43 yellow -= black;
44
45 if ((_plotter->ai_pen_cyan != cyan)
46 || (_plotter->ai_pen_magenta != magenta)
47 || (_plotter->ai_pen_yellow != yellow)
48 || (_plotter->ai_pen_black != black))
49 /* need to change pen CMYK */
50 {
51 sprintf (_plotter->data->page->point, "%.4f %.4f %.4f %.4f K\n",
52 cyan, magenta, yellow, black);
53 _update_buffer (_plotter->data->page);
54 _plotter->ai_pen_cyan = cyan;
55 _plotter->ai_pen_magenta = magenta;
56 _plotter->ai_pen_yellow = yellow;
57 _plotter->ai_pen_black = black;
58 }
59
60 /* keep track of which colors AI uses */
61 if (_plotter->ai_pen_cyan > 0.0)
62 _plotter->ai_cyan_used = true;
63 if (_plotter->ai_pen_magenta > 0.0)
64 _plotter->ai_magenta_used = true;
65 if (_plotter->ai_pen_yellow > 0.0)
66 _plotter->ai_yellow_used = true;
67 if (_plotter->ai_pen_black > 0.0)
68 _plotter->ai_black_used = true;
69 }
70
71 void
_pl_a_set_fill_color(R___ (Plotter * _plotter)bool force_pen_color)72 _pl_a_set_fill_color(R___(Plotter *_plotter) bool force_pen_color)
73 {
74 double red, green, blue;
75 double cyan, magenta, yellow, black, temp;
76
77 if (force_pen_color == false && _plotter->drawstate->fill_type == 0)
78 /* won't be doing filling, so punt */
79 return;
80
81 /* get color; if force_pen_color is set, get pen color instead
82 of fill color */
83 if (force_pen_color)
84 {
85 red = ((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
86 green = ((double)((_plotter->drawstate->fgcolor).green))/0xFFFF;
87 blue = ((double)((_plotter->drawstate->fgcolor).blue))/0xFFFF;
88 }
89 else
90 {
91 red = ((double)((_plotter->drawstate->fillcolor).red))/0xFFFF;
92 green = ((double)((_plotter->drawstate->fillcolor).green))/0xFFFF;
93 blue = ((double)((_plotter->drawstate->fillcolor).blue))/0xFFFF;
94 }
95
96 /* convert from RGB to CMYK */
97 cyan = 1.0 - red;
98 magenta = 1.0 - green;
99 yellow = 1.0 - blue;
100 temp = magenta < yellow ? magenta : yellow;
101 black = cyan < temp ? cyan : temp;
102 cyan -= black;
103 magenta -= black;
104 yellow -= black;
105
106 if ((_plotter->ai_fill_cyan != cyan)
107 || (_plotter->ai_fill_magenta != magenta)
108 || (_plotter->ai_fill_yellow != yellow)
109 || (_plotter->ai_fill_black != black))
110 /* need to change AI fill CMYK */
111 {
112 sprintf (_plotter->data->page->point, "%.4f %.4f %.4f %.4f k\n",
113 cyan, magenta, yellow, black);
114 _update_buffer (_plotter->data->page);
115 _plotter->ai_fill_cyan = cyan;
116 _plotter->ai_fill_magenta = magenta;
117 _plotter->ai_fill_yellow = yellow;
118 _plotter->ai_fill_black = black;
119 }
120
121 /* keep track of which colors AI uses */
122 if (_plotter->ai_fill_cyan > 0.0)
123 _plotter->ai_cyan_used = true;
124 if (_plotter->ai_fill_magenta > 0.0)
125 _plotter->ai_magenta_used = true;
126 if (_plotter->ai_fill_yellow > 0.0)
127 _plotter->ai_yellow_used = true;
128 if (_plotter->ai_fill_black > 0.0)
129 _plotter->ai_black_used = true;
130 }
131