【问题标题】:Setting font in ltk在 ltk 中设置字体
【发布时间】:2020-12-01 14:51:22
【问题描述】:

在 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"))))) 

LTK 手册:http://www.peter-herth.de/ltk/ltkdoc.pdf

【问题讨论】:

    标签: fonts common-lisp ltk


    【解决方案1】:

    我们可以使用(遗憾的是未记录的)函数font-families 打印可用字体:

    (ltk:with-ltk ()
      (print (ltk:font-families)))
    

    LTK 无法识别 FreeMono 字体。合适的等宽字体是 NotoSans。可能会通过font-createfont-configure添加新字体,但缺乏tcl/tk知识,无法确认或解释。

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2016-04-12
      • 2010-09-27
      • 2020-02-14
      • 1970-01-01
      相关资源
      最近更新 更多