Nic*_*tti 4 size fonts text smalltalk squeak
我可以通过多种方式修改Squeak中Text的外观,但仍然找不到简单的方法来显式更改字体大小(以数字表示)。你知道怎么做吗?
这是我的片段:
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 .
Run Code Online (Sandbox Code Playgroud)
看起来大小是字体对象的一部分。这使得我想出的代码片段也不是那么简单:
"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.
Run Code Online (Sandbox Code Playgroud)
在第一种情况下,我包含了ifNil:块,因为如果在Text中的某个位置安装了nil字体,则TextMorph会退出并停止绘制。如果Squeak图像中存在字体系列和大小的组合,则TTCFront仅返回字体。
另请注意,并非所有尺寸都可用。fontOfPointSize:将查找最接近的可用大小,并且小于或等于请求的大小。探索以下内容:
TTCFont registry
TextStyle knownTextStyles
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40 次 |
| 最近记录: |