diff --git a/platform/util/src/com/intellij/util/ui/JBUI.java b/platform/util/src/com/intellij/util/ui/JBUI.java index 25413e0c1966..d6f47ccb0d47 100644 --- a/platform/util/src/com/intellij/util/ui/JBUI.java +++ b/platform/util/src/com/intellij/util/ui/JBUI.java @@ -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 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 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 {