Compare commits

...

4 Commits
1972 ... 360

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) {
dpi = 50;
}
X11GraphicsDevice.setGlobalDPI(dpi);
X11GraphicsDevice.setXftDpi(dpi);
}
}

View File

@@ -223,7 +223,7 @@ public class FontFamily {
case Font.BOLD:
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));
default:

View File

@@ -93,10 +93,13 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
@Override
public boolean accept(File dir, String name) {
if (super.accept(dir, name) && ideaSet.contains(name)) {
return positive;
if (super.accept(dir, name)) {
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.HashSet;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import sun.java2d.opengl.GLXGraphicsConfig;
import sun.java2d.xr.XRGraphicsConfig;
@@ -64,12 +65,20 @@ public final class X11GraphicsDevice extends GraphicsDevice
private DisplayMode origDisplayMode;
private boolean shutdownHookRegistered;
private int scale;
private volatile boolean isNativeScaleDefault;
private static int globalScale; // derived from Xft.dpi
private final AtomicBoolean isScaleFactorDefault = new AtomicBoolean(false);
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) {
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()) {
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 displayMode);
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:
@@ -490,7 +505,7 @@ public final class X11GraphicsDevice extends GraphicsDevice
* X11GraphicsEnvironment when the display mode has been changed.
*/
public synchronized void displayChanged() {
scale = initScaleFactor();
scale = initScaleFactor(1);
// On X11 the visuals do not change, and therefore we don't need
// to reset the defaultConfig, config, doubleBufferVisuals,
// neither do we need to reset the native data.
@@ -519,40 +534,66 @@ public final class X11GraphicsDevice extends GraphicsDevice
return scale;
}
private int getNativeScale() {
private double getNativeScale() {
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);
globalScale = uiScaleEnabled ? (int)Math.round(dpi / 96.0) : 1;
double xftDpiScale = uiScaleEnabled ? XFT_DPI / 96.0 : 1.0;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
X11GraphicsDevice x11gd = (X11GraphicsDevice)gd;
if (x11gd.isNativeScaleDefault || !uiScaleEnabled) {
x11gd.scale = globalScale;
x11gd.isNativeScaleDefault = false;
synchronized (x11gd.isScaleFactorDefault) {
if (x11gd.isScaleFactorDefault.get() || !uiScaleEnabled) {
x11gd.scale = (int)Math.round(xftDpiScale * (uiScaleEnabled ? GDK_SCALE_MULTIPLIER : 1));
x11gd.isScaleFactorDefault.set(false);
}
}
}
}
private int initScaleFactor() {
if (SunGraphicsEnvironment.isUIScaleEnabled()) {
private int initScaleFactor(int defValue) {
boolean uiScaleEnabled = SunGraphicsEnvironment.isUIScaleEnabled();
if (uiScaleEnabled) {
double debugScale = SunGraphicsEnvironment.getDebugScale();
if (debugScale >= 1) {
return (int) debugScale;
}
int nativeScale = getNativeScale();
if (nativeScale > 0) return nativeScale;
if (globalScale > 0) return globalScale;
isNativeScaleDefault = true;
return 1;
double gdkScaleMult = uiScaleEnabled ? GDK_SCALE_MULTIPLIER : 1;
double nativeScale = getNativeScale();
if (nativeScale > 0) {
return (int)Math.round(nativeScale * gdkScaleMult);
}
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 <stdlib.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_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);
if (uiScale != NULL) {
double scale = strtod(uiScale, NULL);
if (scale < 1) {
return -1;
locale_t c_locale = newlocale(LC_NUMERIC_MASK, "C", NULL);
double scale = strtod_l(uiScale, NULL, c_locale);
freelocale(c_locale);
if (scale > 0) {
return scale;
}
return (int) scale;
}
return -1;
return 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;
if (scale == -2) {
scale = getScale("J2D_UISCALE");
scale = (int)getScaleEnvVar("J2D_UISCALE", -1);
}
if (scale > 0) {
@@ -235,7 +241,5 @@ double getNativeScaleFactor(char *output_name, double default_value) {
native_scale = default_value;
}
gdk_scale = getScale("GDK_SCALE");
return gdk_scale > 0 ? (native_scale <= 0 ? 1 : native_scale) * gdk_scale : native_scale;
return native_scale;
}

View File

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

View File

@@ -2233,40 +2233,64 @@ static char *get_output_screen_name(JNIEnv *env, int screen) {
/*
* Class: sun_awt_X11GraphicsDevice
* Method: getNativeScaleFactor
* Signature: (I)D
* Signature: (ID)D
*/
JNIEXPORT jdouble JNICALL
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
char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
double scale = getNativeScaleFactor(name, -1);
#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
double scale = getNativeScaleFactor(name, defValue);
if (name) {
free(name);
}
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;
}