[texhax] visualize font expansion

Paul Isambert zappathustra at free.fr
Thu Jun 23 07:22:20 CEST 2011

Le 22/06/2011 12:07, Arno Trautmann a écrit :
> Paul Isambert wrote:
>> 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.

No, you won't skip anything, Arno!

local g = line.head
while g and not (g.id == 37) do
   g = g.next
if g then
   ... Retrieve the width...

(Note that I erroneously wrote "while not (g.id == 37) THEN" (instead of 
"DO") in the previous message.)
The while loop tests for the existence of "g" before checking its "id" 
field (so you won't have the index-a-nil-value error); it stops as soon 
as there is no more node (g == nil) or there is a glyph (g == 37). Then 
the code retrieving the width is called iff "g" exists, in which case it 
is a glyph, quite obviously.


More information about the texhax mailing list