How to load fonts on an android device?

Hi, so I want to make a sketch on my phone where i load a font but always fails to load the font. I also put it into the sketch’s data folder (both as a *.ttf as well as *.vwl) but none of it worked. Any ideas on what I’m doing wrong?

hi @WeinSim, can you give us a code sample demonstrates your issue?

So I have a code which looks something like that. Only giving “Courier” as a font to load doesn’t work because apparently, the font isn’t saved on my phone. Now in the sketche’s data folder, I’ve included two files: Courier.ttf and Courier.vlw. Trying to load the Courier.ttf file (by typing “Courier = createFont(“Courier.ttf”, width/10);”) crashed the sketch and trying to load the Courier.vlw file is like using the default font (just as in the first example). I also tried copying the two files directly to the place where the sketch is saved but that doesn’t work either.

PFont Courier;

void setup() {
  size(displayWidth, displayHeight);
  Courier = createFont("Courier", width/10);
}

void draw() {
  background(251);
  fill(0);
  textFont(Courier);
  textAlign(CENTER, CENTER);
  text("test", width/2, height/2);
  
  noLoop();
}

What happens if you run it in Java mode instead of Android mode?

how about using the
/data/ … folder?

@kll, WeinSim tried that already.

1 Like

Also @WeinSim, could you share the Courier ttf and vlw files?

I didn’t run it on Android mode from my laptop but I have Processing for Android on my phone and ran the sketch from there. And there is no such thing as Java/Android mode when using your phone.

I couldn’t send the file directly because the forum would only let me send image files, but here are the download links to the ttf file (1st one) and vlw file (2nd one)
http://s000.tinyupload.com/?file_id=63691213872178297765
http://s000.tinyupload.com/?file_id=01858220214284167796

Just checking @WeinSim, you used an app like APDE or something? I’ll try running it on Java mode on my computer.

@WeinSim, I tried it on my computer, and it worked fine once I changed the line that says

Courier = createFont("Courier", width/10);

to

Courier = createFont("Courier.ttf", width/10);

.
And I did place the font called “Courier.ttf” in the data folder.
By the way, in Android mode, you don’t need a size() function. Proof here:

void setup() {
  fullScreen();
  noStroke();
  fill(0);
}

void draw() {
  background(204);
  if (mousePressed) {
    if (mouseX < width/2) {
      rect(0, 0, width/2, height); // Left
    } else {
      rect(width/2, 0, width/2, height); // Right
    }
  }
}

@WeinSim ===

(put your font in the data folder)
then try the code below :



PFont police;
boolean ecrire = false;


void setup(){
  size(600,800);
  background(255);
  textSize(36);
  police = createFont("Courier.ttf", 36);
  textFont(police);
  ecrire= true;
 
  
  
}

void draw(){
  background(255);
  fill(255,0,0);
  if(ecrire){
 text("Essai", width/2, height/2); 
  }
}

Yes I think it’s called APDE. Simply what you get when you google “Processing for android” and download it from their website (or from google play or sth idk).
Now I think on my laptop I got the same results when loading the font files.

Ok so I just checked again, on my laptop it actually works. But for some reason on my phone it doesn’t.

Oh, and thank you for the information.

@WeinSim ===
i dont use APDE but the android mode; as for me the code i have put works fine on 2 phones i have tested , first one running MM, the other kitKat.

Ok but (at least as far as I know), android mode only works when the phone is connected to the computer. And when thinkng a bit ahead (I’m planning to use something like that in an app), it wouldn’t be very practical if you always had to stand right next to a computer when using it.