mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
IDEA-150876 OpenJDK fonts for toolwindow names look worse than Oracles's
don't apply FreeType-returned glyph advance for rotated glyphs rendered by GDI This seems to produce a better looking text (more evenly spaced). Fractional metrics won't be respected by this code, but we can address this later if needed. port commits c9debd5e, ed78cd00, 4c7e1619, 7aa0429c, 7bd6c17c from JBR 9 port from JBR 11 to JBR 15 (cherry picked from commitsd6b588bdab,dbc15fb84e) cherry picked from commit2c0d6150d0
This commit is contained in:
committed by
alexey.ushakov@jetbrains.com
parent
7178335ef2
commit
51cad78be2
@@ -110,6 +110,9 @@ public class FileFontStrike extends PhysicalStrike {
|
||||
/* Used only for communication to native layer */
|
||||
private int intPtSize;
|
||||
|
||||
// -1 - undefined, 0 - horizontal (normal direction), 1 - 90 degrees CCW, 2 - 180 degrees, 3 - 90 degrees CW
|
||||
private int rotation = -1;
|
||||
|
||||
/* Perform global initialisation needed for Windows native rasterizer */
|
||||
private static native boolean initNative();
|
||||
private static boolean isXPorLater = false;
|
||||
@@ -215,12 +218,18 @@ public class FileFontStrike extends PhysicalStrike {
|
||||
!GraphicsEnvironment.isHeadless() &&
|
||||
!fileFont.useJavaRasterizer &&
|
||||
(desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HRGB ||
|
||||
desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR) &&
|
||||
(matrix[1] == 0.0 && matrix[2] == 0.0 &&
|
||||
matrix[0] == matrix[3] &&
|
||||
matrix[0] >= 3.0 && matrix[0] <= 100.0) &&
|
||||
!((TrueTypeFont)fileFont).useEmbeddedBitmapsForSize(intPtSize)) {
|
||||
useNatives = true;
|
||||
desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR)) {
|
||||
double pts = 0;
|
||||
if (matrix[1] == 0.0 && matrix[2] == 0.0 && matrix[0] == matrix[3]) {
|
||||
rotation = matrix[0] > 0 ? 0 : 2;
|
||||
pts = Math.abs(matrix[0]);
|
||||
} else if (matrix[0] == 0.0 && matrix[3] == 0.0 && matrix[1] == -matrix[2]) {
|
||||
rotation = matrix[1] > 0 ? 3 : 1;
|
||||
pts = Math.abs(matrix[1]);
|
||||
}
|
||||
intPtSize = (int) pts;
|
||||
useNatives = rotation >= 0 && pts >= 3.0 && pts <= 100.0 &&
|
||||
!((TrueTypeFont)fileFont).useEmbeddedBitmapsForSize(intPtSize);
|
||||
}
|
||||
if (FontUtilities.isLogging() && FontUtilities.isWindows) {
|
||||
FontUtilities.logInfo("Strike for " + fileFont + " at size = " + intPtSize +
|
||||
@@ -293,6 +302,7 @@ public class FileFontStrike extends PhysicalStrike {
|
||||
int size,
|
||||
int glyphCode,
|
||||
boolean fracMetrics,
|
||||
int rotation,
|
||||
int fontDataSize);
|
||||
|
||||
long getGlyphImageFromWindows(int glyphCode) {
|
||||
@@ -303,6 +313,7 @@ public class FileFontStrike extends PhysicalStrike {
|
||||
long ptr = _getGlyphImageFromWindows
|
||||
(family, style, size, glyphCode,
|
||||
desc.fmHint == INTVAL_FRACTIONALMETRICS_ON,
|
||||
rotation,
|
||||
((TrueTypeFont)fileFont).fontDataSize);
|
||||
if (ptr != 0) {
|
||||
/* Get the advance from the JDK rasterizer. This is mostly
|
||||
@@ -312,9 +323,10 @@ public class FileFontStrike extends PhysicalStrike {
|
||||
* After these are resolved, we can restrict this extra
|
||||
* work to the FM case.
|
||||
*/
|
||||
float advance = getGlyphAdvance(glyphCode, false);
|
||||
StrikeCache.unsafe.putFloat(ptr + StrikeCache.xAdvanceOffset,
|
||||
advance);
|
||||
if (rotation == 0 || rotation == 2) {
|
||||
float advance = getGlyphAdvance(glyphCode, false);
|
||||
StrikeCache.unsafe.putFloat(ptr + StrikeCache.xAdvanceOffset, advance);
|
||||
}
|
||||
return ptr;
|
||||
} else {
|
||||
if (FontUtilities.isLogging()) {
|
||||
|
||||
@@ -163,8 +163,7 @@ JNIEXPORT jboolean JNICALL
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_sun_font_FileFontStrike__1getGlyphImageFromWindows
|
||||
(JNIEnv *env, jobject unused,
|
||||
jstring fontFamily, jint style, jint size, jint glyphCode, jboolean fm,
|
||||
jint fontDataSize) {
|
||||
jstring fontFamily, jint style, jint size, jint glyphCode, jboolean fm, jint rotation, jint fontDataSize) {
|
||||
|
||||
GLYPHMETRICS glyphMetrics;
|
||||
LOGFONTW lf;
|
||||
@@ -226,6 +225,7 @@ Java_sun_font_FileFontStrike__1getGlyphImageFromWindows
|
||||
lf.lfOutPrecision = OUT_TT_PRECIS;
|
||||
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
lf.lfPitchAndFamily = DEFAULT_PITCH;
|
||||
lf.lfEscapement = lf.lfOrientation = 900 * rotation;
|
||||
|
||||
nameLen = (*env)->GetStringLength(env, fontFamily);
|
||||
name = (LPWSTR)alloca((nameLen+1)*2);
|
||||
@@ -366,7 +366,17 @@ Java_sun_font_FileFontStrike__1getGlyphImageFromWindows
|
||||
if (fm) {
|
||||
x += 1;
|
||||
}
|
||||
y = topLeftY - textMetric.tmAscent;
|
||||
if (rotation == 1) {
|
||||
x -= textMetric.tmAscent;
|
||||
} else if (rotation == 3) {
|
||||
x += textMetric.tmAscent;
|
||||
}
|
||||
y = topLeftY;
|
||||
if (rotation == 0) {
|
||||
y -= textMetric.tmAscent;
|
||||
} else if (rotation == 2) {
|
||||
y += textMetric.tmAscent;
|
||||
}
|
||||
err = ExtTextOutW(hMemoryDC, x, y, ETO_GLYPH_INDEX|ETO_OPAQUE,
|
||||
(LPRECT)&rect, (LPCWSTR)&glyphCode, 1, NULL);
|
||||
if (err == 0) {
|
||||
|
||||
Reference in New Issue
Block a user