createFont() creates the same font no matter what

Hi, I'm comparing various fotns to see which is well readable at very small size. I found several candidates in Tools>CreateFont dialog. But when I plot a text samples using these fonts all looks the same. This is strange especialy when I compare monospaced fonts with non-monospaced. In CreateFont dialog the fonts are OK i.e. does not look the same.

I'm using processing 2.2.1 in Ubuntu 14.04 java version "1.7.0_55" OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1) OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

this is the code for plotting text smaples by different fonts:

int sz = 14;
String teststring = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~!@#$%^&*(){}[]_+|';<>?/";
//String teststring = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static String [] fontNames = { "Georgia", "DejaVuSans","DejaVuSansMono", "Dialog.plain",
                               "DroidSansMono", "DroidSerif","DroidSansMono","LiberationMono",
                               "LiberationSans","LucidaSans-Typewriter","Monospaced.plain","SansSerif.plain",
                               "SourceCodePro-Regular","Ubuntu-Light","UbuntuMono-Bold","WenQuanYiMicroHeiMono"
                             };

void setup(){
  print( PFont.list() );
  size(1200,800);
  background(255);
  noSmooth();
  fill(0); 
  for ( int i=0; i<fontNames.length; i++ ){
    String name = fontNames[i];
    PFont myFont = createFont( name, sz, false );
    textFont(myFont);
    text( name      ,10,20+i*(sz+1) );
    text( teststring,200,20+i*(sz+1) );
  }
}
Tagged:

Answers

  • _vk_vk
    edited October 2014

    Your code worked for me for every font that I have properly installed, maybe you don't have them available...

    Try this one, it will check to see if the font is available:

    int sz = 14;
    String teststring = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~!@#$%^&*(){}[]_+|';<>?/";
    String [] fontNames = { 
      "Georgia", "DejaVuSans", "DejaVuSansMono", "Dialog.plain", 
      "DroidSansMono", "DroidSerif", "DroidSansMono", "LiberationMono", 
      "LiberationSans", "LucidaSans-Typewriter", "Monospaced.plain", "SansSerif.plain", 
      "SourceCodePro-Regular", "Ubuntu-Light", "UbuntuMono-Bold", "WenQuanYiMicroHeiMono"
    };
    
    
    
    
    void setup() {
      size(1200, 800);
      background(255);
      String[] existingFonts = PFont.list();
      fill(0); 
      for ( int i=0; i<fontNames.length; i++ ) {
        String name = fontNames[i];
        if (fontExists(name, existingFonts)) {
          PFont myFont = createFont( name, sz, false );
          textFont(myFont);
          fill(0); 
          text( name, 10, 20+i*(sz+7) );
          text( teststring, 200, 20+i*(sz+7));
        } else {
          textFont(createFont("courrier", 13));
          fill(90);
          text( name, 10, 20+i*(sz+7));
          text( "Not Found... ", 200, 20+i*(sz+7));
        }
      }
    }
    
    
    boolean fontExists(String font, String[] installed) {
      for (int i = 0; i < installed.length; i++) {
        if (font.equals(installed[i])) {
          return true;
        }
      }
      return false;
    }
    
  • thanks, yes, the fonts are "not installed" according to PFont.list(), but what does it mean? These font are accesible by Tools>Create font or eg. in LibreOffice font selection. So how can I install them, or rather make them visible for PFont.list()?

Sign In or Register to comment.