The R Project SVN R

Rev

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

Rev 15590 Rev 15641
Line 30... Line 30...
30
#include "Graphics.h"
30
#include "Graphics.h"
31
#include "R_ext/Error.h"
31
#include "R_ext/Error.h"
32
#include "Fileio.h"
32
#include "Fileio.h"
33
#include <Rdevices.h>
33
#include <Rdevices.h>
34
 
34
 
-
 
35
#define INVALID_COL 0xff0a0b0c
-
 
36
 
35
/* Define this to use hyphen except in -[0-9] */
37
/* Define this to use hyphen except in -[0-9] */
36
#undef USE_HYPHEN
38
#undef USE_HYPHEN
37
/* In ISOLatin1, minus is 45 and hyphen is 173 */
39
/* In ISOLatin1, minus is 45 and hyphen is 173 */
38
#ifdef USE_HYPHEN
40
#ifdef USE_HYPHEN
39
static char PS_hyphen = 173;
41
static char PS_hyphen = 173;
Line 1226... Line 1228...
1226
 
1228
 
1227
    pd->current.fontsize = -1;
1229
    pd->current.fontsize = -1;
1228
    pd->current.fontstyle = -1;
1230
    pd->current.fontstyle = -1;
1229
    pd->current.lwd = -1;
1231
    pd->current.lwd = -1;
1230
    pd->current.lty = -1;
1232
    pd->current.lty = -1;
1231
    pd->current.col = 0xffffffff;
1233
    pd->current.col = INVALID_COL;
1232
    pd->current.fill = 0xffffffff;
1234
    pd->current.fill = INVALID_COL;
1233
    pd->current.bg = 0xffffffff;
1235
    pd->current.bg = INVALID_COL;
1234
}
1236
}
1235
 
1237
 
1236
static void PS_Clip(double x0, double x1, double y0, double y1, DevDesc *dd)
1238
static void PS_Clip(double x0, double x1, double y0, double y1, DevDesc *dd)
1237
{
1239
{
1238
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
1240
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
Line 1261... Line 1263...
1261
	pd->pageno++;
1263
	pd->pageno++;
1262
    } else pd->pageno++;
1264
    } else pd->pageno++;
1263
    PostScriptStartPage(pd->psfp, pd->pageno);
1265
    PostScriptStartPage(pd->psfp, pd->pageno);
1264
    Invalidate(dd);
1266
    Invalidate(dd);
1265
 
1267
 
1266
    if(dd->gp.bg != R_RGB(255,255,255)) {
1268
    if(R_ALPHA(dd->gp.bg) == 0) {
1267
	PS_Rect(0, 0, 72.0 * pd->pagewidth, 72.0 * pd->pageheight,
1269
	PS_Rect(0, 0, 72.0 * pd->pagewidth, 72.0 * pd->pageheight,
1268
		DEVICE, dd->gp.bg, NA_INTEGER, dd);
1270
		DEVICE, dd->gp.bg, NA_INTEGER, dd);
1269
    }
1271
    }
1270
}
1272
}
1271
 
1273
 
Line 1368... Line 1370...
1368
    /* code == 0, nothing to draw */
1370
    /* code == 0, nothing to draw */
1369
    /* code == 1, outline only */
1371
    /* code == 1, outline only */
1370
    /* code == 2, fill only */
1372
    /* code == 2, fill only */
1371
    /* code == 3, outline and fill */
1373
    /* code == 3, outline and fill */
1372
 
1374
 
1373
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
1375
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
1374
 
1376
 
1375
    if (code) {
1377
    if (code) {
1376
	if(code & 2)
1378
	if(code & 2)
1377
	    SetFill(bg, dd);
1379
	    SetFill(bg, dd);
1378
	if(code & 1) {
1380
	if(code & 1) {
Line 1396... Line 1398...
1396
    /* code == 0, nothing to draw */
1398
    /* code == 0, nothing to draw */
1397
    /* code == 1, outline only */
1399
    /* code == 1, outline only */
1398
    /* code == 2, fill only */
1400
    /* code == 2, fill only */
1399
    /* code == 3, outline and fill */
1401
    /* code == 3, outline and fill */
1400
 
1402
 
1401
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
1403
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
1402
 
1404
 
1403
    if (code) {
1405
    if (code) {
1404
	if(code & 2)
1406
	if(code & 2)
1405
	    SetFill(bg, dd);
1407
	    SetFill(bg, dd);
1406
	if(code & 1) {
1408
	if(code & 1) {
Line 1419... Line 1421...
1419
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
1421
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
1420
 
1422
 
1421
    GConvert(&x1, &y1, coords, DEVICE, dd);
1423
    GConvert(&x1, &y1, coords, DEVICE, dd);
1422
    GConvert(&x2, &y2, coords, DEVICE, dd);
1424
    GConvert(&x2, &y2, coords, DEVICE, dd);
1423
    /* FIXME : clip to the device extents here */
1425
    /* FIXME : clip to the device extents here */
-
 
1426
    if(R_ALPHA(dd->gp.col) == 0) {
1424
    SetColor(dd->gp.col, dd);
1427
	SetColor(dd->gp.col, dd);
1425
    SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
1428
	SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
1426
    PostScriptStartPath(pd->psfp);
1429
	PostScriptStartPath(pd->psfp);
1427
    PostScriptMoveTo(pd->psfp, x1, y1);
1430
	PostScriptMoveTo(pd->psfp, x1, y1);
1428
    PostScriptLineTo(pd->psfp, x2, y2);
1431
	PostScriptLineTo(pd->psfp, x2, y2);
1429
    PostScriptEndPath(pd->psfp);
1432
	PostScriptEndPath(pd->psfp);
-
 
1433
    }
1430
}
1434
}
1431
 
1435
 
1432
static void PS_Polygon(int n, double *x, double *y, int coords,
1436
static void PS_Polygon(int n, double *x, double *y, int coords,
1433
		       int bg, int fg, DevDesc *dd)
1437
		       int bg, int fg, DevDesc *dd)
1434
{
1438
{
Line 1442... Line 1446...
1442
    /* code == 0, nothing to draw */
1446
    /* code == 0, nothing to draw */
1443
    /* code == 1, outline only */
1447
    /* code == 1, outline only */
1444
    /* code == 2, fill only */
1448
    /* code == 2, fill only */
1445
    /* code == 3, outline and fill */
1449
    /* code == 3, outline and fill */
1446
 
1450
 
1447
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
1451
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
1448
 
1452
 
1449
    if (code) {
1453
    if (code) {
1450
	if(code & 2)
1454
	if(code & 2)
1451
	    SetFill(bg, dd);
1455
	    SetFill(bg, dd);
1452
	if(code & 1) {
1456
	if(code & 1) {
Line 1474... Line 1478...
1474
    PostScriptDesc *pd;
1478
    PostScriptDesc *pd;
1475
    double xx, yy;
1479
    double xx, yy;
1476
    int i;
1480
    int i;
1477
 
1481
 
1478
    pd = (PostScriptDesc*) dd->deviceSpecific;
1482
    pd = (PostScriptDesc*) dd->deviceSpecific;
-
 
1483
    if(R_ALPHA(dd->gp.col) == 0) {
1479
    SetColor(dd->gp.col, dd);
1484
	SetColor(dd->gp.col, dd);
1480
    SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
1485
	SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
1481
    fprintf(pd->psfp, "np\n");
1486
	fprintf(pd->psfp, "np\n");
1482
    xx = x[0];
-
 
1483
    yy = y[0];
-
 
1484
    GConvert(&xx, &yy, coords, DEVICE, dd);
-
 
1485
    fprintf(pd->psfp, "%.2f %.2f m\n", xx, yy);
-
 
1486
    for(i = 1 ; i < n ; i++) {
-
 
1487
	xx = x[i];
1487
	xx = x[0];
1488
	yy = y[i];
1488
	yy = y[0];
1489
	GConvert(&xx, &yy, coords, DEVICE, dd);
1489
	GConvert(&xx, &yy, coords, DEVICE, dd);
1490
	fprintf(pd->psfp, "%.2f %.2f l\n", xx, yy);
1490
	fprintf(pd->psfp, "%.2f %.2f m\n", xx, yy);
-
 
1491
	for(i = 1 ; i < n ; i++) {
-
 
1492
	    xx = x[i];
-
 
1493
	    yy = y[i];
-
 
1494
	    GConvert(&xx, &yy, coords, DEVICE, dd);
-
 
1495
	    fprintf(pd->psfp, "%.2f %.2f l\n", xx, yy);
-
 
1496
	}
-
 
1497
	fprintf(pd->psfp, "o\n");
1491
    }
1498
    }
1492
    fprintf(pd->psfp, "o\n");
-
 
1493
}
1499
}
1494
 
1500
 
-
 
1501
 
1495
static void PS_Text(double x, double y, int coords,
1502
static void PS_Text(double x, double y, int coords,
1496
		    char *str, double rot, double hadj, DevDesc *dd)
1503
		    char *str, double rot, double hadj, DevDesc *dd)
1497
{
1504
{
1498
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
1505
    PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
1499
 
1506
 
1500
    GConvert(&x, &y, coords, DEVICE, dd);
1507
    GConvert(&x, &y, coords, DEVICE, dd);
1501
    SetFont(dd->gp.font, (int)floor(dd->gp.cex * dd->gp.ps + 0.5), dd);
1508
    SetFont(dd->gp.font, (int)floor(dd->gp.cex * dd->gp.ps + 0.5), dd);
-
 
1509
    if(R_ALPHA(dd->gp.col) == 0) {
1502
    SetColor(dd->gp.col, dd);
1510
	SetColor(dd->gp.col, dd);
1503
    PostScriptText(pd->psfp, x, y, str, hadj, 0.0, rot);
1511
	PostScriptText(pd->psfp, x, y, str, hadj, 0.0, rot);
-
 
1512
    }
1504
}
1513
}
1505
 
1514
 
1506
static Rboolean PS_Locator(double *x, double *y, DevDesc *dd)
1515
static Rboolean PS_Locator(double *x, double *y, DevDesc *dd)
1507
{
1516
{
1508
    return FALSE;
1517
    return FALSE;
Line 1970... Line 1979...
1970
	pd->tmpfp = R_fopen(pd->tmpname, "w");
1979
	pd->tmpfp = R_fopen(pd->tmpname, "w");
1971
	XF_FileHeader(pd->psfp, pd->papername, pd->landscape, pd->onefile);
1980
	XF_FileHeader(pd->psfp, pd->papername, pd->landscape, pd->onefile);
1972
	pd->XFigColors[7] = 0xffffff;
1981
	pd->XFigColors[7] = 0xffffff;
1973
	pd->nXFigColors = 32;
1982
	pd->nXFigColors = 32;
1974
    }
1983
    }
1975
     if(dd->dp.bg != R_RGB(255,255,255)) {
1984
     if(R_ALPHA(dd->dp.bg) == 0) {
1976
	 int cbg = XF_SetColor(dd->dp.bg, pd);
1985
	 int cbg = XF_SetColor(dd->dp.bg, pd);
1977
	 int ix0, iy0, ix1, iy1;
1986
	 int ix0, iy0, ix1, iy1;
1978
	 double x0 = 0.0, y0 = 0.0, x1 = 72.0 * pd->pagewidth,
1987
	 double x0 = 0.0, y0 = 0.0, x1 = 72.0 * pd->pagewidth,
1979
	     y1 = 72.0 * pd->pageheight;
1988
	     y1 = 72.0 * pd->pageheight;
1980
	 XFconvert(&x0, &y0, pd); XFconvert(&x1, &y1, pd);
1989
	 XFconvert(&x0, &y0, pd); XFconvert(&x1, &y1, pd);
Line 2026... Line 2035...
2026
    FILE *fp = pd->tmpfp;
2035
    FILE *fp = pd->tmpfp;
2027
    int ix0, iy0, ix1, iy1;
2036
    int ix0, iy0, ix1, iy1;
2028
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2037
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2029
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2038
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2030
 
2039
 
2031
    cpen = (fg != NA_INTEGER)? cfg: -1;
2040
    cpen = (R_ALPHA(fg) == 0)? cfg: -1;
2032
    dofill = (bg != NA_INTEGER)? 20: -1;
2041
    dofill = (R_ALPHA(bg) == 0)? 20: -1;
2033
 
2042
 
2034
    GConvert(&x0, &y0, coords, DEVICE, dd); XFconvert(&x0, &y0, pd);
2043
    GConvert(&x0, &y0, coords, DEVICE, dd); XFconvert(&x0, &y0, pd);
2035
    GConvert(&x1, &y1, coords, DEVICE, dd); XFconvert(&x1, &y1, pd);
2044
    GConvert(&x1, &y1, coords, DEVICE, dd); XFconvert(&x1, &y1, pd);
2036
    ix0 = (int)x0; iy0 = (int)y0; ix1 = (int)x1; iy1 = (int)y1;
2045
    ix0 = (int)x0; iy0 = (int)y0; ix1 = (int)x1; iy1 = (int)y1;
2037
    fprintf(fp, "2 2 "); /* Polyline */
2046
    fprintf(fp, "2 2 "); /* Polyline */
Line 2054... Line 2063...
2054
    FILE *fp = pd->tmpfp;
2063
    FILE *fp = pd->tmpfp;
2055
    int ix, iy, ir;
2064
    int ix, iy, ir;
2056
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2065
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2057
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2066
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2058
 
2067
 
2059
    cpen = (fg != NA_INTEGER)? cfg: -1;
2068
    cpen = (R_ALPHA(fg) == 0)? cfg: -1;
2060
    dofill = (bg != NA_INTEGER)? 20: -1;
2069
    dofill = (R_ALPHA(bg) == 0)? 20: -1;
2061
 
2070
 
2062
    GConvert(&x, &y, coords, DEVICE, dd); XFconvert(&x, &y, pd);
2071
    GConvert(&x, &y, coords, DEVICE, dd); XFconvert(&x, &y, pd);
2063
    ix = (int)x; iy = (int)y; ir = (int)(16.667*r);
2072
    ix = (int)x; iy = (int)y; ir = (int)(16.667*r);
2064
 
2073
 
2065
    fprintf(fp, "1 3 "); /* Circle + radius */
2074
    fprintf(fp, "1 3 "); /* Circle + radius */
Line 2078... Line 2087...
2078
    FILE *fp = pd->tmpfp;
2087
    FILE *fp = pd->tmpfp;
2079
    int lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2088
    int lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2080
 
2089
 
2081
    GConvert(&x1, &y1, coords, DEVICE, dd); XFconvert(&x1, &y1, pd);
2090
    GConvert(&x1, &y1, coords, DEVICE, dd); XFconvert(&x1, &y1, pd);
2082
    GConvert(&x2, &y2, coords, DEVICE, dd); XFconvert(&x2, &y2, pd);
2091
    GConvert(&x2, &y2, coords, DEVICE, dd); XFconvert(&x2, &y2, pd);
-
 
2092
    if(R_ALPHA(dd->gp.col) == 0) {
2083
    fprintf(fp, "2 1 "); /* Polyline */
2093
	fprintf(fp, "2 1 "); /* Polyline */
2084
    fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2094
	fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2085
    fprintf(fp, "%d %d ", XF_SetColor(dd->gp.col, pd), 7);
2095
	fprintf(fp, "%d %d ", XF_SetColor(dd->gp.col, pd), 7);
2086
      /* pen colour fill colour */
2096
	/* pen colour fill colour */
2087
    fprintf(fp, "100 0 -1 "); /* depth, pen style, area fill */
2097
	fprintf(fp, "100 0 -1 "); /* depth, pen style, area fill */
2088
    fprintf(fp, "%.2f 0 0 -1 0 0 ", 4.0*lwd); /* style value, join .... */
2098
	fprintf(fp, "%.2f 0 0 -1 0 0 ", 4.0*lwd); /* style value, join .... */
2089
    fprintf(fp, "%d\n", 2); /* number of points */
2099
	fprintf(fp, "%d\n", 2); /* number of points */
2090
    fprintf(fp, "%d %d %d %d\n", (int)x1, (int)y1, (int)x2, (int)y2);
2100
	fprintf(fp, "%d %d %d %d\n", (int)x1, (int)y1, (int)x2, (int)y2);
-
 
2101
    }
2091
}
2102
}
2092
 
2103
 
2093
static void XFig_Polygon(int n, double *x, double *y, int coords,
2104
static void XFig_Polygon(int n, double *x, double *y, int coords,
2094
			 int bg, int fg, DevDesc *dd)
2105
			 int bg, int fg, DevDesc *dd)
2095
{
2106
{
Line 2098... Line 2109...
2098
    double xx, yy;
2109
    double xx, yy;
2099
    int i;
2110
    int i;
2100
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2111
    int cbg = XF_SetColor(bg, pd), cfg = XF_SetColor(fg, pd), cpen,
2101
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2112
	dofill, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2102
 
2113
 
2103
 
-
 
2104
    cpen = (fg != NA_INTEGER)? cfg: -1;
2114
    cpen = (R_ALPHA(fg) == 0)? cfg: -1;
2105
    dofill = (bg != NA_INTEGER)? 20: -1;
2115
    dofill = (R_ALPHA(bg) == 0)? 20: -1;
2106
 
2116
 
2107
    fprintf(fp, "2 3 "); /* Polyline */
2117
    fprintf(fp, "2 3 "); /* Polyline */
2108
    fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2118
    fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2109
    fprintf(fp, "%d %d ", cpen, cbg); /* pen colour fill colour */
2119
    fprintf(fp, "%d %d ", cpen, cbg); /* pen colour fill colour */
2110
    fprintf(fp, "100 0 %d ", dofill); /* depth, pen style, area fill */
2120
    fprintf(fp, "100 0 %d ", dofill); /* depth, pen style, area fill */
Line 2125... Line 2135...
2125
    XFigDesc *pd = (XFigDesc*) dd->deviceSpecific;
2135
    XFigDesc *pd = (XFigDesc*) dd->deviceSpecific;
2126
    FILE *fp = pd->tmpfp;
2136
    FILE *fp = pd->tmpfp;
2127
    double xx, yy;
2137
    double xx, yy;
2128
    int i, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2138
    int i, lty = XF_SetLty(dd->gp.lty), lwd = dd->gp.lwd*0.833 + 0.5;
2129
 
2139
 
-
 
2140
    if(R_ALPHA(dd->gp.col) == 0) {
2130
    fprintf(fp, "2 1 "); /* Polyline */
2141
	fprintf(fp, "2 1 "); /* Polyline */
2131
    fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2142
	fprintf(fp, "%d %d ", lty, lwd>0?lwd:1); /* style, thickness */
2132
    fprintf(fp, "%d %d ", XF_SetColor(dd->gp.col, pd), 7); /* pen colour fill colour */
2143
	fprintf(fp, "%d %d ", XF_SetColor(dd->gp.col, pd), 7); /* pen colour fill colour */
2133
    fprintf(fp, "100 0 -1 "); /* depth, pen style, area fill */
2144
	fprintf(fp, "100 0 -1 "); /* depth, pen style, area fill */
2134
    fprintf(fp, "%.2f 0 0 -1 0 0 ", 4.0*lwd); /* style value, join .... */
2145
	fprintf(fp, "%.2f 0 0 -1 0 0 ", 4.0*lwd); /* style value, join .... */
2135
    fprintf(fp, "%d\n", n); /* number of points */
2146
	fprintf(fp, "%d\n", n); /* number of points */
2136
    for(i = 0 ; i < n ; i++) {
2147
	for(i = 0 ; i < n ; i++) {
2137
	xx = x[i];
2148
	    xx = x[i];
2138
	yy = y[i];
2149
	    yy = y[i];
2139
	GConvert(&xx, &yy, coords, DEVICE, dd); XFconvert(&xx, &yy, pd);
2150
	    GConvert(&xx, &yy, coords, DEVICE, dd); XFconvert(&xx, &yy, pd);
2140
	fprintf(fp, "  %d %d\n", (int)xx, (int)yy);
2151
	    fprintf(fp, "  %d %d\n", (int)xx, (int)yy);
-
 
2152
	}
2141
    }
2153
    }
2142
}
2154
}
2143
 
2155
 
2144
static int styles[4] = {0,2,1,3};
2156
static int styles[4] = {0,2,1,3};
2145
 
2157
 
Line 2156... Line 2168...
2156
    pd->fontstyle = style;
2168
    pd->fontstyle = style;
2157
    if(style == 5) fontnum = 32;
2169
    if(style == 5) fontnum = 32;
2158
    else fontnum = pd->fontnum + styles[style-1];
2170
    else fontnum = pd->fontnum + styles[style-1];
2159
 
2171
 
2160
    GConvert(&x, &y, coords, DEVICE, dd); XFconvert(&x, &y, pd);
2172
    GConvert(&x, &y, coords, DEVICE, dd); XFconvert(&x, &y, pd);
-
 
2173
    if(R_ALPHA(dd->gp.col) == 0) {
2161
    fprintf(fp, "4 %d ", (int)floor(2*hadj)); /* Text, how justified */
2174
	fprintf(fp, "4 %d ", (int)floor(2*hadj)); /* Text, how justified */
2162
    fprintf(fp, "%d 100 0 ", XF_SetColor(dd->gp.col, pd));
2175
	fprintf(fp, "%d 100 0 ", XF_SetColor(dd->gp.col, pd));
2163
      /* color, depth, pen_style */
2176
	/* color, depth, pen_style */
2164
    fprintf(fp, "%d %d %.4f 4 ", fontnum, (int)size, rot * DEG2RAD);
2177
	fprintf(fp, "%d %d %.4f 4 ", fontnum, (int)size, rot * DEG2RAD);
2165
      /* font pointsize angle flags (Postscript font) */
2178
	/* font pointsize angle flags (Postscript font) */
2166
    fprintf(fp, "%d %d ", (int)(16.667*GStrHeight(str, DEVICE, dd)+0.5),
2179
	fprintf(fp, "%d %d ", (int)(16.667*GStrHeight(str, DEVICE, dd)+0.5),
2167
	    (int)(16.667*GStrWidth(str, DEVICE, dd)+0.5));
2180
		(int)(16.667*GStrWidth(str, DEVICE, dd)+0.5));
2168
    fprintf(fp, "%d %d ", (int)x, (int)y);
2181
	fprintf(fp, "%d %d ", (int)x, (int)y);
2169
    XF_WriteString(fp, str);
2182
	XF_WriteString(fp, str);
2170
    fprintf(fp, "\\001\n");
2183
	fprintf(fp, "\\001\n");
-
 
2184
    }
2171
}
2185
}
2172
 
2186
 
2173
static Rboolean XFig_Locator(double *x, double *y, DevDesc *dd)
2187
static Rboolean XFig_Locator(double *x, double *y, DevDesc *dd)
2174
{
2188
{
2175
    return FALSE;
2189
    return FALSE;
Line 2407... Line 2421...
2407
    pd->current.lwd = 1;
2421
    pd->current.lwd = 1;
2408
    pd->current.lty = -1;
2422
    pd->current.lty = -1;
2409
    /* page starts with black as the default fill and stroke colours */
2423
    /* page starts with black as the default fill and stroke colours */
2410
    pd->current.col = 0;
2424
    pd->current.col = 0;
2411
    pd->current.fill = 0;
2425
    pd->current.fill = 0;
2412
    pd->current.bg = 0xffffffff;
2426
    pd->current.bg = INVALID_COL;
2413
}
2427
}
2414
 
2428
 
2415
static void PDF_SetLineColor(int color, DevDesc *dd)
2429
static void PDF_SetLineColor(int color, DevDesc *dd)
2416
{
2430
{
2417
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2431
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
Line 2686... Line 2700...
2686
	    pd->nobjs, pd->nobjs + 1);
2700
	    pd->nobjs, pd->nobjs + 1);
2687
    pd->startstream = (int) ftell(pd->pdffp);
2701
    pd->startstream = (int) ftell(pd->pdffp);
2688
    fprintf(pd->pdffp, "1 J 1 j 10 M q\n");
2702
    fprintf(pd->pdffp, "1 J 1 j 10 M q\n");
2689
    PDF_Invalidate(dd);
2703
    PDF_Invalidate(dd);
2690
 
2704
 
2691
    if(dd->gp.bg != R_RGB(255,255,255)) {
2705
    if(R_ALPHA(dd->gp.bg) == 0) {
2692
	PDF_SetFill(dd->gp.bg, dd);
2706
	PDF_SetFill(dd->gp.bg, dd);
2693
	fprintf(pd->pdffp, "0 0 %.2f %.2f re f\n",
2707
	fprintf(pd->pdffp, "0 0 %.2f %.2f re f\n",
2694
		72.0 * pd->width, 72.0 * pd->height);
2708
		72.0 * pd->width, 72.0 * pd->height);
2695
    }
2709
    }
2696
    pd->inText = FALSE;
2710
    pd->inText = FALSE;
Line 2712... Line 2726...
2712
		      int bg, int fg, DevDesc *dd)
2726
		      int bg, int fg, DevDesc *dd)
2713
{
2727
{
2714
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2728
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2715
    int code;
2729
    int code;
2716
 
2730
 
2717
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
2731
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
2718
    if (code) {
2732
    if (code) {
2719
	if(pd->inText) textoff(pd);
2733
	if(pd->inText) textoff(pd);
2720
	if(code & 2)
2734
	if(code & 2)
2721
	    PDF_SetFill(bg, dd);
2735
	    PDF_SetFill(bg, dd);
2722
	if(code & 1) {
2736
	if(code & 1) {
Line 2742... Line 2756...
2742
    int code, tr;
2756
    int code, tr;
2743
    double xx, yy, a;
2757
    double xx, yy, a;
2744
 
2758
 
2745
    GConvert(&x, &y, coords, DEVICE, dd);
2759
    GConvert(&x, &y, coords, DEVICE, dd);
2746
 
2760
 
2747
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
2761
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
2748
 
2762
 
2749
    if (code) {
2763
    if (code) {
2750
	if(code & 2)
2764
	if(code & 2)
2751
	    PDF_SetFill(bg, dd);
2765
	    PDF_SetFill(bg, dd);
2752
	if(code & 1) {
2766
	if(code & 1) {
Line 2778... Line 2792...
2778
	       centre = (0.396, 0.347) * size
2792
	       centre = (0.396, 0.347) * size
2779
	    */
2793
	    */
2780
	    a = 2./0.722 * r;
2794
	    a = 2./0.722 * r;
2781
	    xx = x - 0.396*a;
2795
	    xx = x - 0.396*a;
2782
	    yy = y - 0.347*a;
2796
	    yy = y - 0.347*a;
2783
	    tr = (bg != NA_INTEGER) + 2 * (fg != NA_INTEGER) - 1;
2797
	    tr = (R_ALPHA(bg) == 0) + 2 * (R_ALPHA(fg) == 0) - 1;
2784
	    if(!pd->inText) texton(pd);
2798
	    if(!pd->inText) texton(pd);
2785
	    fprintf(pd->pdffp, 
2799
	    fprintf(pd->pdffp, 
2786
		    "/F6 1 Tf %d Tr %.2f 0 0 %.2f %.2f %.2f Tm", 
2800
		    "/F6 1 Tf %d Tr %.2f 0 0 %.2f %.2f %.2f Tm", 
2787
		    tr, a, a, xx, yy);
2801
		    tr, a, a, xx, yy);
2788
	    fprintf(pd->pdffp, " (l) Tj 0 Tr\n");	    
2802
	    fprintf(pd->pdffp, " (l) Tj 0 Tr\n");	    
Line 2793... Line 2807...
2793
static void PDF_Line(double x1, double y1, double x2, double y2,
2807
static void PDF_Line(double x1, double y1, double x2, double y2,
2794
		    int coords, DevDesc *dd)
2808
		    int coords, DevDesc *dd)
2795
{
2809
{
2796
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2810
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2797
 
2811
 
-
 
2812
    if(R_ALPHA(dd->gp.col) == 0) {
2798
    PDF_SetLineColor(dd->gp.col, dd);
2813
	PDF_SetLineColor(dd->gp.col, dd);
2799
    PDF_SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
2814
	PDF_SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
2800
    GConvert(&x1, &y1, coords, DEVICE, dd);
2815
	GConvert(&x1, &y1, coords, DEVICE, dd);
2801
    GConvert(&x2, &y2, coords, DEVICE, dd);
2816
	GConvert(&x2, &y2, coords, DEVICE, dd);
2802
    if(pd->inText) textoff(pd);
2817
	if(pd->inText) textoff(pd);
2803
    fprintf(pd->pdffp, "%.2f %.2f m %.2f %.2f l S\n", x1, y1, x2, y2);
2818
	fprintf(pd->pdffp, "%.2f %.2f m %.2f %.2f l S\n", x1, y1, x2, y2);
-
 
2819
    }
2804
}
2820
}
2805
 
2821
 
2806
static void PDF_Polygon(int n, double *x, double *y, int coords,
2822
static void PDF_Polygon(int n, double *x, double *y, int coords,
2807
			 int bg, int fg, DevDesc *dd)
2823
			 int bg, int fg, DevDesc *dd)
2808
{
2824
{
2809
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2825
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
2810
    double xx, yy;
2826
    double xx, yy;
2811
    int i, code;
2827
    int i, code;
2812
 
2828
 
2813
    code = 2 * (bg != NA_INTEGER) + (fg != NA_INTEGER);
2829
    code = 2 * (R_ALPHA(bg) == 0) + (R_ALPHA(fg) == 0);
2814
 
2830
 
2815
    if (code) {
2831
    if (code) {
2816
	if(pd->inText) textoff(pd);
2832
	if(pd->inText) textoff(pd);
2817
	if(code & 2)
2833
	if(code & 2)
2818
	    PDF_SetFill(bg, dd);
2834
	    PDF_SetFill(bg, dd);
Line 2845... Line 2861...
2845
    PDFDesc *pd = (PDFDesc*) dd->deviceSpecific;
2861
    PDFDesc *pd = (PDFDesc*) dd->deviceSpecific;
2846
    double xx, yy;
2862
    double xx, yy;
2847
    int i;
2863
    int i;
2848
 
2864
 
2849
    if(pd->inText) textoff(pd);
2865
    if(pd->inText) textoff(pd);
-
 
2866
    if(R_ALPHA(dd->gp.col) == 0) {
2850
    PDF_SetLineColor(dd->gp.col, dd);
2867
	PDF_SetLineColor(dd->gp.col, dd);
2851
    PDF_SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
2868
	PDF_SetLineStyle(dd->gp.lty, dd->gp.lwd, dd);
2852
    xx = x[0];
-
 
2853
    yy = y[0];
-
 
2854
    GConvert(&xx, &yy, coords, DEVICE, dd);
-
 
2855
    fprintf(pd->pdffp, "%.2f %.2f m\n", xx, yy);
-
 
2856
    for(i = 1 ; i < n ; i++) {
-
 
2857
	xx = x[i];
2869
	xx = x[0];
2858
	yy = y[i];
2870
	yy = y[0];
2859
	GConvert(&xx, &yy, coords, DEVICE, dd);
2871
	GConvert(&xx, &yy, coords, DEVICE, dd);
2860
	fprintf(pd->pdffp, "%.2f %.2f l\n", xx, yy);
2872
	fprintf(pd->pdffp, "%.2f %.2f m\n", xx, yy);
-
 
2873
	for(i = 1 ; i < n ; i++) {
-
 
2874
	    xx = x[i];
-
 
2875
	    yy = y[i];
-
 
2876
	    GConvert(&xx, &yy, coords, DEVICE, dd);
-
 
2877
	    fprintf(pd->pdffp, "%.2f %.2f l\n", xx, yy);
-
 
2878
	}
-
 
2879
	fprintf(pd->pdffp, "S\n");
2861
    }
2880
    }
2862
    fprintf(pd->pdffp, "S\n");
-
 
2863
}
2881
}
2864
 
2882
 
2865
 
2883
 
2866
static void PDF_Text(double x, double y, int coords,
2884
static void PDF_Text(double x, double y, int coords,
2867
		     char *str, double rot, double hadj, DevDesc *dd)
2885
		     char *str, double rot, double hadj, DevDesc *dd)
Line 2874... Line 2892...
2874
    rot1 = rot * DEG2RAD;
2892
    rot1 = rot * DEG2RAD;
2875
    a = size * cos(rot1);
2893
    a = size * cos(rot1);
2876
    b = size * sin(rot1);
2894
    b = size * sin(rot1);
2877
    GConvert(&x, &y, coords, DEVICE, dd);
2895
    GConvert(&x, &y, coords, DEVICE, dd);
2878
    if(!pd->inText) texton(pd);
2896
    if(!pd->inText) texton(pd);
-
 
2897
    if(R_ALPHA(dd->gp.col) == 0) {
2879
    PDF_SetFill(dd->gp.col, dd);
2898
	PDF_SetFill(dd->gp.col, dd);
2880
    fprintf(pd->pdffp, "/F%d 1 Tf %.2f %.2f %.2f %.2f %.2f %.2f Tm ", 
2899
	fprintf(pd->pdffp, "/F%d 1 Tf %.2f %.2f %.2f %.2f %.2f %.2f Tm ", 
2881
	    face, a, b, -b, a, x, y);
2900
		face, a, b, -b, a, x, y);
2882
    PostScriptWriteString(pd->pdffp, str);
2901
	PostScriptWriteString(pd->pdffp, str);
2883
    fprintf(pd->pdffp, " Tj\n");
2902
	fprintf(pd->pdffp, " Tj\n");
-
 
2903
    }
2884
}
2904
}
2885
 
2905
 
2886
static Rboolean PDF_Locator(double *x, double *y, DevDesc *dd)
2906
static Rboolean PDF_Locator(double *x, double *y, DevDesc *dd)
2887
{
2907
{
2888
    return FALSE;
2908
    return FALSE;