测量角色的真实身高

测量角色的真实身高

假设你有一个位于参考点上方的字符。当你测量它的高度时,参考点上方的空白区域也会包含在其高度测量中,但这不是字符本身的真实高度。因此,如何测量字符的正确高度。

为了更好地了解这一点,请参阅以下文档的输出:

\documentclass{minimal}
\usepackage{fontspec}
\usepackage{showcharinbox}
\newfontfamily\testfont{XB Zar}
\begin{document}
\begin{center}
\ShowCharInBox{\fontsize{500}{510}\testfont \char"0640}
\end{center}
\end{document}

XB Zar 字体可以从以下位置获取这里

答案1

\XeTeXglyphbounds使用 XeTeX即可使用原语。

\documentclass{article}
\usepackage{fontspec}

\newfontface{\geeza}{Geeza Pro}

\begin{document}
\edef\gid{\the\XeTeXcharglyph`- }

Top: \the\XeTeXglyphbounds2 \gid

Bottom: \the\XeTeXglyphbounds4 \gid

-\,\vrule 
  width\dimexpr\fontcharwd\font`- -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 \gid\relax
  height \XeTeXglyphbounds2 \gid
  depth \XeTeXglyphbounds4 \gid
\,\vrule
  width \fontcharwd\font`- height \fontcharht\font`- depth \fontchardp\font`-
\ Real height \the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\relax

\edef\gid{\the\XeTeXcharglyph`; }

;\,\vrule 
  width\dimexpr\fontcharwd\font`- -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 \gid\relax
  height \XeTeXglyphbounds2 \gid
  depth \XeTeXglyphbounds4 \gid
\,\vrule
  width \fontcharwd\font`; height \fontcharht\font`; depth \fontchardp\font`;
\ Real height \the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\relax

{\geeza
\edef\gid{\the\XeTeXcharglyph"0640 }

\char"0640 \,\vrule 
  width\dimexpr\fontcharwd\font"0640 -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 \gid\relax
  height \XeTeXglyphbounds2 \gid
  depth \XeTeXglyphbounds4 \gid
\,\vrule
  width \fontcharwd\font"0640 height \fontcharht\font"0640 depth \fontchardp\font"0640
\xdef\therealheight{\the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\relax}%
}\ Real height \therealheight

\end{document}

在此处输入图片描述

在示例中,每个字符后面都跟有使用“真实”尺寸绘制的规则和使用边界框数据的规则。前两行显示了连字符的边界框数据如何表示。

相关内容