Thursday, October 14, 2010

Square text conky

I had an idea for a conky. I wanted it to be extremely compact and involve text in different orientations. This is what I ended up with!



The problem was that I spent a long time looking for a square font. I found several fonts that I liked but when I came to rotate them and put rotated letters next to regularly orientated letters I found that none of the fonts were actually square. Non were the same width as height.

So I decided to make my own font using the Lua script. I had done something similar in my ascii text lua; a function that read each letter of the text I wanted displayed and converted the letter into ascii.

In this case I created my own square font out of the webdings font. With webdings a "g" gave me a solid color square, while "c" gave me a black square with a color outline. I simply constructed my letters using those blocks like so:

if letter=="T" then
font="webdings"
acrosst=across
downt=down
rotate=rotate*math.pi/180
cairo_translate (cr, acrosst, downt)
cairo_rotate (cr, rotate)
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize);
cairo_set_source_rgba (cr, red, green, blue, alpha);
cairo_move_to (cr, 0, 0);
cairo_show_text (cr, "ggggg")
ldown=fontsize
cairo_move_to (cr, 0, ldown);
cairo_show_text (cr, "ccgcc")
ldown=fontsize+ldown
cairo_move_to (cr, 0, ldown);
cairo_show_text (cr, "ccgcc")
ldown=fontsize+ldown
cairo_move_to (cr, 0, ldown);
cairo_show_text (cr, "ccgcc")
ldown=fontsize+ldown
cairo_move_to (cr, 0, ldown);
cairo_show_text (cr, "ccgcc")
cairo_rotate (cr, -1*rotate)
cairo_translate (cr, -1*acrosst, -1*downt)
end
I actually really like the look of the resulting square "font". And everything fitted nicely together with no gaps :)

Go here to take a look at the code via the link. This is another really long script, mainly because of the letter conversion function. Originally I set up the function converting lowercase letters into upper case letters of the square font. But I didn't like the way they looked, so I re-wrote the letter conversion function to include converting uppercase letters to a different version of the square font.

I just used the lua command string.upper to make everything uppercase and fed it to the conversion function. I never bothered to delete the lowercase conversion lines :)

No comments:

Post a Comment