The R Project SVN R

Rev

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

Rev 30129 Rev 30186
Line 130... Line 130...
130
	    s = CDR(s);
130
	    s = CDR(s);
131
	}
131
	}
132
    }
132
    }
133
}
133
}
134
 
134
 
135
/* 
135
/*
136
 * Extract specified par from list of inline pars
136
 * Extract specified par from list of inline pars
137
 */
137
 */
138
SEXP getInlinePar(SEXP s, char *name)
138
SEXP getInlinePar(SEXP s, char *name)
139
{
139
{
140
    SEXP result = R_NilValue;
140
    SEXP result = R_NilValue;
Line 143... Line 143...
143
	while (s != R_NilValue) {
143
	while (s != R_NilValue) {
144
	    if (isList(CAR(s))) {
144
	    if (isList(CAR(s))) {
145
		result = getInlinePar(CAR(s), name);
145
		result = getInlinePar(CAR(s), name);
146
		if (result)
146
		if (result)
147
		    found = 1;
147
		    found = 1;
148
	    } else 
148
	    } else
149
		if (TAG(s) != R_NilValue)
149
		if (TAG(s) != R_NilValue)
150
		    if (!strcmp(CHAR(PRINTNAME(TAG(s))), name)) {
150
		    if (!strcmp(CHAR(PRINTNAME(TAG(s))), name)) {
151
			result = CAR(s);
151
			result = CAR(s);
152
			found = 1;
152
			found = 1;
153
		    }
153
		    }
154
	    s = CDR(s);
154
	    s = CDR(s);
155
	}
155
	}
156
    }    
156
    }
157
    return result;
157
    return result;
158
}
158
}
159
 
159
 
160
SEXP FixupPch(SEXP pch, int dflt)
160
SEXP FixupPch(SEXP pch, int dflt)
161
{
161
{
Line 1867... Line 1867...
1867
	GConvert(&xx0, &yy0, USER, DEVICE, dd);
1867
	GConvert(&xx0, &yy0, USER, DEVICE, dd);
1868
	GConvert(&xx1, &yy1, USER, DEVICE, dd);
1868
	GConvert(&xx1, &yy1, USER, DEVICE, dd);
1869
	if (R_FINITE(xx0) && R_FINITE(yy0) && R_FINITE(xx1) && R_FINITE(yy1)) {
1869
	if (R_FINITE(xx0) && R_FINITE(yy0) && R_FINITE(xx1) && R_FINITE(yy1)) {
1870
	    if (isNAcol(rawcol, i, ncol))
1870
	    if (isNAcol(rawcol, i, ncol))
1871
		Rf_gpptr(dd)->col = Rf_dpptr(dd)->col;
1871
		Rf_gpptr(dd)->col = Rf_dpptr(dd)->col;
1872
	    else 
1872
	    else
1873
		Rf_gpptr(dd)->col = INTEGER(col)[i % ncol];
1873
		Rf_gpptr(dd)->col = INTEGER(col)[i % ncol];
1874
	    if (nlty == 0 || INTEGER(lty)[i % nlty] == NA_INTEGER)
1874
	    if (nlty == 0 || INTEGER(lty)[i % nlty] == NA_INTEGER)
1875
		Rf_gpptr(dd)->lty = Rf_dpptr(dd)->lty;
1875
		Rf_gpptr(dd)->lty = Rf_dpptr(dd)->lty;
1876
	    else
1876
	    else
1877
		Rf_gpptr(dd)->lty = INTEGER(lty)[i % nlty];
1877
		Rf_gpptr(dd)->lty = INTEGER(lty)[i % nlty];
Line 2413... Line 2413...
2413
	if (R_FINITE(cexval)) Rf_gpptr(dd)->cex = cexval;
2413
	if (R_FINITE(cexval)) Rf_gpptr(dd)->cex = cexval;
2414
	else cexval = cexsave;
2414
	else cexval = cexsave;
2415
	Rf_gpptr(dd)->font = (fontval == NA_INTEGER) ? fontsave : fontval;
2415
	Rf_gpptr(dd)->font = (fontval == NA_INTEGER) ? fontsave : fontval;
2416
	if (isNAcol(rawcol, i, ncol))
2416
	if (isNAcol(rawcol, i, ncol))
2417
	    Rf_gpptr(dd)->col = colsave;
2417
	    Rf_gpptr(dd)->col = colsave;
2418
	else 
2418
	else
2419
	    Rf_gpptr(dd)->col = colval;
2419
	    Rf_gpptr(dd)->col = colval;
2420
	Rf_gpptr(dd)->adj = ComputeAdjValue(adjval, sideval, Rf_gpptr(dd)->las);
2420
	Rf_gpptr(dd)->adj = ComputeAdjValue(adjval, sideval, Rf_gpptr(dd)->las);
2421
	atval = ComputeAtValue(atval, Rf_gpptr(dd)->adj, sideval, Rf_gpptr(dd)->las,
2421
	atval = ComputeAtValue(atval, Rf_gpptr(dd)->adj, sideval, Rf_gpptr(dd)->las,
2422
			       outerval, dd);
2422
			       outerval, dd);
2423
 
2423
 
Line 2906... Line 2906...
2906
    which = asInteger(CAR(args)); args = CDR(args);
2906
    which = asInteger(CAR(args)); args = CDR(args);
2907
    if (which < 1 || which > 4)
2907
    if (which < 1 || which > 4)
2908
	errorcall(call, "invalid \"which\" specification");
2908
	errorcall(call, "invalid \"which\" specification");
2909
    /*
2909
    /*
2910
     * If specified non-NA col then use that, else ...
2910
     * If specified non-NA col then use that, else ...
2911
     * 
2911
     *
2912
     * if specified non-NA fg then use that, else ...
2912
     * if specified non-NA fg then use that, else ...
2913
     *
2913
     *
2914
     * else use par("col")
2914
     * else use par("col")
2915
     */
2915
     */
2916
    col= Rf_gpptr(dd)->col;	
2916
    col= Rf_gpptr(dd)->col;
2917
    ProcessInlinePars(args, dd, call);
2917
    ProcessInlinePars(args, dd, call);
2918
    colsxp = getInlinePar(args, "col");
2918
    colsxp = getInlinePar(args, "col");
2919
    if (isNAcol(colsxp, 0, 1)) {
2919
    if (isNAcol(colsxp, 0, 1)) {
2920
	fgsxp = getInlinePar(args, "fg");
2920
	fgsxp = getInlinePar(args, "fg");
2921
	if (isNAcol(fgsxp, 0, 1))
2921
	if (isNAcol(fgsxp, 0, 1))
2922
	    Rf_gpptr(dd)->col = col;
2922
	    Rf_gpptr(dd)->col = col;
2923
	else
2923
	else
2924
	    Rf_gpptr(dd)->col = Rf_gpptr(dd)->fg;	    
2924
	    Rf_gpptr(dd)->col = Rf_gpptr(dd)->fg;
2925
    } 
2925
    }
2926
    /* override par("xpd") and force clipping to device region */
2926
    /* override par("xpd") and force clipping to device region */
2927
    Rf_gpptr(dd)->xpd = 2;
2927
    Rf_gpptr(dd)->xpd = 2;
2928
    GMode(1, dd);
2928
    GMode(1, dd);
2929
    GBox(which, dd);
2929
    GBox(which, dd);
2930
    GMode(0, dd);
2930
    GMode(0, dd);
Line 3196... Line 3196...
3196
 
3196
 
3197
	return ans;
3197
	return ans;
3198
    }
3198
    }
3199
}
3199
}
3200
 
3200
 
3201
SEXP do_strheight(SEXP call, SEXP op, SEXP args, SEXP env)
3201
/* strheight(str, units)  ||  strwidth(str, units) */
3202
{
-
 
3203
    /* strheight(str, units) */
3202
#define DO_STR_DIM(KIND) 						\
-
 
3203
{									\
3204
    SEXP ans, str, ch;
3204
    SEXP ans, str, ch;							\
3205
    int i, n, units;
3205
    int i, n, units;							\
3206
    double cex, cexsave;
3206
    double cex, cexsave;						\
3207
    DevDesc *dd = CurrentDevice();
3207
    DevDesc *dd = CurrentDevice();					\
3208
 
3208
									\
3209
    checkArity(op,args);
3209
    checkArity(op, args);						\
3210
    GCheckState(dd);
3210
    GCheckState(dd);							\
3211
 
3211
									\
3212
    str = CAR(args);
3212
    str = CAR(args);							\
3213
    if (isSymbol(str) || isLanguage(str))
3213
    if (isSymbol(str) || isLanguage(str))				\
3214
	str = coerceVector(str, EXPRSXP);
3214
	str = coerceVector(str, EXPRSXP);				\
3215
    else if (!isExpression(str))
3215
    else if (!isExpression(str))					\
3216
	str = coerceVector(str, STRSXP);
3216
	str = coerceVector(str, STRSXP);				\
3217
    PROTECT(str);
3217
    PROTECT(str);							\
3218
    args = CDR(args);
3218
    args = CDR(args);							\
3219
 
3219
									\
3220
    if ((units = asInteger(CAR(args))) == NA_INTEGER || units < 0)
3220
    if ((units = asInteger(CAR(args))) == NA_INTEGER || units < 0)	\
3221
	errorcall(call, "invalid units");
3221
	errorcall(call, "invalid units");				\
3222
    args = CDR(args);
3222
    args = CDR(args);							\
3223
 
3223
									\
3224
    if (isNull(CAR(args)))
3224
    if (isNull(CAR(args)))						\
3225
	cex = Rf_gpptr(dd)->cex;
3225
	cex = Rf_gpptr(dd)->cex;					\
3226
    else if (!R_FINITE(cex = asReal(CAR(args))) || cex <= 0.0)
3226
    else if (!R_FINITE(cex = asReal(CAR(args))) || cex <= 0.0)		\
3227
	errorcall(call, "invalid cex value");
3227
	errorcall(call, "invalid cex value");				\
3228
 
3228
									\
3229
    n = LENGTH(str);
3229
    n = LENGTH(str);							\
3230
    PROTECT(ans = allocVector(REALSXP, n));
3230
    PROTECT(ans = allocVector(REALSXP, n));				\
3231
    cexsave = Rf_gpptr(dd)->cex;
3231
    cexsave = Rf_gpptr(dd)->cex;					\
3232
    Rf_gpptr(dd)->cex = cex * Rf_gpptr(dd)->cexbase;
3232
    Rf_gpptr(dd)->cex = cex * Rf_gpptr(dd)->cexbase;			\
3233
    for (i = 0; i < n; i++)
3233
    for (i = 0; i < n; i++)						\
3234
	if (isExpression(str))
3234
	if (isExpression(str))						\
3235
	    REAL(ans)[i] = GExpressionHeight(VECTOR_ELT(str, i),
3235
	    REAL(ans)[i] = GExpression ## KIND(VECTOR_ELT(str, i),	\
3236
					     GMapUnits(units), dd);
3236
					     GMapUnits(units), dd);	\
3237
	else {
3237
	else {								\
3238
	    ch = STRING_ELT(str, i);
3238
	    ch = STRING_ELT(str, i);					\
3239
	    REAL(ans)[i] = (ch == NA_STRING) ? 0.0 :
3239
	    REAL(ans)[i] = (ch == NA_STRING) ? 0.0 :			\
3240
		GStrHeight(CHAR(ch), GMapUnits(units), dd);
3240
		GStr ## KIND(CHAR(ch), GMapUnits(units), dd);		\
3241
	}
3241
	}								\
3242
    Rf_gpptr(dd)->cex = cexsave;
3242
    Rf_gpptr(dd)->cex = cexsave;					\
3243
    UNPROTECT(2);
3243
    UNPROTECT(2);							\
3244
    return ans;
3244
    return ans;								\
3245
}
3245
}
3246
 
3246
 
-
 
3247
SEXP do_strheight(SEXP call, SEXP op, SEXP args, SEXP env)
-
 
3248
DO_STR_DIM(Height)
3247
 
3249
 
3248
SEXP do_strwidth(SEXP call, SEXP op, SEXP args, SEXP env)
3250
SEXP do_strwidth (SEXP call, SEXP op, SEXP args, SEXP env)
3249
{
-
 
3250
    /* strwidth(str, units) */
-
 
3251
    SEXP ans, str, ch;
-
 
3252
    int i, n, units;
-
 
3253
    double cex, cexsave;
-
 
3254
    DevDesc *dd = CurrentDevice();
-
 
3255
 
-
 
3256
    checkArity(op, args);
-
 
3257
    GCheckState(dd);
-
 
3258
 
-
 
3259
    str = CAR(args);
-
 
3260
    if (isSymbol(str) || isLanguage(str))
-
 
3261
	str = coerceVector(str, EXPRSXP);
-
 
3262
    else if (!isExpression(str))
-
 
3263
	str = coerceVector(str, STRSXP);
-
 
3264
    PROTECT(str);
3251
DO_STR_DIM(Width)
3265
 
-
 
3266
    args = CDR(args);
-
 
3267
 
3252
 
3268
    if ((units = asInteger(CAR(args))) == NA_INTEGER || units < 0)
-
 
3269
	errorcall(call, "invalid units");
-
 
3270
    args = CDR(args);
3253
#undef DO_STR_DIM
3271
 
3254
 
3272
    if (isNull(CAR(args)))
-
 
3273
	cex = Rf_gpptr(dd)->cex;
-
 
3274
    else if (!R_FINITE(cex = asReal(CAR(args))) || cex <= 0.0)
-
 
3275
	errorcall(call, "invalid cex value");
-
 
3276
 
-
 
3277
    n = LENGTH(str);
-
 
3278
    PROTECT(ans = allocVector(REALSXP, n));
-
 
3279
    cexsave = Rf_gpptr(dd)->cex;
-
 
3280
    Rf_gpptr(dd)->cex = cex * Rf_gpptr(dd)->cexbase;
-
 
3281
    for (i = 0; i < n; i++)
-
 
3282
	if (isExpression(str))
-
 
3283
	    REAL(ans)[i] = GExpressionWidth(VECTOR_ELT(str, i),
-
 
3284
					    GMapUnits(units), dd);
-
 
3285
	else {
-
 
3286
	    ch = STRING_ELT(str, i);
-
 
3287
	    REAL(ans)[i] = (ch == NA_STRING) ? 0.0 :
-
 
3288
		GStrWidth(CHAR(ch), GMapUnits(units), dd);
-
 
3289
	}
-
 
3290
    Rf_gpptr(dd)->cex = cexsave;
-
 
3291
    UNPROTECT(2);
-
 
3292
    return ans;
-
 
3293
}
-
 
3294
 
3255
 
3295
static int *dnd_lptr;
3256
static int *dnd_lptr;
3296
static int *dnd_rptr;
3257
static int *dnd_rptr;
3297
static double *dnd_hght;
3258
static double *dnd_hght;
3298
static double *dnd_xpos;
3259
static double *dnd_xpos;