IDEA-181964 {@code} blocks in javadoc are not monospaced

This commit is contained in:
Dmitry Batrak
2017-11-24 15:30:14 +03:00
parent 864cd6935c
commit f28baf9253
2 changed files with 14 additions and 21 deletions
@@ -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);
}
@@ -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();