(我不得不更改这个问题的标题,对不起早期的观众。)
我一直都知道我存在严重的范围问题,但到目前为止,代码还“足够好”。我的代码对我来说运行良好,因为我使用的字体有足够的字形来覆盖示例中显示的表格中的键和值。当我开始使用 FontAwesome 时,我不得不面对我的恐惧。
提取目标字体的信息,但排版信息本身
\normalfont
列出字形槽号,
\normalfont
同时说明目标字体中的每个字形
例子
键/值都应该在 中\normalfont
,而值本身应该来自目标字体:
Font Name: <value from target font>
Type of font: <value from target font>
Number of glyphs: <value from target font>
Number of features: <value from target font>
First character: <value from target font>
Last character: <value from target font>
1. <glyph in target font>
2. <glyph in target font>
3. <glyph in target font>
代码
\documentclass{article}
\usepackage{fontspec}% typeset with xelatex
\usepackage{tikz}
\usepackage{xstring}
\usepackage{multicol}
\defaultfontfeatures{Extension=.otf}% Add .otf to \newfontfamily\FA{FontAwesome} fontawesome packagusepackage{fontawesome} % adds defs for easy access to characters
\usepackage{fontawesome} % Add defs for easy access to characters
\begingroup\lccode`\|=`\\
\lowercase{\endgroup\def\removebs#1{\if#1|\else#1\fi}}
\newcommand{\macroname}[1]{\expandafter\removebs\string#1}
\newcommand{\fonttable}[1]{%
\section{Font: \macroname{#1}}
\fontinfo{#1}
#1
\pgfmathtruncatemacro\maxstep{\the\XeTeXcountglyphs\font-1}
\typeout{XeTeXcountglyphs maxstep is \maxstep} % Prints maxstep to log
\begin{multicols}{6}
\foreach \charstep in {1,...,\maxstep}{%
\makebox[3em][l]{\tiny\charstep}%
\bgroup\fontsize{12}{13}\selectfont\textcolor{red}{\XeTeXglyph\charstep}\egroup
\endgraf
}%
\end{multicols}
}%
\newcommand{\fontinfo}[1]{%
\fbox{
\begin{minipage}{\textwidth}
Font: #1\fontname\font \\
Type of font: \getfonttype\\
Number of glyphs: \the\numexpr\XeTeXcountglyphs\font-1\relax\\
Number of features: \the\XeTeXcountfeatures\font\\
First character: \char\XeTeXfirstfontchar\font{} corresponding to unicode base-10 character \the\XeTeXfirstfontchar\font \\
Last character: \char\XeTeXlastfontchar\font{} correponding to unicode base-10 character \the\XeTeXlastfontchar\font \\
\end{minipage}}
}%
\newcommand{\getfonttype}{%
\IfEq{\the\XeTeXfonttype\font}{0}{%
\hologo{TeX} font (a legacy TFM-based font)
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{1}{%
AAT font
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{2}{%
OpenType
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{3}{%
Graphite
}%
{}%
}%
\begin{document}
\fonttable{\normalfont}
\fonttable{\FA}
\end{document}
输出强调范围问题
答案1
您必须仅在需要的地方限制字体选择。
\documentclass{article}
\usepackage{fontspec}% typeset with xelatex
\usepackage{tikz}
\usepackage{xstring}
\usepackage{multicol}
\defaultfontfeatures{Extension=.otf}
\usepackage{fontawesome}
\begingroup\lccode`\|=`\\
\lowercase{\endgroup\def\removebs#1{\if#1|\else#1\fi}}
\newcommand{\macroname}[1]{\expandafter\removebs\string#1}
\newcommand{\fonttable}[1]{%
\section{Font: \macroname{#1}}
\fontinfo{#1}
\begin{multicols}{6}
#1%
\pgfmathtruncatemacro\maxstep{\the\XeTeXcountglyphs\font-1}
\typeout{XeTeXcountglyphs maxstep is \maxstep} % Prints maxstep to log
\foreach \charstep in {1,...,\maxstep}{%
\makebox[20pt][l]{\normalfont\tiny\charstep}%
\textcolor{red}{\XeTeXglyph\charstep}
\endgraf
}
\end{multicols}
}
\newcommand{\fontinfo}[1]{%
\fbox{%
\begingroup#1\edef\x{\endgroup\def\noexpand\fontinfofont{\the\font}}\x
\begin{minipage}{\textwidth}
Font: \fontname\fontinfofont \\
Type of font: \getfonttype\\
Number of glyphs: \the\numexpr\XeTeXcountglyphs\fontinfofont-1\relax\\
Number of features: \the\XeTeXcountfeatures\fontinfofont\\
First character: {\fontinfofont\char\XeTeXfirstfontchar\font}
corresponding to unicode base-10 character
\the\XeTeXfirstfontchar\fontinfofont \\
Last character: {\fontinfofont\char\XeTeXlastfontchar\font}
correponding to unicode base-10 character
\the\XeTeXlastfontchar\fontinfofont \\
\end{minipage}%
}
}
\newcommand{\getfonttype}{%
\IfEq{\the\XeTeXfonttype\font}{0}{%
\hologo{TeX} font (a legacy TFM-based font)
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{1}{%
AAT font
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{2}{%
OpenType
}%
{}%
\IfEq{\the\XeTeXfonttype\font}{3}{%
Graphite
}%
{}%
}
\begin{document}
\fonttable{\normalfont}
\fonttable{\FA}
\end{document}
做什么\begingroup#1\edef\x{\endgroup\def\noexpand\fontinfofont{\the\font}}\x
?
我们打开一个组,在其中执行字体选择;因此在组中将\font
引用要测试的字体,并将\the\font
扩展到选择它的控制序列。我们需要扩展\the\font
,\edef
工具也是如此;\x
临时控制序列定义为扩展到
\endgroup\def\fontinfofont{<the needed control sequence>}
因此执行它将关闭该组并撤消字体选择(并删除定义\x
);但是<the needed control sequence>
在执行时已经在定义的替换文本中了。