FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

new routine estimate_plaintext(enhancedtext) · gnuplot/gnuplot@aeb5f61 · GitHub

Repository navigation

Commit aeb5f61

Browse files
Ethan A Merritt
committed
new routine estimate_plaintext(enhancedtext)
1 parent 9eedc3c commit aeb5f61

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎src/term.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: term.c,v 1.305 2015/01/24 23:54:32 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: term.c,v 1.306 2015/02/18 19:14:28 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - term.c */
@@ -2585,6 +2585,17 @@ int len;
25852585
return len;
25862586
}
25872587

2588+
/*
2589+
* Use estimate.trm to mock up a non-enhanced approximation of the
2590+
* original string.
2591+
*/
2592+
char *
2593+
estimate_plaintext(char *enhancedtext)
2594+
{
2595+
estimate_strlen(enhancedtext);
2596+
return ENHest_plaintext;
2597+
}
2598+
25882599
void
25892600
ignore_enhanced(TBOOLEAN flag)
25902601
{

‎src/term_api.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: term_api.h,v 1.136 2014/09/05 21:51:38 sfeam Exp $
2+
* $Id: term_api.h,v 1.137 2014/12/28 13:09:36 markisch Exp $
33
*/
44

55
/* GNUPLOT - term_api.h */
@@ -467,6 +467,7 @@ struct termentry *change_term __PROTO((const char *name, int length));
467467

468468
void write_multiline __PROTO((unsigned int, unsigned int, char *, JUSTIFY, VERT_JUSTIFY, int, const char *));
469469
int estimate_strlen __PROTO((char *));
470+
char *estimate_plaintext __PROTO((char *));
470471
void list_terms __PROTO((void));
471472
char* get_terminals_names __PROTO((void));
472473
struct termentry *set_term __PROTO((void));

‎term/estimate.trm‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Hello, Emacs, this is -*-C-*-
2-
* $Id: estimate.trm,v 1.10 2010/07/28 20:43:59 sfeam Exp $
2+
* $Id: estimate.trm,v 1.11 2012/05/06 00:31:36 sfeam Exp $
33
*
44
*/
55

@@ -12,6 +12,7 @@
1212
* On return from ENHest_put_text()
1313
* (*term)->xmax = estimated string width
1414
* (*term)->ymax = estimated string height (in tenths of a character height)
15+
* ENHest_plaintext = non-enhanced text approximation of original string
1516
*
1617
* AUTHORS
1718
*
@@ -36,6 +37,9 @@ static double ENHest_fragment_width;
3637
static double ENHest_fontsize;
3738
static double ENHest_min_height, ENHest_max_height;
3839
static double ENHest_total_width;
40+
static char *ENHest_plaintext = NULL;
41+
static int ENHest_plaintext_buflen = 0;
42+
static int ENHest_plaintext_pos = 0;
3943

4044
static TBOOLEAN ENHest_opened_string;
4145
static TBOOLEAN ENHest_show = TRUE;
@@ -125,13 +129,22 @@ ENHest_put_text(unsigned int x, unsigned int y, const char *str)
125129
ENHest_total_width = 0.0;
126130
strncpy(enhanced_escape_format,".",sizeof(enhanced_escape_format));
127131

132+
/* buffer in which we will return plaintext version of enhanced text string */
133+
while (ENHest_plaintext_buflen < strlen(str)) {
134+
ENHest_plaintext_buflen += MAX_ID_LEN;
135+
ENHest_plaintext = gp_realloc(ENHest_plaintext, ENHest_plaintext_buflen+1, "ENHest_plaintext");
136+
}
137+
ENHest_plaintext[0] = '\0';
138+
ENHest_plaintext_pos = 0;
139+
128140
/* If no enhanced text processing is needed, strlen() is sufficient */
129141
if (ignore_enhanced_text || !strpbrk(str, "{}^_@&~\n")) {
130142
if (encoding == S_ENC_UTF8)
131143
term->xmax = strwidth_utf8(str);
132144
else
133145
term->xmax = strlen(str);
134146
term->ymax = 10;
147+
strcpy(ENHest_plaintext, str);
135148
return;
136149
}
137150

@@ -148,6 +161,7 @@ ENHest_put_text(unsigned int x, unsigned int y, const char *str)
148161
break; /* end of string */
149162
}
150163

164+
ENHest_plaintext[ENHest_plaintext_pos] = '\0';
151165
if (ENHest_x > 0.0 && ENHest_x < 1.0)
152166
ENHest_x = 1;
153167
term->xmax = ENHest_total_width;
@@ -176,6 +190,8 @@ ENHest_writec(int c)
176190
}
177191
} else
178192
ENHest_fragment_width += ENHest_fontsize;
193+
194+
ENHest_plaintext[ENHest_plaintext_pos++] = c;
179195
}
180196

181197
/*
@@ -200,7 +216,7 @@ size_t strwidth_utf8(const char *s) {
200216

201217

202218
static struct termentry ENHest = {
203-
"estimate", "estimate width of enhanced text string",
219+
"estimate", NULL,
204220
1, 1, 1, 1, 1, 1,
205221
NULL, NULL, NULL,
206222
NULL, NULL, NULL, NULL, NULL,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL