considering a font, a size of that font, is there a way to calculate the size in pixel of a word written with this font ?
1
float sw = textWidth(str);
PFont font; void setup() { size(500, 500); font = loadFont("SourceSansPro-Regular-50.vlw"); } void draw() { background(255); fill(0); textFont(font); float fitWidth = mouseX; // use the mouse as the "width" String text = "Rabbits"; // text we want to write // calculate the text width at full size (50px in this case) float baseWidth = textWidth(text); float targetSize = fitWidth / baseWidth * font.getSize(); // size to fit textSize(targetSize); text(text, 0, height * 0.5); }