In LTK, I want to write a string on a canvas and surround it with a rectangle. I can set it to wrap around at a given width (in pixels), but because of kerning, I cannot predict how many lines the string will occupy and therefore how tall the rectangle should be. I want to use a monospaced font so that I can predict the height within the program, but the font remains the same. If I use "FreeMono 32" instead of "FreeMono", it changes the size accordingly, but it ignores the font name. I do have the font FreeMono working, as checked in LibreOffice Writer.
Code I tried:
(defun main ()
(ltk:with-ltk ()
(let ((c (make-instance 'ltk:canvas :width 500 :height 500)))
(ltk:pack c)
(let ((txt (ltk:create-text c 100 100 "lorem ipsum dolor sit amet consectetur adipiscing elit")))
(ltk:itemconfigure c txt :width 100)
(ltk:itemconfigure c txt :font "FreeMono")
(ltk:itemconfigure c txt :justify "center")))))
LTK manual: http://www.peter-herth.de/ltk/ltkdoc.pdf
We can print the available fonts with the (sadly undocumented) function font-families
:
(ltk:with-ltk ()
(print (ltk:font-families)))
The FreeMono font was not recognised by LTK. A suitable monospaced font is NotoSans. New fonts might be added through font-create
or font-configure
, but lacking tcl/tk knowledge, I cannot confirm or explain.