本文整理汇总了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;
}