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
4 The GNU plotutils package is free software. You may redistribute it
5 and/or modify it under the terms of the GNU General Public License as
6 published by the Free Software foundation; either version 2, or (at your
7 option) any later version.
8
9 The GNU plotutils package is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with the GNU plotutils package; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17 Boston, MA 02110-1301, USA. */
18
19 /* This file contains the linewidth method, which is a GNU extension to
20 libplot. It sets a drawing attribute: the line width used in subsequent
21 drawing operations, in user units.
22
23 It also computes an estimate for the width of lines in device units.
24 This quantity is used by display devices that do not support `sheared
25 lines'. */
26
27 #include "sys-defines.h"
28 #include "extern.h"
29
30 int
_API_flinewidth(R___ (Plotter * _plotter)double new_line_width)31 _API_flinewidth(R___(Plotter *_plotter) double new_line_width)
32 {
33 double device_line_width, min_sing_val, max_sing_val;
34 int quantized_device_line_width;
35
36 if (!_plotter->data->open)
37 {
38 _plotter->error (R___(_plotter)
39 "flinewidth: invalid operation");
40 return -1;
41 }
42
43 _API_endpath (S___(_plotter)); /* flush path if any */
44
45 if (new_line_width < 0.0) /* reset to default */
46 {
47 new_line_width = _plotter->drawstate->default_line_width;
48 _plotter->drawstate->line_width_is_default = true;
49 }
50 else
51 _plotter->drawstate->line_width_is_default = false;
52
53 /* set the new linewidth in the drawing state */
54 _plotter->drawstate->line_width = new_line_width;
55
56 /* Also compute and set the device-frame line width, and a quantized
57 (i.e. integer) version of same, which is used by most Plotters that
58 use integer device coordinates. */
59
60 _matrix_sing_vals (_plotter->drawstate->transform.m,
61 &min_sing_val, &max_sing_val);
62 device_line_width = min_sing_val * new_line_width;
63 quantized_device_line_width = IROUND(device_line_width);
64
65 /* Don't quantize the device-frame line width to 0 if user specified
66 nonzero width. If it has a bitmap display (rendered with libxmi),
67 quantizing to 0 might be regarded as OK, since libxmi treats 0-width
68 lines as Bresenham lines rather than invisible. However, the Hershey
69 fonts don't look good at small sizes if their line segments are
70 rendered as Bresenham lines. */
71
72 if (quantized_device_line_width == 0 && device_line_width > 0.0)
73 quantized_device_line_width = 1;
74
75 _plotter->drawstate->device_line_width = device_line_width;
76 _plotter->drawstate->quantized_device_line_width
77 = quantized_device_line_width;
78
79 /* flag linewidth as having been invoked on this page (so that fsetmatrix
80 will no longer automatically adjust the line width to a reasonable
81 value) */
82 _plotter->data->linewidth_invoked = true;
83
84 return 0;
85 }
86