【问题标题】:How to specify Text size in Squeak如何在 Squeak 中指定文本大小
【发布时间】:2019-08-10 22:43:24
【问题描述】:

我能够以多种方式修改 Squeak 中 Text 的外观,但我仍然找不到一种简单的方法来明确更改字体大小(作为数字)。你知道怎么做吗?

这是我的sn-p:

text1 := Text string: 'Hello ' attribute: (TextColor color: Color red).

text2 := Text string: 'World!' attribute:TextEmphasis normal.
text2 addAttribute: (TextColor color: Color magenta).
text2 addAttribute:  (TextFontChange font2).
text2 addAttribute:  (TextEmphasis underlined).

text := text1, ' ', text2.

(text asMorph) openInWorld .

【问题讨论】:

    标签: text fonts size smalltalk squeak


    【解决方案1】:

    看起来大小是字体对象的一部分。这使得我想出的代码 sn-ps 也不是很简单:

    "Set a true type font of a certain size"
    text
       addAttribute:
           (TextFontReference toFont:
              ((TTCFont family: 'BitstreamVeraSerif' size: 18)
                  ifNil: [self error: 'Font not found']))
       from: 1 to: 4.
    
    "Use the font of a text style with a certain size"
    text
       addAttribute:
          (TextFontReference toFont:
             ((TextStyle named: 'Bitmap DejaVu Sans') fontOfPointSize: 22))
       from: 1 to: 4.
    
    "Use the current font with a different size"
    text
       addAttribute:
          (TextFontReference toFont:
              ((TextStyle named: (text fontAt: 1 withStyle: TextStyle default) familyName)
                 fontOfPointSize: 18))
       from: 1 to: 4.
    

    我在第一种情况下包含了 ifNil: 块,因为如果您在 Text 中的某处安装 nil 字体,TextMorph 会退出并停止绘制。如果字体系列和大小的组合出现在 Squeak 图像中,TTCFront 仅返回字体。

    另请注意,并非所有尺寸都可用。 fontOfPointSize:将寻找最接近的可用尺寸并且小于或等于请求的尺寸。探索以下内容:

    TTCFont registry
    
    TextStyle knownTextStyles
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-06
      • 2021-04-30
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多