diff --git a/platform/core-api/src/com/intellij/util/IconUtil.java b/platform/core-api/src/com/intellij/util/IconUtil.java index 03394c8a8c51..d4ef5efbea58 100644 --- a/platform/core-api/src/com/intellij/util/IconUtil.java +++ b/platform/core-api/src/com/intellij/util/IconUtil.java @@ -489,7 +489,7 @@ public class IconUtil { */ @NotNull public static Icon scaleByFont(@NotNull Icon icon, @Nullable Component ancestor, float fontSize) { - float scale = fontSize / UIUtil.DEF_SYSTEM_FONT_SIZE; + float scale = JBUI.getFontScale(fontSize); if (icon instanceof ScalableIcon) { if (icon instanceof JBUIScaleTrackable) { JBUIScaleTrackable jbuiIcon = (JBUIScaleTrackable)icon; diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt index ccdb8c3dfb0f..c85456eb1df7 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt @@ -54,7 +54,7 @@ class UISettings : BaseState(), PersistentStateComponent { @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SIZE") - var fontSize by storedProperty((UIUtil.DEF_SYSTEM_FONT_SIZE * UISettings.normalizingScale).toInt()) + var fontSize by storedProperty(defFontSize) @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SCALE") @@ -191,7 +191,7 @@ class UISettings : BaseState(), PersistentStateComponent { val fontData = systemFontFaceAndSize if (fontFace == null) fontFace = fontData.first if (fontSize <= 0) fontSize = fontData.second - if (fontScale <= 0) fontScale = normalizingScale + if (fontScale <= 0) fontScale = defFontScale } class FontFilter : SerializationFilter { @@ -232,7 +232,7 @@ class UISettings : BaseState(), PersistentStateComponent { } fontSize = restoreFontSize(fontSize, fontScale) - fontScale = normalizingScale + fontScale = defFontScale initDefFont() // 1. Sometimes system font cannot display standard ASCII symbols. If so we have @@ -366,21 +366,39 @@ class UISettings : BaseState(), PersistentStateComponent { instance.editorAAType?.let { GraphicsUtil.setAntialiasingType(component, it.textInfo) } } + /** + * Returns the default font scale, which depends on the HiDPI mode (see JBUI#ScaleType). + *

+ * The font is represented: + * - in relative (dpi-independent) points in the JRE-managed HiDPI mode, so the method returns 1.0f + * - in absolute (dpi-dependent) points in the IDE-managed HiDPI mode, so the method returns the default screen scale + * + * @return the system font scale + */ @JvmStatic - val normalizingScale: Float + val defFontScale: Float get() = if (UIUtil.isJreHiDPIEnabled()) 1f else JBUI.sysScale() + /** + * Returns the default font size scaled by #defFontScale + * + * @return the default scaled font size + */ + @JvmStatic + val defFontSize: Int + get() = Math.round(UIUtil.DEF_SYSTEM_FONT_SIZE * defFontScale) + @JvmStatic fun restoreFontSize(readSize: Int, readScale: Float?): Int { var size = readSize if (readScale == null || readScale <= 0) { // Reset font to default on switch from IDE-managed HiDPI to JRE-managed HiDPI. Doesn't affect OSX. - if (UIUtil.isJreHiDPIEnabled() && !SystemInfo.isMac) size = UIUtil.DEF_SYSTEM_FONT_SIZE.toInt() + if (UIUtil.isJreHiDPIEnabled() && !SystemInfo.isMac) size = defFontSize } else { - if (readScale != normalizingScale) size = Math.round((readSize / readScale) * normalizingScale) + if (readScale != defFontScale) size = Math.round((readSize / readScale) * defFontScale) } - LOG.info("Loaded: fontSize=$readSize, fontScale=$readScale; restored: fontSize=$size, fontScale=$normalizingScale") + LOG.info("Loaded: fontSize=$readSize, fontScale=$readScale; restored: fontSize=$size, fontScale=$defFontScale") return size } } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index 4503eb7ddf2c..b8303d26d84f 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -56,6 +56,7 @@ import static com.intellij.ui.ColorUtil.fromHex; public abstract class AbstractColorsScheme extends EditorFontCacheImpl implements EditorColorsScheme, SerializableScheme { private static final int CURR_VERSION = 142; + // todo: unify with UIUtil.DEF_SYSTEM_FONT_SIZE private static final FontSize DEFAULT_FONT_SIZE = FontSize.SMALL; protected EditorColorsScheme myParentScheme; @@ -500,7 +501,7 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement private int readFontSize(Element element, boolean isDefault, Float fontScale) { if (isDefault) { - return (int)(UISettings.getNormalizingScale() * DEFAULT_FONT_SIZE.getSize()); + return UISettings.getDefFontSize(); } Integer intSize = myValueReader.read(Integer.class, element); if (intSize == null) { @@ -551,7 +552,7 @@ public abstract class AbstractColorsScheme extends EditorFontCacheImpl implement * FONT_SCALE value should also be written by that reason. */ if (!(myFontPreferences instanceof DelegatingFontPreferences) || !(myConsoleFontPreferences instanceof DelegatingFontPreferences)) { - JdomKt.addOptionTag(parentNode, FONT_SCALE, String.valueOf(UISettings.getNormalizingScale())); // must precede font options + JdomKt.addOptionTag(parentNode, FONT_SCALE, String.valueOf(UISettings.getDefFontScale())); // must precede font options } if (myParentScheme != null && myParentScheme != EmptyColorScheme.INSTANCE) { diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java index 4de39add37d3..98c1fa403cca 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java @@ -56,7 +56,7 @@ public class AppEditorFontOptions implements PersistentStateComponent fontFamilies = fontPreferences.getEffectiveFontFamilies(); diff --git a/platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java b/platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java index 8dc8a7e93b43..edb6827a7e6c 100644 --- a/platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java +++ b/platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java @@ -116,7 +116,7 @@ class TextPainter extends BasePainter { Printing Graphics is constructed with scale corresponding to the printer DPI settings (~600dpi), the font size is expected to be in 96 dpi, so we should normalize it. */ - int fontSize = Math.round(myPrintSettings.FONT_SIZE / UISettings.getNormalizingScale()); + int fontSize = Math.round(myPrintSettings.FONT_SIZE / UISettings.getDefFontScale()); myPlainFont = new Font(fontName, Font.PLAIN, fontSize); myBoldFont = new Font(fontName, Font.BOLD, fontSize); myItalicFont = new Font(fontName, Font.ITALIC, fontSize); diff --git a/platform/platform-api/src/com/intellij/ui/components/breadcrumbs/Breadcrumbs.java b/platform/platform-api/src/com/intellij/ui/components/breadcrumbs/Breadcrumbs.java index c0e2e044cfdc..b590e9a8f0c0 100644 --- a/platform/platform-api/src/com/intellij/ui/components/breadcrumbs/Breadcrumbs.java +++ b/platform/platform-api/src/com/intellij/ui/components/breadcrumbs/Breadcrumbs.java @@ -25,6 +25,7 @@ import com.intellij.ui.paint.RectanglePainter; import com.intellij.util.IconUtil; import com.intellij.util.ui.AbstractLayoutManager; import com.intellij.util.ui.JBInsets; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.MouseEventHandler; import org.intellij.lang.annotations.JdkConstants.FontStyle; @@ -441,7 +442,7 @@ public class Breadcrumbs extends JComponent { } if (parent != null && parent.background == background && !Registry.is("editor.breadcrumbs.marker")) { Graphics2D g2 = (Graphics2D)g.create(); - float stroke = getFontSize(getFont()) / DEF_SYSTEM_FONT_SIZE; + float stroke = JBUI.getFontScale(getFontSize(getFont())); // calculate a visible width of separator (30% of a whole path) int delta = (int)(scale * (.3 * getRightGap() + getLeftGap())); g2.clipRect(bounds.x - delta, bounds.y, Short.MAX_VALUE, bounds.height); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/TogglePresentationModeAction.java b/platform/platform-impl/src/com/intellij/ide/actions/TogglePresentationModeAction.java index ba0858873b97..84503edb913f 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/TogglePresentationModeAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/TogglePresentationModeAction.java @@ -148,7 +148,7 @@ public class TogglePresentationModeAction extends AnAction implements DumbAware } } } - float scaleFactor = settings.getPresentationModeFontSize() / UIUtil.DEF_SYSTEM_FONT_SIZE; + float scaleFactor = JBUI.getFontScale(settings.getPresentationModeFontSize()); ourSavedScaleFactor = JBUI.scale(1f); JBUI.setUserScaleFactor(scaleFactor); for (Object key : ourSavedValues.keySet()) { diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java index 9cc050c80c9e..4570f43e366a 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java @@ -707,7 +707,7 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC if (uiSettings.getOverrideLafFonts()) { storeOriginalFontDefaults(uiDefaults); initFontDefaults(uiDefaults, uiSettings.getFontSize(), new FontUIResource(uiSettings.getFontFace(), Font.PLAIN, uiSettings.getFontSize())); - JBUI.setUserScaleFactor(uiSettings.getFontSize() / UIUtil.DEF_SYSTEM_FONT_SIZE); + JBUI.setUserScaleFactor(JBUI.getFontScale(uiSettings.getFontSize())); } else { restoreOriginalFontDefaults(uiDefaults); @@ -722,7 +722,7 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC defaults.put(resource, lfDefaults.get(resource)); } } - JBUI.setUserScaleFactor(JBUI.Fonts.label().getSize() / UIUtil.DEF_SYSTEM_FONT_SIZE); + JBUI.setUserScaleFactor(JBUI.getFontScale(JBUI.Fonts.label().getSize())); } private void storeOriginalFontDefaults(UIDefaults defaults) { diff --git a/platform/util/src/com/intellij/util/ui/JBUI.java b/platform/util/src/com/intellij/util/ui/JBUI.java index fb02c4ba7141..ebc773826ccf 100644 --- a/platform/util/src/com/intellij/util/ui/JBUI.java +++ b/platform/util/src/com/intellij/util/ui/JBUI.java @@ -198,7 +198,7 @@ public class JBUI { Pair fdata = UIUtil.getSystemFontData(); int size = fdata == null ? Fonts.label().getSize() : fdata.getSecond(); - return size / UIUtil.DEF_SYSTEM_FONT_SIZE; + return getFontScale(size); } /** @@ -365,6 +365,14 @@ public class JBUI { return (int)scale(fontSize); } + /** + * @param fontSize + * @return the scale factor of {@code fontSize} relative to the standard font size (currently 12pt) + */ + public static float getFontScale(float fontSize) { + return fontSize / UIUtil.DEF_SYSTEM_FONT_SIZE; + } + public static JBDimension size(int width, int height) { return new JBDimension(width, height); }