g_dash.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 linedash method, which is a GNU extension to
  16. libplot. It sets a drawing attribute: the dash array used for
  17. subsequent drawing of paths. */
  18. #include "sys-defines.h"
  19. #include "extern.h"
  20. int
  21. _API_flinedash (R___(Plotter *_plotter) int n, const double *dashes, double offset)
  22. {
  23. double *dash_array;
  24. int i;
  25. if (!_plotter->data->open)
  26. {
  27. _plotter->error (R___(_plotter)
  28. "flinedash: invalid operation");
  29. return -1;
  30. }
  31. if (_plotter->drawstate->path)
  32. _API_endpath (S___(_plotter)); /* flush path if any */
  33. /* sanity checks */
  34. if (n < 0 || (n > 0 && dashes == NULL))
  35. return -1;
  36. for (i = 0; i < n; i++)
  37. if (dashes[i] < 0.0)
  38. return -1;
  39. if (_plotter->drawstate->dash_array_len > 0)
  40. free ((double *)_plotter->drawstate->dash_array);
  41. if (n > 0)
  42. dash_array = (double *)_pl_xmalloc (n * sizeof(double));
  43. else
  44. dash_array = NULL;
  45. _plotter->drawstate->dash_array_len = n;
  46. for (i = 0; i < n; i++)
  47. dash_array[i] = dashes[i];
  48. _plotter->drawstate->dash_array = dash_array;
  49. _plotter->drawstate->dash_offset = offset;
  50. /* for future paths, use dash array rather than line mode */
  51. _plotter->drawstate->dash_array_in_effect = true;
  52. return 0;
  53. }