a_color.c 4.4 KB

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