Skip to content
Permalink
Browse files
8256372: [macos] Unexpected symbol was displayed on JTextField with M…
…onospaced font

Reviewed-by: erikj, serb
  • Loading branch information
Phil Race committed May 20, 2021
1 parent 81f39ed commit 005d8a7fca8b4d9519d2bde0a7cdbbece1cd3981
@@ -447,19 +447,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

@@ -211,7 +211,13 @@ private CompositeFont createCompositeFont() {
PhysicalFont[] fonts = new PhysicalFont[numFonts];
fonts[0] = this;
int idx = 1;
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Cascading list for " + this + " :");
}
for (String s : listOfString) {
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Fallback:" + s);
}
if (s.equals(".AppleSymbolsFB")) {
// Don't know why we get the weird name above .. replace.
s = "AppleSymbols";
@@ -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) {
@@ -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);
@@ -206,13 +179,12 @@ public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask,
/* 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);
@@ -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);
@@ -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;
@@ -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));
@@ -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;
@@ -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,
@@ -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;
}
@@ -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
@@ -363,19 +360,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;
@@ -439,10 +429,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);
}
@@ -38,13 +38,11 @@ typedef struct JDKFontInfo_Struct {
JNIEnv* env;
jobject font2D;
jobject fontStrike;
jlong 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;


0 comments on commit 005d8a7

Please sign in to comment.