processing / processing-website

Repository for the processing.org website
https://processing.org
GNU General Public License v2.0
68 stars 95 forks source link

Wrong number of arguments in LoadFont example #299

Closed knupel closed 2 years ago

knupel commented 2 years ago

Hello, maybe there is an error in the example for the https://processing.org/reference/loadFont_.html

size(400, 400);
PFont font;
// The font must be located in the sketch's 
// "data" directory to load successfully
font = loadFont("LetterGothicStd.otf", 128); // problem here
textFont(font, 128);
text("word", 50, 200);

I think the good thing is

font = loadFont("LetterGothicStd-128.vlw");

I think when the int is used to define the font size is for createFont(String, int);

SableRaf commented 2 years ago

Hey @StanLepunK 👋 Could you share the error you're getting with the existing code?

knupel commented 2 years ago

Hello @SableRaf like I write the function loadFont(String) cannot accept argument loadFont(String, int) see in the Processing core PApplet.java>PApplet>loadFont(String)

  public PFont loadFont(String filename) {
    if (!filename.toLowerCase().endsWith(".vlw")) {
      throw new IllegalArgumentException("loadFont() is for .vlw files, try createFont()");
    }
    try {
      InputStream input = createInput(filename);
      return new PFont(input);

    } catch (Exception e) {
      die("Could not load font " + filename + ". " +
          "Make sure that the font has been copied " +
          "to the data folder of your sketch.", e);
    }
    return null;
  }

It's why I think there an error in the example https://processing.org/reference/loadFont_.html

size(400, 400);
PFont font;
// The font must be located in the sketch's 
// "data" directory to load successfully
font = loadFont("LetterGothicStd.otf", 128); // BAD
textFont(font, 128);
text("word", 50, 200);

must be like that

size(400, 400);
PFont font;
// The font must be located in the sketch's 
// "data" directory to load successfully
font = loadFont("LetterGothicStd.otf"); // GOOD
textFont(font, 128);
text("word", 50, 200);

Et voilà, tralalala

SableRaf commented 2 years ago

Good catch @StanLepunK, thanks! 👍 Fixed in next release.