Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Font] is there an easy way in codea to adjust the kerning for a font?

edited October 19 in Questions Posts: 102

So I'll be using the same font, but depending on where I use it, I want to make it a bit squished or a bit more open.

or i might be doing a special effect where the letters are much more spaced, or squished. you know, animations.

e.g. lets say i want 2 px between letters when drawing to a really tiny button. or i decide to make the letters more open, so i increase that to six or eight pixels

originally i was to make my own ttf files for each variation, but i wondered if you can do this from inside codea.

Comments

  • Posts: 299

    Not that I'm aware of, but if you are thinking of rolling your own then I did design a font class many years ago in the days when text didn't exist.

    You can find it on github. It was designed to use fonts in BDF format (but fontforge can convert easily - I have a script somewhere for the conversion if you like). I later adapted it to use the native fonts, but the original code is still there.

    Even if you don't use it, it may help guide you on your way.

  • dave1707dave1707 Mod
    Posts: 6,325

    @xThomas Not sure if you’re after something like this, but here’s an example of changing the position and size of each letter.

    displayMode(FULLSCREEN)
    supportedOrientations(LANDSCAPE_ANY)
    
    function setup()
        font("Georgia-Bold")
        str="abcdefghijklmnopqrstuvwxyz"
        val=60
        cnt=val
    end
    
    function draw()
        background(0)
        fill(255)
        cnt=cnt+1
        if cnt>val then
            tab={}
        end
        for z=1,#str do
            if cnt>val then
                xx=math.random(-10,10)
                yy=math.random(-10,10)
                zz=math.random(15,40)
                table.insert(tab,vec3(xx,yy,zz))
            end
            a=string.sub(str,z,z)
            fontSize(tab[z].z)
            text(a,100+z*30+tab[z].x,200+tab[z].y)
        end
        if cnt>val then
            cnt=0
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 6,325

    @xThomas Here’s a stripped down version just altering the spacing between letters.

    function setup()
        font("Courier")
        parameter.integer("val",1,30,20)
        str="abcdefghijklmnopqrstuvwxyz"
    end
    
    function draw()
        background(0)
        fill(255)
        for z=1,#str do
            a=string.sub(str,z,z)
            text(a,10+z*val,200)
        end
    end
    
  • em2em2
    Posts: 167

    @dave1707 I love how your solutions are always so concise!

  • Posts: 102

    Thanks guys.

Sign In or Register to comment.