f_retrieve.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 Plotter-specific _retrieve_font method, which is
  16. called by the _set_font() function, which in turn is invoked by the API
  17. functions alabel() and flabelwidth(). It is called when the font_name,
  18. font_size, and textangle fields of the current drawing state have been
  19. filled in. It retrieves the specified font, and fills in the font_type,
  20. typeface_index, font_index, font_is_iso8858, true_font_size, and
  21. font_ascent, and font_descent fields of the drawing state. */
  22. /* This version is for FigPlotters. It also fills in the fig_point_size
  23. field of the drawing state. */
  24. /* This Fig-specific version is needed because xfig supports arbitrary
  25. (non-integer) font sizes for PS fonts only on paper. The current
  26. releases (3.1 and 3.2) of xfig round them to integers. So we quantize
  27. the user-specified font size in such a way that the font size that xfig
  28. will see, and use, will be precisely an integer. */
  29. #include "sys-defines.h"
  30. #include "extern.h"
  31. bool
  32. _pl_f_retrieve_font (S___(Plotter *_plotter))
  33. {
  34. double theta;
  35. double dx, dy, device_dx, device_dy, device_vector_len;
  36. double pointsize, fig_pointsize, size, quantized_size;
  37. int int_fig_pointsize;
  38. double quantization_factor;
  39. /* sanity check */
  40. if (_plotter->drawstate->font_type != PL_F_POSTSCRIPT)
  41. return false;
  42. if (!_plotter->drawstate->transform.uniform
  43. || !_plotter->drawstate->transform.nonreflection)
  44. /* anamorphically transformed PS font not supported, will use Hershey */
  45. return false;
  46. /* text rotation in radians */
  47. theta = _plotter->drawstate->text_rotation * M_PI / 180.0;
  48. /* unit vector along which we'll move when printing label */
  49. dx = cos (theta);
  50. dy = sin (theta);
  51. /* convert to device frame, and compute length in fig units */
  52. device_dx = XDV(dx, dy);
  53. device_dy = YDV(dx, dy);
  54. device_vector_len = sqrt(device_dx * device_dx + device_dy * device_dy);
  55. /* compute xfig pointsize we should use when printing a string in a PS
  56. font, so as to match this vector length. */
  57. size = _plotter->drawstate->font_size; /* in user units */
  58. pointsize = FIG_UNITS_TO_POINTS(size * device_vector_len);
  59. /* FIG_FONT_SCALING = 80/72 is a silly undocumented factor that shouldn't
  60. exist, but does. In xfig, a `point' is not 1/72 inch, but 1/80 inch! */
  61. fig_pointsize = FIG_FONT_SCALING * pointsize;
  62. /* integer xfig pointsize (which really refers to ascent, not overall size)*/
  63. int_fig_pointsize = IROUND(fig_pointsize);
  64. /* Integer font size that xfig will see, in the .fig file. If this is
  65. zero, we won't actually emit a text object to the .fig file, since
  66. xfig can't handle text strings with zero font size. See f_text.c. */
  67. _plotter->drawstate->fig_font_point_size = int_fig_pointsize;
  68. /* what size in user units should have been, to make fig_font_point_size
  69. an integer */
  70. if (device_vector_len == 0.0)
  71. quantized_size = 0.0; /* degenerate case */
  72. else
  73. quantized_size =
  74. (POINTS_TO_FIG_UNITS((double)int_fig_pointsize / FIG_FONT_SCALING))
  75. / (device_vector_len);
  76. _plotter->drawstate->true_font_size = quantized_size;
  77. /* quantize other fields */
  78. if (size == 0.0)
  79. quantization_factor = 0.0; /* degenerate case */
  80. else
  81. quantization_factor = quantized_size / size;
  82. _plotter->drawstate->font_ascent *= quantization_factor;
  83. _plotter->drawstate->font_descent *= quantization_factor;
  84. _plotter->drawstate->font_cap_height *= quantization_factor;
  85. return true;
  86. }