在复合字形中使用多种颜色

在复合字形中使用多种颜色

我尝试用不同的颜色呈现复合字形的多个部分,但生成的复合字形被错误地呈现为单独的字形,而不是一个多色的复合字形。

我可能做错了什么或者遗漏了什么?

\documentclass{report}

\usepackage{fontspec}
\setmainfont{Noto Serif Devanagari}

\usepackage{xcolor}

\newcommand{\red}[1]{\textcolor{red}{#1}}

\newcommand{\green}[1]{\textcolor{green}{#1}}

\begin{document}

श्री:
    
श्\green{र}\red{ी}ः 

\end{document}

使用“Noto Serif Devanagari”字体的输出如下所示(除颜色外,两行应该相同)

诺托衬线天城文

使用“Lohit Devanagari”字体:

洛希特梵文

字体“Vesper Libre”呈现多色复合字形,但复合字形本身不正确(第一行没有颜色,呈现错误):

自由晚祷

我在 Linux 上使用 xalatex

答案1

使用 lualatex 编译你的代码,我得到:

颜色

平均能量损失

% Compile with lualatex
\documentclass{report}

\usepackage{fontspec}
\setmainfont{Noto Serif Devanagari}[Script=Devanagari]

\usepackage{xcolor}

\newcommand{\red}[1]{\textcolor{red}{#1}}

\newcommand{\green}[1]{\textcolor{green}{#1}}

\begin{document}

श्री:
    
श्\green{र}\red{ी}ः 

\end{document}

附录

对于连字,涉及字体和字体渲染器的组合。

此外,根据代码要着色的字形可能不是在连字形成过程中替换的实际连字字形(这取决于字体设计师的意图)。

桌子

平均能量损失

% Compile with lualatex
\documentclass{report}
\usepackage{luacolor}
\usepackage{fontspec}

\newcommand\ffontaname{Noto Serif Devanagari}
\newcommand\ffontbname{Lohit Devanagari}
\newcommand\ffontcname{Akshar Unicode}
\newcommand\ffontdname{Aparajita}
\newcommand\ffontename{Baloo}
\newcommand\ffontfname{Samyak Devanagari}
\newcommand\ffontgname{Sanskrit Text}
\newcommand\ffonthname{Sumana}
\newcommand\ffontiname{Mangal}
\newcommand\ffontjname{Nakula}
\newcommand\ffontkname{Samanata}
\newcommand\ffontlname{Kalimati}
\newcommand\ffontmname{FreeSerif}
\newcommand\ffontnname{Anek Devanagari Medium}
\newcommand\ffontoname{Shobhika}


\newfontface\ffonta{\ffontaname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontb{\ffontbname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontc{\ffontcname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontd{\ffontdname}[Script=Devanagari,Renderer=Node]
\newfontface\ffonte{\ffontename}[Script=Devanagari,Renderer=Node]
\newfontface\ffontf{\ffontgname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontg{\ffontgname}[Script=Devanagari,Renderer=Node]
\newfontface\ffonth{\ffonthname}[Script=Devanagari,Renderer=Node]
\newfontface\ffonti{\ffontiname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontj{\ffontjname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontk{\ffontkname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontl{\ffontlname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontm{\ffontmname}[Script=Devanagari,Renderer=Node]
\newfontface\ffontn{\ffontnname}[Script=Devanagari,Renderer=Node]
\newfontface\ffonto{\ffontoname}[Script=Devanagari,Renderer=Node]

\newfontface\ffontah{\ffontaname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontbh{\ffontbname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontch{\ffontcname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontdh{\ffontdname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffonteh{\ffontename}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontfh{\ffontfname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontgh{\ffontgname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffonthh{\ffonthname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontih{\ffontiname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontjh{\ffontjname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontkh{\ffontkname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontlh{\ffontlname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontmh{\ffontmname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontnh{\ffontnname}[Script=Devanagari,Renderer=HarfBuzz]
\newfontface\ffontoh{\ffontoname}[Script=Devanagari,Renderer=HarfBuzz]

\newcommand\testtext{श्री \color{blue}श्\color{green}र\color{red}^^^^0940\color{black}}
\newcommand\dotest[1]{%
\csname ffont#1name\endcsname &%
\csname ffont#1\endcsname\testtext &%
\csname ffont#1h\endcsname\testtext \\}

\begin{document}

\begin{tabular}{lll}
Font & Renderer=Node & Renderer=HarfBuzz \\ \hline
\dotest{a}
\dotest{b}
\dotest{c}
\dotest{d}
\dotest{e}
\dotest{f}
\dotest{g}
\dotest{h}
\dotest{i}
\dotest{j}
\dotest{k}
\dotest{l}
\dotest{m}
\dotest{n}
\dotest{o}
\end{tabular}



\end{document}

相关内容