[Dev-luatex] The hpack_filter callback
Jonathan.Sauer at silverstroke.com
Tue Apr 29 11:33:40 CEST 2008
> The hpack_filter is not the right callback, at least not for now.
> I could make a dedicated callback for line packaging, maybe?
> It is possible to get the "prepared paragraph" using the
> "post_linebreak_filter", but then you have a bit of work to do.
> Here is the code:
Thank you! A few questions, though:
> callback.register('post_linebreak_filter', function(head)
> % head is the alternating list of hboxes and glues etc.
> for i in node.traverse_id('hlist',head) do
> if i.next == nil then % last line has no next
> v = node.hpack(i.list,'natural')
"v" should be local, of course. The two-parameter form of node.hpack
is a bit strange (since not explained in the manual). Is above line
different from "v = node.hpack(i.list)"?
(Incidentally, the manual also does not note that node.traverse_id
can take a string as its first parameter.)
> print (v.width / 65535)
> % next two lines prevent memory leaks
> v.list = nil
I don't quite understand why this is necessary. Since node.hpack
creates a new node list, why should this list not be freed by
> return true
> If you want to be 'perfect', you should copy i.list to and remove
> the last glue(s) from the copy before hpacking() it: the final
> glue(s) may have a non-zero natural width.
I'll call that a feature ;-)
> > Which leads me to another question: When having a \hbox node list,
> > how to I determine the horizontal (when typesetting horizontally)
> > resp. vertical (when typesetting vertically) position of a node
> > relative to the left/top edge of the \hbox? I would think that
> > after line breaking, each node should know this position, but
> > how do I access it?
> Using the function above, you can calculate the position within a
> paragraph by adding up the various widths and heights and depths.
Umm ... in the case of a glyph node, I then would access the font
using font.fonts[glyph.font] and then retrieve the character's
dimensions from the appropriate table? Since as far as I can see,
not all nodes store their dimension directly.
> Best wishes,
Thanks in advance,
More information about the dev-luatex