本文整理匯總了Java中javafx.scene.text.Font.getFamily方法的典型用法代碼示例。如果您正苦於以下問題:Java Font.getFamily方法的具體用法?Java Font.getFamily怎麽用?Java Font.getFamily使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.text.Font
的用法示例。
在下文中一共展示了Font.getFamily方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import javafx.scene.text.Font; //導入方法依賴的package包/類
@Override
public void write(JsonWriter writer, Font value) throws IOException {
if (value == null) {
writer.nullValue();
return;
}
String s = value.getFamily();
writer.value(s);
}
示例2: loadFont
import javafx.scene.text.Font; //導入方法依賴的package包/類
/**
* Load a font from Google Web Fonts Service
*
* Note: this is only designed to work with simple stylesheets with single
* font in them.
*
* @param googleFontCssUrl The url to css stylesheet with @fontface
* definition
* @return The name of the font family, or "System" if there was a error
* @throws java.net.MalformedURLException
*/
public static String loadFont(String googleFontCssUrl) throws MalformedURLException {
String fontName = "System";
try {
URL cssUrl = new URL(googleFontCssUrl);
URLConnection con = cssUrl.openConnection();
InputStream in = con.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
String fontUrl = null;
StringBuilder srcs = new StringBuilder();
while ((line = reader.readLine()) != null) {
// System.out.println(line);
if (line.contains("src:")) {
Matcher matcher = TTF_PATTERN.matcher(line);
if (matcher.find()) {
fontUrl = matcher.group(0);
// System.out.println("FOUND fontUrl = " + fontUrl);
break;
}
matcher = OTF_PATTERN.matcher(line);
if (matcher.find()) {
fontUrl = matcher.group(0);
// System.out.println("FOUND fontUrl = " + fontUrl);
break;
}
srcs.append(line);
srcs.append('\n');
}
}
if (fontUrl != null) {
Font font = Font.loadFont(fontUrl, 10);
fontName = font.getFamily();
} else {
System.err.println("Failed to find any supported fonts "
+ "(TTF or OTF) in CSS src:\n" + srcs.toString());
}
} catch (IOException ex) {
Logger.getLogger(WebFontEncoder.class.getName()).log(Level.SEVERE, null, ex);
}
return fontName;
}