[texhax] visualize font expansion
Arno Trautmann
Arno.Trautmann at gmx.de
Wed Jun 22 12:07:23 CEST 2011
Paul Isambert wrote:
>
>
> Le 22/06/2011 10:21, Arno Trautmann a écrit :
>> Paul Isambert wrote:
>>> function (head)
>>> local f = font.getfont(font.current()).characters
>>> for l in node.traverse_id(0, head) do
>>> local g = l.head
>>> while not(g.id == 37) do
>>> g = g.next
>>> end
>>> texio.write_nl("Expansion: " .. g.width / f[g.char].width)
>>> end
>>> return head
>>> end
>> I did:
>>
>> for line in node.traverse_id(HLIST,head) do
>> g = line.head
>> while not(g.next == nil) do
>> g = g.next
>> if g.id == 37 then
>> act_width = g.width
>> normal_width =
>> font.getfont(font.current()).characters[g.char].width
>> exp_factor = act_width / normal_width
>> end
>> end
>> end
>>
>> So, as far as I can see, the difference is that I load the font at each
>> comparison which seems to slow down things very much, especially for
>> some 30-line-paragraph. With your code, I don't see any speed loss, too.
>
> Oh, no, what makes your code so slow is that you inspect all glyphs in a
> line. So obviously that takes some time. And actually it takes time to
> print the values to the terminal, not to process the code; if I call
> LuaTeX with your code without the command line, then it isn't slow.
Ok …
> I suppose your inspecting every glyph is unintentional: your "while not
> (g.next == nil)" loop is true as long as your're not on the last node of
> the line. I suppose you meant to retrieve only the first glyph of a
> line, then you should have done:
>
> local g = line.head
> while not (g.id == 37) then
> g = g.next
> end
> ... then retrieve the width...
>
> Note that this code will crash in the unlikely case where there is no
> glyph in a line. I let you fix it.
Yes, that's the reason for the while not(g.next == nil) do. However,
that was sloppy and yes, it should have stopped after the first id ==
37. However, I'll skip this test, as it indeed is very unlikely.
cheers
Arno
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://tug.org/pipermail/texhax/attachments/20110622/3336064f/attachment.bin>
More information about the texhax
mailing list