mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
revert a part of IDEA-CR-9690
Reverted the changes made unintentionally in IDEA-CR-9690.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,61 +37,35 @@ import java.awt.*;
|
||||
public class JBUI {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.util.ui.JBUI");
|
||||
|
||||
private static float SCALE_FACTOR = calculateScaleFactor();
|
||||
private static float scaleFactor = 1.0f;
|
||||
|
||||
private static float calculateScaleFactor() {
|
||||
static {
|
||||
calculateScaleFactor();
|
||||
}
|
||||
|
||||
private static void calculateScaleFactor() {
|
||||
if (SystemInfo.isMac) {
|
||||
LOG.info("UI scale factor: 1.0");
|
||||
return 1.0f;
|
||||
scaleFactor = 1.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
|
||||
LOG.info("UI scale factor: 1.0");
|
||||
return 1.0f;
|
||||
scaleFactor = 1.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
float s = 1f;
|
||||
UIUtil.initSystemFontData();
|
||||
Pair<String, Integer> fdata = UIUtil.getSystemFontData();
|
||||
|
||||
// On Linux: rely on DPI
|
||||
if (SystemInfo.isLinux) {
|
||||
final int dpi = getSystemDPI();
|
||||
if (dpi < 120) s = 1f;
|
||||
else if (dpi < 144) s = 1.25f;
|
||||
else if (dpi < 168) s = 1.5f;
|
||||
else if (dpi < 192) s = 1.75f;
|
||||
else s = 2f;
|
||||
|
||||
LOG.info("UI scale factor: " + s);
|
||||
return s;
|
||||
}
|
||||
|
||||
int size = -1;
|
||||
|
||||
// On Windows: rely on default system font
|
||||
if (SystemInfo.isWindows) {
|
||||
UIUtil.initSystemFontData();
|
||||
Pair<String, Integer> fdata = UIUtil.getSystemFontData();
|
||||
if (fdata != null) size = fdata.getSecond();
|
||||
}
|
||||
if (size == -1) {
|
||||
int size;
|
||||
if (fdata != null) {
|
||||
size = fdata.getSecond();
|
||||
} else {
|
||||
size = Fonts.label().getSize();
|
||||
}
|
||||
if (size <= 13) s = 1.0f;
|
||||
else if (size <= 16) s = 1.25f;
|
||||
else if (size <= 18) s = 1.5f;
|
||||
else if (size < 24) s = 1.75f;
|
||||
else s = 2.0f;
|
||||
|
||||
LOG.info("UI scale factor: " + s);
|
||||
return s;
|
||||
}
|
||||
|
||||
private static int getSystemDPI() {
|
||||
try {
|
||||
return Toolkit.getDefaultToolkit().getScreenResolution();
|
||||
} catch (HeadlessException e) {
|
||||
return 96;
|
||||
}
|
||||
setScaleFactor(size/UIUtil.DEF_SYSTEM_FONT_SIZE);
|
||||
}
|
||||
|
||||
public static void setScaleFactor(float scale) {
|
||||
@@ -109,19 +83,22 @@ public class JBUI {
|
||||
//Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux
|
||||
scale = 1f;
|
||||
}
|
||||
LOG.info("UI scale factor changed: " + scale);
|
||||
if (scaleFactor == scale) {
|
||||
return;
|
||||
}
|
||||
LOG.info("UI scale factor: " + scale);
|
||||
|
||||
SCALE_FACTOR = scale;
|
||||
scaleFactor = scale;
|
||||
IconLoader.setScale(scale);
|
||||
}
|
||||
|
||||
public static int scale(int i) {
|
||||
return Math.round(SCALE_FACTOR * i);
|
||||
return Math.round(scaleFactor * i);
|
||||
}
|
||||
|
||||
public static int scaleFontSize(int fontSize) {
|
||||
if (SCALE_FACTOR == 1.25f) return (int)(fontSize * 1.34f);
|
||||
if (SCALE_FACTOR == 1.75f) return (int)(fontSize * 1.67f);
|
||||
if (scaleFactor == 1.25f) return (int)(fontSize * 1.34f);
|
||||
if (scaleFactor == 1.75f) return (int)(fontSize * 1.67f);
|
||||
return scale(fontSize);
|
||||
}
|
||||
|
||||
@@ -186,7 +163,7 @@ public class JBUI {
|
||||
}
|
||||
|
||||
public static float scale(float f) {
|
||||
return f * SCALE_FACTOR;
|
||||
return f * scaleFactor;
|
||||
}
|
||||
|
||||
public static JBInsets insets(Insets insets) {
|
||||
@@ -194,7 +171,7 @@ public class JBUI {
|
||||
}
|
||||
|
||||
public static boolean isHiDPI() {
|
||||
return SCALE_FACTOR > 1.0f;
|
||||
return scaleFactor > 1.0f;
|
||||
}
|
||||
|
||||
public static class Fonts {
|
||||
|
||||
Reference in New Issue
Block a user