The R Project SVN R

Rev

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

Rev 29864 Rev 30691
Line 169... Line 169...
169
    int fast; /* Use fast fixed-width lines? */
169
    int fast; /* Use fast fixed-width lines? */
170
    unsigned int pngtrans; /* what PNG_TRANS get mapped to */
170
    unsigned int pngtrans; /* what PNG_TRANS get mapped to */
171
    Rboolean buffered;
171
    Rboolean buffered;
172
    int timeafter, timesince;
172
    int timeafter, timesince;
173
    SEXP psenv;
173
    SEXP psenv;
-
 
174
    double res_dpi;
174
} gadesc;
175
} gadesc;
175
 
176
 
176
rect getregion(gadesc *xd)
177
rect getregion(gadesc *xd)
177
{
178
{
178
    rect r = getrect(xd->bm);
179
    rect r = getrect(xd->bm);
Line 281... Line 282...
281
static int Load_Rbitmap_Dll();
282
static int Load_Rbitmap_Dll();
282
void UnLoad_Rbitmap_Dll();
283
void UnLoad_Rbitmap_Dll();
283
static void SaveAsPng(NewDevDesc *dd, char *fn);
284
static void SaveAsPng(NewDevDesc *dd, char *fn);
284
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
285
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
285
static void SaveAsBmp(NewDevDesc *dd, char *fn);
286
static void SaveAsBmp(NewDevDesc *dd, char *fn);
286
static void SaveAsBitmap(NewDevDesc *dd);
287
static void SaveAsBitmap(NewDevDesc *dd, int res);
287
 
288
 
288
static void PrivateCopyDevice(NewDevDesc *dd, NewDevDesc *ndd, char *name)
289
static void PrivateCopyDevice(NewDevDesc *dd, NewDevDesc *ndd, char *name)
289
{
290
{
290
    GEDevDesc* gdd;
291
    GEDevDesc* gdd;
291
    int saveDev = curDevice();
292
    int saveDev = curDevice();
Line 387... Line 388...
387
		       fromDeviceWidth(toDeviceWidth(1.0, GE_NDC, gdd),
388
		       fromDeviceWidth(toDeviceWidth(1.0, GE_NDC, gdd),
388
				       GE_INCHES, gdd),
389
				       GE_INCHES, gdd),
389
		       fromDeviceHeight(toDeviceHeight(-1.0, GE_NDC, gdd),
390
		       fromDeviceHeight(toDeviceHeight(-1.0, GE_NDC, gdd),
390
					GE_INCHES, gdd),
391
					GE_INCHES, gdd),
391
		       (double)0, ((gadesc*) dd->deviceSpecific)->basefontsize,
392
		       (double)0, ((gadesc*) dd->deviceSpecific)->basefontsize,
392
		       0, 1, 0, "", "R Graphics Output"))
393
		       0, 1, 0, "", "R Graphics Output", R_NilValue))
393
	/* horizontal=F, onefile=F, pagecentre=T, print.it=F */
394
	/* horizontal=F, onefile=F, pagecentre=T, print.it=F */
394
	PrivateCopyDevice(dd, ndd, "postscript");
395
	PrivateCopyDevice(dd, ndd, "postscript");
395
}
396
}
396
 
397
 
397
 
398
 
Line 444... Line 445...
444
			fromDeviceWidth(toDeviceWidth(1.0, GE_NDC, gdd),
445
			fromDeviceWidth(toDeviceWidth(1.0, GE_NDC, gdd),
445
					GE_INCHES, gdd),
446
					GE_INCHES, gdd),
446
			fromDeviceHeight(toDeviceHeight(-1.0, GE_NDC, gdd),
447
			fromDeviceHeight(toDeviceHeight(-1.0, GE_NDC, gdd),
447
					 GE_INCHES, gdd),
448
					 GE_INCHES, gdd),
448
			((gadesc*) dd->deviceSpecific)->basefontsize,
449
			((gadesc*) dd->deviceSpecific)->basefontsize,
449
			1, "R Graphics Output"))
450
			1, "R Graphics Output", R_NilValue, 1, 4))
450
	PrivateCopyDevice(dd, ndd, "PDF");
451
	PrivateCopyDevice(dd, ndd, "PDF");
451
}
452
}
452
 
453
 
453
 
454
 
454
 
455
 
Line 1522... Line 1523...
1522
	xd->kind = PRINTER;
1523
	xd->kind = PRINTER;
1523
	xd->gawin = newprinter(MM_PER_INCH * w, MM_PER_INCH * h, &dsp[10]);
1524
	xd->gawin = newprinter(MM_PER_INCH * w, MM_PER_INCH * h, &dsp[10]);
1524
	if (!xd->gawin)
1525
	if (!xd->gawin)
1525
	    return FALSE;
1526
	    return FALSE;
1526
    } else if (!strncmp(dsp, "png:", 4) || !strncmp(dsp,"bmp:", 4)) {
1527
    } else if (!strncmp(dsp, "png:", 4) || !strncmp(dsp,"bmp:", 4)) {
-
 
1528
	xd->res_dpi = (xpos == NA_INTEGER) ? 0 : xpos;
1527
	if(R_OPAQUE(canvascolor))
1529
	if(R_OPAQUE(canvascolor))
1528
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1530
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1529
	else
1531
	else
1530
	    xd->bg = dd->startfill = canvascolor;
1532
	    xd->bg = dd->startfill = canvascolor;
1531
	/* was R_RGB(255, 255, 255); white */
1533
	/* was R_RGB(255, 255, 255); white */
Line 1552... Line 1554...
1552
	    warning("Unable to open file `%s' for writing", buf);
1554
	    warning("Unable to open file `%s' for writing", buf);
1553
	    return FALSE;
1555
	    return FALSE;
1554
	}
1556
	}
1555
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1557
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1556
        char *p = strchr(&dsp[5], ':');
1558
        char *p = strchr(&dsp[5], ':');
-
 
1559
	xd->res_dpi = (xpos == NA_INTEGER) ? 0 : xpos;
1557
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1560
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1558
        xd->kind = JPEG;
1561
        xd->kind = JPEG;
1559
	if (!p) return FALSE;
1562
	if (!p) return FALSE;
1560
	if (!Load_Rbitmap_Dll()) {
1563
	if (!Load_Rbitmap_Dll()) {
1561
	    warning("Unable to load Rbitmap.dll");
1564
	    warning("Unable to load Rbitmap.dll");
Line 1837... Line 1840...
1837
	}
1840
	}
1838
    }
1841
    }
1839
    if ((xd->kind == PNG || xd->kind == JPEG || xd->kind == BMP)
1842
    if ((xd->kind == PNG || xd->kind == JPEG || xd->kind == BMP)
1840
	&& xd->needsave) {
1843
	&& xd->needsave) {
1841
	char buf[600];
1844
	char buf[600];
1842
	SaveAsBitmap(dd);
1845
	SaveAsBitmap(dd, xd->res_dpi);
1843
	snprintf(buf, 600, xd->filename, xd->npage);
1846
	snprintf(buf, 600, xd->filename, xd->npage);
1844
	if ((xd->fp = fopen(buf, "wb")) == NULL)
1847
	if ((xd->fp = fopen(buf, "wb")) == NULL)
1845
	    error("Unable to open file `%s' for writing", buf);
1848
	    error("Unable to open file `%s' for writing", buf);
1846
    }
1849
    }
1847
    if (xd->kind == SCREEN) {
1850
    if (xd->kind == SCREEN) {
Line 1871... Line 1874...
1871
	DRAW(gfillrect(_d, xd->bgcolor, xd->clip));
1874
	DRAW(gfillrect(_d, xd->bgcolor, xd->clip));
1872
    }
1875
    }
1873
    SH;
1876
    SH;
1874
}
1877
}
1875
 
1878
 
-
 
1879
static void deleteGraphMenus(int devnum)
-
 
1880
{
-
 
1881
    char prefix[15];
-
 
1882
 
-
 
1883
    sprintf(prefix, "$Graph%i", devnum);
-
 
1884
    windelmenus(prefix);
-
 
1885
}
-
 
1886
 
1876
	/********************************************************/
1887
	/********************************************************/
1877
	/* device_Close is called when the device is killed	*/
1888
	/* device_Close is called when the device is killed	*/
1878
	/* this function is responsible for destroying any 	*/
1889
	/* this function is responsible for destroying any 	*/
1879
	/* device-specific resources that were created in	*/
1890
	/* device-specific resources that were created in	*/
1880
	/* device_Open and for FREEing the device-specific	*/
1891
	/* device_Open and for FREEing the device-specific	*/
Line 1894... Line 1905...
1894
			      when a windows() device is opened */
1905
			      when a windows() device is opened */
1895
	}
1906
	}
1896
	hide(xd->gawin);
1907
	hide(xd->gawin);
1897
	del(xd->bm);
1908
	del(xd->bm);
1898
	if (xd == GA_xd) GA_xd = NULL;
1909
	if (xd == GA_xd) GA_xd = NULL;
-
 
1910
	deleteGraphMenus(devNumber((DevDesc*) dd) + 1);
1899
    } else if ((xd->kind == PNG) || (xd->kind == JPEG) || (xd->kind == BMP)) {
1911
    } else if ((xd->kind == PNG) || (xd->kind == JPEG) || (xd->kind == BMP)) {
1900
      SaveAsBitmap(dd);
1912
      SaveAsBitmap(dd, xd->res_dpi);
1901
    }
1913
    }
1902
    del(xd->font);
1914
    del(xd->font);
1903
    del(xd->gawin);
1915
    del(xd->gawin);
1904
/*
1916
/*
1905
 * this is needed since the GraphApp delayed clean-up
1917
 * this is needed since the GraphApp delayed clean-up
Line 2545... Line 2557...
2545
    c = ((rgb *)d)[i*png_rows + j];
2557
    c = ((rgb *)d)[i*png_rows + j];
2546
    return c;
2558
    return c;
2547
}
2559
}
2548
 
2560
 
2549
/* This is the device version */
2561
/* This is the device version */
2550
static void SaveAsBitmap(NewDevDesc *dd)
2562
static void SaveAsBitmap(NewDevDesc *dd, int res)
2551
{
2563
{
2552
    rect r, r2;
2564
    rect r, r2;
2553
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2565
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2554
    unsigned char *data;
2566
    unsigned char *data;
2555
 
2567
 
Line 2560... Line 2572...
2560
	if(data) {
2572
	if(data) {
2561
	    png_rows = r2.width;
2573
	    png_rows = r2.width;
2562
	    if (xd->kind == PNG)
2574
	    if (xd->kind == PNG)
2563
		R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2575
		R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2564
			    privategetpixel2, 0, xd->fp,
2576
			    privategetpixel2, 0, xd->fp,
2565
			    R_OPAQUE(xd->bg) ? 0 : xd->pngtrans) ;
2577
			    R_OPAQUE(xd->bg) ? 0 : xd->pngtrans, res) ;
2566
	    else if (xd->kind == JPEG)
2578
	    else if (xd->kind == JPEG)
2567
		R_SaveAsJpeg(data, xd->windowWidth, xd->windowHeight,
2579
		R_SaveAsJpeg(data, xd->windowWidth, xd->windowHeight,
2568
			     privategetpixel2, 0, xd->quality, xd->fp) ;
2580
			     privategetpixel2, 0, xd->quality, xd->fp, res) ;
2569
	    else
2581
	    else
2570
		R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2582
		R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2571
			    privategetpixel2, 0, xd->fp);
2583
			    privategetpixel2, 0, xd->fp, res);
2572
	    free(data);
2584
	    free(data);
2573
	} else
2585
	} else
2574
	    warning("processing of the plot ran out of memory");
2586
	    warning("processing of the plot ran out of memory");
2575
	fclose(xd->fp);
2587
	fclose(xd->fp);
2576
    }
2588
    }
Line 2602... Line 2614...
2602
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2614
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2603
    getbitmapdata2(xd->bm, &data);
2615
    getbitmapdata2(xd->bm, &data);
2604
    if(data) {
2616
    if(data) {
2605
	png_rows = r2.width;
2617
	png_rows = r2.width;
2606
	R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2618
	R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2607
		    privategetpixel2, 0, fp, 0) ;
2619
		    privategetpixel2, 0, fp, 0, 0) ;
2608
	free(data);
2620
	free(data);
2609
    } else
2621
    } else
2610
	warning("processing of the plot ran out of memory");
2622
	warning("processing of the plot ran out of memory");
2611
    /* R_OPAQUE(xd->bg) ? 0 : xd->canvascolor) ; */
2623
    /* R_OPAQUE(xd->bg) ? 0 : xd->canvascolor) ; */
2612
    gsetcliprect(xd->bm, r);
2624
    gsetcliprect(xd->bm, r);
Line 2635... Line 2647...
2635
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2647
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2636
    getbitmapdata2(xd->bm, &data);
2648
    getbitmapdata2(xd->bm, &data);
2637
    if(data) {
2649
    if(data) {
2638
	png_rows = r2.width;
2650
	png_rows = r2.width;
2639
	R_SaveAsJpeg(data,xd->windowWidth, xd->windowHeight,
2651
	R_SaveAsJpeg(data,xd->windowWidth, xd->windowHeight,
2640
		     privategetpixel2, 0, quality, fp) ;
2652
		     privategetpixel2, 0, quality, fp, 0) ;
2641
	free(data);
2653
	free(data);
2642
    } else
2654
    } else
2643
	warning("processing of the plot ran out of memory");
2655
	warning("processing of the plot ran out of memory");
2644
    gsetcliprect(xd->bm, r);
2656
    gsetcliprect(xd->bm, r);
2645
    fclose(fp);
2657
    fclose(fp);
Line 2670... Line 2682...
2670
 
2682
 
2671
    getbitmapdata2(xd->bm, &data);
2683
    getbitmapdata2(xd->bm, &data);
2672
    if(data) {
2684
    if(data) {
2673
	png_rows = r2.width;
2685
	png_rows = r2.width;
2674
	R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2686
	R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2675
		    privategetpixel2, 0, fp) ;
2687
		    privategetpixel2, 0, fp, 0) ;
2676
	free(data);
2688
	free(data);
2677
    } else
2689
    } else
2678
	warning("processing of the plot ran out of memory");
2690
	warning("processing of the plot ran out of memory");
2679
    gsetcliprect(xd->bm, r);
2691
    gsetcliprect(xd->bm, r);
2680
    fclose(fp);
2692
    fclose(fp);
Line 2719... Line 2731...
2719
    if (!gdd) return(0);
2731
    if (!gdd) return(0);
2720
    xd = (gadesc *) gdd->dev->deviceSpecific;
2732
    xd = (gadesc *) gdd->dev->deviceSpecific;
2721
    if (!xd) return(0);
2733
    if (!xd) return(0);
2722
    return(getHandle(xd->gawin));
2734
    return(getHandle(xd->gawin));
2723
}
2735
}
-
 
2736
 
-
 
2737
/* This assumes a menuname of the form $Graph<nn>Main, $Graph<nn>Popup, $Graph<nn>LocMain,
-
 
2738
   or $Graph<nn>LocPopup where <nn> is the
-
 
2739
   device number.  We've already checked the $Graph prefix. */
-
 
2740
 
-
 
2741
menu getGraphMenu(char* menuname)
-
 
2742
{
-
 
2743
    int devnum;
-
 
2744
    GEDevDesc *gdd;
-
 
2745
    gadesc *xd;
-
 
2746
 
-
 
2747
    menuname = menuname + 6;
-
 
2748
    devnum = atoi(menuname);
-
 
2749
    if(devnum < 1 || devnum > R_MaxDevices)
-
 
2750
    	error("invalid graph device number");
-
 
2751
 
-
 
2752
    while (('0' <= *menuname) && (*menuname <= '9')) menuname++;
-
 
2753
 
-
 
2754
    gdd = (GEDevDesc*) GetDevice(devnum - 1);
-
 
2755
 
-
 
2756
    if(!gdd) error("invalid device");
-
 
2757
 
-
 
2758
    xd = (gadesc *) gdd->dev->deviceSpecific;
-
 
2759
 
-
 
2760
    if(!xd || xd->kind != SCREEN) error("bad device");
-
 
2761
 
-
 
2762
    if (strcmp(menuname, "Main") == 0) return(xd->mbar);
-
 
2763
    else if (strcmp(menuname, "Popup") == 0) return(xd->grpopup);
-
 
2764
    else return(NULL);
-
 
2765
}
-
 
2766