123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include "sys-defines.h"
- #include "extern.h"
- #define FONT_TYPE_LATEX 0
- #define FONT_TYPE_PS 4
- #define GOOD_PRINTABLE_ASCII(c) ((c >= 0x20) && (c <= 0x7E))
- /* Fig horizontal alignment styles, indexed by internal number
- (left/center/right) */
- #define FIG_ALIGN_LEFT 0
- #define FIG_ALIGN_CENTER 1
- #define FIG_ALIGN_RIGHT 2
- static const int fig_horizontal_alignment_style[PL_NUM_HORIZ_JUST_TYPES] =
- { FIG_ALIGN_LEFT, FIG_ALIGN_CENTER, FIG_ALIGN_RIGHT };
- /* This prints a single-font, single-font-size label. When this is called,
- the current point is on the intended baseline of the label. */
- /* ARGS: h_just,v_just are PL_JUST_{LEFT|CENTER|RIGHT}, PL_JUST_{TOP etc.} */
- double
- _pl_f_paint_text_string (R___(Plotter *_plotter) const unsigned char *s, int h_just, int v_just)
- {
- int len, master_font_index;
- unsigned char *ptr, *t;
- double theta, costheta, sintheta;
- double label_width, label_ascent;
- double initial_x, initial_y;
- double horizontal_x, horizontal_y, vertical_x, vertical_y;
- double horizontal_fig_length, vertical_fig_length;
- double horizontal_fig_x, vertical_fig_x;
- double horizontal_fig_y, vertical_fig_y;
- double angle_device;
-
- /* sanity check */
- if (_plotter->drawstate->font_type != PL_F_POSTSCRIPT)
- return 0.0;
-
- if (v_just != PL_JUST_BASE)
- return 0.0;
-
- if (*s == (unsigned char)'\0')
- return 0.0;
-
- if (_plotter->drawstate->fig_font_point_size == 0)
- return 0.0;
-
- theta = M_PI * _plotter->drawstate->text_rotation / 180.0;
- sintheta = sin (theta);
- costheta = cos (theta);
-
- master_font_index =
- (_pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
-
- label_width = _plotter->get_text_width (R___(_plotter) s);
- label_ascent = _plotter->drawstate->true_font_size * (_pl_g_ps_font_info[master_font_index]).font_ascent / 1000.0;
-
-
- horizontal_x = costheta * label_width;
- horizontal_y = sintheta * label_width;
- vertical_x = - sintheta * label_ascent;
- vertical_y = costheta * label_ascent;
-
-
- horizontal_fig_x = XDV(horizontal_x, horizontal_y);
- horizontal_fig_y = YDV(horizontal_x, horizontal_y);
- horizontal_fig_length = sqrt(horizontal_fig_x * horizontal_fig_x
- + horizontal_fig_y * horizontal_fig_y);
-
- angle_device = - _xatan2 (horizontal_fig_y, horizontal_fig_x);
- if (angle_device == 0.0)
- angle_device = 0.0;
-
-
- if (angle_device != 0.0 && strcmp ((const char *)s, " ") == 0)
- return _plotter->get_text_width (R___(_plotter) s);
- vertical_fig_x = XDV(vertical_x, vertical_y);
- vertical_fig_y = YDV(vertical_x, vertical_y);
- vertical_fig_length = sqrt(vertical_fig_x * vertical_fig_x
- + vertical_fig_y * vertical_fig_y);
-
-
- initial_x = XD((_plotter->drawstate->pos).x, (_plotter->drawstate->pos).y);
- initial_y = YD((_plotter->drawstate->pos).x, (_plotter->drawstate->pos).y);
-
- _pl_f_set_pen_color (S___(_plotter));
-
-
- len = strlen ((char *)s);
- ptr = (unsigned char *)_pl_xmalloc ((4 * len + 1) * sizeof(char));
- t = ptr;
- while (*s)
- {
- switch (*s)
- {
- case '\\':
- *ptr++ = (unsigned char)'\\';
- *ptr++ = *s++;
- break;
- default:
- if GOOD_PRINTABLE_ASCII (*s)
- *ptr++ = *s++;
- else
- {
- sprintf ((char *)ptr, "\\%03o", (unsigned int)*s);
- ptr += 4;
- s++;
- }
- break;
- }
- }
- *ptr = (unsigned char)'\0';
-
- if (_plotter->fig_drawing_depth > 0)
- (_plotter->fig_drawing_depth)--;
- sprintf(_plotter->data->page->point,
- "#TEXT\n%d %d %d %d %d %d %.3f %.3f %d %.3f %.3f %d %d %s\\001\n",
- 4,
-
- fig_horizontal_alignment_style[h_just],
- _plotter->drawstate->fig_fgcolor,
- _plotter->fig_drawing_depth,
- 0,
- _pl_g_ps_font_info[master_font_index].fig_id,
- (double)_plotter->drawstate->fig_font_point_size,
- angle_device,
- FONT_TYPE_PS,
-
- vertical_fig_length,
- horizontal_fig_length,
-
- IROUND(initial_x),
- IROUND(initial_y),
- t);
- free (t);
- _update_buffer (_plotter->data->page);
- return label_width;
- }
|