mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-164566: [make UI & ColorScheme font size JDK-managed-HiDPI aware]
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.ComponentTreeEventDispatcher;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.xmlb.Accessor;
|
||||
import com.intellij.util.xmlb.SerializationFilter;
|
||||
@@ -67,11 +68,16 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
public static UISettings getShadowInstance() {
|
||||
Application application = ApplicationManager.getApplication();
|
||||
UISettings settings = application == null ? null : getInstance();
|
||||
return settings == null ? new UISettings() : settings;
|
||||
return settings == null ? new UISettings().withDefFont() : settings;
|
||||
}
|
||||
|
||||
// These font properties should not be set in the default ctor,
|
||||
// so that to make the serialization logic judge if a property
|
||||
// should be stored or shouldn't by the provided filter only.
|
||||
@Property(filter = FontFilter.class) public String FONT_FACE;
|
||||
@Property(filter = FontFilter.class) public int FONT_SIZE;
|
||||
@Property(filter = FontFilter.class) private float FONT_SCALE;
|
||||
|
||||
public int RECENT_FILES_LIMIT = 50;
|
||||
public int CONSOLE_COMMAND_HISTORY_LIMIT = 300;
|
||||
public boolean OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = false;
|
||||
@@ -139,7 +145,6 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
|
||||
public UISettings() {
|
||||
tweakPlatformDefaults();
|
||||
setSystemFontFaceAndSize();
|
||||
|
||||
Boolean scrollToSource = WelcomeWizardUtil.getAutoScrollToSource();
|
||||
if (scrollToSource != null) {
|
||||
@@ -147,6 +152,11 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
}
|
||||
}
|
||||
|
||||
private UISettings withDefFont() {
|
||||
initDefFont();
|
||||
return this;
|
||||
}
|
||||
|
||||
private void tweakPlatformDefaults() {
|
||||
// TODO[anton] consider making all IDEs use the same settings
|
||||
if (PlatformUtils.isAppCode()) {
|
||||
@@ -182,12 +192,11 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
}
|
||||
}
|
||||
|
||||
private void setSystemFontFaceAndSize() {
|
||||
if (FONT_FACE == null || FONT_SIZE <= 0) {
|
||||
final Pair<String, Integer> fontData = getSystemFontFaceAndSize();
|
||||
FONT_FACE = fontData.first;
|
||||
FONT_SIZE = fontData.second;
|
||||
}
|
||||
private void initDefFont() {
|
||||
Pair<String, Integer> fontData = getSystemFontFaceAndSize();
|
||||
if (FONT_FACE == null) FONT_FACE = fontData.first;
|
||||
if (FONT_SIZE <= 0) FONT_SIZE = fontData.second;
|
||||
if (FONT_SCALE <= 0) FONT_SCALE = JBUI.scale(1f);
|
||||
}
|
||||
|
||||
private static Pair<String, Integer> getSystemFontFaceAndSize() {
|
||||
@@ -203,15 +212,15 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
@Override
|
||||
public boolean accepts(@NotNull Accessor accessor, @NotNull Object bean) {
|
||||
UISettings settings = (UISettings)bean;
|
||||
return !hasDefaultFontSetting(settings);
|
||||
final Pair<String, Integer> fontData = getSystemFontFaceAndSize();
|
||||
if ("FONT_FACE".equals(accessor.getName())) {
|
||||
return !fontData.first.equals(settings.FONT_FACE);
|
||||
}
|
||||
// store only in pair
|
||||
return !(fontData.second.equals(settings.FONT_SIZE) && 1f == settings.FONT_SCALE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasDefaultFontSetting(final UISettings settings) {
|
||||
final Pair<String, Integer> fontData = getSystemFontFaceAndSize();
|
||||
return fontData.first.equals(settings.FONT_FACE) && fontData.second.equals(settings.FONT_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UISettings getState() {
|
||||
return this;
|
||||
@@ -238,7 +247,15 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
|
||||
ALPHA_MODE_RATIO = 0.5f;
|
||||
}
|
||||
|
||||
setSystemFontFaceAndSize();
|
||||
if (FONT_SCALE <= 0) {
|
||||
if (UIUtil.isJDKManagedHiDPI()) FONT_SIZE = (int)UIUtil.DEF_SYSTEM_FONT_SIZE;
|
||||
}
|
||||
else {
|
||||
FONT_SIZE = (int)JBUI.scale(FONT_SIZE / FONT_SCALE);
|
||||
}
|
||||
FONT_SCALE = JBUI.scale(1f);
|
||||
initDefFont();
|
||||
|
||||
// 1. Sometimes system font cannot display standard ASCII symbols. If so we have
|
||||
// find any other suitable font withing "preferred" fonts first.
|
||||
boolean fontIsValid = isValidFont(new Font(FONT_FACE, Font.PLAIN, FONT_SIZE));
|
||||
|
||||
+30
-11
@@ -31,6 +31,7 @@ import com.intellij.openapi.options.SchemeManager;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.JdomKt;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
@@ -102,6 +103,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
@NonNls private static final String BACKGROUND_COLOR_NAME = "BACKGROUND";
|
||||
@NonNls private static final String LINE_SPACING = "LINE_SPACING";
|
||||
@NonNls private static final String CONSOLE_LINE_SPACING = "CONSOLE_LINE_SPACING";
|
||||
@NonNls private static final String FONT_SCALE = "FONT_SCALE";
|
||||
@NonNls private static final String EDITOR_FONT_SIZE = "EDITOR_FONT_SIZE";
|
||||
@NonNls private static final String CONSOLE_FONT_SIZE = "CONSOLE_FONT_SIZE";
|
||||
@NonNls private static final String EDITOR_LIGATURES = "EDITOR_LIGATURES";
|
||||
@@ -345,17 +347,18 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
}
|
||||
|
||||
myMetaInfo.clear();
|
||||
Ref<Float> fontScale = Ref.create();
|
||||
for (Element childNode : node.getChildren()) {
|
||||
String childName = childNode.getName();
|
||||
switch (childName) {
|
||||
case OPTION_ELEMENT:
|
||||
readSettings(childNode, isDefault);
|
||||
readSettings(childNode, isDefault, fontScale);
|
||||
break;
|
||||
case EDITOR_FONT:
|
||||
readFontSettings(childNode, myFontPreferences, isDefault);
|
||||
readFontSettings(childNode, myFontPreferences, isDefault, fontScale.get());
|
||||
break;
|
||||
case CONSOLE_FONT:
|
||||
readFontSettings(childNode, myConsoleFontPreferences, isDefault);
|
||||
readFontSettings(childNode, myConsoleFontPreferences, isDefault, fontScale.get());
|
||||
break;
|
||||
case COLORS_ELEMENT:
|
||||
readColors(childNode);
|
||||
@@ -463,15 +466,19 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
}
|
||||
}
|
||||
|
||||
private void readSettings(@NotNull Element childNode, boolean isDefault) {
|
||||
private void readSettings(@NotNull Element childNode, boolean isDefault, @NotNull Ref<Float> fontScale) {
|
||||
switch (childNode.getAttributeValue(NAME_ATTR)) {
|
||||
case FONT_SCALE: {
|
||||
fontScale.set(myValueReader.read(Float.class, childNode));
|
||||
break;
|
||||
}
|
||||
case LINE_SPACING: {
|
||||
Float value = myValueReader.read(Float.class, childNode);
|
||||
if (value != null) myLineSpacing = value;
|
||||
break;
|
||||
}
|
||||
case EDITOR_FONT_SIZE: {
|
||||
int value = readFontSize(childNode, isDefault);
|
||||
int value = readFontSize(childNode, isDefault, fontScale.get());
|
||||
if (value > 0) setEditorFontSize(value);
|
||||
break;
|
||||
}
|
||||
@@ -486,7 +493,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
break;
|
||||
}
|
||||
case CONSOLE_FONT_SIZE: {
|
||||
int value = readFontSize(childNode, isDefault);
|
||||
int value = readFontSize(childNode, isDefault, fontScale.get());
|
||||
if (value > 0) setConsoleFontSize(value);
|
||||
break;
|
||||
}
|
||||
@@ -513,12 +520,22 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
}
|
||||
}
|
||||
|
||||
private int readFontSize(Element element, boolean isDefault) {
|
||||
Integer size = myValueReader.read(Integer.class, element);
|
||||
return size == null ? -1 : !isDefault ? size : JBUI.scaleFontSize(size);
|
||||
private int readFontSize(Element element, boolean isDefault, Float fontScale) {
|
||||
Float size = (float)myValueReader.read(Integer.class, element);
|
||||
if (size == null) {
|
||||
return -1;
|
||||
}
|
||||
if (!isDefault) {
|
||||
size = (fontScale != null) ? size / fontScale : DEFAULT_FONT_SIZE.getSize();
|
||||
}
|
||||
return JBUI.scaleFontSize(size);
|
||||
}
|
||||
|
||||
private void readFontSettings(@NotNull Element element, @NotNull FontPreferences preferences, boolean isDefaultScheme) {
|
||||
private void readFontSettings(@NotNull Element element,
|
||||
@NotNull FontPreferences preferences,
|
||||
boolean isDefaultScheme,
|
||||
@Nullable Float fontScale)
|
||||
{
|
||||
List children = element.getChildren(OPTION_ELEMENT);
|
||||
String fontFamily = null;
|
||||
int size = -1;
|
||||
@@ -528,7 +545,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
fontFamily = myValueReader.read(String.class, e);
|
||||
}
|
||||
else if (EDITOR_FONT_SIZE.equals(e.getAttributeValue(NAME_ATTR))) {
|
||||
size = readFontSize(e, isDefaultScheme);
|
||||
size = readFontSize(e, isDefaultScheme, fontScale);
|
||||
}
|
||||
}
|
||||
if (fontFamily != null && size > 1) {
|
||||
@@ -543,6 +560,8 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
|
||||
parentNode.setAttribute(NAME_ATTR, getName());
|
||||
parentNode.setAttribute(VERSION_ATTR, Integer.toString(myVersion));
|
||||
|
||||
JdomKt.addOptionTag(parentNode, FONT_SCALE, String.valueOf(JBUI.scale(1f))); // must precede font options
|
||||
|
||||
if (myParentScheme != null && myParentScheme != EmptyColorScheme.INSTANCE) {
|
||||
parentNode.setAttribute(PARENT_SCHEME_ATTR, myParentScheme.getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user