texjporg / ptex-manual

Japanese pTeX Manual
BSD 3-Clause "New" or "Revised" License
23 stars 1 forks source link

[e-(u)pTeX] \iffontchar, \fontcharwd など #3

Closed aminophen closed 4 years ago

aminophen commented 5 years ago

これまた実用上あまり重要ではない話ですが…。

「e-TeX と e-pTeX を比較してドキュメント化しよう」と思ったのですが,フォント関連のプリミティブ(etex_man.pdf に挙がっている 5 つ)について確認させてください。

\iffontchar ⟨font⟩ ⟨8-bit number⟩ \fontcharht ⟨font⟩ ⟨8-bit number⟩ \fontcharwd ⟨font⟩ ⟨8-bit number⟩ \fontchardp ⟨font⟩ ⟨8-bit number⟩ \fontcharic ⟨font⟩ ⟨8-bit number⟩

2011 年のマクロツイーター

には「\jfont、\tfont に対してこれらの命令を用いた場合は \iffontchar と同様にデタラメな結果を返す」との記載がありますが,forum:1452 の時に修正が入っていま🍣,今簡単に試した範囲では以下のようです。

調査結果

\iffontchar の(★1)の挙動は,「数値としては ⟨character code⟩ を受け入れるが,実際は文字タイプとして扱われる」という点にさえ留意すれば,何かに役立つかも?と思います。(強いて言うなら,数値のチェック時に 0--255 しか受け付けないようにすると良いかも,くらい。)

# そもそも pTeX 系列では「和文フォントについては、その有効な符号空間の全部の文字が、あたかも常に存在するかのように動作」しますから,真面目に ⟨character code⟩ とみなす実装だと「常に真」で,役に立たないはずです。それなら,現状の文字タイプ扱いでもいいじゃないか,という気持ちです。

\fontchar{ht,wd,dp,ic} の(★2)は少々気になります。e-pTeX では問題ないはずですが,e-upTeX だと ⟨°⟩ (U+00B0) や ⟨·⟩ (U+00B7) などの width が 0pt になってしまいます。

%#!euptex
% 現在の和文横組フォントを upjisr-h に
\jfont\x=upjisr-h\x

% 現在の和文フォントに符合位置があるか?
\message{\fontname\x}
\newcount\CNT
\loop\ifnum\CNT<65536\relax
\iffontchar\x\CNT\relax
 \message{\the\CNT}
\fi
\advance\CNT1\relax
\repeat

% 現在の和文横組フォントの寸法
\showthe\fontcharwd\jfont`°\relax % => 0.0pt
\showthe\fontcharwd\jfont"B7\relax % => 0.0pt
\showthe\fontcharwd\jfont`ー\relax % => 10.0pt
\showthe\fontcharwd\jfont`、\relax % => 5.0pt
\showthe\fontcharwd\jfont`(\relax % => 5.0pt
\showthe\fontcharwd\tfont`漢\relax % => 10.0pt

\bye
aminophen commented 5 years ago

与えられた ⟨character code⟩ が 256 以上であれば

eptex.ech#L531

    begin if cur_val>=256 then {Japanese Character}

    else cur_val:=0;
    end

を,e-upTeX では取っ払うようにすると良い…?

aminophen commented 5 years ago

おっと,cur_val>=256is_char_kanji(cur_val) に変えるのが綺麗ですね。

つまり eptex.ech#L531

    begin if cur_val>=256 then {Japanese Character}

    begin if is_char_kanji(cur_val) then {Japanese Character}

に変える。

aminophen commented 5 years ago

texjporg/tex-jp-build#77 に出しました。

aminophen commented 5 years ago

結局,r51624 で

\iffontchar: 引数が非負のときは is_char_kanji,負数 c のときは文字タイプ -(c + 1) の存在判定 \fontchar??: 引数が負数 c のときは文字タイプ -(c + 1) の存在判定

をコミットしたので,これをドキュメント化しましょう。

aminophen commented 4 years ago

eptex-190709 ブランチ (9eb8cd2) で r51694 ベースで書いてみました。