The R Project SVN R

Rev

Rev 20779 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20779 Rev 21024
Line 135... Line 135...
135
    menuitem mR, mfit, mfix;
135
    menuitem mR, mfit, mfix;
136
    Rboolean recording, replaying, needsave;
136
    Rboolean recording, replaying, needsave;
137
    bitmap bm;
137
    bitmap bm;
138
  /* PNG and JPEG section */
138
  /* PNG and JPEG section */
139
    FILE *fp;
139
    FILE *fp;
-
 
140
    char filename[512];
140
    int quality;
141
    int quality;
-
 
142
    int npage;
-
 
143
    double w, h;
141
  /* Used to rescale font size so that bitmap devices have 72dpi */
144
  /* Used to rescale font size so that bitmap devices have 72dpi */
142
    int truedpi, wanteddpi; 
145
    int truedpi, wanteddpi; 
143
    rgb   fgcolor;		/* Foreground color */
146
    rgb   fgcolor;		/* Foreground color */
144
    rgb   bgcolor;		/* Background color */
147
    rgb   bgcolor;		/* Background color */
145
    rgb   canvascolor;		/* Canvas color */
148
    rgb   canvascolor;		/* Canvas color */
Line 1402... Line 1405...
1402
static Rboolean GA_Open(NewDevDesc *dd, gadesc *xd, char *dsp,
1405
static Rboolean GA_Open(NewDevDesc *dd, gadesc *xd, char *dsp,
1403
			double w, double h, Rboolean recording,
1406
			double w, double h, Rboolean recording,
1404
			int resize, int canvascolor, double gamma)
1407
			int resize, int canvascolor, double gamma)
1405
{
1408
{
1406
    rect  rr;
1409
    rect  rr;
-
 
1410
    char buf[512];
1407
 
1411
 
1408
    if (!fontinitdone)
1412
    if (!fontinitdone)
1409
	RFontInit();
1413
	RFontInit();
1410
 
1414
 
1411
    /* Foreground and Background Colors */
1415
    /* Foreground and Background Colors */
Line 1416... Line 1420...
1416
    xd->bgcolor = xd->canvascolor = GArgb(canvascolor, gamma);
1420
    xd->bgcolor = xd->canvascolor = GArgb(canvascolor, gamma);
1417
    xd->outcolor = myGetSysColor(COLOR_APPWORKSPACE);
1421
    xd->outcolor = myGetSysColor(COLOR_APPWORKSPACE);
1418
    xd->rescale_factor = 1.0;
1422
    xd->rescale_factor = 1.0;
1419
    xd->fast = 1;  /* Use `cosmetic pens' if available */
1423
    xd->fast = 1;  /* Use `cosmetic pens' if available */
1420
    xd->xshift = xd->yshift = 0;
1424
    xd->xshift = xd->yshift = 0;
-
 
1425
    xd->npage = 0;
1421
    if (!dsp[0]) {
1426
    if (!dsp[0]) {
1422
	if (!setupScreenDevice(dd, xd, w, h, recording, resize)) 
1427
	if (!setupScreenDevice(dd, xd, w, h, recording, resize)) 
1423
	    return FALSE;
1428
	    return FALSE;
1424
    } else if (!strncmp(dsp, "win.print:", 10)) {
1429
    } else if (!strncmp(dsp, "win.print:", 10)) {
1425
	xd->kind = PRINTER;
1430
	xd->kind = PRINTER;
Line 1431... Line 1436...
1431
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1436
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1432
	else
1437
	else
1433
	    xd->bg = dd->startfill = canvascolor;
1438
	    xd->bg = dd->startfill = canvascolor;
1434
	/* was R_RGB(255, 255, 255); white */
1439
	/* was R_RGB(255, 255, 255); white */
1435
        xd->kind = (dsp[0]=='p') ? PNG : BMP;
1440
        xd->kind = (dsp[0]=='p') ? PNG : BMP;
-
 
1441
	strcpy(xd->filename, dsp+4);
1436
	if (!Load_Rbitmap_Dll()) {
1442
	if (!Load_Rbitmap_Dll()) {
1437
	    warning("Unable to load Rbitmap.dll");
1443
	    warning("Unable to load Rbitmap.dll");
1438
	    return FALSE;
1444
	    return FALSE;
1439
	}
1445
	}
1440
	/*
1446
	/*
Line 1443... Line 1449...
1443
	  if required depth > 1
1449
	  if required depth > 1
1444
	*/
1450
	*/
1445
	if ((xd->gawin = newbitmap(w, h, 256)) == NULL) {
1451
	if ((xd->gawin = newbitmap(w, h, 256)) == NULL) {
1446
	    warning("Unable to allocate bitmap");
1452
	    warning("Unable to allocate bitmap");
1447
	    return FALSE;
1453
	    return FALSE;
1448
	}  
1454
	}
-
 
1455
	sprintf(buf, xd->filename, 1);
1449
	if ((xd->fp = fopen(&dsp[4], "wb")) == NULL) {
1456
	if ((xd->fp = fopen(buf, "wb")) == NULL) {
1450
	    del(xd->gawin);
1457
	    del(xd->gawin);
1451
	    warning("Unable to open file `%s' for writing", &dsp[4]);
1458
	    warning("Unable to open file `%s' for writing", buf);
1452
	    return FALSE;
1459
	    return FALSE;
1453
	}
1460
	}
1454
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1461
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1455
        char *p = strchr(&dsp[5], ':');
1462
        char *p = strchr(&dsp[5], ':');
1456
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1463
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
Line 1461... Line 1468...
1461
	    return FALSE;
1468
	    return FALSE;
1462
	}
1469
	}
1463
	*p = '\0';
1470
	*p = '\0';
1464
	xd->quality = atoi(&dsp[5]);
1471
	xd->quality = atoi(&dsp[5]);
1465
	*p = ':' ;
1472
	*p = ':' ;
-
 
1473
	strcpy(xd->filename, p+1);
1466
	if((xd->gawin = newbitmap(w, h, 256)) == NULL) {
1474
	if((xd->gawin = newbitmap(w, h, 256)) == NULL) {
1467
	    warning("Unable to allocate bitmap");
1475
	    warning("Unable to allocate bitmap");
1468
	    return FALSE;
1476
	    return FALSE;
1469
	}  
1477
	}  
-
 
1478
	sprintf(buf, xd->filename, 1);
1470
	if ((xd->fp = fopen(p+1, "wb")) == NULL) {
1479
	if ((xd->fp = fopen(buf, "wb")) == NULL) {
1471
	    del(xd->gawin);
1480
	    del(xd->gawin);
1472
	    warning("Unable to open file `%s' for writing", p+1);
1481
	    warning("Unable to open file `%s' for writing", buf);
1473
	    return FALSE;
1482
	    return FALSE;
1474
	}
1483
	}
1475
    } else {
1484
    } else {
1476
	/*
1485
	/*
1477
	 * win.metafile[:] in memory (for the clipboard)
1486
	 * win.metafile[:] in memory (for the clipboard)
Line 1484... Line 1493...
1484
 
1493
 
1485
	if (ls > ld)
1494
	if (ls > ld)
1486
	    return FALSE;
1495
	    return FALSE;
1487
	if (strncmp(dsp, s, ls) || (dsp[ls] && (dsp[ls] != ':')))
1496
	if (strncmp(dsp, s, ls) || (dsp[ls] && (dsp[ls] != ':')))
1488
	    return FALSE;
1497
	    return FALSE;
1489
	xd->gawin = newmetafile((ld > ls) ? &dsp[ls + 1] : "",
1498
	strcpy(xd->filename, (ld > ls) ? &dsp[ls + 1] : "");
-
 
1499
	sprintf(buf, xd->filename, 1);
-
 
1500
	xd->w = MM_PER_INCH * w;
1490
				MM_PER_INCH * w, MM_PER_INCH * h);
1501
	xd->h =  MM_PER_INCH * h;
-
 
1502
	xd->gawin = newmetafile(buf, MM_PER_INCH * w, MM_PER_INCH * h);
1491
	xd->kind = METAFILE;
1503
	xd->kind = METAFILE;
1492
	xd->fast = 0; /* use scalable line widths */
1504
	xd->fast = 0; /* use scalable line widths */
1493
	if (!xd->gawin) {
1505
	if (!xd->gawin) {
1494
	    if(ld > ls)
1506
	    if(ld > ls)
1495
		warning("Unable to open metafile `%s' for writing", 
1507
		warning("Unable to open metafile `%s' for writing", buf);
1496
			&dsp[ls + 1]);
-
 
1497
	    else
1508
	    else
1498
		warning("Unable to open clipboard to write metafile");
1509
		warning("Unable to open clipboard to write metafile");
1499
	    return FALSE;
1510
	    return FALSE;
1500
	}
1511
	}
1501
    }
1512
    }
Line 1700... Line 1711...
1700
	/********************************************************/
1711
	/********************************************************/
1701
 
1712
 
1702
static void GA_NewPage(int fill, double gamma, NewDevDesc *dd)
1713
static void GA_NewPage(int fill, double gamma, NewDevDesc *dd)
1703
{
1714
{
1704
    gadesc *xd = (gadesc *) dd->deviceSpecific;
1715
    gadesc *xd = (gadesc *) dd->deviceSpecific;
-
 
1716
    char buf[512];
1705
 
1717
 
-
 
1718
    xd->npage++;
1706
    if ((xd->kind == PRINTER) && xd->needsave)
1719
    if ((xd->kind == PRINTER) && xd->needsave)
1707
	nextpage(xd->gawin);
1720
	nextpage(xd->gawin);
1708
    if ((xd->kind == METAFILE) && xd->needsave)
1721
    if ((xd->kind == METAFILE) && xd->needsave) {
-
 
1722
	if (strlen(xd->filename) == 0)
1709
	error("A metafile can store only one figure.");
1723
	    error("A clipboard metafile can store only one figure.");
-
 
1724
	else {
-
 
1725
	    del(xd->gawin);
1710
    if ((xd->kind == PNG) && xd->needsave)
1726
	    sprintf(buf, xd->filename, xd->npage);
1711
	error("A png file can store only one figure.");
1727
	    xd->gawin = newmetafile(buf, xd->w, xd->h);
-
 
1728
	}
-
 
1729
    }
1712
    if ((xd->kind == JPEG) && xd->needsave)
1730
    if ((xd->kind == PNG || xd->kind == JPEG || xd->kind == BMP) 
-
 
1731
	&& xd->needsave) {
-
 
1732
	SaveAsBitmap(dd);
1713
	error("A jpeg file can store only one figure.");
1733
	sprintf(buf, xd->filename, xd->npage);
1714
    if ((xd->kind == BMP) && xd->needsave)
1734
	if ((xd->fp = fopen(buf, "wb")) == NULL)
1715
	error("A bmp file can store only one figure.");
1735
	    error("Unable to open file `%s' for writing", buf);
-
 
1736
    }
1716
    if (xd->kind == SCREEN) {
1737
    if (xd->kind == SCREEN) {
1717
#ifdef PLOTHISTORY
1738
#ifdef PLOTHISTORY
1718
	if (xd->recording && xd->needsave)
1739
	if (xd->recording && xd->needsave)
1719
	    AddtoPlotHistory(dd->savedSnapshot, 0);
1740
	    AddtoPlotHistory(dd->savedSnapshot, 0);
1720
	if (xd->replaying)
1741
	if (xd->replaying)
Line 2387... Line 2408...
2387
{
2408
{
2388
    rect r;
2409
    rect r;
2389
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2410
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2390
    r = ggetcliprect(xd->gawin);
2411
    r = ggetcliprect(xd->gawin);
2391
    gsetcliprect(xd->gawin, getrect(xd->gawin));
2412
    gsetcliprect(xd->gawin, getrect(xd->gawin));
-
 
2413
    if(xd->fp) {
2392
    if (xd->kind==PNG) 
2414
	if (xd->kind==PNG) 
2393
	R_SaveAsPng(xd->gawin, xd->windowWidth, xd->windowHeight,
2415
	    R_SaveAsPng(xd->gawin, xd->windowWidth, xd->windowHeight,
2394
		    privategetpixel, 0, xd->fp,
2416
			privategetpixel, 0, xd->fp,
2395
		    R_OPAQUE(xd->bg) ? 0 : xd->pngtrans) ;
2417
			R_OPAQUE(xd->bg) ? 0 : xd->pngtrans) ;
2396
    else if (xd->kind==JPEG)
2418
	else if (xd->kind==JPEG)
2397
	R_SaveAsJpeg(xd->gawin, xd->windowWidth, xd->windowHeight,
2419
	    R_SaveAsJpeg(xd->gawin, xd->windowWidth, xd->windowHeight,
2398
		     privategetpixel, 0, xd->quality, xd->fp) ;
2420
			 privategetpixel, 0, xd->quality, xd->fp) ;
2399
    else 
2421
	else 
2400
	R_SaveAsBmp(xd->gawin, xd->windowWidth, xd->windowHeight,
2422
	    R_SaveAsBmp(xd->gawin, xd->windowWidth, xd->windowHeight,
2401
		    privategetpixel, 0, xd->fp) ;
2423
			privategetpixel, 0, xd->fp);
-
 
2424
	fclose(xd->fp);
-
 
2425
    }
2402
    gsetcliprect(xd->gawin, r);
2426
    gsetcliprect(xd->gawin, r);
2403
    fclose(xd->fp);
2427
    xd->fp = NULL;
2404
}
2428
}
2405
 
2429
 
2406
/* This are the menu item version */
2430
/* These are the menu item versions */
2407
static void SaveAsPng(NewDevDesc *dd,char *fn)
2431
static void SaveAsPng(NewDevDesc *dd,char *fn)
2408
{
2432
{
2409
    FILE *fp;
2433
    FILE *fp;
2410
    rect r;
2434
    rect r;
2411
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2435
    gadesc *xd = (gadesc *) dd->deviceSpecific;