[cairo-commit] CairoJava/jni utils.cpp,NONE,1.1

Soorya Kuloor commit at pdx.freedesktop.org
Tue May 11 12:50:57 PDT 2004


Committed by: skuloor

Update of /cvs/cairo/CairoJava/jni
In directory pdx:/tmp/cvs-serv814/jni

Added Files:
	utils.cpp 
Log Message:
Initial version

--- NEW FILE: utils.cpp ---
#include "utils.h"

#define SURFACENOTSUPPORTEDEXCEPTION_CLASS_STRING "org/cairographics/cairo/SurfaceNotSupportedException"
#define CAIRO_EXCEPTION_CLASS_STRING "org/cairographics/cairo/CairoException"

void throw_not_supported_exception(JNIEnv *env, const char* surfaceType) {
    jclass newExcCls = env->FindClass(SURFACENOTSUPPORTEDEXCEPTION_CLASS_STRING);
    if (newExcCls == 0) { 
        fprintf(stderr, "%s surfaces not available. Check cairo-features.h\n", surfaceType);
    } else {
        char buff[128];
        sprintf(buff, "%s surfaces not available. Check cairo-features.h", surfaceType);
        env->ThrowNew(newExcCls, buff); 
    }
}

void check_cairo_error(JNIEnv *env, cairo_t *cr)
{
    check_cairo_status(env, cairo_status(cr));
}

void check_cairo_status(JNIEnv *env, cairo_status_t status)
{
    if (status == CAIRO_STATUS_SUCCESS) return;
    
    jclass newExcCls = env->FindClass(CAIRO_EXCEPTION_CLASS_STRING);
    if (newExcCls != 0) {

        jmethodID ctor = env->GetMethodID(newExcCls, "<init>", "(S)V");
        if (ctor != 0) {
            jshort code = status;
            jthrowable exceptionObj = (jthrowable) env->NewObject(newExcCls, ctor, code);
            if (exceptionObj != 0) {
                env->Throw(exceptionObj);
            }
        }
    }
}






More information about the cairo-commit mailing list