最近我开始对德国 fraktur 字体进行一些实验,该字体包含几个上下文替换,用于控制长字符和连字符的正确设置。通常,长字符或连字符的设置有一个一般规则,例外情况则定义为反向替换列表。
下面给出了一个示例,说明如何用长字符 (calt1) 替换 s,并用 2 个特殊短语 (calt2) 替换 s(针对 lualatex)。此外,还实现了 3 个案例的 t_z 连字符的反向替换 (calt 3)(我使用 Linux Biolinum 字体进行演示,但任何其他包含长字符和 t_z 连字符的字体都可以以相同的方式工作)。这些功能以 lua 代码的形式添加,但使用 fontforge 直接在字体中实现会产生相同或类似的结果。
\documentclass[12pt]{article}
%\usepackage[english]{babel}
\usepackage{polyglossia}
\setdefaultlanguage{german}
\usepackage{fontspec}
\directlua
{
fonts.handlers.otf.addfeature {
name = "calt1",
type = "chainsubstitution",
lookups = {{
type = "single",
data = { ["s"] = { "longs" } }}},
data = { rules = {
{
after = {{"o"}},
current = {{"s"}},
lookups = { 1 },
},
{
after = {{"p"}},
current = {{"s"}},
lookups = { 1 },
},
{
after = {{"s"}},
current = {{"s"}},
lookups = { 1 },
},
{
after = {{"t"}},
current = {{"s"}},
lookups = { 1 },
}}}}
fonts.handlers.otf.addfeature {
name = "calt2",
type = "chainsubstitution",
lookups = {{
type = "single",
data = { ["longs"] = { "s" } }}},
data = { rules = {
{
before = {{"h"}, {"o"}},
after = {{"p"}, {"h"}},
current = {{"longs"}},
lookups = { 1 },
},
{
before = {{"B"}, {"u"}, {"n"}, {"d"}, {"e"}},
current = {{"longs"}},
lookups = { 1 },
}}}}
fonts.handlers.otf.addfeature {
name = "calt3",
type = "chainsubstitution",
lookups = {{
type = "multiple",
data = { ["t_z"] = { "t" , "z" } }}},
data = { rules = {
{
before = {{"Z"}, {"e"}, {"i"}},
current = {{"t_z"}},
lookups = { 1 },
},
{
after = {{"u"}, {"longs"}, {"t"}, {"a"}, {"n"}, {"d"}},
current = {{"t_z"}},
lookups = { 1 },
},
{
after = {{"u"}, {"s"}, {"t"}, {"a"}, {"n"}, {"d"}},
current = {{"t_z"}},
lookups = { 1 },
}}}}
}
\setmainfont[RawFeature={+dlig,+calt1,+calt2,+calt3}]{Linux Biolinum}
\begin{document}
\noindent
calt1: (substitution of s by longs if it is before the letters o, p, s or t)\\
calt2: (back-substitution of longs by s in the phrases 'ho\/sph' and 'Bunde\/ſ')\\
Phosphor, Phosphfi, Phosph, Phosphor \\
Phosphor Phosphor Phosphat Phosphz, Phosph, Phosphfi\\
Bundes Bundestag Bundesstaat Bundesorden Bundespolizei Bundes\\
\\
calt3: (back-substitution of the ligatur tz which was activated by +dlig to t and z in the the phrases 'Zei\/tz' and 'tz\/ustand')\\
Erhitzen, sitzen, Latzhose\\
Aggregatzustand, tzustand, Istzustand\\
Zeitzone Zeitz Zeitzone Zeitzustand\\
Zeitzung Zeitz; Zeitzung Zeitzan Zeitzling\\
\end{document}
使用 luatex 0.95 时一切正常,但使用 luatex 1.04、1.06.2 或 1.07(均在当前 TeXLive 2017 环境中测试),会出现反向替换无法按预期工作的情况。对于某些单词,反向替换根本就不会发生。根据语言设置(lualatex 的 babel/polyglossia 或上下文的 \mainlanguage),不同的单词会受到影响。正确的输出应如下所示:
在当前独立的 Context 发行版中,我只能测试 calt3 功能,它显示出与之前描述的相同的问题(TeXLive 环境中的 luatex 1.0x)。如果启用 calt1 和 calt2 功能,文档编译将失败。
有谁知道如何使上下文替换与当前的 luatex 版本兼容吗?