From 1bae670acfef3fd1cee349ea3b16b10bfd254189 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 10 Aug 2017 16:02:21 +0300 Subject: [PATCH] vcs-log: use FontFallbackIterator for details view rendering `getFontAbleToDisplay(char, ...)` can return wrong font for symbols, that consist of multiple characters. follow-up: f9e87096304a9ccee8e98e35a795e685b455e73e --- .../com/intellij/openapi/vcs/ui/FontUtil.java | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/FontUtil.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/FontUtil.java index dc7cacf2244c..41d6f783ac30 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/FontUtil.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/FontUtil.java @@ -15,20 +15,13 @@ */ package com.intellij.openapi.vcs.ui; -import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry; +import com.intellij.openapi.editor.impl.FontFallbackIterator; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.awt.*; public class FontUtil { - @Nullable - public static Font getFontAbleToDisplay(char c, int size, int style, @NotNull String family) { - Font font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, size, style, family, null).getFont(); - return font.canDisplay(c) ? font : null; - } - @NotNull public static String getHtmlWithFonts(@NotNull String input) { Font font = UIUtil.getLabelFont(); @@ -40,26 +33,29 @@ public class FontUtil { int start = baseFont.canDisplayUpTo(input); if (start == -1) return input; - Font font = null; - StringBuilder result = new StringBuilder(input.substring(0, start)); - 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; + StringBuilder result = new StringBuilder(); + + FontFallbackIterator it = new FontFallbackIterator(); + it.setPreferredFont(baseFont.getFamily(), baseFont.getSize()); + it.setFontStyle(style); + + it.start(input, 0, input.length()); + while (!it.atEnd()) { + Font font = it.getFont(); + + boolean insideFallbackBlock = !font.getFamily().equals(baseFont.getFamily()); + if (insideFallbackBlock) { + result.append(""); } - else if (font != null && font.canDisplay(c)) { - result.append(c); - } - else { - if (font != null) result.append(""); - font = getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily()); - if (font != null) result.append(""); - result.append(c); + + result.append(input, it.getStart(), it.getEnd()); + + if (insideFallbackBlock) { + result.append(""); } + + it.advance(); } - if (font != null) result.append(""); return result.toString(); }