1 /* 2 * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Sun designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Sun in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 /* 27 * <PRE> 28 * This class filters TrueType font files from other file 29 * found in the font path. 30 * 31 * </PRE> 32 * 33 * @author Ilya Bagrak 34 */ 35 36 package build.tools.fontchecker; 37 38 import java.awt.*; 39 import java.io.*; 40 41 public class FontFileFilter implements java.io.FileFilter, FontCheckerConstants { 42 43 /** 44 * Boolean flag indicating whether this filter filters out 45 * non-TrueType fonts. 46 */ 47 private boolean checkNonTTF; 48 49 public FontFileFilter() { 50 this(false); 51 } 52 53 public FontFileFilter(boolean checkNonTTF) { 54 super(); 55 this.checkNonTTF = checkNonTTF; 56 } 57 58 /** 59 * Checks whether a file is accepted by this filter. 60 * <BR> 61 * This method checks whehter a file is accepted by this filter. 62 * This filter is made to accept all the file whose extension is 63 * either .ttf or .TTF. These files are assumed to be TrueType fonts. 64 * <BR><BR> 65 * @return returns a boolean value indicating whether or not a file is 66 * accepted 67 */ 68 public boolean accept(File pathname) { 69 70 String name = pathname.getName(); 71 return (name.endsWith(".ttf") || 72 name.endsWith(".TTF") || 73 name.endsWith(".ttc") || 74 name.endsWith(".TTC")) || 75 (name.endsWith(".pfb") || 76 name.endsWith(".PFB") || 77 name.endsWith(".pfa") || 78 name.endsWith(".PFA") && 79 checkNonTTF == true); 80 } 81 82 public static int getFontType(String filename) { 83 if (filename.endsWith(".ttf") || 84 filename.endsWith(".TTF") || 85 filename.endsWith(".ttc") || 86 filename.endsWith(".TTC")) 87 return Font.TRUETYPE_FONT; 88 else if (filename.endsWith(".pfb") || 89 filename.endsWith(".PFB") || 90 filename.endsWith(".pfa") || 91 filename.endsWith(".PFA")) 92 return Font.TYPE1_FONT; 93 else 94 return 999; 95 } 96 97 }