currently, the only way to obtain point coordinates from text string is to call .textToPoints() from a new p5.Font() object.
var font;
function preload() {
font = loadFont('./assets/Avenir.otf'); // this file must exists
}
function setup() {
var points1 = font.textToPoints('Hello, world!', 200,200,20); // this works
var points2 = p5.Font.textToPoints('Hi again' , 200,200,20); //doesn't work
textFont("Tahoma");
var points3 = p5.Font.textToPoints('Good bye!', 200,200,20); //doesn't work
}
.textToPoints() only work if you provide a font file along with the project. But what if you just want to use a system font like 'Tahoma` or 'Arial', or you just don't care what font is the default, just as long as you don't need to provide a font file?
If someone doesn't want the default font, he/she could simply call textFont("my_special_font_name_here") right before calling textToPoints().
It would be excellent if textToPoints() work from the global scope just like text() and textSize() and textFont() because it behaves almost like them.
This is by design, as browser fonts don't expose path data (correct me on this if I'm mistaken) -- so textToPoints() can _only_ work on a specific opentype-compatible font instance
Most helpful comment
This is by design, as browser fonts don't expose path data (correct me on this if I'm mistaken) -- so textToPoints() can _only_ work on a specific opentype-compatible font instance