X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/facd762ca8b5eb6cad4171cb3deb2f3ef2957dc0..e0e7dff87dc3f482da6ab00317664474b0f82995:/unix/pterm.c diff --git a/unix/pterm.c b/unix/pterm.c index b7f93f9c..dbcb5455 100644 --- a/unix/pterm.c +++ b/unix/pterm.c @@ -48,6 +48,7 @@ struct gui_data { GdkColor cols[NCOLOURS]; GdkColormap *colmap; wchar_t *pastein_data; + int direct_to_font; int pastein_data_len; char *pasteout_data, *pasteout_data_utf8; int pasteout_data_len, pasteout_data_utf8_len; @@ -82,6 +83,23 @@ char *x_get_default(char *key) return XGetDefault(GDK_DISPLAY(), app_name, key); } +/* + * Default settings that are specific to pterm. + */ +char *platform_default_s(char *name) +{ + if (!strcmp(name, "Font")) + return "fixed"; /* COE_NORMAL works badly in an xterm */ + return NULL; +} + +int platform_default_i(char *name, int def) +{ + if (!strcmp(name, "CloseOnExit")) + return COE_ALWAYS; /* COE_NORMAL works badly in an xterm */ + return def; +} + void ldisc_update(void *frontend, int echo, int edit) { /* @@ -836,7 +854,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) printf("\n"); #endif - if (inst->fontinfo[0].charset != CS_NONE) { + if (!inst->direct_to_font) { /* * The stuff we've just generated is assumed to be * ISO-8859-1! This sounds insane, but `man @@ -1231,7 +1249,7 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect) * Set up UTF-8 paste data. This only happens if we aren't in * direct-to-font mode using the D800 hack. */ - if (inst->fontinfo[0].charset != CS_NONE) { + if (!inst->direct_to_font) { wchar_t *tmp = data; int tmplen = len; @@ -1241,18 +1259,31 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect) charset_from_unicode(&tmp, &tmplen, inst->pasteout_data_utf8, inst->pasteout_data_utf8_len, CS_UTF8, NULL, NULL, 0); - inst->pasteout_data_utf8 = - srealloc(inst->pasteout_data_utf8, inst->pasteout_data_utf8_len); + if (inst->pasteout_data_utf8_len == 0) { + sfree(inst->pasteout_data_utf8); + inst->pasteout_data_utf8 = NULL; + } else { + inst->pasteout_data_utf8 = + srealloc(inst->pasteout_data_utf8, + inst->pasteout_data_utf8_len); + } } else { inst->pasteout_data_utf8 = NULL; inst->pasteout_data_utf8_len = 0; } - inst->pasteout_data = smalloc(len); - inst->pasteout_data_len = len; - wc_to_mb(line_codepage, 0, data, len, - inst->pasteout_data, inst->pasteout_data_len, - NULL, NULL); + inst->pasteout_data = smalloc(len*6); + inst->pasteout_data_len = len*6; + inst->pasteout_data_len = wc_to_mb(line_codepage, 0, data, len, + inst->pasteout_data, + inst->pasteout_data_len, NULL, NULL); + if (inst->pasteout_data_len == 0) { + sfree(inst->pasteout_data); + inst->pasteout_data = NULL; + } else { + inst->pasteout_data = + srealloc(inst->pasteout_data, inst->pasteout_data_len); + } if (gtk_selection_owner_set(inst->area, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME)) { @@ -1304,7 +1335,7 @@ void request_paste(void *frontend) * comes back _then_ we can call term_do_paste(). */ - if (inst->fontinfo[0].charset != CS_NONE) { + if (!inst->direct_to_font) { /* * First we attempt to retrieve the selection as a UTF-8 * string (which we will convert to the correct code page @@ -1576,7 +1607,22 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len, * nothing at all; such is life. */ } else if (inst->fontinfo[fontid].is_wide) { - gwcs = smalloc(sizeof(GdkWChar) * (len+1)); + /* + * At least one version of gdk_draw_text_wc() has a + * weird bug whereby it reads `len' elements of the + * input string, but only draws `len/2'. Hence I'm + * going to make its input array twice as long as it + * theoretically needs to be, and pass in twice the + * actual number of characters. If a fixed gdk actually + * takes the doubled length seriously, then (a) the + * array will stand scrutiny up to the full length, (b) + * the spare elements of the array are full of zeroes + * which will probably be an empty glyph in the font, + * and (c) the clip rectangle should prevent it causing + * trouble anyway. + */ + gwcs = smalloc(sizeof(GdkWChar) * (len*2+1)); + memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1)); /* * FIXME: when we have a wide-char equivalent of * from_unicode, use it instead of this. @@ -2260,7 +2306,7 @@ int main(int argc, char **argv) inst->compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE); inst->utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); - init_ucs(font_charset); + inst->direct_to_font = init_ucs(font_charset); inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);