From e06e135b746a10cea4147e76805f0894e8b9f9f3 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 23 Mar 2016 23:59:46 +0300 Subject: [PATCH] [vcs-log] use fallback fonts for renderring commit message in details IDEA-143113 --- .../vcs/log/ui/frame/DetailsPanel.java | 25 ++++++-- .../intellij/vcs/log/ui/frame/FontUtil.java | 57 +++++++++++++++++++ 2 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/FontUtil.java diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java index 032bf599e281..74c1c5a8ecca 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/DetailsPanel.java @@ -288,14 +288,29 @@ class DetailsPanel extends JPanel implements ListSelectionListener { myMainText = null; } else { - String header = commit.getId().toShortString() + " " + getAuthorText(commit) + - (myMultiRoot ? " [" + commit.getRoot().getName() + "]" : ""); + String header = getHtmlWithFonts(commit.getId().toShortString() + " " + getAuthorText(commit) + + (myMultiRoot ? " [" + commit.getRoot().getName() + "]" : "")); String body = getMessageText(commit); myMainText = header + "
" + body; } update(); } + @NotNull + private static String getHtmlWithFonts(@NotNull String input) { + return getHtmlWithFonts(input, getBaseFont().getStyle()); + } + + @NotNull + private static String getHtmlWithFonts(@NotNull String input, int style) { + return FontUtil.getHtmlWithFonts(input, style, getBaseFont()); + } + + @NotNull + private static Font getBaseFont() { + return EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); + } + void setBranches(@Nullable List branches) { if (branches == null) { myBranches = null; @@ -313,7 +328,7 @@ class DetailsPanel extends JPanel implements ListSelectionListener { } else { setText("" + - UIUtil.getCssFontDeclaration(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN)) + + UIUtil.getCssFontDeclaration(getBaseFont()) + "" + myMainText + "
" + @@ -413,8 +428,8 @@ class DetailsPanel extends JPanel implements ListSelectionListener { int separator = fullMessage.indexOf("\n\n"); String subject = separator > 0 ? fullMessage.substring(0, separator) : fullMessage; String description = fullMessage.substring(subject.length()); - return "" + escapeMultipleSpaces(IssueLinkHtmlRenderer.formatTextWithLinks(myProject, subject)) + "" + - escapeMultipleSpaces(IssueLinkHtmlRenderer.formatTextWithLinks(myProject, description)); + return "" + getHtmlWithFonts(escapeMultipleSpaces(IssueLinkHtmlRenderer.formatTextWithLinks(myProject, subject)), Font.BOLD) + "" + + getHtmlWithFonts(escapeMultipleSpaces(IssueLinkHtmlRenderer.formatTextWithLinks(myProject, description))); } @NotNull diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/FontUtil.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/FontUtil.java new file mode 100644 index 000000000000..9bbf20a83b60 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/FontUtil.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2016 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. + */ +package com.intellij.vcs.log.ui.frame; + +import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public class FontUtil { + @NotNull + public static Font getFontAbleToDisplay(char c, int style, @NotNull Font baseFont) { + return ComplementaryFontsRegistry.getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily()).getFont(); + } + + @NotNull + public static String getHtmlWithFonts(@NotNull String input, int style, @NotNull Font baseFont) { + int start = baseFont.canDisplayUpTo(input); + if (start == -1) return input; + + Font font = null; + StringBuilder result = new StringBuilder(); + for (int i = start; i < input.length(); i++) { + char c = input.charAt(i); + if (baseFont.canDisplay(c)) { + if (font != null) result.append(""); + result.append(c); + font = null; + } + else if (font != null && font.canDisplay(c)) { + result.append(c); + } + else { + if (font != null) result.append(""); + font = getFontAbleToDisplay(c, style, baseFont); + if (font != baseFont) result.append(""); + result.append(c); + } + } + if (font != null) result.append(""); + + return result.toString(); + } +}