I want to calculate the Font Size due to a width value.
//Custom Font
Font.loadFont(Fonts.class.getResourceAsStream("/font/bignood/bignoodletoo.ttf"), 10)
String text = "Hello World";
Double width = 100;
Similiar SO Question to Java AWT
Similar SO Question to Java AWT 2
Edit: Use case
Think about a button that have a text "PLAY MONEY"¹
.
Now I will translate the text to PT_BR and it calls now "DINHEIRO FICTICIO"²
.
As you can see, the word² is bigger than word¹, so if you set the same Font Size
then you gonna see DINHEIRO FIC...
inside the button.
So the mission here is get the width
value of the Button
, get the text
and apply the Font Size
to fit the full text inside the Button
, whenever I change the text
.