又可以接着做 ConTeXt MkIV 的中文标点处理了

LiYanrui posted @ Nov 24, 2009 05:54:52 AM in Dream of TeX with tags ConTeXt MkIV luatex , 4975 阅读

今天在翻看 LuaTeX 文档时,无意中看到已经看了好几遍的一句话:

Callback assignments are always global. You can use the special value nil instead of a function for clearing the callback.

这让我想起四个多月前败了一次就放弃的 ConTeXt MkIV 中文标点处理的事情。当时只是怀疑 Hans 在做字体的 Fallback 时已经利用了那个pre_linebreak_filter 回调函数,以致于只要我使用了自定义的 pre_linebreak_filter 回调函数就会把 Hans 的覆盖掉,所以导致 ConTeXt 的字体机制不正常。所以就简单地放弃了。

刚才进入 /path-to/texmf-context/tex/context/base 目录 grep 了一下,发现 Hans 的确是用了 pre_linebreak_filter:

$ grep pre_linebreak_filter *
node-ini.mkiv:%       callbacks.push('pre_linebreak_filter')
node-ini.mkiv:%       callbacks.pop('pre_linebreak_filter')
node-pro.lua:function nodes.processors.pre_linebreak_filter(head,groupcode)
node-pro.lua:callback.register('pre_linebreak_filter', nodes.processors.pre_linebreak_filter)

仔细想想,其实是有办法来解决这个回调函数冲撞的问题的,只是我对动态语言太缺乏实战经验,所以一直逃避至今。

大致可以这样解决:

local old_pre_linebreak_filter = callback.find ('pre_linebreak_filter')

function new_pre_line_break (head, groupcode)
    old_pre_linebreak_filter (head, groupcode)
    
    -- 下面是我自己的代码
    ... ...
    
    return true
end

callback.register ('pre_linebreak_filter', new_pre_line_break)

这个问题一旦解决了,那么基于以前所做的那些有关 LuaTeX 的尝试,实现中文标点横排压缩和边界对齐只是个体力活。

Head_small
galeki 说:
2009年11月26日 01:40

今天试验了一下,尽管 luatex-0.45 对 bounding box 的计算结果要比以前粗略一些,不过用来计算标点符号左右方向间距压缩值还是比较精确的。现在,我还不知道如何在上下方向上调整标点的位置,因为左右方向上的调整可以直接用 kern 结点来做,但是 luatex 没有直接提供类似 \raise 或者 \lower 这样的结点类型,估计只能用 hlist 结点来模拟一下。


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter