diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java index 121d6f5171d6..ac5ce7f87890 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java @@ -46,10 +46,7 @@ import com.intellij.ui.popup.AbstractPopup; import com.intellij.util.Url; import com.intellij.util.Urls; import com.intellij.util.containers.HashMap; -import com.intellij.util.ui.GraphicsUtil; -import com.intellij.util.ui.JBDimension; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.*; import com.intellij.util.ui.accessibility.AccessibleContextUtil; import com.intellij.util.ui.accessibility.ScreenReader; import org.jetbrains.annotations.NonNls; @@ -258,8 +255,10 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr myEditorPane.setBackground(EditorColorsUtil.getGlobalOrDefaultColor(COLOR_KEY)); HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit(false); String editorFontName = StringUtil.escapeQuotes(EditorColorsManager.getInstance().getGlobalScheme().getEditorFontName()); - editorKit.getStyleSheet().addRule("code {font-family:\"" + editorFontName + "\"}"); - editorKit.getStyleSheet().addRule("pre {font-family:\"" + editorFontName + "\"}"); + if (isMonospacedFont(editorFontName)) { + editorKit.getStyleSheet().addRule("code {font-family:\"" + editorFontName + "\"}"); + editorKit.getStyleSheet().addRule("pre {font-family:\"" + editorFontName + "\"}"); + } myEditorPane.setEditorKit(editorKit); myScrollPane = new JBScrollPane(myEditorPane) { @Override @@ -451,6 +450,10 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr updateControlState(); } + private static boolean isMonospacedFont(String fontName) { + return FontInfo.isMonospaced(new Font(fontName, Font.PLAIN, 12)); + } + public DocumentationComponent(final DocumentationManager manager) { this(manager, null); } diff --git a/platform/util/src/com/intellij/util/ui/FontInfo.java b/platform/util/src/com/intellij/util/ui/FontInfo.java index 9a5a97724778..ef2bca8837ad 100644 --- a/platform/util/src/com/intellij/util/ui/FontInfo.java +++ b/platform/util/src/com/intellij/util/ui/FontInfo.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.ui; import java.awt.*; @@ -208,6 +194,10 @@ public final class FontInfo { return width == getCharWidth(font, 'l') && width == getCharWidth(font, 'W') ? width : 0; } + public static boolean isMonospaced(Font font) { + return getFontWidth(font, Font.PLAIN) > 0; + } + private static int getCharWidth(Font font, char ch) { if (font.canDisplay(ch)) { Rectangle bounds = font.getStringBounds(new char[]{ch}, 0, 1, DEFAULT_CONTEXT).getBounds();