作为后续行动这些 二问题,我有兴趣尝试微调转换字符的输出,使它们看起来不会太不对齐。目前,这方面的主要用例是使用十几进制或十十二进制数字系统排版文档。虽然 Unicode 中提供了所需的字符,但几乎所有字体中都不存在这些字符,因此字符转换暂时是必要的。
我有两个目的。首先,如果字体中有正确的 Unicode 字形,我不想执行转换/替换。其次,更重要的是,如果执行了转换,我想避免转换字符时出现的尴尬字距调整。如何改进渲染?
这是 MWE。让它工作的初始代码被厚颜无耻地从 egreg 的回答中窃取而来第一个链接问题。字体并不是必需的,但它们是我在输入的文档中首选的字体,因此改善它们的外观非常重要。
\documentclass{article}
\usepackage{fontspec}
\usepackage{microtype}
% Special characters for dozenal numerals
% newunicodechar and graphicx are needed to substitute and rotate the characters
\usepackage{newunicodechar}
\usepackage{graphicx}
\newcommand{\DeclareUnicodeCharacter}[2]{%
\begingroup\lccode`|=\string"#1\relax
\lowercase{\endgroup\newunicodechar{|}}{#2}%
}
\DeclareUnicodeCharacter{218A}{\turnedtwo}
\DeclareUnicodeCharacter{218B}{\turnedthree}
\makeatletter
\DeclareRobustCommand{\turnedtwo}{\make@turned{2}}
\DeclareRobustCommand{\turnedthree}{\make@turned{3}}
\newcommand{\make@turned}[1]{%
\raisebox{\depth}{\scalebox{-1}[-1]{#1}}%
}
\makeatother
\setmainfont{Linux Libertine O}[
Ligatures=TeX,
Numbers=Uppercase,
]
\setsansfont{Fira Sans}[
Ligatures=TeX,
Numbers=Uppercase,
Scale=MatchLowercase,
BoldFont={* SemiBold},
]
\setmonofont{Fira Mono}[
Ligatures=TeX,
Scale=MatchLowercase,
]
\begin{document}
\Huge
123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\sffamily 123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\end{document}
答案1
我建议在字体倾斜时(更准确地说,当字形具有非零斜体校正时)在两侧添加一些字距调整(相互抵消)。此外,编码也可以简化。您可以尝试获得更好的定位。
\documentclass{article}
\usepackage{fontspec}
\usepackage{microtype}
% Special characters for dozenal numerals
% newunicodechar and graphicx are needed to substitute and rotate the characters
\usepackage{newunicodechar}
\usepackage{graphicx}
\newunicodechar{^^^^218a}{\turnedtwo}
\newunicodechar{^^^^218b}{\turnedthree}
\makeatletter
\newcommand{\turnedtwo}{\make@turned{2}{0.15em}}
\newcommand{\turnedthree}{\make@turned{3}{0.15em}}
\newcommand{\make@turned}[2]{%
\ifdim\fontcharic\font`#1>0pt\relax
\kern#2\relax
\fi
\raisebox{\depth}{%
\scalebox{-1}[-1]{%
#1%
}%
}%
\ifdim\fontcharic\font`#1>0pt\relax
\kern-#2\relax
\fi
}
\makeatother
\setmainfont{Linux Libertine O}[
Ligatures=TeX,
Numbers=Uppercase,
]
\setsansfont{Fira Sans}[
Ligatures=TeX,
Numbers=Uppercase,
Scale=MatchLowercase,
BoldFont={* SemiBold},
]
\setmonofont{Fira Mono}[
Ligatures=TeX,
Scale=MatchLowercase,
]
\begin{document}
\Huge
123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\sffamily 123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\end{document}
答案2
将您的论点\scalebox
从更改#1
为\itfix-\kern-.4pt#1\/\itfix+\kern.4pt}
。
\itfixcheck
之前,我已经使用和确定了字体形状和系列\famfixcheck
,然后我根据形状模式和字体系列通过宏开发了字距\itfix{}
。如果形状不是斜体,则校正为 0pt。如果形状是斜体,那么如果系列以“F”(Fira)开头,则应用 .3pt 校正,否则(Linux Libertine)2.5pt
应用校正。
\documentclass{article}
\usepackage{fontspec}
\usepackage{microtype}
% Special characters for dozenal numerals
% newunicodechar and graphicx are needed to substitute and rotate the characters
\usepackage{newunicodechar}
\usepackage{graphicx}
\newcommand{\DeclareUnicodeCharacter}[2]{%
\begingroup\lccode`|=\string"#1\relax
\lowercase{\endgroup\newunicodechar{|}}{#2}%
}
\DeclareUnicodeCharacter{218A}{\turnedtwo}
\DeclareUnicodeCharacter{218B}{\turnedthree}
\makeatletter
\DeclareRobustCommand{\turnedtwo}{\make@turned{2}}
\DeclareRobustCommand{\turnedthree}{\make@turned{3}}
\newcommand{\make@turned}[1]{%
\itfixcheck%
\famfixcheck%
\raisebox{\depth}{\scalebox{-1}[-1]{\itfix-\kern-.4pt#1\/\itfix+\kern.4pt}}%
}
\newcommand\itfixcheck{\edef\tmp{\f@shape}\expandafter\itfixaux\tmp\relax}
\def\itfixaux#1#2\relax{\ifx i#1\gdef\itfixscale{1}\else\gdef\itfixscale{0}\fi}
\newcommand\famfixcheck{\edef\tmp{\f@family}\expandafter\famfixaux\tmp\relax}
\def\famfixaux#1#2\relax{\ifx F#1\gdef\famfixdim{.3pt}\else\gdef\famfixdim{2.5pt}\fi}
\newcommand\itfix[1]{\kern#1\itfixscale\dimexpr\famfixdim\relax}
\makeatother
\setmainfont{Linux Libertine O}[
Ligatures=TeX,
Numbers=Uppercase,
]
\setsansfont{Fira Sans}[
Ligatures=TeX,
Numbers=Uppercase,
Scale=MatchLowercase,
BoldFont={* SemiBold},
]
\setmonofont{Fira Mono}[
Ligatures=TeX,
Scale=MatchLowercase,
]
\begin{document}
\Huge
123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\sffamily 123456789↊↋0
\textit{123456789↊↋0}
\textbf{123456789↊↋0}
\textbf{\itshape 123456789↊↋0}
\end{document}