mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs-log: use FontFallbackIterator for details view rendering
`getFontAbleToDisplay(char, ...)` can return wrong font for symbols,
that consist of multiple characters.
follow-up: f9e8709630
This commit is contained in:
committed by
Aleksey Pivovarov
parent
aee9e0a22c
commit
1bae670acf
@@ -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("</font>");
|
||||
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("<font face=\"").append(font.getFamily()).append("\">");
|
||||
}
|
||||
else if (font != null && font.canDisplay(c)) {
|
||||
result.append(c);
|
||||
}
|
||||
else {
|
||||
if (font != null) result.append("</font>");
|
||||
font = getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily());
|
||||
if (font != null) result.append("<font face=\"").append(font.getFamily()).append("\">");
|
||||
result.append(c);
|
||||
|
||||
result.append(input, it.getStart(), it.getEnd());
|
||||
|
||||
if (insideFallbackBlock) {
|
||||
result.append("</font>");
|
||||
}
|
||||
|
||||
it.advance();
|
||||
}
|
||||
if (font != null) result.append("</font>");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user