Skip to content

Commit fa160d2

Browse files
committed
JBR-1872 Backport JDK-8217731 Font rendering and glyph spacing has changed from jdk-8 to jdk-11
The fix backported with some minor modifications
1 parent c0397fb commit fa160d2

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/java.desktop/share/native/libfontmanager/freetypeScaler.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@
3030
#include "sun_font_FreetypeFontScaler.h"
3131

3232
#include <stdlib.h>
33-
#if defined(_WIN32) || defined(MACOSX)
34-
#define DISABLE_FONTCONFIG
35-
#endif
36-
3733
#include <math.h>
3834

39-
#ifndef DISABLE_FONTCONFIG
35+
#if !defined(_WIN32) && !defined(__APPLE_)
4036
#include <dlfcn.h>
37+
#else
38+
#define DISABLE_FONTCONFIG
4139
#endif
4240

4341
#include "ft2build.h"
@@ -48,6 +46,7 @@
4846
#include FT_SIZES_H
4947
#include FT_OUTLINE_H
5048
#include FT_SYNTHESIS_H
49+
#include FT_MODULE_H
5150
#include FT_LCD_FILTER_H
5251

5352
#ifndef DISABLE_FONTCONFIG
@@ -447,6 +446,52 @@ static unsigned long ReadTTFontFileFunc(FT_Stream stream,
447446
}
448447
}
449448

449+
typedef FT_Error (*FT_Prop_Set_Func)(FT_Library library,
450+
const FT_String* module_name,
451+
const FT_String* property_name,
452+
const void* value );
453+
454+
/**
455+
* Prefer the older v35 freetype byte code interpreter.
456+
*/
457+
static void setInterpreterVersion(FT_Library library) {
458+
459+
char* props = getenv("FREETYPE_PROPERTIES");
460+
int version = 35;
461+
const char* module = "truetype";
462+
const char* property = "interpreter-version";
463+
464+
/* If some one is setting this, don't override it */
465+
if (props != NULL && strstr(property, props)) {
466+
return;
467+
}
468+
/*
469+
* FT_Property_Set was introduced in 2.4.11.
470+
* Some older supported Linux OSes may not include it so look
471+
* this up dynamically.
472+
* And if its not available it doesn't matter, since the reason
473+
* we need it dates from 2.7.
474+
* On Windows & Mac the library is always bundled so it is safe
475+
* to use directly in those cases.
476+
*/
477+
#if defined(_WIN32) || defined(__APPLE__)
478+
FT_Property_Set(library, module, property, (void*)(&version));
479+
#else
480+
void *lib = dlopen("libfreetype.so", RTLD_LOCAL|RTLD_LAZY);
481+
if (lib == NULL) {
482+
lib = dlopen("libfreetype.so.6", RTLD_LOCAL|RTLD_LAZY);
483+
if (lib == NULL) {
484+
return;
485+
}
486+
}
487+
FT_Prop_Set_Func func = (FT_Prop_Set_Func)dlsym(lib, "FT_Property_Set");
488+
if (func != NULL) {
489+
func(library, module, property, (void*)(&version));
490+
}
491+
dlclose(lib);
492+
#endif
493+
}
494+
450495
/*
451496
* Class: sun_font_FreetypeFontScaler
452497
* Method: initNativeScaler
@@ -486,6 +531,7 @@ Java_sun_font_FreetypeFontScaler_initNativeScaler(
486531
free(scalerInfo);
487532
return 0;
488533
}
534+
setInterpreterVersion(scalerInfo->library);
489535

490536
#define TYPE1_FROM_JAVA 2
491537

0 commit comments

Comments
 (0)