在为所有字体系列应用粗体和斜体样式时,将大胆和斜体样式应用于某些字体。在某些情况下,像阿尔及利亚人这样的大胆风格没有应用。是否有任何方法可以为阿尔及利亚人和一些类似的字体家庭处理这些特殊案例,而大胆风格不会应用?
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class FontTest extends Application {
public static void main(String[] args) {
// TODO Auto-generated method stub
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
Text t=new Text();
t.setText("Abc");
t.setX(50);
t.setY(50);
Font font = Font.font("Algerian", FontWeight.BOLD, FontPosture.ITALIC, 19);
t.setFont(font);
Group group = new Group(t);
//Creating a Scene by passing the group object, height and width
Scene scene = new Scene(group ,200, 200);
primaryStage.setTitle("Sample Application");
//Adding scene to the stage
primaryStage.setScene(scene);
//Displaying the contents of the stage
primaryStage.show();
}
}
并非所有字体都支持多个字体权重和姿势,而阿尔及利亚字体则属于只有一种样式的组。如果字体本身不知道如何以粗体或斜体的方式渲染文本,那么Javafx就不会神奇地知道如何做。
如果您需要始终显示显示粗体或斜体文本,则必须使用支持该字体的字体。如果您正在编写或设计模块,则应尽可能避免更改字体的功能。如果您拥有对字体的唯一控制权,并且您知道这些字体支持粗体或斜体样式,那么您可以确定您的应用程序将始终以粗体或斜体显示文本。