Changeset 777


Ignore:
Timestamp:
01/29/14 10:29:04 (10 years ago)
Author:
jts21
Message:

Only try to init fonts after they've been extracted so they can actually be loaded

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

Legend:

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

    r763 r777  
    4242import org.expeditee.items.Item;
    4343import org.expeditee.items.ItemUtils;
     44import org.expeditee.items.Text;
    4445import org.expeditee.items.widgets.WidgetCacheManager;
    4546import org.expeditee.network.FrameShare;
     
    282283                       
    283284                        Settings.Init();
     285                       
     286                        Text.InitFonts();
    284287
    285288                        DisplayIO.Init(this);
  • trunk/src/org/expeditee/items/Text.java

    r776 r777  
    77import java.awt.GradientPaint;
    88import java.awt.Graphics2D;
     9import java.awt.GraphicsEnvironment;
    910import java.awt.Point;
    1011import java.awt.Polygon;
     
    2223import java.awt.geom.Point2D;
    2324import java.awt.geom.Rectangle2D;
     25import java.io.File;
    2426import java.text.AttributedString;
    2527import java.util.Collection;
     
    3941import org.expeditee.gui.FreeItems;
    4042import org.expeditee.math.ExpediteeJEP;
    41 import org.expeditee.settings.UserSettings;
    4243import org.expeditee.settings.experimental.ExperimentalFeatures;
    4344import org.nfunk.jep.Node;
     
    142143        // The font to display this text in
    143144        private Font _font;
     145       
     146        public static void InitFonts() {
     147                try {
     148                        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     149
     150                        if (ge != null) {
     151                               
     152                            File fontDirectory = new File(FrameIO.FONT_PATH);
     153                            if (fontDirectory != null) {
     154                                File[] fontFiles = fontDirectory.listFiles();
     155                                if (fontFiles != null) {
     156   
     157                                    if (fontFiles.length>0) {
     158                                        System.out.println("Loading custom fonts:");
     159                                    }
     160   
     161                                    boolean first_item = true;                             
     162                                    for (File fontFile : fontFiles) {
     163                                        String ext = "";
     164                                        String fileName = fontFile.getName().toLowerCase();
     165                               
     166                                        int i = fileName.lastIndexOf('.');
     167                                int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
     168                               
     169                                if (i > p) {
     170                                    ext = fileName.substring(i+1);
     171                                }
     172       
     173                                                if (ext.equals("ttf")) {
     174                                                    if (first_item) {
     175                                                        System.out.print("  " + fontFile.getName());
     176                                                    }
     177                                                    else {
     178                                                        System.out.print(", " + fontFile.getName());
     179                                                    }
     180                                                    System.out.flush();
     181       
     182                                                    Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
     183                                                   
     184                                                    ge.registerFont(font);
     185                                                    first_item = false;
     186                                                }
     187                                    }
     188                                    System.out.println();
     189   
     190                                }
     191                            }
     192                        }
     193                        else {
     194                                System.err.println("No graphics environment detected.  Skipping the loading of the custom fonts");
     195                        }
     196                }
     197                catch (Exception e) {
     198                        System.err.println("Failed to load custom fonts");
     199                        e.printStackTrace();
     200                }
     201        }
    144202
    145203        /**
  • trunk/src/org/expeditee/settings/UserSettings.java

    r768 r777  
    392392                }
    393393        };
    394        
    395        
    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     }
    412394
    413395        // add default values
     
    428410                UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
    429411                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                
    484412        }
    485413
Note: See TracChangeset for help on using the changeset viewer.