private void syncFontFamilies() { if (myIsInSchemeChange) { return; } FontPreferences fontPreferences = getFontPreferences(); fontPreferences.clearFonts(); String primaryFontFamily = (String)myPrimaryCombo.getSelectedItem(); String secondaryFontFamily = mySecondaryCombo.isEnabled() ? (String)mySecondaryCombo.getSelectedItem() : null; int fontSize = getFontSizeFromField(); if (primaryFontFamily != null ) { if (!FontPreferences.DEFAULT_FONT_NAME.equals(primaryFontFamily)) { fontPreferences.addFontFamily(primaryFontFamily); } fontPreferences.register(primaryFontFamily, JBUI.scale(fontSize)); } if (secondaryFontFamily != null) { if (!FontPreferences.DEFAULT_FONT_NAME.equals(secondaryFontFamily)){ fontPreferences.addFontFamily(secondaryFontFamily); } fontPreferences.register(secondaryFontFamily, JBUI.scale(fontSize)); } updateDescription(true); }
@Override public void updateOptionsList() { myIsInSchemeChange = true; myLineSpacingField.setText(Float.toString(getLineSpacing())); FontPreferences fontPreferences = getFontPreferences(); List<String> fontFamilies = fontPreferences.getEffectiveFontFamilies(); myPrimaryCombo.setSelectedItem(fontPreferences.getFontFamily()); boolean isThereSecondaryFont = fontFamilies.size() > 1; myUseSecondaryFontCheckbox.setSelected(isThereSecondaryFont); mySecondaryCombo.setSelectedItem(isThereSecondaryFont ? fontFamilies.get(1) : null); myEditorFontSizeField.setText(String.valueOf(fontPreferences.getSize(fontPreferences.getFontFamily()))); boolean readOnly = ColorAndFontOptions.isReadOnly(myOptions.getSelectedScheme()); myPrimaryCombo.setEnabled(!readOnly); mySecondaryCombo.setEnabled(isThereSecondaryFont && !readOnly); myOnlyMonospacedCheckBox.setEnabled(!readOnly); myLineSpacingField.setEnabled(!readOnly); myEditorFontSizeField.setEditable(!readOnly); myUseSecondaryFontCheckbox.setEnabled(!readOnly); myIsInSchemeChange = false; }
private void updateModel() { if (myFontNames == null || myMonospacedFontNames == null) return; if (myMonospacedOnly == null || myMonospacedOnly.booleanValue() != EditorColorsManager.getInstance().isUseOnlyMonospacedFonts()) { myMonospacedOnly = EditorColorsManager.getInstance().isUseOnlyMonospacedFonts(); Object tmp = getSelectedItem(); myModel.removeAllElements(); List toAdd = myMonospacedOnly ? myMonospacedFontNames : myFontNames; for (Object o : toAdd) { myModel.addElement(o); } if (myModel.getIndexOf(tmp) != -1) { setSelectedItem(tmp); } else { setSelectedItem(FontPreferences.DEFAULT_FONT_NAME); } fireActionEvent(); revalidate(); repaint(); } }
@NotNull public static FontInfo getFontAbleToDisplay(char c, @JdkConstants.FontStyle int style, @NotNull FontPreferences preferences) { boolean tryDefaultFont = true; List<String> fontFamilies = preferences.getEffectiveFontFamilies(); FontInfo result; for (String fontFamily : fontFamilies) { result = doGetFontAbleToDisplay(c, preferences.getSize(fontFamily), style, fontFamily); if (result != null) { return result; } tryDefaultFont &= !FontPreferences.DEFAULT_FONT_NAME.equals(fontFamily); } int size = FontPreferences.DEFAULT_FONT_SIZE; if (!fontFamilies.isEmpty()) { size = preferences.getSize(fontFamilies.get(0)); } if (tryDefaultFont) { result = doGetFontAbleToDisplay(c, size, style, FontPreferences.DEFAULT_FONT_NAME); if (result != null) { return result; } } return doGetFontAbleToDisplay(c, size, style); }
@Override public void copyTo(@Nonnull final FontPreferences preferences) { if (preferences instanceof ModifiableFontPreferences) { ModifiableFontPreferences modifiablePreferences = (ModifiableFontPreferences)preferences; modifiablePreferences.setEffectiveFontFamilies(myEffectiveFontFamilies); modifiablePreferences.setRealFontFamilies(myRealFontFamilies); modifiablePreferences.setTemplateFontSize(myTemplateFontSize); modifiablePreferences.resetFontSizes(); for (String fontFamily : myRealFontFamilies) { if (myFontSizes.containsKey(fontFamily)) { modifiablePreferences.setFontSize(fontFamily, myFontSizes.get(fontFamily)); } } modifiablePreferences.setUseLigatures(myUseLigatures); modifiablePreferences.setLineSpacing(myLineSpacing); } }
@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; }
private void syncFontFamilies() { if (myIsInSchemeChange) { return; } ModifiableFontPreferences fontPreferences = getFontPreferences(); fontPreferences.clearFonts(); String primaryFontFamily = myPrimaryCombo.getFontName(); String secondaryFontFamily = mySecondaryCombo.isEnabled() ? mySecondaryCombo.getFontName() : null; int fontSize = getFontSizeFromField(); if (primaryFontFamily != null ) { if (!FontPreferences.DEFAULT_FONT_NAME.equals(primaryFontFamily)) { fontPreferences.addFontFamily(primaryFontFamily); } fontPreferences.register(primaryFontFamily, JBUI.scale(fontSize)); } if (secondaryFontFamily != null) { if (!FontPreferences.DEFAULT_FONT_NAME.equals(secondaryFontFamily)){ fontPreferences.addFontFamily(secondaryFontFamily); } fontPreferences.register(secondaryFontFamily, JBUI.scale(fontSize)); } updateDescription(true); }
private static List<BidiRun> createFragments(@NotNull EditorView view, @NotNull CharSequence text, @JdkConstants.FontStyle int fontStyle) { if (text.length() == 0) return Collections.emptyList(); EditorImpl editor = view.getEditor(); FontRenderContext fontRenderContext = view.getFontRenderContext(); FontPreferences fontPreferences = editor.getColorsScheme().getFontPreferences(); char[] chars = CharArrayUtil.fromSequence(text); List<BidiRun> runs = createRuns(editor, chars, -1); for (BidiRun run : runs) { for (Chunk chunk : run.getChunks()) { addFragments(run, chunk, chars, chunk.startOffset, chunk.endOffset, fontStyle, fontPreferences, fontRenderContext, null); } } return runs; }
private static void addFragments(BidiRun run, Chunk chunk, char[] text, int start, int end, int fontStyle, FontPreferences fontPreferences, FontRenderContext fontRenderContext, @Nullable TabFragment tabFragment) { assert start < end; Font currentFont = null; int currentIndex = start; for(int i = start; i < end; i++) { char c = text[i]; if (c == '\t' && tabFragment != null) { assert run.level == 0; addTextFragmentIfNeeded(chunk, text, currentIndex, i, currentFont, fontRenderContext, false); chunk.fragments.add(tabFragment); currentFont = null; currentIndex = i + 1; } else { Font font = ComplementaryFontsRegistry.getFontAbleToDisplay(c, fontStyle, fontPreferences).getFont(); if (!font.equals(currentFont)) { addTextFragmentIfNeeded(chunk, text, currentIndex, i, currentFont, fontRenderContext, run.isRtl()); currentFont = font; currentIndex = i; } } } addTextFragmentIfNeeded(chunk, text, currentIndex, end, currentFont, fontRenderContext, run.isRtl()); assert !chunk.fragments.isEmpty(); }
public void testSecondaryFontIsAvailable() throws Exception { FontPreferences globalPrefs = myTestScheme.getFontPreferences(); 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)); }
@NotNull public static Font getFontAbleToDisplay(@NotNull String s, @NotNull Font defaultFont) { if (SystemInfo.isMac // On Macs, all fonts can display all the characters because the system renders using fallback fonts. || 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).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; }
@Override public void register(@Nonnull String fontFamily, int size) { String fallbackFontFamily = FontPreferences.getFallbackName(fontFamily, size, null); if (!myRealFontFamilies.contains(fontFamily)) { myRealFontFamilies.add(fontFamily); } String effectiveFontFamily = fallbackFontFamily == null ? fontFamily : fallbackFontFamily; if (!myEffectiveFontFamilies.contains(effectiveFontFamily)) { myEffectiveFontFamilies.add(effectiveFontFamily); } setSize(fontFamily, size); }
@Override public void addFontFamily(@Nonnull String fontFamily) { String fallbackFontFamily = FontPreferences.getFallbackName(fontFamily, DEFAULT_FONT_SIZE, null); if (!myRealFontFamilies.contains(fontFamily)) { myRealFontFamilies.add(fontFamily); } String effectiveFontFamily = fallbackFontFamily == null ? fontFamily : fallbackFontFamily; if (!myEffectiveFontFamilies.contains(effectiveFontFamily)) { myEffectiveFontFamilies.add(effectiveFontFamily); } if (myChangeListener != null) { myChangeListener.run(); } }
private static List<BidiRun> createFragments(@Nonnull EditorView view, @Nonnull 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; }
@SuppressWarnings("AssignmentToForLoopParameter") private static void addFragments(BidiRun run, Chunk chunk, char[] text, int start, int end, int fontStyle, FontPreferences fontPreferences, FontRenderContext fontRenderContext, @Nullable TabFragment tabFragment) { assert start < end; FontInfo currentFontInfo = null; int currentIndex = start; for(int i = start; i < end; i++) { char c = text[i]; if (c == '\t' && tabFragment != null) { assert run.level == 0; addTextFragmentIfNeeded(chunk, text, currentIndex, i, currentFontInfo, false); chunk.fragments.add(tabFragment); currentFontInfo = null; currentIndex = i + 1; } else { boolean surrogatePair = false; int codePoint = c; if (Character.isHighSurrogate(c) && (i + 1 < end)) { char nextChar = text[i + 1]; if (Character.isLowSurrogate(nextChar)) { codePoint = Character.toCodePoint(c, nextChar); surrogatePair = true; } } FontInfo fontInfo = ComplementaryFontsRegistry.getFontAbleToDisplay(codePoint, fontStyle, fontPreferences, fontRenderContext); if (!fontInfo.equals(currentFontInfo)) { addTextFragmentIfNeeded(chunk, text, currentIndex, i, currentFontInfo, run.isRtl()); currentFontInfo = fontInfo; currentIndex = i; } if (surrogatePair) i++; } } addTextFragmentIfNeeded(chunk, text, currentIndex, end, currentFontInfo, run.isRtl()); assert !chunk.fragments.isEmpty(); }
private static FontInfo getFontInfo(@Nonnull Editor editor) { EditorColorsScheme colorsScheme = editor.getColorsScheme(); FontPreferences fontPreferences = colorsScheme.getFontPreferences(); TextAttributes attributes = editor.getColorsScheme().getAttributes(DebuggerColors.INLINED_VALUES_EXECUTION_LINE); int fontStyle = attributes == null ? Font.PLAIN : attributes.getFontType(); return ComplementaryFontsRegistry.getFontAbleToDisplay('a', fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.getContentComponent())); }
@Override public void updateOptionsList() { myIsInSchemeChange = true; myLineSpacingField.setText(Float.toString(getLineSpacing())); FontPreferences fontPreferences = getFontPreferences(); List<String> fontFamilies = fontPreferences.getEffectiveFontFamilies(); myPrimaryCombo.setFontName(fontPreferences.getFontFamily()); boolean isThereSecondaryFont = fontFamilies.size() > 1; myUseSecondaryFontCheckbox.setSelected(isThereSecondaryFont); mySecondaryCombo.setFontName(isThereSecondaryFont ? fontFamilies.get(1) : null); myEditorFontSizeField.setText(String.valueOf(fontPreferences.getSize(fontPreferences.getFontFamily()))); boolean readOnly = ColorAndFontOptions.isReadOnly(myOptions.getSelectedScheme()); myPrimaryCombo.setEnabled(!readOnly); mySecondaryCombo.setEnabled(isThereSecondaryFont && !readOnly); myOnlyMonospacedCheckBox.setEnabled(!readOnly); myLineSpacingField.setEnabled(!readOnly); myEditorFontSizeField.setEnabled(!readOnly); myUseSecondaryFontCheckbox.setEnabled(!readOnly); myEnableLigaturesCheckbox.setEnabled(!readOnly); myLigaturesInfoLinkLabel.setEnabled(!readOnly); myEnableLigaturesCheckbox.setSelected(fontPreferences.useLigatures()); myIsInSchemeChange = false; }
@NotNull protected FontPreferences getFontPreferences() { return getCurrentScheme().getFontPreferences(); }
@NotNull @Override protected FontPreferences getFontPreferences() { return getCurrentScheme().getConsoleFontPreferences(); }
private SegmentIterator(CharSequence charSequence, FontPreferences fontPreferences) { myCharSequence = charSequence; myFontPreferences = fontPreferences; }
public static DelegateColorScheme updateConsoleColorScheme(EditorColorsScheme scheme) { return new DelegateColorScheme(scheme) { @NotNull @Override public Color getDefaultBackground() { final Color color = getColor(ConsoleViewContentType.CONSOLE_BACKGROUND_KEY); return color == null ? super.getDefaultBackground() : color; } @NotNull @Override public FontPreferences getFontPreferences() { return getConsoleFontPreferences(); } @Override public int getEditorFontSize() { return getConsoleFontSize(); } @Override public String getEditorFontName() { return getConsoleFontName(); } @Override public float getLineSpacing() { return getConsoleLineSpacing(); } @Override public Font getFont(EditorFontType key) { return super.getFont(EditorFontType.getConsoleType(key)); } @Override public void setEditorFontSize(int fontSize) { setConsoleFontSize(fontSize); } }; }
@Override public void updateOptionsList() { myIsInSchemeChange = true; myLineSpacingField.setText(Float.toString(getLineSpacing())); mySelectedFontsModel.clear(); FontPreferences fontPreferences = getFontPreferences(); List<String> fontFamilies = fontPreferences.getEffectiveFontFamilies(); Set<String> selectedFonts = ContainerUtilRt.newHashSet(); Object selectedValue = mySelectedFontsList.getSelectedValue(); mySelectedFontsModel.clear(); if (fontFamilies.isEmpty()) { // Add default font. mySelectedFontsModel.addElement(fontPreferences.getFontFamily()); selectedFonts.add(fontPreferences.getFontFamily()); } else { for (String fontFamily : fontFamilies) { mySelectedFontsModel.addElement(fontFamily); selectedFonts.add(fontFamily); } } int newSelectionIndex = 0; if (selectedValue != null) { newSelectionIndex = Math.max(0, mySelectedFontsModel.indexOf(selectedValue)); } mySelectedFontsList.setSelectedIndex(newSelectionIndex); for (int i = myAllFontsModel.size() - 1; i >= 0; i--) { if (selectedFonts.contains(myAllFontsModel.getElementAt(i))) { myAllFontsModel.remove(i); } } myEditorFontSizeField.setText(String.valueOf(fontPreferences.getSize(fontPreferences.getFontFamily()))); boolean enabled = !ColorAndFontOptions.isReadOnly(myOptions.getSelectedScheme()); myOnlyMonospacedCheckBox.setEnabled(enabled); myLineSpacingField.setEnabled(enabled); myEditorFontSizeField.setEditable(enabled); myFontsControl.setEnabled(enabled); myIsInSchemeChange = false; }
@Test public void shouldInitializeFontPreferencesBeforeAllOtherTestsSoThatItDoesNotThrowExceptionsInTravis() { new FontPreferences(); }
/** * @deprecated Use {{@link #getFontAbleToDisplay(int, int, FontPreferences, FontRenderContext)}} instead. */ @Nonnull public static FontInfo getFontAbleToDisplay(int codePoint, @JdkConstants.FontStyle int style, @Nonnull FontPreferences preferences) { return getFontAbleToDisplay(codePoint, style, preferences, null); }
FontPreferences getFontPreferences() { return myFontPreferences; }