什麼時候使用 \XeTeXcharglyph 而不是 \iffontchar

什麼時候使用 \XeTeXcharglyph 而不是 \iffontchar

在 XeLaTeX 中,\XeTeXcharglyph和都\iffontchar可以用來檢查字體是否包含特定的字形。在LuaLaTeX中,\iffontchar似乎是唯一的選擇。兩者的使用方式如下:

  • \ifnum\XeTeXcharglyph`#1>0\found\else\notfound\fi
  • \iffontchar\font`#1\found\else\notfound\fi

有什麼理由\XeTeXcharglyph更喜歡\iffontchar

答案1

如果你看看這兩個指令的定義xetex.web,你會發現它們幾乎是一樣的。

主要區別在於,它\iffontchar採用兩個參數(字體和字形)並且始終返回布林值,而\XeTeXcharglyph根據當前活動字體檢查字形,如果當前字體不是 AAT、OTF 或 Graphite,則可能會引發錯誤。這其實是一個強而有力的理由反對使用\XeTeXcharglyph因為它不能處理 8 位元字體。

內部都使用map_char_to_glyph.

if_in_csname_code: b:=is_in_csname;
if_font_char_code:begin scan_font_ident; n:=cur_val; scan_usv_num;
  if is_native_font(n) then
    b:=(map_char_to_glyph(n, cur_val) > 0)
  else begin
    if (font_bc[n]<=cur_val)and(font_ec[n]>=cur_val) then
      b:=char_exists(char_info(n)(qi(cur_val)))
    else b:=false;
    end;
  end;
XeTeX_map_char_to_glyph_code:
  begin
    if is_native_font(cur_font) then begin
      scan_int; n:=cur_val; cur_val:=map_char_to_glyph(cur_font, n)
    end else begin
      not_native_font_error(last_item, m, cur_font); cur_val:=0
    end
  end;

\XeTeXcharglyphMWE在 Plain TeX 中失敗:

\the\XeTeXcharglyph`a
\bye
! Cannot use \XeTeXcharglyph with cmr10; not a native platform font.
l.1 \the\XeTeXcharglyph
                       `a

相關內容