Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
8256372: [macos] Unexpected symbol was displayed on JTextField with M…
Browse files Browse the repository at this point in the history
…onospaced font

Reviewed-by: bae
Backport-of: 005d8a7fca8b4d9519d2bde0a7cdbbece1cd3981
  • Loading branch information
Yuri Nesterenko committed Jul 26, 2022
1 parent 3a5ebd1 commit 2c66a09
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 1,360 deletions.
6 changes: 0 additions & 6 deletions make/lib/Awt2dLibraries.gmk
Expand Up @@ -557,19 +557,13 @@ else
ifeq ($(call isTargetOs, linux macosx), true)
HARFBUZZ_CFLAGS += -DHAVE_INTEL_ATOMIC_PRIMITIVES
endif
ifeq ($(call isTargetOs, macosx), true)
HARFBUZZ_CFLAGS += -DHAVE_CORETEXT
endif

# Early re-canonizing has to be disabled to workaround an internal XlC compiler error
# when building libharfbuzz
ifeq ($(call isTargetOs, aix), true)
HARFBUZZ_CFLAGS += -qdebug=necan
endif

ifeq ($(call isTargetOs, macosx), false)
LIBFONTMANAGER_EXCLUDE_FILES += libharfbuzz/hb-coretext.cc
endif
# hb-ft.cc is not presently needed, and requires freetype 2.4.2 or later.
LIBFONTMANAGER_EXCLUDE_FILES += libharfbuzz/hb-ft.cc

Expand Down
6 changes: 6 additions & 0 deletions src/java.desktop/macosx/classes/sun/font/CFont.java
Expand Up @@ -211,7 +211,13 @@ private CompositeFont createCompositeFont() {
PhysicalFont[] fonts = new PhysicalFont[numFonts];
fonts[0] = this;
int idx = 1;
if (FontUtilities.isLogging()) {
FontUtilities.getLogger().info("Cascading list for " + this + " :");
}
for (String s : listOfString) {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger().info("Fallback:" + s);
}
if (s.equals(".AppleSymbolsFB")) {
// Don't know why we get the weird name above .. replace.
s = "AppleSymbols";
Expand Down
34 changes: 3 additions & 31 deletions src/java.desktop/share/classes/sun/font/SunLayoutEngine.java
Expand Up @@ -151,34 +151,9 @@ private SunLayoutEngine(LayoutEngineKey key) {
this.key = key;
}

static WeakHashMap<Font2D, Boolean> aatInfo = new WeakHashMap<>();
private static final WeakHashMap<Font2D, FaceRef> facePtr =
new WeakHashMap<>();

private static boolean isAAT(Font2D font) {
Boolean aatObj;
synchronized (aatInfo) {
aatObj = aatInfo.get(font);
}
if (aatObj != null) {
return aatObj.booleanValue();
}
boolean aat = false;
if (font instanceof TrueTypeFont) {
TrueTypeFont ttf = (TrueTypeFont)font;
aat = ttf.getDirectoryEntry(TrueTypeFont.morxTag) != null ||
ttf.getDirectoryEntry(TrueTypeFont.mortTag) != null;
} else if (font instanceof PhysicalFont) {
PhysicalFont pf = (PhysicalFont)font;
aat = pf.getTableBytes(TrueTypeFont.morxTag) != null ||
pf.getTableBytes(TrueTypeFont.mortTag) != null;
}
synchronized (aatInfo) {
aatInfo.put(font, Boolean.valueOf(aat));
}
return aat;
}

private long getFacePtr(Font2D font2D) {
FaceRef ref;
synchronized (facePtr) {
Expand All @@ -192,11 +167,9 @@ public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask,
Point2D.Float pt, GVData data) {
Font2D font = key.font();
FontStrike strike = font.getStrike(desc);
long pNativeFont = font.getPlatformNativeFontPtr(); // used on OSX
long pFace = getFacePtr(font);
if (pFace != 0) {
shape(font, strike, ptSize, mat, pNativeFont,
pFace, isAAT(font),
shape(font, strike, ptSize, mat, pFace,
tr.text, data, key.script(),
tr.start, tr.limit, baseIndex, pt,
typo_flags, gmask);
Expand All @@ -206,13 +179,12 @@ pFace, isAAT(font),
/* Native method to invoke harfbuzz layout engine */
private static native boolean
shape(Font2D font, FontStrike strike, float ptSize, float[] mat,
long pNativeFont, long pFace, boolean aat,
long pFace,
char[] chars, GVData data,
int script, int offset, int limit,
int baseIndex, Point2D.Float pt, int typo_flags, int slot);

private static native long createFace(Font2D font,
boolean aat,
long platformNativeFontPtr);

private static native void disposeFace(long facePtr);
Expand All @@ -227,7 +199,7 @@ private FaceRef(Font2D font) {

private synchronized long getNativePtr() {
if (facePtr == null) {
facePtr = createFace(font, isAAT(font),
facePtr = createFace(font,
font.getPlatformNativeFontPtr());
if (facePtr != 0) {
Disposer.addObjectRecord(font, this);
Expand Down
16 changes: 3 additions & 13 deletions src/java.desktop/share/native/libfontmanager/HBShaper.c
Expand Up @@ -28,9 +28,6 @@
#include "hb.h"
#include "hb-jdk.h"
#include "hb-ot.h"
#ifdef MACOSX
#include "hb-coretext.h"
#endif
#include "scriptMapping.h"

static jclass gvdClass = 0;
Expand Down Expand Up @@ -201,9 +198,7 @@ JDKFontInfo*
jobject font2D,
jobject fontStrike,
jfloat ptSize,
jlong pNativeFont,
jfloatArray matrix,
jboolean aat) {
jfloatArray matrix) {


JDKFontInfo *fi = (JDKFontInfo*)malloc(sizeof(JDKFontInfo));
Expand All @@ -213,13 +208,11 @@ JDKFontInfo*
fi->env = env; // this is valid only for the life of this JNI call.
fi->font2D = font2D;
fi->fontStrike = fontStrike;
fi->nativeFont = pNativeFont;
fi->aat = aat;
(*env)->GetFloatArrayRegion(env, matrix, 0, 4, fi->matrix);
fi->ptSize = ptSize;
fi->xPtSize = euclidianDistance(fi->matrix[0], fi->matrix[1]);
fi->yPtSize = euclidianDistance(fi->matrix[2], fi->matrix[3]);
if (!aat && (getenv("HB_NODEVTX") != NULL)) {
if (getenv("HB_NODEVTX") != NULL) {
fi->devScale = fi->xPtSize / fi->ptSize;
} else {
fi->devScale = 1.0f;
Expand All @@ -238,9 +231,7 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
jobject fontStrike,
jfloat ptSize,
jfloatArray matrix,
jlong pNativeFont,
jlong pFace,
jboolean aat,
jcharArray text,
jobject gvdata,
jint script,
Expand Down Expand Up @@ -268,8 +259,7 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
unsigned int buflen;

JDKFontInfo *jdkFontInfo =
createJDKFontInfo(env, font2D, fontStrike, ptSize,
pNativeFont, matrix, aat);
createJDKFontInfo(env, font2D, fontStrike, ptSize, matrix);
if (!jdkFontInfo) {
return JNI_FALSE;
}
Expand Down
18 changes: 2 additions & 16 deletions src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc
Expand Up @@ -28,9 +28,6 @@

#include "hb.h"
#include "hb-jdk.h"
#ifdef MACOSX
#include "hb-coretext.h"
#endif
#include <stdlib.h>

#if defined(__GNUC__) && __GNUC__ >= 4
Expand Down Expand Up @@ -366,19 +363,12 @@ extern "C" {
/*
* Class: sun_font_SunLayoutEngine
* Method: createFace
* Signature: (Lsun/font/Font2D;ZJJ)J
* Signature: (Lsun/font/Font2D;JJ)J
*/
JNIEXPORT jlong JNICALL Java_sun_font_SunLayoutEngine_createFace(JNIEnv *env,
jclass cls,
jobject font2D,
jboolean aat,
jlong platformFontPtr) {
#ifdef MACOSX
if (aat && platformFontPtr) {
hb_face_t *face = hb_coretext_face_create((CGFontRef)platformFontPtr);
return ptr_to_jlong(face);
}
#endif
Font2DPtr *fi = (Font2DPtr*)malloc(sizeof(Font2DPtr));
if (!fi) {
return 0;
Expand Down Expand Up @@ -442,10 +432,6 @@ static hb_font_t* _hb_jdk_ct_font_create(hb_face_t* face,
hb_font_t* hb_jdk_font_create(hb_face_t* hbFace,
JDKFontInfo *jdkFontInfo,
hb_destroy_func_t destroy) {
#ifdef MACOSX
if (jdkFontInfo->aat && jdkFontInfo->nativeFont) {
return _hb_jdk_ct_font_create(hbFace, jdkFontInfo);
}
#endif

return _hb_jdk_font_create(hbFace, jdkFontInfo, destroy);
}
2 changes: 0 additions & 2 deletions src/java.desktop/share/native/libfontmanager/hb-jdk.h
Expand Up @@ -38,13 +38,11 @@ typedef struct JDKFontInfo_Struct {
JNIEnv* env;
jobject font2D;
jobject fontStrike;
long nativeFont;
float matrix[4];
float ptSize;
float xPtSize;
float yPtSize;
float devScale; // How much applying the full glyph tx scales x distance.
jboolean aat;
} JDKFontInfo;


Expand Down

1 comment on commit 2c66a09

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.