Changeset 7896 in josm


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

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

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
6 edited

Legend:

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

    r7894 r7896  
    88
    99import java.awt.Dimension;
     10import java.awt.GraphicsEnvironment;
    1011import java.awt.Image;
    1112import java.awt.Toolkit;
     
    368369        FontsManager.initialize();
    369370
     371        handleSpecialLanguages();
     372
    370373        final JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
    371374        Main.parent = mainFrame;
     
    479482            info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
    480483            RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
     484        }
     485    }
     486
     487    private static void handleSpecialLanguages() {
     488        // Use special font for Khmer script, as the default Java font do not display these characters
     489        if ("km".equals(Main.pref.get("language"))) {
     490            Collection<String> fonts = Arrays.asList(
     491                    GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
     492            for (String f : new String[]{"Khmer UI", "DaunPenh", "MoolBoran"}) {
     493                if (fonts.contains(f)) {
     494                    GuiHelper.setUIFont(f);
     495                    break;
     496                }
     497            }
    481498        }
    482499    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r7563 r7896  
    66
    77import java.awt.Dimension;
    8 import java.awt.Font;
    98import java.awt.GridBagLayout;
    109import java.util.ArrayList;
     
    4544import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    4645import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
     46import org.openstreetmap.josm.gui.util.GuiHelper;
    4747import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    4848import org.openstreetmap.josm.tools.GBC;
     
    9595        JPanel p = new JPanel(new GridBagLayout());
    9696        JosmTextArea txtData = new JosmTextArea();
    97         txtData.setFont(new Font("Monospaced", txtData.getFont().getStyle(), txtData.getFont().getSize()));
     97        txtData.setFont(GuiHelper.getMonospacedFont(txtData));
    9898        txtData.setEditable(false);
    9999        txtData.setText(buildDataText());
     
    325325        p.setLayout(new GridBagLayout());
    326326        txtMappaint = new JosmTextArea();
    327         txtMappaint.setFont(new Font("Monospaced", txtMappaint.getFont().getStyle(), txtMappaint.getFont().getSize()));
     327        txtMappaint.setFont(GuiHelper.getMonospacedFont(txtMappaint));
    328328        txtMappaint.setEditable(false);
    329329
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r7668 r7896  
    7373import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
    7474import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     75import org.openstreetmap.josm.gui.util.GuiHelper;
    7576import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    7677import org.openstreetmap.josm.gui.widgets.FileChooserManager;
     
    615616        private void buildSourcePanel(StyleSource s, JPanel p) {
    616617            JosmTextArea txtSource = new JosmTextArea();
    617             txtSource.setFont(new Font("Monospaced", txtSource.getFont().getStyle(), txtSource.getFont().getSize()));
     618            txtSource.setFont(GuiHelper.getMonospacedFont(txtSource));
    618619            txtSource.setEditable(false);
    619620            p.add(new JScrollPane(txtSource), GBC.std().fill());
     
    636637        private void buildErrorsPanel(StyleSource s, JPanel p) {
    637638            JosmTextArea txtErrors = new JosmTextArea();
    638             txtErrors.setFont(new Font("Monospaced", txtErrors.getFont().getStyle(), txtErrors.getFont().getSize()));
     639            txtErrors.setFont(GuiHelper.getMonospacedFont(txtErrors));
    639640            txtErrors.setEditable(false);
    640641            p.add(new JScrollPane(txtErrors), GBC.std().fill());
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java

    r7592 r7896  
    213213        }
    214214        JosmTextArea txt = new JosmTextArea();
    215         txt.setFont(new Font("Monospaced", txt.getFont().getStyle(), txt.getFont().getSize()));
     215        txt.setFont(GuiHelper.getMonospacedFont(txt));
    216216        txt.setEditable(false);
    217217        txt.setBackground(p.getBackground());
  • 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}
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmEditorPane.java

    r6935 r7896  
    1616import javax.swing.text.html.StyleSheet;
    1717
     18import org.openstreetmap.josm.Main;
    1819import org.openstreetmap.josm.gui.util.GuiHelper;
    1920import org.openstreetmap.josm.tools.Utils;
     
    8384        return result;
    8485    }
    85    
     86
    8687    /**
    8788     * Adapts a {@link JEditorPane} to be used as a powerful replacement of {@link javax.swing.JLabel}.
     
    103104        ss.addRule("ol {margin-left: 1cm; margin-top: 0.1cm; margin-bottom: 0.2cm; list-style-type: decimal}");
    104105        ss.addRule("ul {margin-left: 1cm; margin-top: 0.1cm; margin-bottom: 0.2cm; list-style-type: disc}");
     106        if ("km".equals(Main.pref.get("language"))) {
     107            // Fix rendering problem for Khmer script
     108            ss.addRule("p {" + getFontRule(UIManager.getFont("Label.font")) + "}");
     109        }
    105110        kit.setStyleSheet(ss);
    106111        pane.setEditorKit(kit);
Note: See TracChangeset for help on using the changeset viewer.