Is there a way for a Processing sketch to support kerning?

edited August 2015 in How To...

Looking around there are some quite old posts about this (all saying 'no') - has this changed at all in recent years? Any work arounds discovered?

I attach an image of a comparison between text rendered in Indesign, Chrome and Processing to illustrate what I mean.

cheers

platformComparison

Tagged:

Answers

  • Answer ✓

    In a word: No.

  • _vk_vk
    edited August 2015

    Without digging into proper kerning logics (I don't know if there is much more about it than the simple...). This looks ok to me...

    Code edited: minor improvements...

    String test = "It's funny how the colors of the real world only " + 
    "seem really real when you viddy them on the screen.";
    
    PFont f;
    int fontSize = 22;
    
    
    void setup() {
      size (1000, 300, P2D);
    
      f = createFont("Arial", fontSize);
      textFont(f, fontSize);
      fill(0);
    }
    
    void draw() {
      background(255);
    
      text(test, 20, 150);
    
      float kern = map (mouseY, 0, height, 0, 1.5);
      kernedText(test, f, fontSize, 20, 180, kern);
    }
    
    
    void kernedText(String s, PFont f, int fSize, int x, int y, float kern) {
      float acc = 0;
      textFont(f, fSize);
      for (int i = 0; i < s.length(); i++) {
        text(s.charAt(i), x + acc * kern, y);
        acc += textWidth(s.charAt(i))* kern;
      }
    }
    
  • _vk_vk
    edited August 2015

    Funny enough the "kern" that seems to mimics the default is 1.0075

  • Try it with the text, and font, of the original.

    That said, the original looks wrong to me, too extreme in the way it bunches up around the commas...

  • TfGuy44 - 'No.' Haha! Glad I could make the no more contemporary.

    _vk - love your example, I suppose it could be developed so that it applies between individual character pairs, which is really what kerning is, rather than just the letter spacing between all characters?

    koogs - example from _vk's code below. You're right, it's not 'right' as such but it's on the way to how I want it to be. The characters are taken from these paintings and are not uniform or particularly well designed as a set.

    kernTest

  • I new it could not be so simple... :)

    This one seems to be tracking...

    For P5 2.x you can try

    http://www.ricardmarxer.com/geomerative/

    I can't remember but there were some others libraries for typography.

  • Thanks anyway, I will probably just have to accept the updated 'no.'

  • Java seems to have support for kerning, so if java can do it ... But I don't know how to integrate this with a processing sketch, PFont etc.

    If you wanna have a look:

    https://docs.oracle.com/javase/tutorial/2d/text/textattributes.html

    http://docs.oracle.com/javase/7/docs/api/java/awt/font/TextAttribute.html

    http://grepcode.com/file/repo1.maven.org/maven2/com.flagstone/transform/3.0/com/flagstone/transform/font/Kerning.java

    and many more...

    ;)

Sign In or Register to comment.