Search in sources :

Example 1 with FontPreferences

use of com.intellij.openapi.editor.colors.FontPreferences in project intellij-community by JetBrains.

the class LineLayout method createFragments.

private static List<BidiRun> createFragments(@NotNull EditorView view, @NotNull CharSequence text, @JdkConstants.FontStyle int fontStyle) {
    if (text.length() == 0)
        return Collections.emptyList();
    FontRenderContext fontRenderContext = view.getFontRenderContext();
    FontPreferences fontPreferences = view.getEditor().getColorsScheme().getFontPreferences();
    char[] chars = CharArrayUtil.fromSequence(text);
    List<BidiRun> runs = createRuns(view, chars, -1);
    for (BidiRun run : runs) {
        for (Chunk chunk : run.getChunks(text, 0)) {
            chunk.fragments = new ArrayList<>();
            addFragments(run, chunk, chars, chunk.startOffset, chunk.endOffset, fontStyle, fontPreferences, fontRenderContext, null);
        }
    }
    return runs;
}
Also used : FontPreferences(com.intellij.openapi.editor.colors.FontPreferences) FontRenderContext(java.awt.font.FontRenderContext)

Example 2 with FontPreferences

use of com.intellij.openapi.editor.colors.FontPreferences in project android by JetBrains.

the class FontUtil method getFontAbleToDisplay.

@NotNull
public static Font getFontAbleToDisplay(@NotNull String s, @NotNull Font defaultFont) {
    if (// On Macs, all fonts can display all the characters because the system renders using fallback fonts.
    SystemInfo.isMac || isExtendedAscii(s)) {
        // Assume that default font can handle ASCII
        return defaultFont;
    }
    Set<Font> fonts = Sets.newHashSetWithExpectedSize(10);
    FontPreferences fontPreferences = EditorColorsManager.getInstance().getGlobalScheme().getFontPreferences();
    for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) > 255) {
            fonts.add(ComplementaryFontsRegistry.getFontAbleToDisplay(s.charAt(i), Font.PLAIN, fontPreferences, null).getFont());
        }
    }
    if (fonts.isEmpty()) {
        return defaultFont;
    }
    // find the font the can handle the most # of characters
    Font bestFont = defaultFont;
    int max = 0;
    for (Font f : fonts) {
        int supportedChars = 0;
        for (int i = 0; i < s.length(); i++) {
            if (f.canDisplay(s.charAt(i))) {
                supportedChars++;
            }
        }
        if (supportedChars > max) {
            max = supportedChars;
            bestFont = f;
        }
    }
    return bestFont;
}
Also used : FontPreferences(com.intellij.openapi.editor.colors.FontPreferences) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FontPreferences

use of com.intellij.openapi.editor.colors.FontPreferences in project intellij-community by JetBrains.

the class EditorColorsSchemeDelegateTest method testSecondaryFontIsAvailable.

public void testSecondaryFontIsAvailable() throws Exception {
    FontPreferences globalPrefs = myTestScheme.getFontPreferences();
    assertInstanceOf(globalPrefs, ModifiableFontPreferences.class);
    ((ModifiableFontPreferences) globalPrefs).register("DummyFont", globalPrefs.getSize(globalPrefs.getFontFamily()));
    assertEquals(2, globalPrefs.getRealFontFamilies().size());
    init("blah", TestFileType.TEXT);
    FontPreferences editorPrefs = myEditor.getColorsScheme().getFontPreferences();
    assertEquals(2, editorPrefs.getRealFontFamilies().size());
    assertEquals("DummyFont", editorPrefs.getRealFontFamilies().get(1));
}
Also used : FontPreferences(com.intellij.openapi.editor.colors.FontPreferences) ModifiableFontPreferences(com.intellij.openapi.editor.colors.ModifiableFontPreferences) ModifiableFontPreferences(com.intellij.openapi.editor.colors.ModifiableFontPreferences)

Example 4 with FontPreferences

use of com.intellij.openapi.editor.colors.FontPreferences in project intellij-community by JetBrains.

the class ConsoleFontOptions method setDelegatingPreferences.

@Override
protected void setDelegatingPreferences(boolean isDelegating) {
    FontPreferences currPrefs = getCurrentScheme().getConsoleFontPreferences();
    if (currPrefs instanceof DelegatingFontPreferences == isDelegating)
        return;
    if (isDelegating) {
        getCurrentScheme().setUseEditorFontPreferencesInConsole();
    } else {
        getCurrentScheme().setConsoleFontPreferences(getFontPreferences());
    }
    updateOptionsList();
    updateDescription(true);
}
Also used : FontPreferences(com.intellij.openapi.editor.colors.FontPreferences) DelegatingFontPreferences(com.intellij.openapi.editor.colors.DelegatingFontPreferences) DelegatingFontPreferences(com.intellij.openapi.editor.colors.DelegatingFontPreferences)

Example 5 with FontPreferences

use of com.intellij.openapi.editor.colors.FontPreferences in project intellij-community by JetBrains.

the class LookupCellRenderer method getFontAbleToDisplay.

@Nullable
Font getFontAbleToDisplay(LookupElementPresentation p) {
    String sampleString = p.getItemText() + p.getTailText() + p.getTypeText();
    // assume a single font can display all lookup item chars
    Set<Font> fonts = ContainerUtil.newHashSet();
    FontPreferences fontPreferences = myLookup.getFontPreferences();
    for (int i = 0; i < sampleString.length(); i++) {
        fonts.add(ComplementaryFontsRegistry.getFontAbleToDisplay(sampleString.charAt(i), Font.PLAIN, fontPreferences, null).getFont());
    }
    eachFont: for (Font font : fonts) {
        if (font.equals(myNormalFont))
            continue;
        for (int i = 0; i < sampleString.length(); i++) {
            if (!font.canDisplay(sampleString.charAt(i))) {
                continue eachFont;
            }
        }
        return font;
    }
    return null;
}
Also used : FontPreferences(com.intellij.openapi.editor.colors.FontPreferences) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FontPreferences (com.intellij.openapi.editor.colors.FontPreferences)5 LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)1 DelegatingFontPreferences (com.intellij.openapi.editor.colors.DelegatingFontPreferences)1 ModifiableFontPreferences (com.intellij.openapi.editor.colors.ModifiableFontPreferences)1 FontRenderContext (java.awt.font.FontRenderContext)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1