Changeset 761


Ignore:
Timestamp:
01/28/14 10:30:16 (10 years ago)
Author:
davidb
Message:

Code added to load any TTF fonts located in the resources 'fonts' folder

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameIO.java

    r734 r761  
    6060                HELP_PATH = PARENT_FOLDER + "documentation" + File.separator;
    6161                DICT_PATH = PARENT_FOLDER + "dict" + File.separator;
     62                FONT_PATH = PARENT_FOLDER + "fonts" + File.separator;
    6263                PROFILE_PATH = PARENT_FOLDER + "profiles" + File.separator;
    6364                EXPORTS_DIR = PARENT_FOLDER + "exports" + File.separator;
     
    8586
    8687        public static String HELP_PATH;
     88
     89        public static String FONT_PATH;
    8790       
    8891        public static String TEMPLATES_PATH;
  • trunk/src/org/expeditee/settings/UserSettings.java

    r747 r761  
    22
    33import java.awt.Color;
     4import java.awt.Font;
     5import java.awt.GraphicsEnvironment;
    46import java.io.File;
    57import java.io.FileNotFoundException;
     
    392394       
    393395       
     396    protected static final String filenameExtension(String fileName) {
     397        // Code excerpt from:
     398        //   http://stackoverflow.com/questions/3571223/how-do-i-get-the-file-extension-of-a-file-in-java
     399        // packed up here as a method
     400
     401        String extension = "";
     402       
     403        int i = fileName.lastIndexOf('.');
     404        int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
     405       
     406        if (i > p) {
     407            extension = fileName.substring(i+1);
     408        }
     409
     410        return extension;
     411    }
     412
    394413        // add default values
    395414        static {
    396415                String expeditee_home = System.getProperty("expeditee.home");
    397416                if (expeditee_home != null) {
    398             FrameIO.changeParentFolder(expeditee_home + File.separator);
    399         } else {
    400                 FrameIO.changeParentFolder(getSaveLocation());
    401         }
     417                    FrameIO.changeParentFolder(expeditee_home + File.separator);
     418                } else {
     419                    FrameIO.changeParentFolder(getSaveLocation());
     420                }
    402421         
    403422                UserSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
     
    409428                UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
    410429                UserSettings.ImageDirs.setDefault(UserSettings.ImageDirs.get());
     430               
     431               
     432               
     433                try {
     434                        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     435
     436                        if (ge != null) {
     437
     438
     439                            File fontDirectory = new File(FrameIO.FONT_PATH);
     440                            if (fontDirectory != null) {
     441                                File[] fontFiles = fontDirectory.listFiles();
     442                                if (fontFiles != null) {
     443
     444                                    if (fontFiles.length>0) {
     445                                        System.out.println("Loading custom fonts:");
     446                                    }
     447
     448                                    boolean first_item = true;                             
     449                                    for (File fontFile : fontFiles) {
     450
     451                                        String ext = filenameExtension(fontFile.getName().toLowerCase());
     452
     453                                        if (ext.equals("ttf")) {
     454                                            if (first_item) {
     455                                                System.out.print("  " + fontFile.getName());
     456                                            }
     457                                            else {
     458                                                System.out.print(", " + fontFile.getName());
     459                                            }
     460                                            System.out.flush();
     461
     462                                            Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
     463                                           
     464                                            ge.registerFont(font);
     465                                            first_item = false;
     466                                        }
     467                                    }
     468                                    System.out.println();
     469
     470                                }
     471                            }
     472                        }
     473                        else {
     474                                System.err.println("No graphics environment detected.  Skipping the loading of the custom font Metamorphous");
     475                        }
     476                }
     477                catch (Exception e) {
     478                        System.err.println("Failed to load custom font Metamorphous");
     479                        e.printStackTrace();
     480                }
     481
     482               
     483               
    411484        }
    412485
Note: See TracChangeset for help on using the changeset viewer.