Skip to content

Commit

Permalink
8349925: [REDO] Support static JDK in libfontmanager/freetypeScaler.c
Browse files Browse the repository at this point in the history
Reviewed-by: prr
  • Loading branch information
jianglizhou committed Feb 13, 2025
1 parent c2fc947 commit 18958c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions make/modules/java.desktop/lib/ClientLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBFONTMANAGER, \
LDFLAGS_aix := -Wl$(COMMA)-berok, \
JDK_LIBS := libawt java.base:libjava $(LIBFONTMANAGER_JDK_LIBS), \
JDK_LIBS_macosx := libawt_lwawt, \
JDK_LIBS_unix := java.base:libjvm, \
LIBS := $(LIBFONTMANAGER_LIBS), \
LIBS_unix := $(LIBM), \
LIBS_macosx := \
Expand Down
18 changes: 17 additions & 1 deletion src/java.desktop/share/native/libfontmanager/freetypeScaler.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdlib.h>
#if !defined(_WIN32) && !defined(__APPLE_)
#include <dlfcn.h>
#include "jvm.h"
#endif
#include <math.h>
#include "ft2build.h"
Expand Down Expand Up @@ -298,14 +299,29 @@ static void setInterpreterVersion(FT_Library library) {
#if defined(_WIN32) || defined(__APPLE__)
FT_Property_Set(library, module, property, (void*)(&version));
#else

FT_Prop_Set_Func func = NULL;
if (JVM_IsStaticallyLinked()) {
// The bundled libfreetype may be statically linked with
// the launcher.
func = (FT_Prop_Set_Func)dlsym(RTLD_DEFAULT, "FT_Property_Set");
if (func != NULL) {
func(library, module, property, (void*)(&version));
return;
}

// libfreetype is not statically linked with the executable,
// fall through to find the system provided library dynamically.
}

void *lib = dlopen("libfreetype.so", RTLD_LOCAL|RTLD_LAZY);
if (lib == NULL) {
lib = dlopen("libfreetype.so.6", RTLD_LOCAL|RTLD_LAZY);
if (lib == NULL) {
return;
}
}
FT_Prop_Set_Func func = (FT_Prop_Set_Func)dlsym(lib, "FT_Property_Set");
func = (FT_Prop_Set_Func)dlsym(lib, "FT_Property_Set");
if (func != NULL) {
func(library, module, property, (void*)(&version));
}
Expand Down

0 comments on commit 18958c6

Please sign in to comment.