--- old/modules/graphics/src/main/java/javafx/scene/text/Font.java 2016-05-19 14:56:15.280738920 -0700
+++ new/modules/graphics/src/main/java/javafx/scene/text/Font.java 2016-05-19 14:56:15.164738923 -0700
@@ -399,6 +399,59 @@
* @return the Font, or null if the font cannot be created.
*/
public static Font loadFont(String urlStr, double size) {
+ Font[] fonts = loadFontInternal(urlStr, size, false);
+ return (fonts == null) ? null : fonts[0];
+ }
+
+ /**
+ * Loads font resources from the specified URL. If the load is successful
+ * such that the location is readable, and it represents a supported
+ * font format then an array ofFont
object will be returned.
+ *
+ * The use case for this method is for loading all fonts + * from a TrueType Collection (TTC). + *
+ * If a security manager is present, the application + * must have both permission to read from the specified URL location + * and the {@link javafx.util.FXPermission} "loadFont". + * If the application does not have permission to read from the specified + * URL location, then null is returned. + * If the application does not have the "loadFont" permission then this method + * will return an array of one element which is the default + * system font with the specified font size. + *
+ * Any failure such as a malformed URL being unable to locate or read
+ * from the resource, or if it doesn't represent a font, will result in
+ * a null
return. It is the application's responsibility
+ * to check this before use.
+ *
+ * On a successful (non-null) return the fonts will be registered + * with the FX graphics system for creation by available constructors + * and factory methods, and the application should use it in this + * manner rather than calling this method again, which would + * repeat the overhead of downloading and installing the fonts. + *
+ * The font size
parameter is a convenience so that in
+ * typical usage the application can directly use the returned (non-null)
+ * font rather than needing to create one via a constructor. Invalid sizes
+ * are those <=0 and will result in a default size.
+ *
+ * If the URL represents a local disk file, then no copying is performed
+ * and the font file is required to persist for the lifetime of the
+ * application. Updating the file in any manner will result
+ * in unspecified and likely undesired behaviours.
+ *
+ * @param urlStr from which to load the fonts, specified as a String.
+ * @param size of the returned fonts.
+ * @return array of Font, or null if the fonts cannot be created.
+ * @since 9
+ */
+ public static Font[] loadFonts(String urlStr, double size) {
+ return loadFontInternal(urlStr, size, true);
+ }
+
+ private static Font[] loadFontInternal(String urlStr, double size,
+ boolean loadAll) {
URL url = null;
try {
url = new URL(urlStr); // null string arg. is caught here.
@@ -426,15 +479,17 @@
} catch (Exception e) {
return null;
}
- return Toolkit.getToolkit().getFontLoader().loadFont(path, size);
+ return
+ Toolkit.getToolkit().getFontLoader().loadFont(path, size, loadAll);
}
- Font font = null;
+ Font[] fonts = null;
URLConnection connection = null;
InputStream in = null;
try {
connection = url.openConnection();
in = connection.getInputStream();
- font = Toolkit.getToolkit().getFontLoader().loadFont(in, size);
+ fonts =
+ Toolkit.getToolkit().getFontLoader().loadFont(in, size, loadAll);
} catch (Exception e) {
return null;
} finally {
@@ -445,7 +500,7 @@
} catch (Exception e) {
}
}
- return font;
+ return fonts;
}
/**
@@ -454,6 +509,50 @@
* fully read, and it represents a supported font format then a
* Font
object will be returned.
*
+ * The use case for this method is for loading all fonts + * from a TrueType Collection (TTC). + *
+ * If a security manager is present, the application + * must have the {@link javafx.util.FXPermission} "loadFont". + * If the application does not have permission then this method + * will return the default system font with the specified font size. + *
+ * Any failure such as abbreviated input, or an unsupported font format
+ * will result in a null
return. It is the application's
+ * responsibility to check this before use.
+ *
+ * On a successful (non-null) return the fonts will be registered + * with the FX graphics system for creation by available constructors + * and factory methods, and the application should use it in this + * manner rather than calling this method again, which would + * repeat the overhead of re-reading and installing the font. + *
+ * The font size
parameter is a convenience so that in
+ * typical usage the application can directly use the returned (non-null)
+ * fonts rather than needing to create one via a constructor. Invalid sizes
+ * are those <=0 and will result in a default size.
+ *
+ * This method does not close the input stream.
+ * @param in stream from which to load the font.
+ * @param size of the returned font.
+ * @return array of Font, or null if the fonts cannot be created.
+ * @since 9
+ */
+ public static Font loadFont(InputStream in, double size) {
+ if (size <= 0) {
+ size = getDefaultSystemFontSize();
+ }
+ Font[] fonts =
+ Toolkit.getToolkit().getFontLoader().loadFont(in, size, false);
+ return (fonts == null) ? null : fonts[0];
+ }
+
+ /**
+ * Loads font resources from the specified input stream.
+ * If the load is successful such that the stream can be
+ * fully read, and it represents a supported font format then a
+ * an array of Font
object will be returned.
+ *
* If a security manager is present, the application * must have the {@link javafx.util.FXPermission} "loadFont". * If the application does not have permission then this method @@ -479,11 +578,13 @@ * @param size of the returned font. * @return the Font, or null if the font cannot be created. */ - public static Font loadFont(InputStream in, double size) { + public static Font[] loadFonts(InputStream in, double size) { if (size <= 0) { size = getDefaultSystemFontSize(); } - return Toolkit.getToolkit().getFontLoader().loadFont(in, size); + Font[] fonts = + Toolkit.getToolkit().getFontLoader().loadFont(in, size, true); + return (fonts == null) ? null : fonts; } /**