GUI: use "Droid Sans" as default font 46/17646/8
Clément DAVID [Thu, 7 Jan 2016 09:37:56 +0000 (10:37 +0100)]
This commit only change the Java initialised components not Scilab
uicontrols. To enforce a specific font for uicontrols we should provide
a custom JVM (with a modified lib/fonts directory and a custom
fontconfig.properties.src file).

Change-Id: I2e13182b2b69e77b51ec6ffa194d5b08f4852cea

16 files changed:
scilab/CHANGES_6.0.X
scilab/desktop/DroidSans-Bold.ttf [new file with mode: 0644]
scilab/desktop/DroidSans.ttf [new file with mode: 0644]
scilab/desktop/DroidSansMono.ttf [new file with mode: 0644]
scilab/desktop/DroidSerif-Bold.ttf [new file with mode: 0644]
scilab/desktop/DroidSerif-BoldItalic.ttf [new file with mode: 0644]
scilab/desktop/DroidSerif-Italic.ttf [new file with mode: 0644]
scilab/desktop/DroidSerif-Regular.ttf [new file with mode: 0644]
scilab/desktop/Makefile.am
scilab/desktop/Makefile.in
scilab/modules/console/etc/configuration.xml
scilab/modules/core/src/java/org/scilab/modules/core/Scilab.java
scilab/modules/gui/etc/XConfiguration-font.xml
scilab/modules/gui/etc/flexdock-themes.xml
scilab/modules/gui/gui.iss
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/LookAndFeelManager.java

index 4f05623..37188d5 100644 (file)
@@ -36,6 +36,10 @@ earlier versions:
    automatically converted to the 6.0 format: they cannot be opened again
    in Scilab/Xcos 5.x.
 
+Scilab now use the Droid fonts across all platforms. This might generally
+improve the look 'n feel of the software but might regress sometimes.
+
+
 Bug Fixes
 =========
 
diff --git a/scilab/desktop/DroidSans-Bold.ttf b/scilab/desktop/DroidSans-Bold.ttf
new file mode 100644 (file)
index 0000000..d065b64
Binary files /dev/null and b/scilab/desktop/DroidSans-Bold.ttf differ
diff --git a/scilab/desktop/DroidSans.ttf b/scilab/desktop/DroidSans.ttf
new file mode 100644 (file)
index 0000000..ad1efca
Binary files /dev/null and b/scilab/desktop/DroidSans.ttf differ
diff --git a/scilab/desktop/DroidSansMono.ttf b/scilab/desktop/DroidSansMono.ttf
new file mode 100644 (file)
index 0000000..4a27887
Binary files /dev/null and b/scilab/desktop/DroidSansMono.ttf differ
diff --git a/scilab/desktop/DroidSerif-Bold.ttf b/scilab/desktop/DroidSerif-Bold.ttf
new file mode 100644 (file)
index 0000000..838d255
Binary files /dev/null and b/scilab/desktop/DroidSerif-Bold.ttf differ
diff --git a/scilab/desktop/DroidSerif-BoldItalic.ttf b/scilab/desktop/DroidSerif-BoldItalic.ttf
new file mode 100644 (file)
index 0000000..0b1601f
Binary files /dev/null and b/scilab/desktop/DroidSerif-BoldItalic.ttf differ
diff --git a/scilab/desktop/DroidSerif-Italic.ttf b/scilab/desktop/DroidSerif-Italic.ttf
new file mode 100644 (file)
index 0000000..2972809
Binary files /dev/null and b/scilab/desktop/DroidSerif-Italic.ttf differ
diff --git a/scilab/desktop/DroidSerif-Regular.ttf b/scilab/desktop/DroidSerif-Regular.ttf
new file mode 100644 (file)
index 0000000..5b4fe81
Binary files /dev/null and b/scilab/desktop/DroidSerif-Regular.ttf differ
index 40d83ea..035b3a5 100644 (file)
@@ -34,3 +34,14 @@ mime_DATA = scilab.xml
 # Note that here, it is datadir and NOT pkgdatadir
 appdatadir = $(datadir)/appdata
 appdata_DATA = scilab.appdata.xml
+
+# Embedded font file
+# Note that here, it is datadir and NOT pkgdatadir
+fontdir = $(datadir)/fonts/google-droid/
+font_DATA = DroidSans-Bold.ttf \
+DroidSansMono.ttf \
+DroidSans.ttf \
+DroidSerif-BoldItalic.ttf \
+DroidSerif-Bold.ttf \
+DroidSerif-Italic.ttf \
+DroidSerif-Regular.ttf
index 4a7133f..2d3d16f 100644 (file)
@@ -185,8 +185,8 @@ am__uninstall_files_from_dir = { \
          $(am__cd) "$$dir" && rm -f $$files; }; \
   }
 am__installdirs = "$(DESTDIR)$(appdatadir)" "$(DESTDIR)$(desktopdir)" \
-       "$(DESTDIR)$(mimedir)"
-DATA = $(appdata_DATA) $(desktop_DATA) $(mime_DATA)
+       "$(DESTDIR)$(fontdir)" "$(DESTDIR)$(mimedir)"
+DATA = $(appdata_DATA) $(desktop_DATA) $(font_DATA) $(mime_DATA)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 am__recursive_targets = \
@@ -552,6 +552,18 @@ mime_DATA = scilab.xml
 # Note that here, it is datadir and NOT pkgdatadir
 appdatadir = $(datadir)/appdata
 appdata_DATA = scilab.appdata.xml
+
+# Embedded font file
+# Note that here, it is datadir and NOT pkgdatadir
+fontdir = $(datadir)/fonts/google-droid/
+font_DATA = DroidSans-Bold.ttf \
+DroidSansMono.ttf \
+DroidSans.ttf \
+DroidSerif-BoldItalic.ttf \
+DroidSerif-Bold.ttf \
+DroidSerif-Italic.ttf \
+DroidSerif-Regular.ttf
+
 all: all-recursive
 
 .SUFFIXES:
@@ -632,6 +644,27 @@ uninstall-desktopDATA:
        @list='$(desktop_DATA)'; test -n "$(desktopdir)" || list=; \
        files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
        dir='$(DESTDIR)$(desktopdir)'; $(am__uninstall_files_from_dir)
+install-fontDATA: $(font_DATA)
+       @$(NORMAL_INSTALL)
+       @list='$(font_DATA)'; test -n "$(fontdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(fontdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(fontdir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(fontdir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(fontdir)" || exit $$?; \
+       done
+
+uninstall-fontDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(font_DATA)'; test -n "$(fontdir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       dir='$(DESTDIR)$(fontdir)'; $(am__uninstall_files_from_dir)
 install-mimeDATA: $(mime_DATA)
        @$(NORMAL_INSTALL)
        @list='$(mime_DATA)'; test -n "$(mimedir)" || list=; \
@@ -813,7 +846,7 @@ check: check-recursive
 all-am: Makefile $(DATA)
 installdirs: installdirs-recursive
 installdirs-am:
-       for dir in "$(DESTDIR)$(appdatadir)" "$(DESTDIR)$(desktopdir)" "$(DESTDIR)$(mimedir)"; do \
+       for dir in "$(DESTDIR)$(appdatadir)" "$(DESTDIR)$(desktopdir)" "$(DESTDIR)$(fontdir)" "$(DESTDIR)$(mimedir)"; do \
          test -z "$$dir" || $(MKDIR_P) "$$dir"; \
        done
 install: install-recursive
@@ -867,7 +900,7 @@ info: info-recursive
 info-am:
 
 install-data-am: install-appdataDATA install-desktopDATA \
-       install-mimeDATA
+       install-fontDATA install-mimeDATA
 
 install-dvi: install-dvi-recursive
 
@@ -912,7 +945,7 @@ ps: ps-recursive
 ps-am:
 
 uninstall-am: uninstall-appdataDATA uninstall-desktopDATA \
-       uninstall-mimeDATA
+       uninstall-fontDATA uninstall-mimeDATA
 
 .MAKE: $(am__recursive_targets) install-am install-strip
 
@@ -922,14 +955,15 @@ uninstall-am: uninstall-appdataDATA uninstall-desktopDATA \
        distclean-tags distdir dvi dvi-am html html-am info info-am \
        install install-am install-appdataDATA install-data \
        install-data-am install-desktopDATA install-dvi install-dvi-am \
-       install-exec install-exec-am install-html install-html-am \
-       install-info install-info-am install-man install-mimeDATA \
-       install-pdf install-pdf-am install-ps install-ps-am \
-       install-strip installcheck installcheck-am installdirs \
-       installdirs-am maintainer-clean maintainer-clean-generic \
-       mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
-       ps ps-am tags tags-am uninstall uninstall-am \
-       uninstall-appdataDATA uninstall-desktopDATA uninstall-mimeDATA
+       install-exec install-exec-am install-fontDATA install-html \
+       install-html-am install-info install-info-am install-man \
+       install-mimeDATA install-pdf install-pdf-am install-ps \
+       install-ps-am install-strip installcheck installcheck-am \
+       installdirs installdirs-am maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-generic \
+       mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+       uninstall-am uninstall-appdataDATA uninstall-desktopDATA \
+       uninstall-fontDATA uninstall-mimeDATA
 
 .PRECIOUS: Makefile
 
index 31a91a3..2f09e61 100644 (file)
@@ -31,7 +31,7 @@
         <ScrollableBlockIncrement useCache="true" value="20"/>
         <VerticalWrapAllowed useCache="true" value="false"/>
         <HorizontalWrapAllowed useCache="true" value="false"/>
-        <FontName useCache="true" value="Monospaced"/>
+        <FontName useCache="true" value="Droid Sans Mono"/>
         <FontStyle useCache="true" value="0"/>
         <!-- 0=PLAIN, 1=BOLD, 2=ITALIC, 3=BOLD+ITALIC -->
         <FontSize useCache="true" value="13"/>
index cd7c72f..49bc43f 100644 (file)
@@ -170,7 +170,7 @@ public class Scilab {
                 /* Init the LookAndFeelManager all the time since we can
                  * create windows in the NW mode */
                 if (!GraphicsEnvironment.isHeadless()) {
-                    LookAndFeelManager lookAndFeel = new LookAndFeelManager();
+                    LookAndFeelManager lookAndFeel = LookAndFeelManager.getInstance();
 
                     if (lookAndFeel.isSupportedLookAndFeel(scilabLookAndFeel)) {
                         lookAndFeel.setLookAndFeel(scilabLookAndFeel);
@@ -178,7 +178,7 @@ public class Scilab {
                         lookAndFeel.setSystemLookAndFeel();
                     }
                 }
-            } catch (java.lang.NoClassDefFoundError exception) {
+            } catch (Exception exception) {
                 System.err.println("Could not initialize graphics Environment");
                 System.err.println("Scilab Graphical option may not be working correctly.");
                 System.err.println("An error occurred: " + exception.getLocalizedMessage());
index e8cdf08..feff346 100644 (file)
@@ -2,8 +2,8 @@
 <fonts title="_(Fonts)">
     <body>
         <fonts item="Console" system="true" font-name="Monospaced" font-face="plain" font-size="13" latex="15">
-            <item xconf-uid="console-font" name="Console" desktop="false" font-name="Monospaced" font-face="plain" font-size="13"/>
-            <item xconf-uid="scinotes-font" name="Scinotes" desktop="false" font-name="Monospaced" font-face="plain" font-size="12"/>
+            <item xconf-uid="console-font" name="Console" desktop="false" font-name="Droid Sans Mono" font-face="plain" font-size="13"/>
+            <item xconf-uid="scinotes-font" name="Scinotes" desktop="false" font-name="Droid Sans Mono" font-face="plain" font-size="12"/>
             <!--item name="Command History" desktop="true" font-name="Monospaced" font-face="plain" font-size="10"/>
       <item name="Variable Browser" desktop="true" font-name="Monospaced" font-face="plain" font-size="10"/>
       <item name="Help" desktop="true" font-name="Monospaced" font-face="plain" font-size="10"/>
index bfc69b8..8b1c8b5 100644 (file)
@@ -17,6 +17,7 @@
         <!-- List the various titlebars that are available -->
         <titlebar-ui name="scilab" extends="default">
             <property name="icon-map" value="scilab" />
+            <property name="font" value="Droid Sans, 0, 11" handler="font" />
         </titlebar-ui>
         
         <icon-resource name="scilab.undock">
index e07d0e1..cac54f6 100644 (file)
@@ -46,6 +46,7 @@ Source: modules\{#GUI}\etc\*.xml; DestDir: {app}\modules\{#GUI}\etc; Components:
 Source: modules\{#GUI}\etc\*.xsl; DestDir: {app}\modules\{#GUI}\etc; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 Source: modules\{#GUI}\images\icons\*.png; DestDir: {app}\modules\{#GUI}\images\icons; Flags: recursesubdirs; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 Source: modules\{#GUI}\images\preferences\*.png; DestDir: {app}\modules\{#GUI}\images\preferences; Flags: recursesubdirs; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
+Source: desktop\*.ttf; DestDir: {app}\desktop; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 ;
 ;Source: modules\{#GUI}\includes\*.h; DestDir: {app}\modules\{#GUI}\includes; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 ;
index b9b7649..7eea666 100644 (file)
@@ -2,6 +2,7 @@
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2007 - INRIA - Allan CORNET
  * Copyright (C) 2007 - INRIA - Sylvestre Ledru
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
 
 package org.scilab.modules.gui.utils;
 
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.awt.GraphicsEnvironment;
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 
 import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.FontUIResource;
 
 /**
  * Class used to modify look and feel in Scilab GUIs
@@ -29,16 +37,70 @@ import javax.swing.UnsupportedLookAndFeelException;
  * @author Sylvestre Ledru
  */
 public class LookAndFeelManager {
+    private static LookAndFeelManager instance;
 
-    private static UIManager.LookAndFeelInfo[] availableLookAndFeels = UIManager.getInstalledLookAndFeels();
+    public static LookAndFeelManager getInstance() {
+        if (instance == null) {
+            instance = new LookAndFeelManager();
+        }
+        return instance;
+    }
+
+    private final UIManager.LookAndFeelInfo[] availableLookAndFeels;
     private boolean ret;
 
+    private Font serif;
+    private Font sansSerif;
+    private Font monospaced;
+    private Font dialog;
+    private Font dialogInput;
+
+
     /**
      * Constructor
      */
     public LookAndFeelManager() {
+        availableLookAndFeels = UIManager.getInstalledLookAndFeels();
     }
 
+    public Font getSerifFont() {
+        if (serif == null) {
+            serif = new Font(Font.SERIF, Font.PLAIN, 12);
+        }
+        return serif;
+    }
+
+    public Font getSansSerifFont() {
+        if (sansSerif == null) {
+            sansSerif = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
+        }
+        return sansSerif;
+    }
+
+    public Font getMonospacedFont() {
+        if (monospaced == null) {
+            monospaced = new Font(Font.MONOSPACED, Font.PLAIN, 12);
+        }
+        return monospaced;
+    }
+
+    public Font getDialogFont() {
+        if (dialog == null) {
+            dialog = new Font(Font.DIALOG, Font.PLAIN, 12);
+        }
+        return dialog;
+    }
+
+    public Font getDialogInputFont() {
+        if (dialogInput == null) {
+            dialogInput = new Font(Font.DIALOG_INPUT, Font.PLAIN, 12);
+        }
+        return dialogInput;
+    }
+
+
+
+
     /**
      * Get Installed Look and Feels
      * @return an array of String
@@ -93,6 +155,10 @@ public class LookAndFeelManager {
                 public void run() {
                     try {
                         UIManager.setLookAndFeel(lookandfeel);
+                        registerEmbeddedFonts();
+                        storeEmbeddedFonts();
+                        initComponentDefaults(UIManager.getDefaults());
+
                         ret = true;
                     } catch (UnsupportedLookAndFeelException e) {
                         System.err.println("Cannot find this look and feel:");
@@ -106,6 +172,12 @@ public class LookAndFeelManager {
                     } catch (InstantiationException e) {
                         System.err.println("Instantiation error while setting the Look And Feel:");
                         System.err.println(e.getLocalizedMessage());
+                    } catch (FontFormatException e) {
+                        System.err.println("Invalid Font format:");
+                        System.err.println(e.getLocalizedMessage());
+                    } catch (IOException e) {
+                        System.err.println("Unable to open Font:");
+                        System.err.println(e.getLocalizedMessage());
                     }
                 }
             });
@@ -118,6 +190,115 @@ public class LookAndFeelManager {
     }
 
     /**
+     * Register the shipped fonts
+     */
+    private void registerEmbeddedFonts() throws FontFormatException, IOException {
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+
+        File[] possibleDirs = {
+            new File(System.getenv("SCI"), "/../fonts/google-droid"),   // binary version (eg.  where we have a "share")
+            new File(System.getenv("SCI"), "/desktop"),                 // Linux dev. version or Windows install
+        };
+
+        // detect existing dir
+        File dir = null;
+        for (File d : possibleDirs) {
+            if (d.isDirectory()) { // also check if it exists implicitly
+                dir = d;
+                break;
+            }
+        }
+        if (dir == null) {
+            return;
+        }
+
+        // register fonts
+        String[] filenames = {"DroidSans-Bold.ttf", "DroidSansMono.ttf", "DroidSans.ttf", "DroidSerif-BoldItalic.ttf", "DroidSerif-Bold.ttf", "DroidSerif-Italic.ttf", "DroidSerif-Regular.ttf"}; ;
+        final Float size = 11f;
+
+        for (String filename : filenames) {
+            File f  = new File(dir, filename);
+
+            if (f.canRead()) {
+                Font base = Font.createFont(Font.TRUETYPE_FONT, f);
+
+                Font derived = base.deriveFont(size);
+                ge.registerFont(derived);
+            }
+        }
+    }
+
+    /**
+     * Store on local fields the default used fonts
+     */
+    private void storeEmbeddedFonts() {
+        serif = new Font("Droid Serif", Font.PLAIN, 12);
+        sansSerif = new Font("Droid Sans", Font.PLAIN, 12);
+        monospaced = new Font("Droid Sans Mono", Font.PLAIN, 12);
+        dialog = new Font("Droid Sans", Font.PLAIN, 12);
+        dialogInput = new Font("Droid Sans Mono", Font.PLAIN, 12);
+    }
+
+    /**
+     * Override some defaults previously set in GTKLookAndFell#initComponentDefaults(UIDefaults)
+     *
+     * @param table the default settings
+     */
+    private void initComponentDefaults(UIDefaults table) {
+        final FontUIResource defaultFontUIResource = new FontUIResource(getDialogFont());
+        final FontUIResource defaultMonospacedFontUIResource = new FontUIResource(getMonospacedFont());
+
+        table.put("ArrowButton.font", defaultFontUIResource);
+        table.put("Button.font", defaultFontUIResource);
+        table.put("CheckBox.font", defaultFontUIResource);
+        table.put("CheckBoxMenuItem.font", defaultFontUIResource);
+        table.put("ColorChooser.font", defaultFontUIResource);
+        table.put("ComboBox.font", defaultFontUIResource);
+        table.put("DesktopPane.font", defaultFontUIResource);
+        table.put("DesktopIcon.font", defaultFontUIResource);
+        table.put("EditorPane.font", defaultFontUIResource);
+        table.put("FileChooser.font", defaultFontUIResource);
+        table.put("FormattedTextField.font", defaultFontUIResource);
+        table.put("InternalFrame.font", defaultFontUIResource);
+        table.put("InternalFrameTitlePane.font", defaultFontUIResource);
+        table.put("Label.font", defaultFontUIResource);
+        table.put("List.font", defaultFontUIResource);
+        table.put("Menu.font", defaultFontUIResource);
+        table.put("MenuBar.font", defaultFontUIResource);
+        table.put("MenuItem.font", defaultFontUIResource);
+        table.put("OptionPane.font", defaultFontUIResource);
+        table.put("Panel.font", defaultFontUIResource);
+        table.put("PasswordField.font", defaultFontUIResource);
+        table.put("PopupMenu.font", defaultFontUIResource);
+        table.put("PopupMenuSeparator.font", defaultFontUIResource);
+        table.put("ProgressBar.font", defaultFontUIResource);
+        table.put("RadioButton.font", defaultFontUIResource);
+        table.put("RadioButtonMenuItem.font", defaultFontUIResource);
+        table.put("RootPane.font", defaultFontUIResource);
+        table.put("ScrollBar.font", defaultFontUIResource);
+        table.put("ScrollBarTrack.font", defaultFontUIResource);
+        table.put("ScrollBarThumb.font", defaultFontUIResource);
+        table.put("ScrollPane.font", defaultFontUIResource);
+        table.put("Separator.font", defaultFontUIResource);
+        table.put("Slider.font", defaultFontUIResource);
+        table.put("SliderTrack.font", defaultFontUIResource);
+        table.put("SliderThumb.font", defaultFontUIResource);
+        table.put("Spinner.font", defaultFontUIResource);
+        table.put("SplitPane.font", defaultFontUIResource);
+        table.put("TabbedPane.font", defaultFontUIResource);
+        table.put("Table.font", defaultFontUIResource);
+        table.put("TableHeader.font", defaultFontUIResource);
+        table.put("TextArea.font", defaultFontUIResource);
+        table.put("TextField.font", defaultMonospacedFontUIResource);
+        table.put("TextPane.font", defaultMonospacedFontUIResource);
+        table.put("ToggleButton.font", defaultFontUIResource);
+        table.put("ToolBar.font", defaultFontUIResource);
+        table.put("ToolTip.font", defaultFontUIResource);
+        table.put("Tree.font", defaultFontUIResource);
+        table.put("Viewport", defaultFontUIResource);
+    }
+
+    /**
      * Set System Look and Feel
      * @return a boolean
      */