File: g_linewidth.c

package info (click to toggle)
plotutils 2.4.1-11
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,676 kB
  • ctags: 6,967
  • sloc: ansic: 76,305; sh: 15,172; cpp: 12,403; yacc: 2,604; makefile: 888; lex: 144
file content (73 lines) | stat: -rw-r--r-- 2,518 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* This file contains the linewidth method, which is a GNU extension to
   libplot.  It sets a drawing attribute: the line width used in subsequent
   drawing operations, in user units.

   It also computes an estimate for the width of lines in device units.
   This quantity is used by display devices that do not support `sheared
   lines'. */

#include "sys-defines.h"
#include "extern.h"

int
#ifdef _HAVE_PROTOS
_API_flinewidth(R___(Plotter *_plotter) double new_line_width)
#else
_API_flinewidth(R___(_plotter) new_line_width)
     S___(Plotter *_plotter;)
     double new_line_width;
#endif
{
  double device_line_width, min_sing_val, max_sing_val;
  int quantized_device_line_width;

  if (!_plotter->data->open)
    {
      _plotter->error (R___(_plotter) 
		       "flinewidth: invalid operation");
      return -1;
    }

  _API_endpath (S___(_plotter)); /* flush path if any */

  if (new_line_width < 0.0)	/* reset to default */
    {
      new_line_width = _plotter->drawstate->default_line_width;
      _plotter->drawstate->line_width_is_default = true;
    }
  else
    _plotter->drawstate->line_width_is_default = false;
  
  /* set the new linewidth in the drawing state */
  _plotter->drawstate->line_width = new_line_width;
  
  /* Also compute and set the device-frame line width, and a quantized
     (i.e. integer) version of same, which is used by most Plotters that
     use integer device coordinates. */

  _matrix_sing_vals (_plotter->drawstate->transform.m, 
		     &min_sing_val, &max_sing_val);
  device_line_width = min_sing_val * new_line_width;
  quantized_device_line_width = IROUND(device_line_width);

  /* Don't quantize the device-frame line width to 0 if user specified
     nonzero width.  If it has a bitmap display (rendered with libxmi),
     quantizing to 0 might be regarded as OK, since libxmi treats 0-width
     lines as Bresenham lines rather than invisible.  However, the Hershey
     fonts don't look good at small sizes if their line segments are
     rendered as Bresenham lines.  */

  if (quantized_device_line_width == 0 && device_line_width > 0.0)
    quantized_device_line_width = 1;
  
  _plotter->drawstate->device_line_width = device_line_width;
  _plotter->drawstate->quantized_device_line_width 
    = quantized_device_line_width;

  /* flag linewidth as having been invoked on this page (so that fsetmatrix
     will no longer automatically adjust the line width to a reasonable
     value) */
  _plotter->data->linewidth_invoked = true;

  return 0;
}