Search in sources :

Example 6 with FontUIResource

use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.

the class DarculaLaf method installMacOSXFonts.

private static void installMacOSXFonts(UIDefaults defaults) {
    final String face = "HelveticaNeue-Regular";
    final FontUIResource uiFont = getFont(face, 13, Font.PLAIN);
    LafManagerImpl.initFontDefaults(defaults, 13, uiFont);
    for (Object key : new HashSet<>(defaults.keySet())) {
        Object value = defaults.get(key);
        if (value instanceof FontUIResource) {
            FontUIResource font = (FontUIResource) value;
            if (font.getFamily().equals("Lucida Grande") || font.getFamily().equals("Serif")) {
                if (!key.toString().contains("Menu")) {
                    defaults.put(key, getFont(face, font.getSize(), font.getStyle()));
                }
            }
        }
    }
    FontUIResource uiFont11 = getFont(face, 11, Font.PLAIN);
    defaults.put("TableHeader.font", uiFont11);
    FontUIResource buttonFont = getFont("HelveticaNeue-Medium", 13, Font.PLAIN);
    defaults.put("Button.font", buttonFont);
    Font menuFont = getFont("Lucida Grande", 14, Font.PLAIN);
    defaults.put("Menu.font", menuFont);
    defaults.put("MenuItem.font", menuFont);
    defaults.put("MenuItem.acceleratorFont", menuFont);
    defaults.put("PasswordField.font", defaults.getFont("TextField.font"));
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Example 7 with FontUIResource

use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.

the class LafManagerImpl method patchLafFonts.

private void patchLafFonts(UIDefaults uiDefaults) {
    //if (JBUI.isHiDPI()) {
    //  HashMap<Object, Font> newFonts = new HashMap<Object, Font>();
    //  for (Object key : uiDefaults.keySet().toArray()) {
    //    Object val = uiDefaults.get(key);
    //    if (val instanceof Font) {
    //      newFonts.put(key, JBFont.create((Font)val));
    //    }
    //  }
    //  for (Map.Entry<Object, Font> entry : newFonts.entrySet()) {
    //    uiDefaults.put(entry.getKey(), entry.getValue());
    //  }
    //} else
    UISettings uiSettings = UISettings.getInstance();
    if (uiSettings.getOverrideLafFonts()) {
        storeOriginalFontDefaults(uiDefaults);
        JBUI.setUserScaleFactor(uiSettings.getFontSize() / UIUtil.DEF_SYSTEM_FONT_SIZE);
        initFontDefaults(uiDefaults, uiSettings.getFontSize(), new FontUIResource(uiSettings.getFontFace(), Font.PLAIN, uiSettings.getFontSize()));
    } else {
        restoreOriginalFontDefaults(uiDefaults);
    }
}
Also used : UISettings(com.intellij.ide.ui.UISettings) FontUIResource(javax.swing.plaf.FontUIResource)

Example 8 with FontUIResource

use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.

the class LafManagerImpl method initFontDefaults.

@SuppressWarnings({ "HardCodedStringLiteral" })
public static void initFontDefaults(UIDefaults defaults, int fontSize, FontUIResource uiFont) {
    defaults.put("Tree.ancestorInputMap", null);
    FontUIResource textFont = new FontUIResource("Serif", Font.PLAIN, fontSize);
    FontUIResource monoFont = new FontUIResource("Monospaced", Font.PLAIN, fontSize);
    for (String fontResource : ourPatchableFontResources) {
        defaults.put(fontResource, uiFont);
    }
    if (!SystemInfo.isMac) {
        defaults.put("PasswordField.font", monoFont);
    }
    defaults.put("TextArea.font", monoFont);
    defaults.put("TextPane.font", textFont);
    defaults.put("EditorPane.font", textFont);
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Example 9 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.

the class FontUtilities method getCompositeFontUIResource.

public static FontUIResource getCompositeFontUIResource(Font font) {
    FontUIResource fuir = new FontUIResource(font);
    Font2D font2D = FontUtilities.getFont2D(font);
    if (!(font2D instanceof PhysicalFont)) {
        /* Swing should only be calling this when a font is obtained
             * from desktop properties, so should generally be a physical font,
             * an exception might be for names like "MS Serif" which are
             * automatically mapped to "Serif", so there's no need to do
             * anything special in that case. But note that suggested usage
             * is first to call fontSupportsDefaultEncoding(Font) and this
             * method should not be called if that were to return true.
             */
        return fuir;
    }
    FontManager fm = FontManagerFactory.getInstance();
    Font2D dialog = fm.findFont2D("dialog", font.getStyle(), FontManager.NO_FALLBACK);
    // Should never be null, but MACOSX fonts are not CompositeFonts
    if (dialog == null || !(dialog instanceof CompositeFont)) {
        return fuir;
    }
    CompositeFont dialog2D = (CompositeFont) dialog;
    PhysicalFont physicalFont = (PhysicalFont) font2D;
    ConcurrentHashMap<PhysicalFont, CompositeFont> compMap = compMapRef.get();
    if (compMap == null) {
        // Its been collected.
        compMap = new ConcurrentHashMap<PhysicalFont, CompositeFont>();
        compMapRef = new SoftReference(compMap);
    }
    CompositeFont compFont = compMap.get(physicalFont);
    if (compFont == null) {
        compFont = new CompositeFont(physicalFont, dialog2D);
        compMap.put(physicalFont, compFont);
    }
    FontAccess.getFontAccess().setFont2D(fuir, compFont.handle);
    /* marking this as a created font is needed as only created fonts
         * copy their creator's handles.
         */
    FontAccess.getFontAccess().setCreatedFont(fuir);
    return fuir;
}
Also used : SoftReference(java.lang.ref.SoftReference) FontUIResource(javax.swing.plaf.FontUIResource)

Example 10 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.

the class FontUtilities method getFontConfigFUIR.

/* This is called by Swing passing in a fontconfig family name
     * such as "sans". In return Swing gets a FontUIResource instance
     * that has queried fontconfig to resolve the font(s) used for this.
     * Fontconfig will if asked return a list of fonts to give the largest
     * possible code point coverage.
     * For now we use only the first font returned by fontconfig, and
     * back it up with the most closely matching JDK logical font.
     * Essentially this means pre-pending what we return now with fontconfig's
     * preferred physical font. This could lead to some duplication in cases,
     * if we already included that font later. We probably should remove such
     * duplicates, but it is not a significant problem. It can be addressed
     * later as part of creating a Composite which uses more of the
     * same fonts as fontconfig. At that time we also should pay more
     * attention to the special rendering instructions fontconfig returns,
     * such as whether we should prefer embedded bitmaps over antialiasing.
     * There's no way to express that via a Font at present.
     */
public static FontUIResource getFontConfigFUIR(String fcFamily, int style, int size) {
    String mapped = mapFcName(fcFamily);
    if (mapped == null) {
        mapped = "sansserif";
    }
    FontUIResource fuir;
    FontManager fm = FontManagerFactory.getInstance();
    if (fm instanceof SunFontManager) {
        SunFontManager sfm = (SunFontManager) fm;
        fuir = sfm.getFontConfigFUIR(mapped, style, size);
    } else {
        fuir = new FontUIResource(mapped, style, size);
    }
    return fuir;
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Aggregations

FontUIResource (javax.swing.plaf.FontUIResource)25 Font (java.awt.Font)5 UIDefaults (javax.swing.UIDefaults)5 ColorUIResource (javax.swing.plaf.ColorUIResource)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 JFrame (javax.swing.JFrame)2 UISettings (com.intellij.ide.ui.UISettings)1 FontDescriptor (com.intellij.uiDesigner.lw.FontDescriptor)1 Plastic3DLookAndFeel (com.jgoodies.looks.plastic.Plastic3DLookAndFeel)1 SkyBluer (com.jgoodies.looks.plastic.theme.SkyBluer)1 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1