g_pentype.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* This file contains the pentype method, which is a GNU extension to
  16. libplot. It sets a drawing attribute: whether or not a pen should be
  17. used. (Objects drawn without a pen may still be filled.) */
  18. /* This file also contains the filltype method, which is a GNU extension to
  19. libplot. It sets a drawing attribute: the desaturation level of the
  20. filling, for all objects created by the drawing operations that follow.
  21. (For those that can be filled, that is; text cannot be filled.)
  22. The argument to filltype ranges from 0 to 0xFFFF. The value 0 is
  23. special; it signifies no filling at all (the object will be
  24. transparent). The value 1 signifies that the fill color should be the
  25. user-specified fill color, and a value of 0xFFFF signifies complete
  26. desaturation of this color (i.e., white). Values intermediate between 1
  27. and 0xFFFF yield intermediate saturations of the user-specified fill
  28. color. An out-of-bounds argument resets the desaturation level to a
  29. default value. */
  30. #include "sys-defines.h"
  31. #include "extern.h"
  32. int
  33. _API_pentype (R___(Plotter *_plotter) int level)
  34. {
  35. if (!_plotter->data->open)
  36. {
  37. _plotter->error (R___(_plotter)
  38. "pentype: invalid operation");
  39. return -1;
  40. }
  41. _API_endpath (S___(_plotter)); /* flush path if any */
  42. if ((level < 0) || (level > 0xffff))
  43. /* OOB switches to default */
  44. level = _default_drawstate.pen_type;
  45. _plotter->drawstate->pen_type = level;
  46. return 0;
  47. }
  48. int
  49. _API_filltype (R___(Plotter *_plotter) int level)
  50. {
  51. int red, green, blue;
  52. double red_d, green_d, blue_d;
  53. double desaturate;
  54. plColor new_rgb;
  55. if (!_plotter->data->open)
  56. {
  57. _plotter->error (R___(_plotter)
  58. "filltype: invalid operation");
  59. return -1;
  60. }
  61. _API_endpath (S___(_plotter)); /* flush path if any */
  62. if ((level < 0) || (level > 0xffff))
  63. /* OOB switches to default */
  64. level = _default_drawstate.fill_type;
  65. _plotter->drawstate->fill_type = level;
  66. if (level == 0)
  67. /* won't be doing filling, so stop right here */
  68. return 0;
  69. /* update fillcolor, taking fill type into account */
  70. /* start with base fillcolor */
  71. red = _plotter->drawstate->fillcolor_base.red;
  72. green = _plotter->drawstate->fillcolor_base.green;
  73. blue = _plotter->drawstate->fillcolor_base.blue;
  74. /* scale each RGB from a 16-bit quantity to range [0.0,1.0] */
  75. red_d = ((double)red)/0xFFFF;
  76. green_d = ((double)green)/0xFFFF;
  77. blue_d = ((double)blue)/0xFFFF;
  78. /* fill_type, if nonzero, specifies the extent to which the nominal fill
  79. color should be desaturated. 1 means no desaturation, 0xffff means
  80. complete desaturation (white). */
  81. desaturate = ((double)_plotter->drawstate->fill_type - 1.)/0xFFFE;
  82. red_d = red_d + desaturate * (1.0 - red_d);
  83. green_d = green_d + desaturate * (1.0 - green_d);
  84. blue_d = blue_d + desaturate * (1.0 - blue_d);
  85. /* restore each RGB to a 16-bit quantity (48 bits in all) */
  86. new_rgb.red = IROUND(0xFFFF * red_d);
  87. new_rgb.green = IROUND(0xFFFF * green_d);
  88. new_rgb.blue = IROUND(0xFFFF * blue_d);
  89. /* store actual fill color in drawing state */
  90. _plotter->drawstate->fillcolor = new_rgb;
  91. return 0;
  92. }