Java FX:某些字体家族未应用粗体和斜体样式 [英] Java FX: Bold and Italic styles are not getting applied for some of the font families

查看:124
本文介绍了Java FX:某些字体家族未应用粗体和斜体样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将粗体和斜体样式应用于所有字体系列时,粗体和斜体样式将应用于某些字体.在某些情况下(例如阿尔及利亚),粗体-斜体样式不适用.有什么方法可以处理阿尔及利亚和某些相似字体系列的特殊情况,而这些字体没有应用粗斜体样式?

While applying bold and italic style to all font families, the bold and italic styles gets applied to some of the fonts. In some of the cases like Algerian the bold-italic style does not applied. Is there any way for handling these special cases for Algerian and some similar font families for which bold-italic style does not get applied?

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不可能神奇地知道如何做到这一点.

Not all fonts have support for multiple font weights and posture, and Algerian font belongs to the group that has only one single style. If the font itself doesn't know how to render texts in a bold or italic manner, there is no way JavaFX would magically know how to do so.

如果您需要始终显示粗体或斜体文本,则必须使用支持该字体的字体.如果正在编写或设计模块,则应尽可能避免公开更改字体的功能.如果您拥有唯一的字体控制权,并且知道这些字体支持粗体或斜体样式,那么可以确保您的应用程序将始终以粗体或斜体显示文本.

If you need to always display bold or italic texts, then you must use a font that supports that. If you are writing or designing a module, you should, as far as possible, avoid exposing the capability to change the font. If you hold the only control over the font, and you know those fonts support bold or italic styles, then you can be sure that your application will always display texts in bold or italics.

这篇关于Java FX:某些字体家族未应用粗体和斜体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆