P5.js: Is there a way to use .textToPoints() without loading an external font file?

Created on 4 Feb 2018  路  1Comment  路  Source: processing/p5.js

Nature of issue?

  • [ ] New feature request
  • [ ] Existing feature enhancement

Most appropriate sub-area of p5.js?

  • [ ] IO
  • [ ] Typography
  • [ ] Other (specify if possible)

New feature details:

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.

typography

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

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Patchy12 picture Patchy12  路  3Comments

NamanSharma5 picture NamanSharma5  路  3Comments

kartikay-bagla picture kartikay-bagla  路  3Comments

b0nb0n picture b0nb0n  路  3Comments

aman-tiwari picture aman-tiwari  路  3Comments