Compare commits

...

4 Commits

Author SHA1 Message Date
Anton Tarasov
6b0cb095e2 JBR-1429 [followup] Scale is huge due to GDK_SCALE
(cherry picked from commit 2ea40c8d84)
2019-08-01 16:10:30 +03:00
Anton Tarasov
909a0a5dd3 JBR-1429 Scale is huge due to GDK_SCALE
(cherry picked from commit 1c3477df2e)
2019-08-01 16:10:21 +03:00
Alexey Ushakov
c488780937 JBR-1624 Fonts rendering is broken in the 2019.2 EAP (Fira Code)
Corrected lookup for bold fonts

(cherry picked from commit 114b8af38f)
2019-07-29 12:49:03 +02:00
Alexey Ushakov
3551756be6 JBR-1645 javax/swing/JTextArea/TestTabSize.java: Tab width calculation wrong
Corrected idea font filter

(cherry picked from commit 62f9d1f46a)
2019-07-29 12:48:54 +02:00
7 changed files with 137 additions and 64 deletions

View File

@@ -1458,7 +1458,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
if (dpi < 50) { if (dpi < 50) {
dpi = 50; dpi = 50;
} }
X11GraphicsDevice.setGlobalDPI(dpi); X11GraphicsDevice.setXftDpi(dpi);
} }
} }

View File

@@ -223,7 +223,7 @@ public class FontFamily {
case Font.BOLD: case Font.BOLD:
case Font.BOLD|Font.ITALIC: case Font.BOLD|Font.ITALIC:
return (Math.abs(newWeight - Font2D.FWEIGHT_BOLD) < return (Math.abs(newWeight - Font2D.FWEIGHT_BOLD) <=
Math.abs(currFont.getWeight() - Font2D.FWEIGHT_BOLD)); Math.abs(currFont.getWeight() - Font2D.FWEIGHT_BOLD));
default: default:

View File

@@ -93,10 +93,13 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
if (super.accept(dir, name) && ideaSet.contains(name)) { if (super.accept(dir, name)) {
return positive; if (ideaSet.contains(name))
return positive;
else
return !positive;
} }
return !positive; return false;
} }
} }

View File

@@ -37,6 +37,7 @@ import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import sun.java2d.opengl.GLXGraphicsConfig; import sun.java2d.opengl.GLXGraphicsConfig;
import sun.java2d.xr.XRGraphicsConfig; import sun.java2d.xr.XRGraphicsConfig;
@@ -64,12 +65,20 @@ public final class X11GraphicsDevice extends GraphicsDevice
private DisplayMode origDisplayMode; private DisplayMode origDisplayMode;
private boolean shutdownHookRegistered; private boolean shutdownHookRegistered;
private int scale; private int scale;
private volatile boolean isNativeScaleDefault; private final AtomicBoolean isScaleFactorDefault = new AtomicBoolean(false);
private static int globalScale; // derived from Xft.dpi private static final int XRM_XFT_DPI;
private static volatile int XFT_DPI;
private static final int GDK_SCALE;
private static final double GDK_DPI_SCALE;
private static final double GDK_SCALE_MULTIPLIER;
public X11GraphicsDevice(int screennum) { public X11GraphicsDevice(int screennum) {
this.screen = screennum; this.screen = screennum;
this.scale = initScaleFactor(); int scaleFactor = initScaleFactor(-1);
synchronized (isScaleFactorDefault) {
isScaleFactorDefault.set(scaleFactor == -1);
this.scale = isScaleFactorDefault.get() ? 1 : scaleFactor;
}
} }
/* /*
@@ -82,6 +91,10 @@ public final class X11GraphicsDevice extends GraphicsDevice
if (!GraphicsEnvironment.isHeadless()) { if (!GraphicsEnvironment.isHeadless()) {
initIDs(); initIDs();
} }
XRM_XFT_DPI = getXrmXftDpi(-1);
GDK_SCALE = (int)getGdkScale("GDK_SCALE", -1);
GDK_DPI_SCALE = getGdkScale("GDK_DPI_SCALE", -1);
GDK_SCALE_MULTIPLIER = GDK_SCALE != -1 ? GDK_SCALE * (GDK_DPI_SCALE != -1 ? GDK_DPI_SCALE : 1) : 1;
} }
/** /**
@@ -283,7 +296,9 @@ public final class X11GraphicsDevice extends GraphicsDevice
int width, int height, int width, int height,
int displayMode); int displayMode);
private static native void resetNativeData(int screen); private static native void resetNativeData(int screen);
private static native double getNativeScaleFactor(int screen); private static native double getNativeScaleFactor(int screen, double defValue);
private static native double getGdkScale(String name, double defValue);
private static native int getXrmXftDpi(int defValue);
/** /**
* Returns true only if: * Returns true only if:
@@ -490,7 +505,7 @@ public final class X11GraphicsDevice extends GraphicsDevice
* X11GraphicsEnvironment when the display mode has been changed. * X11GraphicsEnvironment when the display mode has been changed.
*/ */
public synchronized void displayChanged() { public synchronized void displayChanged() {
scale = initScaleFactor(); scale = initScaleFactor(1);
// On X11 the visuals do not change, and therefore we don't need // On X11 the visuals do not change, and therefore we don't need
// to reset the defaultConfig, config, doubleBufferVisuals, // to reset the defaultConfig, config, doubleBufferVisuals,
// neither do we need to reset the native data. // neither do we need to reset the native data.
@@ -519,40 +534,66 @@ public final class X11GraphicsDevice extends GraphicsDevice
return scale; return scale;
} }
private int getNativeScale() { private double getNativeScale() {
isXrandrExtensionSupported(); isXrandrExtensionSupported();
return (int)Math.round(getNativeScaleFactor(screen)); return getNativeScaleFactor(screen, -1);
} }
public static void setGlobalDPI(int dpi) { public static void setXftDpi(int dpi) {
XFT_DPI = dpi;
boolean uiScaleEnabled = SunGraphicsEnvironment.isUIScaleEnabled(dpi); boolean uiScaleEnabled = SunGraphicsEnvironment.isUIScaleEnabled(dpi);
globalScale = uiScaleEnabled ? (int)Math.round(dpi / 96.0) : 1; double xftDpiScale = uiScaleEnabled ? XFT_DPI / 96.0 : 1.0;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
X11GraphicsDevice x11gd = (X11GraphicsDevice)gd; X11GraphicsDevice x11gd = (X11GraphicsDevice)gd;
if (x11gd.isNativeScaleDefault || !uiScaleEnabled) { synchronized (x11gd.isScaleFactorDefault) {
x11gd.scale = globalScale; if (x11gd.isScaleFactorDefault.get() || !uiScaleEnabled) {
x11gd.isNativeScaleDefault = false; x11gd.scale = (int)Math.round(xftDpiScale * (uiScaleEnabled ? GDK_SCALE_MULTIPLIER : 1));
x11gd.isScaleFactorDefault.set(false);
}
} }
} }
} }
private int initScaleFactor() { private int initScaleFactor(int defValue) {
boolean uiScaleEnabled = SunGraphicsEnvironment.isUIScaleEnabled();
if (SunGraphicsEnvironment.isUIScaleEnabled()) { if (uiScaleEnabled) {
double debugScale = SunGraphicsEnvironment.getDebugScale(); double debugScale = SunGraphicsEnvironment.getDebugScale();
if (debugScale >= 1) { if (debugScale >= 1) {
return (int) debugScale; return (int) debugScale;
} }
int nativeScale = getNativeScale(); double gdkScaleMult = uiScaleEnabled ? GDK_SCALE_MULTIPLIER : 1;
if (nativeScale > 0) return nativeScale; double nativeScale = getNativeScale();
if (globalScale > 0) return globalScale; if (nativeScale > 0) {
isNativeScaleDefault = true; return (int)Math.round(nativeScale * gdkScaleMult);
return 1; }
if (XRM_XFT_DPI > 0) {
return (int)Math.round((XRM_XFT_DPI / 96.0) * gdkScaleMult);
}
if (XFT_DPI > 0) {
return (int)Math.round((XFT_DPI / 96.0) * gdkScaleMult);
}
} }
return defValue;
}
return 1; /**
* Used externally for diagnostic purpose.
*/
public String[][] getDpiInfo() {
int xftDpi = XRM_XFT_DPI != -1 ? XRM_XFT_DPI : XFT_DPI;
String xftDpiStr = xftDpi != -1 ? String.valueOf(xftDpi) : "undefined";
double gsettingsScale = getNativeScaleFactor(screen, -1);
String gsettingsScaleStr = gsettingsScale != -1 ? String.valueOf(gsettingsScale) : "undefined";
String gdkScaleStr = GDK_SCALE != -1 ? String.valueOf(GDK_SCALE) : "undefined";
String gdkDpiScaleStr = GDK_DPI_SCALE != -1 ? String.valueOf(GDK_DPI_SCALE) : "undefined";
return new String[][] {
{"Xft.DPI", xftDpiStr, "Font DPI (X resources value)"},
{"GSettings scale factor", gsettingsScaleStr, "http://wiki.archlinux.org/index.php/HiDPI"},
{"GDK_SCALE", gdkScaleStr, "http://developer.gnome.org/gtk3/stable/gtk-x11.html"},
{"GDK_DPI_SCALE", gdkDpiScaleStr, "http://developer.gnome.org/gtk3/stable/gtk-x11.html"}
};
} }
/** /**

View File

@@ -31,6 +31,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <locale.h>
#ifdef __APPLE__
# include <xlocale.h>
#endif
typedef void* g_settings_schema_source_get_default(); typedef void* g_settings_schema_source_get_default();
typedef void* g_settings_schema_source_ref(void *); typedef void* g_settings_schema_source_ref(void *);
@@ -204,16 +209,17 @@ static double getDesktopScale(char *output_name) {
} }
static int getScale(const char *name) { double getScaleEnvVar(const char *name, double default_value) {
char *uiScale = getenv(name); char *uiScale = getenv(name);
if (uiScale != NULL) { if (uiScale != NULL) {
double scale = strtod(uiScale, NULL); locale_t c_locale = newlocale(LC_NUMERIC_MASK, "C", NULL);
if (scale < 1) { double scale = strtod_l(uiScale, NULL, c_locale);
return -1; freelocale(c_locale);
if (scale > 0) {
return scale;
} }
return (int) scale;
} }
return -1; return default_value;
} }
double getNativeScaleFactor(char *output_name, double default_value) { double getNativeScaleFactor(char *output_name, double default_value) {
@@ -222,7 +228,7 @@ double getNativeScaleFactor(char *output_name, double default_value) {
int gdk_scale = 0; int gdk_scale = 0;
if (scale == -2) { if (scale == -2) {
scale = getScale("J2D_UISCALE"); scale = (int)getScaleEnvVar("J2D_UISCALE", -1);
} }
if (scale > 0) { if (scale > 0) {
@@ -235,7 +241,5 @@ double getNativeScaleFactor(char *output_name, double default_value) {
native_scale = default_value; native_scale = default_value;
} }
gdk_scale = getScale("GDK_SCALE"); return native_scale;
return gdk_scale > 0 ? (native_scale <= 0 ? 1 : native_scale) * gdk_scale : native_scale;
} }

View File

@@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
double getNativeScaleFactor(char *output_name, double default_value); double getNativeScaleFactor(char *output_name, double default_value);
double getScaleEnvVar(const char* var_name, double default_value);
#endif #endif

View File

@@ -2233,40 +2233,64 @@ static char *get_output_screen_name(JNIEnv *env, int screen) {
/* /*
* Class: sun_awt_X11GraphicsDevice * Class: sun_awt_X11GraphicsDevice
* Method: getNativeScaleFactor * Method: getNativeScaleFactor
* Signature: (I)D * Signature: (ID)D
*/ */
JNIEXPORT jdouble JNICALL JNIEXPORT jdouble JNICALL
Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
(JNIEnv *env, jobject this, jint screen) { (JNIEnv *env, jobject this, jint screen, jdouble defValue) {
// in case of Xinerama individual screen scales are not supported // in case of Xinerama individual screen scales are not supported
char *name = get_output_screen_name(env, usingXinerama ? 0 : screen); char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
double scale = getNativeScaleFactor(name, -1); double scale = getNativeScaleFactor(name, defValue);
#ifndef HEADLESS
// Ubuntu 18.04 introduced a new settings for a scale factor: Settings > Devices > Displays > Scale.
// It is propagated to Xresource (and is read fine with 'xrdb' util) but is not propagated to GSettings
// (gtk3 doesn't see it in 'gtk-xft-dpi'). So, retrieve "Xft.dpi" from Xresource via X11 API call.
if (scale <= 0) {
Display *display = XOpenDisplay(NULL); // need to open new display to get up-to-date XResource value
if (display) {
char *resource_manager = XResourceManagerString(display);
if (resource_manager) {
XrmDatabase db = XrmGetStringDatabase(resource_manager);
if (db) {
XrmValue value;
char *type;
if (XrmGetResource(db, "Xft.dpi", "Xft.dpi", &type, &value)) {
scale = (double)atoi(value.addr) / 96;
}
}
}
XCloseDisplay(display);
}
}
#endif
if (name) { if (name) {
free(name); free(name);
} }
return scale; return scale;
} }
/*
* Class: sun_awt_X11GraphicsDevice
* Method: getGdkScale
* Signature: (Ljava/lang/String;D)D
*/
JNIEXPORT jdouble JNICALL
Java_sun_awt_X11GraphicsDevice_getGdkScale
(JNIEnv *env, jobject this, jstring envVarName, jdouble defValue)
{
const char* name = (*env)->GetStringUTFChars(env, envVarName, 0);
double value = getScaleEnvVar(name, defValue);
(*env)->ReleaseStringUTFChars(env, envVarName, name);
return value;
}
/*
* Class: sun_awt_X11GraphicsDevice
* Method: getXrmXftDpi
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_sun_awt_X11GraphicsDevice_getXrmXftDpi
(JNIEnv *env, jobject this, jint defValue)
{
int dpi = defValue;
#ifndef HEADLESS
// Ubuntu 18.04 introduced a new settings for a scale factor: Settings > Devices > Displays > Scale.
// It is propagated to Xresource (and is read fine with 'xrdb' util) but is not propagated to GSettings
// (gtk3 doesn't see it in 'gtk-xft-dpi'). So, retrieve "Xft.dpi" from Xresource via X11 API call.
Display *display = XOpenDisplay(NULL); // need to open new display to get up-to-date XResource value
if (display) {
char *resource_manager = XResourceManagerString(display);
if (resource_manager) {
XrmDatabase db = XrmGetStringDatabase(resource_manager);
if (db) {
XrmValue value;
char *type;
if (XrmGetResource(db, "Xft.dpi", "Xft.dpi", &type, &value)) {
dpi = atoi(value.addr);
}
}
}
XCloseDisplay(display);
}
#endif
return dpi;
}