Text 如何在Squeak中指定文本大小

Text 如何在Squeak中指定文本大小,text,fonts,size,smalltalk,squeak,Text,Fonts,Size,Smalltalk,Squeak,我能够以多种方式修改Squeak中文本的外观,但仍然找不到一种简单的方法来明确更改字体大小(作为数字)。你知道怎么做吗 这是我的片段: text1 := Text string: 'Hello ' attribute: (TextColor color: Color red). text2 := Text string: 'World!' attribute:TextEmphasis normal. text2 addAttribute: (TextColor color: Color mag

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

这是我的片段:

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 .

看起来大小是字体对象的一部分。这使得我提出的代码片段也不太简单:

"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:block,因为如果在文本中的某个地方安装了nil字体,TextMorph将退出并停止绘制。TTCFront仅在Squeak图像中存在字体系列和大小组合时返回字体

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

TTCFont registry

TextStyle knownTextStyles