< prev index next >

src/java.desktop/share/classes/sun/font/FontFamily.java

Print this page




  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.font;
  27 
  28 import java.io.File;
  29 import java.awt.Font;

  30 import java.util.Collection;
  31 import java.util.HashMap;
  32 import java.util.concurrent.ConcurrentHashMap;
  33 import java.util.Locale;
  34 
  35 public class FontFamily {
  36 
  37     private static ConcurrentHashMap<String, FontFamily>
  38         familyNameMap = new ConcurrentHashMap<String, FontFamily>();
  39     private static HashMap<String, FontFamily> allLocaleNames;
  40 
  41     protected String familyName;
  42     protected Font2D plain;
  43     protected Font2D bold;
  44     protected Font2D italic;
  45     protected Font2D bolditalic;
  46     protected boolean logicalFont = false;
  47     protected int familyRank;
  48 
  49     public static FontFamily getFamily(String name) {


 115         FileFont existingFont = null;
 116         if (plain instanceof FileFont) {
 117             existingFont = (FileFont)plain;
 118         } else if (bold instanceof FileFont) {
 119             existingFont = (FileFont)bold;
 120         } else if (italic instanceof FileFont) {
 121              existingFont = (FileFont)italic;
 122         } else if (bolditalic instanceof FileFont) {
 123              existingFont = (FileFont)bolditalic;
 124         }
 125         // A family isn't created until there's a font.
 126         // So if we didn't find a file font it means this
 127         // isn't a file-based family.
 128         if (existingFont == null) {
 129             return false;
 130         }
 131         File existDir = (new File(existingFont.platName)).getParentFile();
 132 
 133         FileFont newFont = (FileFont)font;
 134         File newDir = (new File(newFont.platName)).getParentFile();










 135         return java.util.Objects.equals(newDir, existDir);
 136     }
 137 
 138     /*
 139      * We want a family to be of the same width and prefer medium/normal width.
 140      * Once we find a particular width we accept more of the same width
 141      * until we find one closer to normal when we 'evict' all existing fonts.
 142      * So once we see a 'normal' width font we evict all members that are not
 143      * normal width and then accept only new ones that are normal width.
 144      *
 145      * Once a font passes the width test we subject it to the weight test.
 146      * For Plain we target the weight the closest that is <= NORMAL (400)
 147      * For Bold we target the weight that is closest to BOLD (700).
 148      *
 149      * In the future, rather than discarding these fonts, we should
 150      * extend the family to include these so lookups on these properties
 151      * can locate them, as presently they will only be located by full name
 152      * based lookup.
 153      */
 154 




  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.font;
  27 
  28 import java.io.File;
  29 import java.awt.Font;
  30 import java.io.IOException;
  31 import java.util.Collection;
  32 import java.util.HashMap;
  33 import java.util.concurrent.ConcurrentHashMap;
  34 import java.util.Locale;
  35 
  36 public class FontFamily {
  37 
  38     private static ConcurrentHashMap<String, FontFamily>
  39         familyNameMap = new ConcurrentHashMap<String, FontFamily>();
  40     private static HashMap<String, FontFamily> allLocaleNames;
  41 
  42     protected String familyName;
  43     protected Font2D plain;
  44     protected Font2D bold;
  45     protected Font2D italic;
  46     protected Font2D bolditalic;
  47     protected boolean logicalFont = false;
  48     protected int familyRank;
  49 
  50     public static FontFamily getFamily(String name) {


 116         FileFont existingFont = null;
 117         if (plain instanceof FileFont) {
 118             existingFont = (FileFont)plain;
 119         } else if (bold instanceof FileFont) {
 120             existingFont = (FileFont)bold;
 121         } else if (italic instanceof FileFont) {
 122              existingFont = (FileFont)italic;
 123         } else if (bolditalic instanceof FileFont) {
 124              existingFont = (FileFont)bolditalic;
 125         }
 126         // A family isn't created until there's a font.
 127         // So if we didn't find a file font it means this
 128         // isn't a file-based family.
 129         if (existingFont == null) {
 130             return false;
 131         }
 132         File existDir = (new File(existingFont.platName)).getParentFile();
 133 
 134         FileFont newFont = (FileFont)font;
 135         File newDir = (new File(newFont.platName)).getParentFile();
 136         if (existDir != null) {
 137             try {
 138                 existDir = existDir.getCanonicalFile();
 139             } catch (IOException ignored) {}
 140         }
 141         if (newDir != null) {
 142             try {
 143                 newDir = newDir.getCanonicalFile();
 144             } catch (IOException ignored) {}
 145         }
 146         return java.util.Objects.equals(newDir, existDir);
 147     }
 148 
 149     /*
 150      * We want a family to be of the same width and prefer medium/normal width.
 151      * Once we find a particular width we accept more of the same width
 152      * until we find one closer to normal when we 'evict' all existing fonts.
 153      * So once we see a 'normal' width font we evict all members that are not
 154      * normal width and then accept only new ones that are normal width.
 155      *
 156      * Once a font passes the width test we subject it to the weight test.
 157      * For Plain we target the weight the closest that is <= NORMAL (400)
 158      * For Bold we target the weight that is closest to BOLD (700).
 159      *
 160      * In the future, rather than discarding these fonts, we should
 161      * extend the family to include these so lookups on these properties
 162      * can locate them, as presently they will only be located by full name
 163      * based lookup.
 164      */
 165 


< prev index next >