dram.me

Squeak V5.3中文支持

之前在Squeak中文支持中有讨论Squeak对于中文的支持,现在针对V5.3做一定更新完善。

代码补丁

为更好支持中文,需要对系统中的一些问题予以修正,以下补丁主要修正编码、字体支持相关问题。

File List支持UTF-8文件显示

调整File List工具对.cs文件和.st文件的编码处理。

FileList compile: (
	(FileList sourceCodeAt: #defaultEncoderFor:)
		copyReplaceAll: 'MacRomanTextConverter' with: 'UTF8TextConverter'
) classified: 'private'.

File In支持UTF-8文件导入

在File In导入文件时,直接依UTF-8编码处理。

MultiByteFileStream removeSelector: #fileIn.

FileStream class compile: '
fileIn: fullName
	^ (MultiByteFileStream readOnlyFileNamed: fullName) converter: UTF8TextConverter new; fileIn
' classified: '*System-Files'.

完善TTF字体导入

在TTF文件cmap解析中,与idDelta相关的计算需要依65536取模,详见这里的说明。

TTFontReader compile: (
	(TTFontReader sourceCodeAt: #decodeCmapFmtTable:)
 		copyReplaceAll: 'cmap at: i + 1 put: code' with: 'cmap at: i + 1  put: code \\ 65536'
) classified: 'private'.

字体设置

Squeak支持TTF和TTC字体导入,可供选择的中文字体有UMing / UKai文泉驿思源黑体第三方TTF版本)、思源等宽等,另外未来荧黑后续推出TTF版本后,也可以使用。

这里以文泉驿微米黑以及IBM Plex(当前不支持中文)为例,说明字体导入的方式(样式采用Trim (dark))。

文泉驿微米黑

(TTCFontDescription addFromTTFile:  'wqy-microhei.ttc') do: [:each | TTCFont newTextStyleFromTT: each].

(UserInterfaceTheme named: 'Trim (dark)')
	set: #standardButtonFont to: (TTCFont family: 'WenQuanYiMicroHei' size: 15);
	set: #standardCodeFont to: (TTCFont family: 'WenQuanYiMicroHeiMono' size: 15);
	set: #standardListFont to: (TTCFont family: 'WenQuanYiMicroHei' size: 15);
	set: #standardMenuFont to: (TTCFont family: 'WenQuanYiMicroHei' size: 15);
	set: #standardSystemFont to: (TTCFont family: 'WenQuanYiMicroHei' size: 15);
	set: #windowTitleFont to: (TTCFont family: 'WenQuanYiMicroHei' size: 15);
apply.

IBM Plex

(TTCFont newTextStyleFromTTFile: 'IBMPlexMono-Medium.ttf') addNewFontSize: 16.
(TTCFont newTextStyleFromTTFile: 'IBMPlexSans-Medium.ttf') addNewFontSize: 16.
(TTCFont newTextStyleFromTTFile: 'IBMPlexSans-Text.ttf') addNewFontSize: 16.

(UserInterfaceTheme named: 'Trim (dark)')
	set: #standardButtonFont to: (TTCFont family: 'IBMPlexSansText' size: 16);
	set: #standardCodeFont to: (TTCFont family: 'IBMPlexMonoMedium' size: 16);
	set: #standardListFont to: (TTCFont family: 'IBMPlexSansText' size: 16);
	set: #standardMenuFont to: (TTCFont family: 'IBMPlexSansText' size: 16);
	set: #standardSystemFont to: (TTCFont family: 'IBMPlexSansText' size: 16);
	set: #windowTitleFont to: (TTCFont family: 'IBMPlexSansMedium' size: 16);
apply.

其他

这里是一份完整的Squeak初始配置示例代码。