/* * The goal of this function is to find all "system" fonts which * are needed by the JRE to display text in supported locales etc, and * to support APIs which allow users to enumerate all system fonts and use * them from their Java applications. * The preferred mechanism is now using the new "fontconfig" library * This exists on newer versions of Linux and Solaris (S10 and above) * The library is dynamically located. The results are merged with * a set of "known" locations and with the X11 font path, if running in * a local X11 environment. * The hardwired paths are built into the JDK binary so as new font locations * are created on a host plaform for them to be located by the JRE they will * need to be added ito the host's font configuration database, typically * /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir * NB: Fontconfig also depends heavily for performance on the host O/S * maintaining up to date caches. * This is consistent with the requirements of the desktop environments * on these OSes. * This also frees us from X11 APIs as JRE is required to function in * a "headless" mode where there is no Xserver. */ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1, jboolean isX11) { char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL; /* As of 1.5 we try to use fontconfig on both Solaris and Linux. * If its not available NULL is returned. */ fcdirs = getFontConfigLocations(); #if defined(__linux__) knowndirs = fullLinuxFontPath; #elif defined(__solaris__) knowndirs = fullSolarisFontPath; #elif defined(_AIX) knowndirs = fullAixFontPath; #endif /* REMIND: this code requires to be executed when the GraphicsEnvironment * is already initialised. That is always true, but if it were not so, * this code could throw an exception and the fontpath would fail to * be initialised. */ #ifndef HEADLESS if (isX11) { // The following only works in an x11 environment. #if defined(__linux__) /* There's no headless build on linux ... */ if (!AWTIsHeadless()) { /* .. so need to call a function to check */ #endif /* Using the X11 font path to locate font files is now a fallback * useful only if fontconfig failed, or is incomplete. So we could * remove this code completely and the consequences should be rare * and non-fatal. If this happens, then the calling Java code can * be modified to no longer require that the AWT lock (the X11GE) * be initialised prior to calling this code. */ AWT_LOCK(); if (isDisplayLocal(env)) { x11dirs = getX11FontPath(); } AWT_UNLOCK(); #if defined(__linux__) } #endif } #endif /* !HEADLESS */ path = mergePaths(fcdirs, x11dirs, knowndirs, noType1); if (fcdirs != NULL) { char **p = fcdirs; while (*p != NULL) free(*p++); free(fcdirs); } if (x11dirs != NULL) { char **p = x11dirs; while (*p != NULL) free(*p++); free(x11dirs); } return path; }
/* * The goal of this function is to find all "system" fonts which * are needed by the JRE to display text in supported locales etc, and * to support APIs which allow users to enumerate all system fonts and use * them from their Java applications. * The preferred mechanism is now using the new "fontconfig" library * This exists on newer versions of Linux and Solaris (S10 and above) * The library is dynamically located. The results are merged with * a set of "known" locations and with the X11 font path, if running in * a local X11 environment. * The hardwired paths are built into the JDK binary so as new font locations * are created on a host plaform for them to be located by the JRE they will * need to be added ito the host's font configuration database, typically * /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir * NB: Fontconfig also depends heavily for performance on the host O/S * maintaining up to date caches. * This is consistent with the requirements of the desktop environments * on these OSes. * This also frees us from X11 APIs as JRE is required to function in * a "headless" mode where there is no Xserver. */ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) { char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL; /* As of 1.5 we try to use fontconfig on both Solaris and Linux. * If its not available NULL is returned. */ fcdirs = getFontConfigLocations(); #ifdef __linux__ knowndirs = fullLinuxFontPath; #else /* IF SOLARIS */ knowndirs = fullSolarisFontPath; #endif /* REMIND: this code requires to be executed when the GraphicsEnvironment * is already initialised. That is always true, but if it were not so, * this code could throw an exception and the fontpath would fail to * be initialised. */ #ifndef HEADLESS #ifdef __linux__ /* There's no headless build on linux ... */ if (!AWTIsHeadless()) { /* .. so need to call a function to check */ #endif AWT_LOCK(); if (isDisplayLocal(env)) { x11dirs = getX11FontPath(); } AWT_UNLOCK(); #ifdef __linux__ } #endif #endif /* !HEADLESS */ path = mergePaths(fcdirs, x11dirs, knowndirs, noType1); if (fcdirs != NULL) { char **p = fcdirs; while (*p != NULL) free(*p++); free(fcdirs); } if (x11dirs != NULL) { char **p = x11dirs; while (*p != NULL) free(*p++); free(x11dirs); } return path; }
jint AWT_OnLoad(JavaVM *vm, void *reserved) { Dl_info dlinfo; char buf[MAXPATHLEN]; int32_t len; char *p, *tk = 0; JNI_OnLoad_type *JNI_OnLoad_ptr; struct utsname name; JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2); void *v; char *envvar; jstring toolkit = NULL, grenv = NULL, fmanager = NULL; jstring tkProp = NULL, geProp = NULL, fmProp = NULL; if (awtHandle != NULL) { /* Avoid several loading attempts */ return JNI_VERSION_1_2; } jvm = vm; /* Get address of this library and the directory containing it. */ dladdr((void *)JNI_OnLoad, &dlinfo); realpath((char *)dlinfo.dli_fname, buf); len = strlen(buf); p = strrchr(buf, '/'); /* * The code below is responsible for: * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class, * (if user has specified the toolkit in env varialble) */ tkProp = (*env)->NewStringUTF(env, "awt.toolkit"); geProp = (*env)->NewStringUTF(env, "java.awt.graphicsenv"); fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager"); /* Check if toolkit is specified in env variable */ #ifdef MACOSX envvar = getenv("AWT_TOOLKIT"); if (envvar && strstr(envvar, "XToolkit")) { #endif toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit"); grenv = (*env)->NewStringUTF(env, "sun.awt.X11GraphicsEnvironment"); fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager"); tk = "/xawt/libmawt"; #ifdef MACOSX } else { toolkit = (*env)->NewStringUTF(env, "sun.lwawt.macosx.LWCToolkit"); grenv = (*env)->NewStringUTF(env, "sun.awt.CGraphicsEnvironment"); fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager"); tk = "/lwawt/liblwawt"; } #endif if (toolkit && tkProp) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", tkProp, toolkit); } if (grenv && geProp) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", geProp, grenv); } if (fmanager && fmProp) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", fmProp, fmanager); } /* Calculate library name to load */ #ifndef MACOSX if (AWTIsHeadless()) { strcpy(p, "/headless/libmawt"); } else if (tk) { #endif strcpy(p, tk); #ifndef MACOSX } #endif if (toolkit) { (*env)->DeleteLocalRef(env, toolkit); } if (tkProp) { (*env)->DeleteLocalRef(env, tkProp); } if (grenv) { (*env)->DeleteLocalRef(env, grenv); } if (geProp) { (*env)->DeleteLocalRef(env, geProp); } #ifdef MACOSX strcat(p, ".dylib"); #else strcat(p, ".so"); #endif if (tk) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load", "(Ljava/lang/String;)V", JNU_NewStringPlatform(env, buf)); awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); } return JNI_VERSION_1_2; }
jint AWT_OnLoad(JavaVM *vm, void *reserved) { Dl_info dlinfo; char buf[MAXPATHLEN]; int32_t len; char *p, *tk = 0; JNI_OnLoad_type *JNI_OnLoad_ptr; struct utsname name; JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2); void *v; char *envvar; jstring fmanager = NULL; jstring fmProp = NULL; if (awtHandle != NULL) { /* Avoid several loading attempts */ return JNI_VERSION_1_2; } jvm = vm; /* Get address of this library and the directory containing it. */ dladdr((void *)AWT_OnLoad, &dlinfo); realpath((char *)dlinfo.dli_fname, buf); len = strlen(buf); p = strrchr(buf, '/'); /* * 1. Set the "sun.font.fontmanager" system property, * 2. Choose the library image name. */ fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager"); /* Check if toolkit is specified in env variable */ #ifdef MACOSX envvar = getenv("AWT_TOOLKIT"); if (envvar && strstr(envvar, "XToolkit")) { #endif fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager"); tk = "/xawt/libmawt"; #ifdef MACOSX } else { fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager"); tk = "/lwawt/liblwawt"; } #endif if (fmanager && fmProp) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", fmProp, fmanager); } /* Calculate library name to load */ #ifndef MACOSX if (AWTIsHeadless()) { strcpy(p, "/headless/libmawt"); } else if (tk) { #endif strcpy(p, tk); #ifndef MACOSX } #endif #ifdef MACOSX strcat(p, ".dylib"); #else strcat(p, ".so"); #endif if (tk) { JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load", "(Ljava/lang/String;)V", JNU_NewStringPlatform(env, buf)); awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); } return JNI_VERSION_1_2; }