Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xeCJK: 将汉字放进盒子里面 #347

Open
qinglee opened this issue Mar 24, 2018 · 1 comment
Open

xeCJK: 将汉字放进盒子里面 #347

qinglee opened this issue Mar 24, 2018 · 1 comment

Comments

@qinglee
Copy link
Member

qinglee commented Mar 24, 2018

目前对汉字的特殊处理可以通过重新定义 \CJKsymbol 来实现,但是这种方法有很大的局限性,很容易与 XeTeX 的字符类机制冲突。

事实上,我们可以在 \XeTeXinterchartoks 中把汉字放进一个盒子变量里,然后通过自定义函数来操作这个盒子变量实现特殊效果。这种方法应该更为安全和灵活。

下面是一个简单的汉字旋转和基线调整的例子。

% !TeX program  = XeTeX
% !TeX encoding = UTF-8

\input expl3-generic %

\ExplSyntaxOn
\char_set_catcode_letter:N \@

\newXeTeXintercharclass \l_@@_rotate_class
\newXeTeXintercharclass \l_@@_raise_class

\xetex_interchartoks:D \c_one \l_@@_rotate_class
  { \@@_box_begin:w }
\xetex_interchartoks:D \l_@@_rotate_class \c_one
  { \@@_box_end:N \@@_rotate_char: }
\xetex_interchartoks:D \l_@@_rotate_class \xe@charclass@boundary
  { \@@_box_end:N \@@_rotate_char: }

\xetex_interchartoks:D \c_one \l_@@_raise_class
  { \@@_box_begin:w }
\xetex_interchartoks:D \l_@@_raise_class \c_one
  { \@@_box_end:N \@@_raise_char: }
\xetex_interchartoks:D \l_@@_raise_class \xe@charclass@boundary
  { \@@_box_end:N \@@_raise_char: }

\cs_new_protected_nopar:Npn \@@_box_begin:w
  { \hbox_set:Nw \l_@@_char_box }
\cs_new_protected_nopar:Npn \@@_box_end:N #1
  { \hbox_set_end: #1 }
\box_new:N \l_@@_char_box
\cs_new_protected_nopar:Npn \@@_rotate_char:
  {
    \box_rotate:Nn \l_@@_char_box { \l_@@_char_rotate_fp }
    \box_use:N \l_@@_char_box
  }
\cs_new_protected_nopar:Npn \@@_raise_char:
  {
    \box_move_up:nn { \l_@@_char_raise_tl }
      { \box_use:N \l_@@_char_box }
  }

\keys_define:nn { @@ }
  {
    rotate .fp_set:N  = \l_@@_char_rotate_fp ,
    raise  .tl_set:N  = \l_@@_char_raise_tl ,
    raise  .initial:n = \c_zero_dim
  }
\cs_new_protected_nopar:Npn \set
  { \keys_set:nn { @@ } }

\xetex_charclass:D `地 = \l_@@_rotate_class
\xetex_charclass:D `黄 = \l_@@_raise_class
\int_set_eq:NN \xetex_interchartokenstate:D \c_one

\tex_font:D \l_@@_main_font = "[FandolSong-Regular.otf]" \scan_stop:

\l_@@_main_font

\ExplSyntaxOff

天地玄黄

\set{rotate=45, raise=1ex}
天地玄黄

\set{rotate=-45, raise=-1ex}
天地玄黄

\bye

default

@qinglee qinglee self-assigned this Mar 24, 2018
@leo-liu
Copy link
Member

leo-liu commented Mar 25, 2018

看起来不错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants