示例#1
0
void getJavaGDPPI(NewDevDesc *dd, double *xpi, double *ypi) {
	newJavaGDDesc *xd = (newJavaGDDesc *) dd->deviceSpecific;
	JNIEnv *env = getJNIEnv();
	jobject jo;
	
	if (!env || !xd || !xd->talk) return;
	
	*xpi = 96.0;
	*ypi = 96.0;
	
	jo = (*env)->CallObjectMethod(env, xd->talk, jmGDInterfaceGetPPI);
	if (jo) {
		jdouble *ac = (jdouble*)(*env)->GetDoubleArrayElements(env, jo, 0);
		if (!ac) {
			(*env)->DeleteLocalRef(env, jo);
			gdWarning("getPPI: cant's get double*, using default");
			return;
		}
		if (ac[0] > 0.0 && ac[1] > 0.0) {
			*xpi = ac[0];
			*ypi = ac[1];
		}
		(*env)->ReleaseDoubleArrayElements(env, jo, ac, 0);
		(*env)->DeleteLocalRef(env, jo);
	} else {
		gdWarning("getPPI: method returned null, using default");
	}
	chkX(env);
}
示例#2
0
文件: jGDtalk.c 项目: cran/JavaGD
static void newJavaGD_Size(double *left, double *right,  double *bottom, double *top,  NewDevDesc *dd)
{
    newJavaGDDesc *xd = (newJavaGDDesc *) dd->deviceSpecific;
    JNIEnv *env = getJNIEnv();
    jmethodID mid;
    
    if(!env || !xd || !xd->talk) return;
    
    mid = (*env)->GetMethodID(env, xd->talkClass, "gdSize", "()[D");
    if (mid) {
        jobject o=(*env)->CallObjectMethod(env, xd->talk, mid);
        if (o) {
            jdouble *ac=(jdouble*)(*env)->GetDoubleArrayElements(env, o, 0);
            if (!ac) {
	      (*env)->DeleteLocalRef(env, o);
	      gdWarning("gdSize: cant's get double*");
	      return;
	    }
            *left=ac[0]; *right=ac[1]; *bottom=ac[2]; *top=ac[3];
            (*env)->ReleaseDoubleArrayElements(env, o, ac, 0);
	    (*env)->DeleteLocalRef(env, o);
        } else gdWarning("gdSize: gdSize returned null");
    }
    else gdWarning("gdSize: can't get mid ");
	chkX(env);
}
示例#3
0
void initJavaGD(newJavaGDDesc *xd, double *width, double *height, int *unit, double *xpi, double *ypi) {
	JNIEnv *env = getJNIEnv();
	jobject jo;
	
	if(!env || !xd || !xd->talk) return;
	
	jo = (*env)->CallObjectMethod(env, xd->talk, jmGDInterfaceInit,
			(jdouble) *width, (jdouble) *height, (jint) *unit, (jdouble) *xpi, (jdouble) *ypi);
	if (jo) {
		jdouble *ac = (jdouble*)(*env)->GetDoubleArrayElements(env, jo, 0);
		if (!ac) {
			(*env)->DeleteLocalRef(env, jo);
			gdWarning("gdInit: cant's get double*");
			if (*unit != 1) {
				*width = 672.0;
				*height = 672.0;
			}
			return;
		}
		*width = ac[0];
		*height = ac[1];
		(*env)->ReleaseDoubleArrayElements(env, jo, ac, 0);
		(*env)->DeleteLocalRef(env, jo);
	} else {
		gdWarning("gdInit: method returned null");
		if (*unit != 1) {
			*width = 672.0;
			*height = 672.0;
		}
	}
	chkX(env);
}
示例#4
0
文件: jGDtalk.c 项目: cran/JavaGD
Rboolean newJavaGD_Open(NewDevDesc *dd, newJavaGDDesc *xd, const char *dsp, double w, double h)
{   
    if (initJavaGD(xd)) return FALSE;
    
    xd->fill = 0xffffffff; /* transparent, was R_RGB(255, 255, 255); */
    xd->col = R_RGB(0, 0, 0);
    xd->canvas = R_RGB(255, 255, 255);
    xd->windowWidth = w;
    xd->windowHeight = h;
    xd->holdlevel = 0;
        
    {
        JNIEnv *env = getJNIEnv();
        jmethodID mid;
        
        if(!env || !xd || !xd->talk) {
            gdWarning("gdOpen: env, xd or talk is null");
            return FALSE;
        }
        
        /* we're not using dsp atm! */
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdOpen", "(DD)V");
        if (mid)
            (*env)->CallVoidMethod(env, xd->talk, mid, w, h);
        else {
            gdWarning("gdOpen: can't get mid");
			chkX(env);
            return FALSE;
        }
		chkX(env);
    }
    
    return TRUE;
}
示例#5
0
文件: jGDtalk.c 项目: cran/JavaGD
/** check changes in GC and issue corresponding commands if necessary */
static void sendGC(JNIEnv *env, newJavaGDDesc *xd, R_GE_gcontext *gc, int sendAll) {
    jmethodID mid;
    
    if (sendAll || gc->col != lastGC.col) {
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdcSetColor", "(I)V");
        if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, CONVERT_COLOR(gc->col));
        else gdWarning("checkGC.gdcSetColor: can't get mid");
		chkX(env);
    }

    if (sendAll || gc->fill != lastGC.fill)  {
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdcSetFill", "(I)V");
        if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, CONVERT_COLOR(gc->fill));
        else gdWarning("checkGC.gdcSetFill: can't get mid");
		chkX(env);
    }

    if (sendAll || gc->lwd != lastGC.lwd || gc->lty != lastGC.lty) {
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdcSetLine", "(DI)V");
        if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, gc->lwd, gc->lty);
        else gdWarning("checkGC.gdcSetLine: can't get mid");
		chkX(env);
    }

    if (sendAll || gc->cex!=lastGC.cex || gc->ps!=lastGC.ps || gc->lineheight!=lastGC.lineheight || gc->fontface!=lastGC.fontface || strcmp(gc->fontfamily, lastGC.fontfamily)) {
        jstring s = (*env)->NewStringUTF(env, gc->fontfamily);
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdcSetFont", "(DDDILjava/lang/String;)V");
        if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, gc->cex, gc->ps, gc->lineheight, gc->fontface, s);
        else gdWarning("checkGC.gdcSetFont: can't get mid");
		chkX(env);
    }
    memcpy(&lastGC, gc, sizeof(lastGC));
}
示例#6
0
文件: jGDtalk.c 项目: cran/JavaGD
static void newJavaGD_Rect(double x0, double y0, double x1, double y1,  R_GE_gcontext *gc,  NewDevDesc *dd)
{
    newJavaGDDesc *xd = (newJavaGDDesc *) dd->deviceSpecific;
    JNIEnv *env = getJNIEnv();
    jmethodID mid;
    
    if(!env || !xd || !xd->talk) return;
    
    checkGC(env,xd, gc);
    
    mid = (*env)->GetMethodID(env, xd->talkClass, "gdRect", "(DDDD)V");
    if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, x0, y0, x1, y1);
    else gdWarning("gdRect: can't get mid ");
	chkX(env);
}
示例#7
0
文件: jGDtalk.c 项目: cran/JavaGD
static void newJavaGD_Polyline(int n, double *x, double *y,  R_GE_gcontext *gc,  NewDevDesc *dd)
{
    newJavaGDDesc *xd = (newJavaGDDesc *) dd->deviceSpecific;
    JNIEnv *env = getJNIEnv();
    jmethodID mid;
    jarray xa, ya;
    
    if(!env || !xd || !xd->talk) return;
    
    checkGC(env, xd, gc);
    
    xa = newDoubleArray(env, n, x);
    if (!xa) return;
    ya = newDoubleArray(env, n, y);
    if (!ya) return;
    
    mid = (*env)->GetMethodID(env, xd->talkClass, "gdPolyline", "(I[D[D)V");
    if (mid) (*env)->CallVoidMethod(env, xd->talk, mid, n, xa, ya);
    else gdWarning("gdPolyline: can't get mid ");
    (*env)->DeleteLocalRef(env, xa); 
    (*env)->DeleteLocalRef(env, ya);
    chkX(env);
}
示例#8
0
Rboolean createJavaGD(newJavaGDDesc *xd) {
	jclass jc = 0;
	jobject jo = 0;
	
	JNIEnv *env=getJNIEnv();
	
    if (!jvm) {
        initJVM(jarClassPath);
        env=getJNIEnv();
    }
    
    if (!env) return FALSE;
    
	char *customClass = getenv("RJGD_CLASS_NAME");
	if (!customClass) { 
		//customClass = "org.rosuda.javaGD.JavaGD";
		customClass = "de.walware.rj.server.gd.JavaGD";
	}
	
	if (!jcGDInterface) {
		jclass jc = getJClass(env, "org.rosuda.javaGD.GDInterface", (RJ_ERROR_RERROR | RJ_GLOBAL_REF));
		jmGDInterfaceActivate = getJMethod(env, jc, "gdActivate", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceCircle = getJMethod(env, jc, "gdCircle", "(DDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceClip = getJMethod(env, jc, "gdClip", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceClose = getJMethod(env, jc, "gdClose", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceDeactivate = getJMethod(env, jc, "gdDeactivate", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceGetPPI = getJMethod(env, jc, "gdPPI", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceInit = getJMethod(env, jc, "gdInit", "(DDIDD)[D", RJ_ERROR_RERROR);
		jmGDInterfaceLocator = getJMethod(env, jc, "gdLocator", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceLine = getJMethod(env, jc, "gdLine", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceMetricInfo = getJMethod(env, jc, "gdMetricInfo", "(I)[D", RJ_ERROR_RERROR);
		jmGDInterfaceMode = getJMethod(env, jc, "gdMode", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceNewPage = getJMethod(env, jc, "gdNewPage", "()V", RJ_ERROR_RERROR);
		jmGDInterfaceNewPageConfirm = getJMethod(env, jc, "gdNewPageConfirm", "()Z", RJ_ERROR_RERROR);
		jmGDInterfaceOpen = getJMethod(env, jc, "gdOpen", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfacePolygon = getJMethod(env, jc, "gdPolygon", "(I[D[D)V", RJ_ERROR_RERROR);
		jmGDInterfacePolyline = getJMethod(env, jc, "gdPolyline", "(I[D[D)V", RJ_ERROR_RERROR);
		jmGDInterfaceRect = getJMethod(env, jc, "gdRect", "(DDDD)V", RJ_ERROR_RERROR);
		jmGDInterfaceSize = getJMethod(env, jc, "gdSize", "()[D", RJ_ERROR_RERROR);
		jmGDInterfaceStrWidth = getJMethod(env, jc, "gdStrWidth", "(Ljava/lang/String;)D", RJ_ERROR_RERROR);
		jmGDInterfaceText = getJMethod(env, jc, "gdText", "(DDLjava/lang/String;DD)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetColor = getJMethod(env, jc, "gdcSetColor", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetFill = getJMethod(env, jc, "gdcSetFill", "(I)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetLine = getJMethod(env, jc, "gdcSetLine", "(DI)V", RJ_ERROR_RERROR);
		jmGDInterfaceSetFont = getJMethod(env, jc, "gdcSetFont", "(DDDILjava/lang/String;)V", RJ_ERROR_RERROR);
		jcGDInterface = jc;
	}
	
	jc = getJClass(env, customClass, (RJ_ERROR_RERROR | RJ_GLOBAL_REF));
	{	jmethodID jm = (*env)->GetMethodID(env, jc, "<init>", "()V");
		if (!jm) {
			(*env)->DeleteLocalRef(env, jc);  
			handleJError(env, RJ_ERROR_RERROR, "Cannot find default constructor for GD class '%s'.", customClass);
		}
		jo = (*env)->NewObject(env, jc, jm);
		if (!jo) {
			(*env)->DeleteLocalRef(env, jc);  
			handleJError(env, RJ_ERROR_RERROR, "Cannot instantiate object of GD class '%s'.", customClass);
		}
	}
	
	xd->talk = (*env)->NewGlobalRef(env, jo);
	(*env)->DeleteLocalRef(env, jo);
	xd->talkClass = jc;
	
	if (!xd->talk) {
		chkX(env);
		gdWarning("Rjgd_NewDevice: talk is null");
		return FALSE;
	}
	
	return TRUE;
}