The R Project SVN R

Rev

Rev 37376 | Rev 39766 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37376 Rev 37396
Line 17... Line 17...
17
 *  You should have received a copy of the GNU General Public License
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
20
 */
20
 */
21
 
21
 
22
/* The version for R 2.1.0 is partly based on patches by 
22
/* The version for R 2.1.0 is partly based on patches by
23
   Ei-ji Nakama <nakama@ki.rim.or.jp> for use in Japanese. 
23
   Ei-ji Nakama <nakama@ki.rim.or.jp> for use in Japanese.
24
 
24
 
25
   <MBCS> all the strings manipulated here like display and fonts specs 
25
   <MBCS> all the strings manipulated here like display and fonts specs
26
   are probably ASCII, or at least start with ASCII in the part searched.
26
   are probably ASCII, or at least start with ASCII in the part searched.
27
*/
27
*/
28
 
28
 
29
#ifdef HAVE_CONFIG_H
29
#ifdef HAVE_CONFIG_H
30
# include <config.h>
30
# include <config.h>
Line 672... Line 672...
672
{
672
{
673
    R_XFont *tmp;
673
    R_XFont *tmp;
674
    tmp = (R_XFont *) malloc(sizeof(R_XFont));
674
    tmp = (R_XFont *) malloc(sizeof(R_XFont));
675
    tmp->type = One_Font;
675
    tmp->type = One_Font;
676
    tmp->font = XLoadQueryFont(display, name);
676
    tmp->font = XLoadQueryFont(display, name);
677
    if(tmp->font) 
677
    if(tmp->font)
678
	return tmp; 
678
	return tmp;
679
    else {
679
    else {
680
	free(tmp);
680
	free(tmp);
681
	return NULL;
681
	return NULL;
682
    }
682
    }
683
}
683
}
Line 699... Line 699...
699
{
699
{
700
    R_XFont *tmp = (R_XFont *) malloc(sizeof(R_XFont));
700
    R_XFont *tmp = (R_XFont *) malloc(sizeof(R_XFont));
701
    XFontSet fontset;
701
    XFontSet fontset;
702
    int  /*i,*/ missing_charset_count;
702
    int  /*i,*/ missing_charset_count;
703
    char **missing_charset_list, *def_string;
703
    char **missing_charset_list, *def_string;
704
  
704
 
705
#ifdef DEBUG_X11
705
#ifdef DEBUG_X11
706
    printf("loading fontset %s\n", fontset_name);
706
    printf("loading fontset %s\n", fontset_name);
707
#endif
707
#endif
708
    fontset = XCreateFontSet(display, fontset_name, &missing_charset_list,
708
    fontset = XCreateFontSet(display, fontset_name, &missing_charset_list,
709
			     &missing_charset_count, &def_string);
709
			     &missing_charset_count, &def_string);
710
    if(!fontset) {
710
    if(!fontset) {
711
	free(tmp);
711
	free(tmp);
712
	return NULL;	
712
	return NULL;
713
    }
713
    }
714
    if (missing_charset_count) {
714
    if (missing_charset_count) {
715
#ifdef DEBUG_X11
715
#ifdef DEBUG_X11
716
	int i;
716
	int i;
717
	for(i = 0; i < missing_charset_count; i++)
717
	for(i = 0; i < missing_charset_count; i++)
Line 1132... Line 1132...
1132
    char *p = dsp;
1132
    char *p = dsp;
1133
    XGCValues gcv;
1133
    XGCValues gcv;
1134
    /* Indicates whether the display is created within this particular call: */
1134
    /* Indicates whether the display is created within this particular call: */
1135
    Rboolean DisplayOpened = FALSE;
1135
    Rboolean DisplayOpened = FALSE;
1136
    static const char *title = "R Graphics";
1136
    static const char *title = "R Graphics";
1137
    XSizeHints *hint; 
1137
    XSizeHints *hint;
1138
 
1138
 
1139
#ifdef USE_FONTSET
1139
#ifdef USE_FONTSET
1140
    if (!XSupportsLocale ())
1140
    if (!XSupportsLocale ())
1141
	warning(_("locale not supported by Xlib: some X ops will operate in C locale"));
1141
	warning(_("locale not supported by Xlib: some X ops will operate in C locale"));
1142
    if (!XSetLocaleModifiers ("")) warning(_("X cannot set locale modifiers"));
1142
    if (!XSetLocaleModifiers ("")) warning(_("X cannot set locale modifiers"));
Line 1258... Line 1258...
1258
 
1258
 
1259
	    hint = XAllocSizeHints();
1259
	    hint = XAllocSizeHints();
1260
	    if(xpos == NA_INTEGER)
1260
	    if(xpos == NA_INTEGER)
1261
		hint->x = numX11Devices*20 %
1261
		hint->x = numX11Devices*20 %
1262
		    ( DisplayWidth(display, screen) - iw - 10 );
1262
		    ( DisplayWidth(display, screen) - iw - 10 );
1263
	    else hint->x = (xpos >= 0) ? xpos : 
1263
	    else hint->x = (xpos >= 0) ? xpos :
1264
		DisplayWidth(display, screen) - iw + xpos;
1264
		DisplayWidth(display, screen) - iw + xpos;
1265
	    
1265
 
1266
	    if(ypos == NA_INTEGER)
1266
	    if(ypos == NA_INTEGER)
1267
		hint->y = numX11Devices*20 %
1267
		hint->y = numX11Devices*20 %
1268
		    ( DisplayHeight(display, screen) + ih - 10 );
1268
		    ( DisplayHeight(display, screen) + ih - 10 );
1269
	    else hint->y = (ypos >= 0)? ypos :
1269
	    else hint->y = (ypos >= 0)? ypos :
1270
		DisplayHeight(display, screen) - iw - ypos;
1270
		DisplayHeight(display, screen) - iw - ypos;
Line 1284... Line 1284...
1284
		app_con = XtCreateApplicationContext();
1284
		app_con = XtCreateApplicationContext();
1285
		XtAppSetFallbackResources(app_con, x_fallback_resources);
1285
		XtAppSetFallbackResources(app_con, x_fallback_resources);
1286
		xtdpy = XtOpenDisplay(app_con, NULL, "r_x11", "R_x11",
1286
		xtdpy = XtOpenDisplay(app_con, NULL, "r_x11", "R_x11",
1287
				      NULL, 0, &zero, NULL);
1287
				      NULL, 0, &zero, NULL);
1288
		toplevel = XtAppCreateShell(NULL, "R_x11",
1288
		toplevel = XtAppCreateShell(NULL, "R_x11",
1289
					    applicationShellWidgetClass, 
1289
					    applicationShellWidgetClass,
1290
					    xtdpy, NULL, 0);
1290
					    xtdpy, NULL, 0);
1291
		XtGetApplicationResources(toplevel, (XtPointer) &xdev,
1291
		XtGetApplicationResources(toplevel, (XtPointer) &xdev,
1292
					  x_resources, 
1292
					  x_resources,
1293
					  x_resource_count,
1293
					  x_resource_count,
1294
					  NULL, 0);
1294
					  NULL, 0);
1295
		XtDestroyWidget(toplevel);
1295
		XtDestroyWidget(toplevel);
1296
		XtCloseDisplay(xtdpy);
1296
		XtCloseDisplay(xtdpy);
1297
		XtDestroyApplicationContext(app_con);
1297
		XtDestroyApplicationContext(app_con);
1298
		if (xdev.geometry != NULL) {
1298
		if (xdev.geometry != NULL) {
1299
		    char gstr[40];
1299
		    char gstr[40];
1300
		    int bitmask;
1300
		    int bitmask;
1301
		    
1301
 
1302
		    sprintf(gstr, "%dx%d+%d+%d", hint->width,
1302
		    sprintf(gstr, "%dx%d+%d+%d", hint->width,
1303
			    hint->height, hint->x, hint->y);
1303
			    hint->height, hint->x, hint->y);
1304
		    bitmask = XWMGeometry(display, DefaultScreen(display),
1304
		    bitmask = XWMGeometry(display, DefaultScreen(display),
1305
					  xdev.geometry, gstr, 
1305
					  xdev.geometry, gstr,
1306
					  1,
1306
					  1,
1307
					  hint,
1307
					  hint,
1308
					  &hint->x, &hint->y,
1308
					  &hint->x, &hint->y,
1309
					  &hint->width, &hint->height,
1309
					  &hint->width, &hint->height,
1310
					  &hint->win_gravity);
1310
					  &hint->win_gravity);
1311
		    
1311
 
1312
		    if (bitmask & (XValue | YValue))
1312
		    if (bitmask & (XValue | YValue))
1313
			hint->flags |= USPosition;
1313
			hint->flags |= USPosition;
1314
		    if (bitmask & (WidthValue | HeightValue)) 
1314
		    if (bitmask & (WidthValue | HeightValue))
1315
			hint->flags |= USSize;
1315
			hint->flags |= USSize;
1316
		    /* Restore user-specified settings */
1316
		    /* Restore user-specified settings */
1317
		    if(xpos != NA_INTEGER)
1317
		    if(xpos != NA_INTEGER)
1318
			hint->x = (xpos >= 0) ? xpos : 
1318
			hint->x = (xpos >= 0) ? xpos :
1319
			    DisplayWidth(display, screen) - iw + xpos;
1319
			    DisplayWidth(display, screen) - iw + xpos;
1320
		    if(ypos != NA_INTEGER)
1320
		    if(ypos != NA_INTEGER)
1321
			hint->y = (ypos >= 0)? ypos :
1321
			hint->y = (ypos >= 0)? ypos :
1322
			    DisplayHeight(display, screen) - iw - ypos;
1322
			    DisplayHeight(display, screen) - iw - ypos;
1323
		    if(!ISNA(w)) hint->width = iw;
1323
		    if(!ISNA(w)) hint->width = iw;
Line 1382... Line 1382...
1382
	    */
1382
	    */
1383
	}
1383
	}
1384
    } else { /* PIXMAP */
1384
    } else { /* PIXMAP */
1385
	xd->windowWidth = iw = w;
1385
	xd->windowWidth = iw = w;
1386
	xd->windowHeight = ih = h;
1386
	xd->windowHeight = ih = h;
-
 
1387
	if (iw < 20 && ih < 20)
-
 
1388
	    warning(_("'width=%d, height=%d' are unlikely values in pixels"),
-
 
1389
		    iw, ih);
1387
	if ((xd->window = XCreatePixmap(
1390
	if ((xd->window = XCreatePixmap(
1388
	    display, rootwin,
1391
	    display, rootwin,
1389
	    iw, ih, DefaultDepth(display, screen))) == 0) {
1392
	    iw, ih, DefaultDepth(display, screen))) == 0) {
1390
	    warning(_("unable to create pixmap"));
1393
	    warning(_("unable to create pixmap"));
1391
	    return FALSE;
1394
	    return FALSE;
Line 1521... Line 1524...
1521
	    for (i = 0; i < cnt; i++) printf("%s\n", ml[i]);
1524
	    for (i = 0; i < cnt; i++) printf("%s\n", ml[i]);
1522
	    printf("--- end of fontlist ---\n\n");
1525
	    printf("--- end of fontlist ---\n\n");
1523
#else
1526
#else
1524
	    XFontsOfFontSet(xd->font->fontset, &fs_list, &ml);
1527
	    XFontsOfFontSet(xd->font->fontset, &fs_list, &ml);
1525
#endif
1528
#endif
1526
	    
1529
 
1527
	    f = fs_list[0];
1530
	    f = fs_list[0];
1528
	} else f = xd->font->font;
1531
	} else f = xd->font->font;
1529
	first = f->min_char_or_byte2;
1532
	first = f->min_char_or_byte2;
1530
	last = f->max_char_or_byte2;
1533
	last = f->max_char_or_byte2;
1531
    } else return;
1534
    } else return;
Line 1541... Line 1544...
1541
	char buf[10];
1544
	char buf[10];
1542
	wchar_t wc[2] = L" ";XRectangle ink, log;
1545
	wchar_t wc[2] = L" ";XRectangle ink, log;
1543
	wchar_t *wcs=wc;
1546
	wchar_t *wcs=wc;
1544
 
1547
 
1545
	wc[0] = (unsigned int) c;
1548
	wc[0] = (unsigned int) c;
1546
	
1549
 
1547
	wcsrtombs(buf, (const wchar_t **)&wcs, sizeof(wc), NULL);
1550
	wcsrtombs(buf, (const wchar_t **)&wcs, sizeof(wc), NULL);
1548
#ifdef HAVE_XUTF8TEXTEXTENTS
1551
#ifdef HAVE_XUTF8TEXTEXTENTS
1549
	if(utf8locale)
1552
	if(utf8locale)
1550
	    Xutf8TextExtents(xd->font->fontset, buf, strlen(buf), &ink, &log);
1553
	    Xutf8TextExtents(xd->font->fontset, buf, strlen(buf), &ink, &log);
1551
	else
1554
	else
Line 1583... Line 1586...
1583
	*ascent = f->ascent;
1586
	*ascent = f->ascent;
1584
	*descent = f->descent;
1587
	*descent = f->descent;
1585
	*width = f->max_bounds.width;
1588
	*width = f->max_bounds.width;
1586
    } else if (first <= c && c <= last) {
1589
    } else if (first <= c && c <= last) {
1587
    /* It seems that per_char could be NULL
1590
    /* It seems that per_char could be NULL
1588
       http://www.ac3.edu.au/SGI_Developer/books/XLib_PG/sgi_html/ch06.html 
1591
       http://www.ac3.edu.au/SGI_Developer/books/XLib_PG/sgi_html/ch06.html
1589
    */
1592
    */
1590
	if(f->per_char) {
1593
	if(f->per_char) {
1591
	    *ascent = f->per_char[c-first].ascent;
1594
	    *ascent = f->per_char[c-first].ascent;
1592
	    *descent = f->per_char[c-first].descent;
1595
	    *descent = f->per_char[c-first].descent;
1593
	    *width = f->per_char[c-first].width;
1596
	    *width = f->per_char[c-first].width;
Line 2105... Line 2108...
2105
			    X_COLORTYPE colormodel,
2108
			    X_COLORTYPE colormodel,
2106
			    int maxcube,
2109
			    int maxcube,
2107
			    int bgcolor,
2110
			    int bgcolor,
2108
			    int canvascolor,
2111
			    int canvascolor,
2109
			    SEXP sfonts,
2112
			    SEXP sfonts,
2110
			    int res, 
2113
			    int res,
2111
			    int xpos, int ypos)
2114
			    int xpos, int ypos)
2112
{
2115
{
2113
    newX11Desc *xd;
2116
    newX11Desc *xd;
2114
    char *fn;
2117
    char *fn;
2115
 
2118
 
Line 2198... Line 2201...
2198
 
2201
 
2199
    SetBaseFont(xd);
2202
    SetBaseFont(xd);
2200
    {
2203
    {
2201
	XFontStruct *f;
2204
	XFontStruct *f;
2202
#ifdef USE_FONTSET
2205
#ifdef USE_FONTSET
2203
	/* Use fudge size of M, not the max of the first font or the 
2206
	/* Use fudge size of M, not the max of the first font or the
2204
	   whole fontset which may have very wide characters if it contains
2207
	   whole fontset which may have very wide characters if it contains
2205
	   a comprehensive ISO 10646 font.
2208
	   a comprehensive ISO 10646 font.
2206
	 */
2209
	 */
2207
	if(xd->font->type == Font_Set) {
2210
	if(xd->font->type == Font_Set) {
2208
	    char buf[10];
2211
	    char buf[10];
2209
	    XRectangle ink, log;
2212
	    XRectangle ink, log;
2210
	    
2213
 
2211
	    wcstombs(buf, L"M", 10);
2214
	    wcstombs(buf, L"M", 10);
2212
#ifdef HAVE_XUTF8TEXTEXTENTS
2215
#ifdef HAVE_XUTF8TEXTEXTENTS
2213
	    if(utf8locale)
2216
	    if(utf8locale)
2214
		Xutf8TextExtents(xd->font->fontset, buf, strlen(buf), &ink, &log);
2217
		Xutf8TextExtents(xd->font->fontset, buf, strlen(buf), &ink, &log);
2215
	    else
2218
	    else
Line 2507... Line 2510...
2507
    if (!strncmp(display, "png::", 5)) devname = "PNG";
2510
    if (!strncmp(display, "png::", 5)) devname = "PNG";
2508
    else if (!strncmp(display, "jpeg::", 6)) devname = "JPEG";
2511
    else if (!strncmp(display, "jpeg::", 6)) devname = "JPEG";
2509
    else if (!strcmp(display, "XImage")) devname = "XImage";
2512
    else if (!strcmp(display, "XImage")) devname = "XImage";
2510
 
2513
 
2511
    Rf_addX11Device(display, width, height, ps, gamma, colormodel,
2514
    Rf_addX11Device(display, width, height, ps, gamma, colormodel,
2512
		    maxcubesize, bgcolor, canvascolor, devname, sfonts, 
2515
		    maxcubesize, bgcolor, canvascolor, devname, sfonts,
2513
		    res, xpos, ypos);
2516
		    res, xpos, ypos);
2514
    vmaxset(vmax);
2517
    vmaxset(vmax);
2515
    return R_NilValue;
2518
    return R_NilValue;
2516
}
2519
}
2517
 
2520
 
Line 2538... Line 2541...
2538
    XEvent evt;
2541
    XEvent evt;
2539
    unsigned char *buffer;
2542
    unsigned char *buffer;
2540
    unsigned long pty_size, pty_items;
2543
    unsigned long pty_size, pty_items;
2541
    int pty_format, ret;
2544
    int pty_format, ret;
2542
    Rboolean res = TRUE;
2545
    Rboolean res = TRUE;
2543
  
2546
 
2544
    if (!displayOpen) {
2547
    if (!displayOpen) {
2545
	if ((display = XOpenDisplay(NULL)) == NULL) {
2548
	if ((display = XOpenDisplay(NULL)) == NULL) {
2546
	    warning(_("unable to contact X11 display"));
2549
	    warning(_("unable to contact X11 display"));
2547
	    return FALSE;
2550
	    return FALSE;
2548
	}
2551
	}
2549
    }
2552
    }
2550
    if(strcmp(type, "X11_secondary") == 0) sel = XA_SECONDARY;
2553
    if(strcmp(type, "X11_secondary") == 0) sel = XA_SECONDARY;
2551
 
2554
 
2552
    pty = XInternAtom(display, "RCLIP_READ", False);
2555
    pty = XInternAtom(display, "RCLIP_READ", False);
2553
 
2556
 
2554
    clpwin = XCreateSimpleWindow(display, DefaultRootWindow(display), 
2557
    clpwin = XCreateSimpleWindow(display, DefaultRootWindow(display),
2555
				 0, 0, 1, 1, 0, 0, 0);
2558
				 0, 0, 1, 1, 0, 0, 0);
2556
    /* send a selection request */
2559
    /* send a selection request */
2557
    ret = XConvertSelection(display, sel, XA_STRING, pty, clpwin, CurrentTime);
2560
    ret = XConvertSelection(display, sel, XA_STRING, pty, clpwin, CurrentTime);
2558
 
2561
 
2559
    /* wait for the response */
2562
    /* wait for the response */
2560
    while(1) {
2563
    while(1) {
2561
	XNextEvent(display, &evt);	
2564
	XNextEvent(display, &evt);
2562
	if (evt.type == SelectionNotify) break;
2565
	if (evt.type == SelectionNotify) break;
2563
    }
2566
    }
2564
    
2567
 
2565
    /* find the size and format of the data in the selection */
2568
    /* find the size and format of the data in the selection */
2566
    XGetWindowProperty(display, clpwin, pty, 0, 0, False, AnyPropertyType, 
2569
    XGetWindowProperty(display, clpwin, pty, 0, 0, False, AnyPropertyType,
2567
		       &pty_type, &pty_format, &pty_items, &pty_size, &buffer);
2570
		       &pty_type, &pty_format, &pty_items, &pty_size, &buffer);
2568
    XFree(buffer);
2571
    XFree(buffer);
2569
    if (pty_format != 8) { /* bytes */
2572
    if (pty_format != 8) { /* bytes */
2570
	warning(_("clipboard cannot be opened or contains no text"));
2573
	warning(_("clipboard cannot be opened or contains no text"));
2571
	res = FALSE;
2574
	res = FALSE;
2572
    } else { /* read the property */
2575
    } else { /* read the property */
2573
	XGetWindowProperty(display, clpwin, pty, 0, (long)pty_size, False,
2576
	XGetWindowProperty(display, clpwin, pty, 0, (long)pty_size, False,
2574
			   AnyPropertyType, &pty_type, &pty_format, 
2577
			   AnyPropertyType, &pty_type, &pty_format,
2575
			   &pty_items, &pty_size, &buffer);
2578
			   &pty_items, &pty_size, &buffer);
2576
	this->buff = (char *)malloc(pty_items + 1);
2579
	this->buff = (char *)malloc(pty_items + 1);
2577
	this->last = this->len = pty_items;
2580
	this->last = this->len = pty_items;
2578
	if(this->buff) {
2581
	if(this->buff) {
2579
	    /* property always ends in 'extra' zero byte */
2582
	    /* property always ends in 'extra' zero byte */