|
30 | 30 | #include "sun_font_FreetypeFontScaler.h" |
31 | 31 |
|
32 | 32 | #include <stdlib.h> |
33 | | -#if defined(_WIN32) || defined(MACOSX) |
34 | | -#define DISABLE_FONTCONFIG |
35 | | -#endif |
36 | | - |
37 | 33 | #include <math.h> |
38 | 34 |
|
39 | | -#ifndef DISABLE_FONTCONFIG |
| 35 | +#if !defined(_WIN32) && !defined(__APPLE_) |
40 | 36 | #include <dlfcn.h> |
| 37 | +#else |
| 38 | +#define DISABLE_FONTCONFIG |
41 | 39 | #endif |
42 | 40 |
|
43 | 41 | #include "ft2build.h" |
|
48 | 46 | #include FT_SIZES_H |
49 | 47 | #include FT_OUTLINE_H |
50 | 48 | #include FT_SYNTHESIS_H |
| 49 | +#include FT_MODULE_H |
51 | 50 | #include FT_LCD_FILTER_H |
52 | 51 |
|
53 | 52 | #ifndef DISABLE_FONTCONFIG |
@@ -447,6 +446,52 @@ static unsigned long ReadTTFontFileFunc(FT_Stream stream, |
447 | 446 | } |
448 | 447 | } |
449 | 448 |
|
| 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 | + |
450 | 495 | /* |
451 | 496 | * Class: sun_font_FreetypeFontScaler |
452 | 497 | * Method: initNativeScaler |
@@ -486,6 +531,7 @@ Java_sun_font_FreetypeFontScaler_initNativeScaler( |
486 | 531 | free(scalerInfo); |
487 | 532 | return 0; |
488 | 533 | } |
| 534 | + setInterpreterVersion(scalerInfo->library); |
489 | 535 |
|
490 | 536 | #define TYPE1_FROM_JAVA 2 |
491 | 537 |
|
|
0 commit comments