Had space(more than 1px) between letters with custom font

Posted on
Page
of 2
Prev
/ 2
  • You can make the letters overlap by passing a negative spacing into the function I posted:

    drawStringWithSpacing("foo", 0, 0, -1);
    
  • Thanks @NebbishHacker for the code.
    the slanted font need a different width to have a good kerning.
    I use a fixed size font of 9x8 px.
    i had an array to specify the with of each letter for a correct kerning

    //                    a b c d e f g h i j k l m n o p q r s t u v w x y z
    var largeurLettres = [3,0,0,0,6,5,4,0,3,5,5,3,8,0,0,0,5,5,0,4­,0];
    function drawStringSlanted(text, x, y) {
      var largeur = 0;
      for (var char of text) {
        g.drawString(char, x, y);
        index = char.charCodeAt(0);
    // 65 is my offset in the array for lowercase (i do  not draw all the font) and 32 for my first char (space)
        x += (largeurLettres[index-(65-32)]+ 2);
      }
    }
    

    2 Attachments

  • Nice, looks like a good solution :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Had space(more than 1px) between letters with custom font

Posted by Avatar for Mrbbp @Mrbbp

Actions