g_linewidth.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 linewidth method, which is a GNU extension to
  16. libplot. It sets a drawing attribute: the line width used in subsequent
  17. drawing operations, in user units.
  18. It also computes an estimate for the width of lines in device units.
  19. This quantity is used by display devices that do not support `sheared
  20. lines'. */
  21. #include "sys-defines.h"
  22. #include "extern.h"
  23. int
  24. _API_flinewidth(R___(Plotter *_plotter) double new_line_width)
  25. {
  26. double device_line_width, min_sing_val, max_sing_val;
  27. int quantized_device_line_width;
  28. if (!_plotter->data->open)
  29. {
  30. _plotter->error (R___(_plotter)
  31. "flinewidth: invalid operation");
  32. return -1;
  33. }
  34. _API_endpath (S___(_plotter)); /* flush path if any */
  35. if (new_line_width < 0.0) /* reset to default */
  36. {
  37. new_line_width = _plotter->drawstate->default_line_width;
  38. _plotter->drawstate->line_width_is_default = true;
  39. }
  40. else
  41. _plotter->drawstate->line_width_is_default = false;
  42. /* set the new linewidth in the drawing state */
  43. _plotter->drawstate->line_width = new_line_width;
  44. /* Also compute and set the device-frame line width, and a quantized
  45. (i.e. integer) version of same, which is used by most Plotters that
  46. use integer device coordinates. */
  47. _matrix_sing_vals (_plotter->drawstate->transform.m,
  48. &min_sing_val, &max_sing_val);
  49. device_line_width = min_sing_val * new_line_width;
  50. quantized_device_line_width = IROUND(device_line_width);
  51. /* Don't quantize the device-frame line width to 0 if user specified
  52. nonzero width. If it has a bitmap display (rendered with libxmi),
  53. quantizing to 0 might be regarded as OK, since libxmi treats 0-width
  54. lines as Bresenham lines rather than invisible. However, the Hershey
  55. fonts don't look good at small sizes if their line segments are
  56. rendered as Bresenham lines. */
  57. if (quantized_device_line_width == 0 && device_line_width > 0.0)
  58. quantized_device_line_width = 1;
  59. _plotter->drawstate->device_line_width = device_line_width;
  60. _plotter->drawstate->quantized_device_line_width
  61. = quantized_device_line_width;
  62. /* flag linewidth as having been invoked on this page (so that fsetmatrix
  63. will no longer automatically adjust the line width to a reasonable
  64. value) */
  65. _plotter->data->linewidth_invoked = true;
  66. return 0;
  67. }