Forwarding to 2d-dev as asked by Oleg Sukhodolsky (originally from awt-dev).
Begin forwarded message: Date: Mon, 21 May 2007 17:45:29 +0200 From: Diego 'Flameeyes' Pettenò <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: [PATCH] Allow linking in (shared) libfontconfig directy As it is, OpenJDK tries to dlopen fontconfig (multiple times too), to avoid a direct link dependency over it. This could be quite slow as the dynamic linker has to do its job multiple times, but is understandable for redistributable packages. Distributions, though, might want to just depend on fontconfig itself and link it directly. The attached patch allows that through the DIRECT_LINK_FONTCONFIG=true option at make. -- Diego "Flameeyes" Pettenò http://farragut.flameeyes.is-a-geek.org/ -- Diego "Flameeyes" Pettenò http://farragut.flameeyes.is-a-geek.org/
Index: openjdk/j2se/src/solaris/native/sun/awt/fontpath.c
===================================================================
--- openjdk.orig/j2se/src/solaris/native/sun/awt/fontpath.c
+++ openjdk/j2se/src/solaris/native/sun/awt/fontpath.c
@@ -612,6 +612,9 @@ Java_sun_font_FontManager_populateFontFi
#include <link.h>
#endif
+#ifdef DIRECT_LINK_FONTCONFIG
+# include <fontconfig/fontconfig.h>
+#else /* DIRECT_LINK_FONTCONFIG */
#include "fontconfig.h"
@@ -734,21 +737,12 @@ typedef FcPattern* (*FcFontMatchFuncType
FcResult *result);
typedef FcFontSet* (*FcFontSetCreateFuncType)();
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
-
+#endif /* DIRECT_LINK_FONTCONFIG */
static char **getFontConfigLocations() {
char **fontdirs;
int numdirs = 0;
- FcInitLoadConfigFuncType FcInitLoadConfig;
- FcPatternBuildFuncType FcPatternBuild;
- FcObjectSetFuncType FcObjectSetBuild;
- FcFontListFuncType FcFontList;
- FcPatternGetStringFuncType FcPatternGetString;
- FcStrDirnameFuncType FcStrDirname;
- FcPatternDestroyFuncType FcPatternDestroy;
- FcFontSetDestroyFuncType FcFontSetDestroy;
-
FcConfig *fontconfig;
FcPattern *pattern;
FcObjectSet *objset;
@@ -758,6 +752,16 @@ static char **getFontConfigLocations() {
int i, f, found, len=0;
char **fontPath;
+#ifndef DIRECT_LINK_FONTCONFIG
+ FcInitLoadConfigFuncType FcInitLoadConfig;
+ FcPatternBuildFuncType FcPatternBuild;
+ FcObjectSetFuncType FcObjectSetBuild;
+ FcFontListFuncType FcFontList;
+ FcPatternGetStringFuncType FcPatternGetString;
+ FcStrDirnameFuncType FcStrDirname;
+ FcPatternDestroyFuncType FcPatternDestroy;
+ FcFontSetDestroyFuncType FcFontSetDestroy;
+
void* libfontconfig = openFontConfig();
if (libfontconfig == NULL) {
@@ -789,6 +793,7 @@ static char **getFontConfigLocations() {
closeFontConfig(libfontconfig, JNI_FALSE);
return NULL;
}
+#endif
/* Make calls into the fontconfig library to build a search for
* outline fonts, and to get the set of full file paths from the matches.
@@ -831,7 +836,9 @@ static char **getFontConfigLocations() {
/* Free memory and close the ".so" */
(*FcFontSetDestroy)(fontSet);
(*FcPatternDestroy)(pattern);
+#ifndef DIRECT_LINK_FONTCONFIG
closeFontConfig(libfontconfig, JNI_TRUE);
+#endif
return fontdirs;
}
@@ -849,6 +856,7 @@ JNIEXPORT jint JNICALL
Java_sun_font_FontManager_getFontConfigAASettings
(JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
+#ifndef DIRECT_LINK_FONTCONFIG
FcNameParseFuncType FcNameParse;
FcPatternAddStringFuncType FcPatternAddString;
FcConfigSubstituteFuncType FcConfigSubstitute;
@@ -857,6 +865,7 @@ Java_sun_font_FontManager_getFontConfigA
FcPatternGetBoolFuncType FcPatternGetBool;
FcPatternGetIntegerFuncType FcPatternGetInteger;
FcPatternDestroyFuncType FcPatternDestroy;
+#endif
FcPattern *pattern, *matchPattern;
FcResult result;
@@ -875,6 +884,7 @@ Java_sun_font_FontManager_getFontConfigA
}
locale = (*env)->GetStringUTFChars(env, localeStr, 0);
+#ifndef DIRECT_LINK_FONTCONFIG
if ((libfontconfig = openFontConfig()) == NULL) {
(*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
if (locale) {
@@ -914,7 +924,7 @@ Java_sun_font_FontManager_getFontConfigA
closeFontConfig(libfontconfig, JNI_FALSE);
return -1;
}
-
+#endif
pattern = (*FcNameParse)((FcChar8 *)fcName);
if (locale != NULL) {
@@ -938,7 +948,9 @@ Java_sun_font_FontManager_getFontConfigA
if (locale) {
(*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
}
+#ifndef DIRECT_LINK_FONTCONFIG
closeFontConfig(libfontconfig, JNI_TRUE);
+#endif
if (antialias == FcFalse) {
return TEXT_AA_OFF;
@@ -960,6 +972,7 @@ JNIEXPORT void JNICALL
Java_sun_font_FontManager_getFontConfig
(JNIEnv *env, jclass obj, jstring localeStr, jobjectArray fontInfoArray) {
+#ifndef DIRECT_LINK_FONTCONFIG
FcNameParseFuncType FcNameParse;
FcPatternAddStringFuncType FcPatternAddString;
FcConfigSubstituteFuncType FcConfigSubstitute;
@@ -967,6 +980,7 @@ Java_sun_font_FontManager_getFontConfig
FcFontMatchFuncType FcFontMatch;
FcPatternGetStringFuncType FcPatternGetString;
FcPatternDestroyFuncType FcPatternDestroy;
+#endif
int i, arrlen;
jobject fontInfoObj;
@@ -997,6 +1011,7 @@ Java_sun_font_FontManager_getFontConfig
return;
}
+#ifndef DIRECT_LINK_FONTCONFIG
if ((libfontconfig = openFontConfig()) == NULL) {
return;
}
@@ -1024,6 +1039,7 @@ Java_sun_font_FontManager_getFontConfig
closeFontConfig(libfontconfig, JNI_FALSE);
return;
}
+#endif
locale = (*env)->GetStringUTFChars(env, localeStr, 0);
@@ -1073,6 +1089,8 @@ Java_sun_font_FontManager_getFontConfig
if (locale) {
(*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
}
+#ifndef DIRECT_LINK_FONTCONFIG
closeFontConfig(libfontconfig, JNI_TRUE);
+#endif
}
Index: openjdk/j2se/make/sun/awt/Makefile
===================================================================
--- openjdk.orig/j2se/make/sun/awt/Makefile
+++ openjdk/j2se/make/sun/awt/Makefile
@@ -580,6 +580,11 @@ ifeq ($(PLATFORM), linux)
LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
endif
+ifeq ($(DIRECT_LINK_FONTCONFIG), true)
+CPPFLAGS += -DDIRECT_LINK_FONTCONFIG
+LDFLAGS += -lfontconfig
+endif
+
LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/$(TSOBJDIR) \
$(AWT_RUNPATH)
Index: openjdk/j2se/make/sun/xawt/Makefile
===================================================================
--- openjdk.orig/j2se/make/sun/xawt/Makefile
+++ openjdk/j2se/make/sun/xawt/Makefile
@@ -62,6 +62,11 @@ LDFLAGS += -lpthread
dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
endif
+ifeq ($(DIRECT_LINK_FONTCONFIG), true)
+CPPFLAGS += -DDIRECT_LINK_FONTCONFIG
+LDFLAGS += -lfontconfig
+endif
+
# Since this library will be living in a subdirectory below the other libraries
# we need to add an extra runpath so that libraries in the upper directory
# are found at runtime.
signature.asc
Description: PGP signature
