textStyle Italic bold and others

How, would I go about setting the text to italic in processing. There is textStyle() in p5.js but I cannot seem to find its equivalent in processing.

Thanks.

1 Like

i used 2 .ttf files i downloaded.
in a modified example LETTER

1 Like

but if you like that functionality from p5.js more, just make it!

/**
 * Letters. 
 * 
 * Draws letters to the screen. This requires loading a font, 
 * setting the font, and then drawing the letters.
 */

//kll test add medium, mediumitalic, bold, bolditalic ttf files
// add a textStyle(style,size); function

// TAB MAIN
void setup() {
  size(640, 360);
  setup_text();
  background(0);
  draw_text();
}

void draw_text() {
  textAlign(CENTER, CENTER);
  int margin = 10;
  translate(margin*4, margin*4);
  int gap = 46;
  int counter = 35;
  for (int y = 0; y < height-gap; y += gap) {
    for (int x = 0; x < width-gap; x += gap) {
      char letter = char(counter);
      if (letter == 'A' || letter == 'E' || letter == 'I' || letter == 'O' || letter == 'U') {
        fill(255, 204, 0);
        //textFont(f_italic);
        //textSize(25);
        textStyle(BOLDITALIC,25);
      } else {
        fill(255);
        //textFont(f);
        //textSize(15);
        textStyle(NORMAL,15);
      }
      text(letter, x, y);
      counter++;
    }
  }
}


// TAB MY_THEME
PFont f, f_italic, f_bold, f_bold_italic;
final int tsize = 24; //______ default size
final int NORMAL     = 0;
final int ITALIC     = 1;
final int BOLD       = 2;
final int BOLDITALIC = 3;

void setup_text() {
  //printArray(PFont.list());  
  // expect that files under /data/*.ttf
  f             = createFont("SourceCodePro-Medium.ttf", tsize);
  f_italic      = createFont("SourceCodePro-MediumItalic.ttf", tsize);
  f_bold        = createFont("SourceCodePro-Bold.ttf", tsize);
  f_bold_italic = createFont("SourceCodePro-BoldItalic.ttf", tsize);

  textStyle(NORMAL, tsize);
}

void textStyle(int tstyle) {  // NORMAL, ITALIC, BOLD or BOLDITALIC 0,1,2,3
  textStyle( tstyle, tsize);
}

void textStyle(int tstyle, int tsize) {
  switch(tstyle) {
  case 0: // NORMAL
    textFont(f);
    break;
  case 1: // ITALIC
    textFont(f_italic);
    break;
  case 2: //  BOLD
    textFont(f_bold);
    break;
  case 3: // BOLDITALIC
    textFont(f_bold_italic);
    break;
  default:
    println("wrong font style");
    break;
  }
  textSize(tsize);
}

2 Likes

If there’s no italic font available or you prefer to use a single font, perhaps you can obtain the italic effect with shearX.

2 Likes

Hello,

In the tools Processing IDE (PDE) Tools tab you can use Create Font:

References:
https://processing.org/reference/loadFont_.html
https://processing.org/reference/createFont_.html

:slight_smile:

For those that may wonder:
IDE


PDE
https://processing.org/reference/environment/

“Wonder is the beginning of wisdom” - Socrates

:slight_smile:

2 Likes