1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: estimate.trm,v 1.4.2.1 2007/11/26 04:06:36 sfeam Exp $
6 /* GNUPLOT - estimate.trm */
9 * This file is included by ../src/term.c via term.h.
11 * This terminal driver supports:
12 * On return from ENHest_put_text()
13 * (*term)->xmax = estimated string width
14 * (*term)->ymax = estimated string height
15 * enhanced_min_height = lowest baseline used
16 * enhanced_max_height = highest (baseline + fontsize) used
20 * Ethan A Merritt - Dec 2004
26 TERM_PUBLIC void ENHest_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
27 TERM_PUBLIC void ENHest_OPEN __PROTO((char * fontname, double fontsize,
28 double base, TBOOLEAN widthflag, TBOOLEAN showflag,
30 TERM_PUBLIC void ENHest_FLUSH __PROTO((void));
31 #endif /* TERM_PROTO */
35 static double ENHest_x, ENHest_y;
36 static double ENHest_xsave, ENHest_ysave;
37 static double ENHest_fragment_width;
38 static double ENHest_fontsize;
40 static TBOOLEAN ENHest_opened_string;
41 static TBOOLEAN ENHest_show = TRUE;
42 static int ENHest_overprint = 0;
43 static TBOOLEAN ENHest_widthflag = TRUE;
44 #define ENHest_font ""
45 static double ENHest_base;
50 double fontsize, double base,
51 TBOOLEAN widthflag, TBOOLEAN showflag,
54 /* There are two special cases:
55 * overprint = 3 means save current position
56 * overprint = 4 means restore saved position
59 ENHest_xsave = ENHest_x;
60 ENHest_ysave = ENHest_y;
62 } else if (overprint == 4) {
63 ENHest_x = ENHest_xsave;
64 ENHest_y = ENHest_ysave;
68 if (!ENHest_opened_string) {
69 ENHest_opened_string = TRUE;
70 /* Start new text fragment */
71 ENHest_fragment_width = 0;
72 /* Scale fractional font height */
73 ENHest_base = base * 1.0;
74 /* Keep track of whether we are supposed to show this string */
75 ENHest_show = showflag;
76 /* 0/1/2 no overprint / 1st pass / 2nd pass */
77 ENHest_overprint = overprint;
78 /* widthflag FALSE means do not update text position after printing */
79 ENHest_widthflag = widthflag;
80 /* font size will be used to estimate width of each character */
81 ENHest_fontsize = fontsize > 2.0 ? 1.0 : fontsize;
88 double len = ENHest_fragment_width;
90 if (ENHest_opened_string) {
91 ENHest_fragment_width = 0;
93 if (!ENHest_widthflag)
94 /* don't update position */
96 else if (ENHest_overprint == 1)
97 /* First pass of overprint, leave position in center of fragment */
100 /* Normal case is to update position to end of fragment */
103 ENHest_opened_string = FALSE;
108 ENHest_put_text(unsigned int x, unsigned int y, const char *str)
110 /* Set up global variables needed by enhanced_recursion() */
111 ENHest_fontsize = 1.0;
112 ENHest_opened_string = FALSE;
113 enhanced_max_height = 1;
114 enhanced_min_height = 0;
116 /* If no enhanced text processing is needed, strlen() is sufficient */
117 if (ignore_enhanced_text || !strpbrk(str, "{}^_@&~")) {
118 term->xmax = strlen(str);
125 while (*(str = enhanced_recursion((char *)str, TRUE,
126 ENHest_font, ENHest_fontsize,
127 0.0, TRUE, TRUE, 0))) {
128 (term->enhanced_flush)();
132 break; /* end of string */
135 if (ENHest_x > 0.0 && ENHest_x < 1.0)
138 term->xmax = ENHest_x;
139 term->ymax = enhanced_max_height - enhanced_min_height;
145 ENHest_fragment_width += ENHest_fontsize;
149 static struct termentry ENHest = {
150 "estimate", "estimate width of enhanced text string",
153 NULL, NULL, NULL, NULL, NULL,
154 NULL, ENHest_put_text, NULL,
155 NULL, NULL, NULL, NULL,
156 0, 0, /* pointsize, flags */
157 NULL, NULL, NULL, NULL
159 , NULL, NULL, NULL, NULL, NULL
161 , NULL, NULL, NULL, NULL
165 , ENHest_OPEN, ENHest_FLUSH, ENHest_writec
168 #endif /* TERM_BODY */