1

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();
    }

}

1 Answers1

1

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.

Jai
  • 8,165
  • 2
  • 21
  • 52