gscolor3.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gscolor3.c,v 1.9 2004/09/15 07:59:18 igor Exp $ */
  14. /* "Operators" for LanguageLevel 3 color facilities */
  15. #include "gx.h"
  16. #include "gserrors.h"
  17. #include "gsmatrix.h" /* for gscolor2.h */
  18. #include "gscolor3.h"
  19. #include "gsptype2.h"
  20. #include "gxcolor2.h" /* for gxpcolor.h */
  21. #include "gxcspace.h" /* for gs_cspace_init */
  22. #include "gxdcolor.h" /* for gxpcolor.h */
  23. #include "gxpcolor.h" /* for gs_color_space_type_Pattern */
  24. #include "gzstate.h"
  25. #include "gzpath.h"
  26. #include "gxpaint.h" /* (requires gx_path) */
  27. #include "gxshade.h"
  28. /* setsmoothness */
  29. int
  30. gs_setsmoothness(gs_state * pgs, floatp smoothness)
  31. {
  32. pgs->smoothness =
  33. (smoothness < 0 ? 0 : smoothness > 1 ? 1 : smoothness);
  34. return 0;
  35. }
  36. /* currentsmoothness */
  37. float
  38. gs_currentsmoothness(const gs_state * pgs)
  39. {
  40. return pgs->smoothness;
  41. }
  42. /* shfill */
  43. int
  44. gs_shfill(gs_state * pgs, const gs_shading_t * psh)
  45. {
  46. /*
  47. * shfill is equivalent to filling the current clipping path (or, if
  48. * clipping, its bounding box) with the shading, disregarding the
  49. * Background if any. In order to produce reasonable high-level output,
  50. * we must actually implement this by calling gs_fill rather than
  51. * gs_shading_fill_path. However, filling with a shading pattern does
  52. * paint the Background, so if necessary, we construct a copy of the
  53. * shading with Background removed.
  54. */
  55. gs_pattern2_template_t pat;
  56. gx_path cpath;
  57. gs_matrix imat;
  58. gs_client_color cc;
  59. gs_color_space cs;
  60. gx_device_color devc;
  61. int code;
  62. gs_pattern2_init(&pat);
  63. pat.Shading = psh;
  64. gs_make_identity(&imat);
  65. code = gs_make_pattern(&cc, (gs_pattern_template_t *)&pat, &imat, pgs,
  66. pgs->memory);
  67. if (code < 0)
  68. return code;
  69. code = gs_pattern2_set_shfill(&cc);
  70. if (code < 0)
  71. return code;
  72. gs_cspace_init(&cs, &gs_color_space_type_Pattern, pgs->memory, false);
  73. cs.params.pattern.has_base_space = false;
  74. code = cs.type->remap_color(&cc, &cs, &devc, (gs_imager_state *)pgs,
  75. pgs->device, gs_color_select_texture);
  76. if (code >= 0) {
  77. gx_path_init_local(&cpath, pgs->memory);
  78. code = gx_cpath_to_path(pgs->clip_path, &cpath);
  79. if (code >= 0)
  80. code = gx_fill_path(&cpath, &devc, pgs, gx_rule_winding_number,
  81. fixed_0, fixed_0);
  82. gx_path_free(&cpath, "gs_shfill");
  83. }
  84. gs_pattern_reference(&cc, -1);
  85. return code;
  86. }