在 LTK 中,我想在画布上写一个字符串并用一个矩形包围它。我可以将它设置为以给定的宽度(以像素为单位)环绕,但由于字距调整,我无法预测字符串将占用多少行,因此无法预测矩形应该有多高。我想使用等宽字体,以便可以预测程序中的高度,但字体保持不变。如果我使用“FreeMono 32”而不是“FreeMono”,它会相应地更改大小,但会忽略字体名称。正如在 LibreOffice Writer 中检查的那样,我确实可以使用 FreeMono 字体。
我试过的代码:
(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")))))