File: f_retrieve.c

package info (click to toggle)
plotutils 2.6-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 13,156 kB
  • ctags: 7,141
  • sloc: ansic: 68,670; sh: 20,082; cpp: 12,382; yacc: 2,588; makefile: 889; lex: 137
file content (106 lines) | stat: -rw-r--r-- 4,439 bytes parent folder | download | duplicates (7)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
   1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.

   The GNU plotutils package is free software.  You may redistribute it
   and/or modify it under the terms of the GNU General Public License as
   published by the Free Software foundation; either version 2, or (at your
   option) any later version.

   The GNU plotutils package is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with the GNU plotutils package; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
   Boston, MA 02110-1301, USA. */

/* This file contains the Plotter-specific _retrieve_font method, which is
   called by the _set_font() function, which in turn is invoked by the API
   functions alabel() and flabelwidth().  It is called when the font_name,
   font_size, and textangle fields of the current drawing state have been
   filled in.  It retrieves the specified font, and fills in the font_type,
   typeface_index, font_index, font_is_iso8858, true_font_size, and
   font_ascent, and font_descent fields of the drawing state. */

/* This version is for FigPlotters.  It also fills in the fig_point_size
   field of the drawing state. */

/* This Fig-specific version is needed because xfig supports arbitrary
   (non-integer) font sizes for PS fonts only on paper.  The current
   releases (3.1 and 3.2) of xfig round them to integers.  So we quantize
   the user-specified font size in such a way that the font size that xfig
   will see, and use, will be precisely an integer. */

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

bool
_pl_f_retrieve_font (S___(Plotter *_plotter))
{
  double theta;
  double dx, dy, device_dx, device_dy, device_vector_len;
  double pointsize, fig_pointsize, size, quantized_size;
  int int_fig_pointsize;
  double quantization_factor;

  /* sanity check */
  if (_plotter->drawstate->font_type != PL_F_POSTSCRIPT)
    return false;
  
  if (!_plotter->drawstate->transform.uniform 
      || !_plotter->drawstate->transform.nonreflection)
    /* anamorphically transformed PS font not supported, will use Hershey */
    return false;

  /* text rotation in radians */
  theta = _plotter->drawstate->text_rotation * M_PI / 180.0;

  /* unit vector along which we'll move when printing label */
  dx = cos (theta);
  dy = sin (theta);

  /* convert to device frame, and compute length in fig units */
  device_dx = XDV(dx, dy);
  device_dy = YDV(dx, dy);  
  device_vector_len = sqrt(device_dx * device_dx + device_dy * device_dy);

  /* compute xfig pointsize we should use when printing a string in a PS
     font, so as to match this vector length. */

  size = _plotter->drawstate->font_size; /* in user units */
  pointsize = FIG_UNITS_TO_POINTS(size * device_vector_len);

  /* FIG_FONT_SCALING = 80/72 is a silly undocumented factor that shouldn't
     exist, but does.  In xfig, a `point' is not 1/72 inch, but 1/80 inch!  */
  fig_pointsize = FIG_FONT_SCALING * pointsize;
  /* integer xfig pointsize (which really refers to ascent, not overall size)*/
  int_fig_pointsize = IROUND(fig_pointsize);

  /* Integer font size that xfig will see, in the .fig file.  If this is
     zero, we won't actually emit a text object to the .fig file, since
     xfig can't handle text strings with zero font size.  See f_text.c. */
  _plotter->drawstate->fig_font_point_size = int_fig_pointsize;
 
  /* what size in user units should have been, to make fig_font_point_size
     an integer */
  if (device_vector_len == 0.0)
    quantized_size = 0.0;	/* degenerate case */
  else
    quantized_size = 
      (POINTS_TO_FIG_UNITS((double)int_fig_pointsize / FIG_FONT_SCALING))
      / (device_vector_len);
  _plotter->drawstate->true_font_size = quantized_size;

  /* quantize other fields */
  if (size == 0.0)
    quantization_factor = 0.0;	/* degenerate case */
  else
    quantization_factor = quantized_size / size;
  _plotter->drawstate->font_ascent *= quantization_factor;
  _plotter->drawstate->font_descent *= quantization_factor;
  _plotter->drawstate->font_cap_height *= quantization_factor;

  return true;
}