Ignore:
Timestamp:
2014-12-27T05:25:53+01:00 (9 years ago)
Author:
Don-vip
Message:

fix font problems with Khmer. Only tested on Java 8/Windows 7 right now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r7539 r7896  
    2323import java.lang.reflect.InvocationTargetException;
    2424import java.util.Arrays;
     25import java.util.Enumeration;
    2526import java.util.List;
    2627import java.util.concurrent.Callable;
     
    3132import javax.swing.Icon;
    3233import javax.swing.ImageIcon;
     34import javax.swing.JComponent;
    3335import javax.swing.JLabel;
    3436import javax.swing.JOptionPane;
     
    3739import javax.swing.SwingUtilities;
    3840import javax.swing.Timer;
     41import javax.swing.UIManager;
     42import javax.swing.plaf.FontUIResource;
    3943
    4044import org.openstreetmap.josm.Main;
    4145import org.openstreetmap.josm.gui.ExtendedDialog;
    4246import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     47import org.openstreetmap.josm.tools.CheckParameterUtil;
    4348import org.openstreetmap.josm.tools.GBC;
    4449import org.openstreetmap.josm.tools.ImageProvider;
     
    297302
    298303    /**
     304     * Gets the font used to display monospaced text in a component, if possible.
     305     * @param component The component
     306     * @return the font used to display monospaced text in a component, if possible
     307     * @since 7896
     308     */
     309    public static Font getMonospacedFont(JComponent component) {
     310        // Special font for Khmer script
     311        if ("km".equals(Main.pref.get("language"))) {
     312            return component.getFont();
     313        } else {
     314            return new Font("Monospaced", component.getFont().getStyle(), component.getFont().getSize());
     315        }
     316    }
     317
     318    /**
    299319     * Gets the font used to display JOSM title in about dialog and splash screen.
    300320     * @return By order or priority, the first font available in local fonts:
     
    303323     *         3. Arial Bold 20
    304324     *         4. SansSerif Bold 20
     325     *         Except if current language is Khmer, where it will be current font at size 20
    305326     * @since 5797
    306327     */
    307328    public static Font getTitleFont() {
    308329        List<String> fonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
     330        // Special font for Khmer script
     331        if ("km".equals(Main.pref.get("language"))) {
     332            return UIManager.getFont("Label.font").deriveFont(20.0f);
     333        }
    309334        // Helvetica is the preferred choice but is not available by default on Windows
    310335        // (https://www.microsoft.com/typography/fonts/product.aspx?pid=161)
     
    346371        return Main.isPlatformOsx() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK;
    347372    }
     373
     374    /**
     375     * Sets a global font for all UI, replacing default font of current look and feel.
     376     * @param name Font name. It is up to the caller to make sure the font exists
     377     * @since 7896
     378     * @throws IllegalArgumentException if name is null
     379     */
     380    public static void setUIFont(String name) {
     381        CheckParameterUtil.ensureParameterNotNull(name, "name");
     382        Main.info("Setting "+name+" as the default UI font");
     383        Enumeration<?> keys = UIManager.getDefaults().keys();
     384        while (keys.hasMoreElements()) {
     385            Object key = keys.nextElement();
     386            Object value = UIManager.get(key);
     387            if (value != null && value instanceof FontUIResource) {
     388                FontUIResource fui = (FontUIResource)value;
     389                UIManager.put(key, new FontUIResource(name, fui.getStyle(), fui.getSize()));
     390            }
     391        }
     392    }
    348393}
Note: See TracChangeset for help on using the changeset viewer.