40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
485
486
487
488
489
490
491
492
493
494
495
496
497
498
...
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
if me.linbuf == nil then
me.linbuf = ss.strac()
end
me.linbuf(text)
end;
txt = function(me, str, ...)
if str == nil then return end
me:raw(gsan(str))
-- WARN this will cause problems if str is ever allowed to
-- include a line break. we can sanitize by converting
-- every line break into a new entry in the table, but i
-- don't think it should be possible for a \n to reach us
-- at this point, so i'm omitting the safety check as it
-- would involve an excessive hit to performance
................................................................................
me:flush()
me:txt(...)
end;
req = function(me, r)
me:flush()
table.insert(me.lines, '.'..r)
end;
esc = function(me, e)
me:raw('\\' .. e)
end;
flush = function(me)
if me.linbuf ~= nil then
local line = me.linbuf:compile()
local first = line:sub(1,1)
-- make sure our lines aren't accidentally interpreted
-- as groff requests. groff is kinda hostile to script
-- generation, huh?
................................................................................
};
color = {'.color'};
insert = {};
footnote = {
'.de footnote-blank';
'. sp 0.25m';
'..';
'.ev footnote-env';
'. ps 8p';
'. in 0.5c';
'. blm footnote-blank';
'.ev';
'.de footnote-print';
-- '. sp |\\\\n[.p]u-\\\\n[footnote-pos]u';
'. sp 0.5c';
'. ev footnote-env';
'. fn';
'. ev';
'. rm fn';
'. nr footnote-pos 0';
-- move the trap past the bottom of the page so it's not
-- invoked again until more footnotes have been assembled
'. ch footnote-print |\\\\n[.p]u+10';
'. bp';
'..';
'.wh |\\n[.p]u footnote-print';
};
root = {
-- these are macros included in all documents
-- page offset is hideously broken and unusable; we
-- zero it out so we can use .in to control indents
-- instead. note that the upshot of this is we need
-- to manually specify the indent in every other
-- environment from now on, .evc doesn't seem to cut it
-- set up the page title environment & trap
"'in 2c";
"'ll 18c";
"'po 0";
"'ps 13p";
"'vs 15p";
".ev pgti";
". evc 0";
". fam H";
". ps 10pt";
................................................................................
'. lt 19c';
". tl '\\\\*[doctitle]'\\fB\\\\*[title]\\f[]'%'";
'. po 0';
". br";
'. ev';
'. sp 1.2c';
'..';
'.wh 0 ph';
'.de np';
'. sp 0.2c';
'..';
'.blm np'
};
}
rs.macsNeeded = {
order = {};
map = {};
count = 0;
................................................................................
elseif spanRenderers[v.kind] then
spanRenderers[v.kind](rc, v, b, sec)
end
end
end
local blockRenderers = {}
function blockRenderers.label(rc, b, sec)
if ct.sec.is(b.captions) then
local sizes = {36,24,12,8,4,2}
local margins = {0,5,2,1,0.5}
local dedents = {2.5,1.3,0.8,0.4}
rc.prop.dsz = sizes[b.captions.depth] or 10
rc.prop.underline = b.captions.depth < 4
rc.prop.bold = b.captions.depth > 3
rc.prop.margin = {
top = margins[b.captions.depth] or 0;
bottom = 0.1;
}
rc.prop.indent = -(dedents[b.captions.depth] or 0)
rc.prop.underline = true
rc.prop.chtitle = collectText(rc, b.spans, b.spec):compile()
if b.captions.depth == 1 then
rc.prop.breakBefore = true
end
rs.renderSpans(rc, b.spans, b, sec)
else
ss.bug 'tried to render label for an unknown object type':throw()
................................................................................
local skippedFirstPagebreak = doc.secorder[1]:visible()
local deferrer = ss.declare {
ident = 'groff-deferrer';
mk = function(buf) return {ops={}, tgt=buf} end;
fns = {
esc = function(me, str) table.insert(me.ops, {0, str}) end;
req = function(me, str) table.insert(me.ops, {1, str}) end;
flush = function(me)
for i=#me.ops,1,-1 do
local d = me.ops[i]
if d[1] == 0 then
me.tgt:esc(d[2])
elseif d[1] == 1 then
me.tgt:req(d[2])
end
end
me.ops = {}
end;
};
}
function rs.emitSpan(gtxt, s)
................................................................................
else
gtxt:txt(s.txt)
end
defer:flush()
if s.div then
for div, body in pairs(s.div) do
if div == 'fn' then
gtxt:req 'ev footnote-env'
end
gtxt:req('boxa '..div)
gtxt:txt(body)
gtxt:raw '\n'
gtxt:req 'boxa'
if div == 'fn' then
gtxt:req 'ev'
gtxt:req 'nr footnote-pos (\\n[footnote-pos]u+\\n[dn]u)'
gtxt:req 'ch footnote-print -(\\n[footnote-pos]u+1c)'
end
end
end
end
function rs.emitBlock(gtxt, b)
local didfinalbreak = false
local defer = deferrer(gtxt)
................................................................................
end
if ln.breakBefore then
if skippedFirstPagebreak then
gtxt:req 'bp'
else
skippedFirstPagebreak = true
end
end
if ln.indent then
if ln.indent < 0 then
gtxt:req('in '..tostring(ln.indent)..'m')
defer:req 'in'
gtxt:req('ll +'..tostring(-ln.indent)..'m')
defer:req 'll'
................................................................................
if ln.margin then
if ln.margin.top then
gtxt:req(string.format('sp %sm', ln.margin.top))
end
end
if ln.underline then
defer:esc("D'l \\n[.ll]u-\\n[.in]u 0'")
defer:esc"v'-0.5'"
defer:req'br'
end
if ln.dsz and ln.dsz > 0 then
gtxt:req('ps +' .. tostring(ln.dsz) .. 'p')
defer:req('ps -' .. tostring(ln.dsz) .. 'p')
elseif ln.sz or ln.dsz then
if ln.sz and ln.sz <= 0 then
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
>
>
>
|
|
>
|
<
|
|
>
>
>
>
>
|
>
|
|
>
<
>
>
>
|
|
|
|
|
|
>
>
>
>
>
|
>
>
<
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
if me.linbuf == nil then
me.linbuf = ss.strac()
end
me.linbuf(text)
end;
txt = function(me, str, ...)
if str == nil then return end
if me.linbuf == nil then
-- prevent unwanted linebreaks
str = str:gsub('^%s+','')
end
me:raw(gsan(str))
-- WARN this will cause problems if str is ever allowed to
-- include a line break. we can sanitize by converting
-- every line break into a new entry in the table, but i
-- don't think it should be possible for a \n to reach us
-- at this point, so i'm omitting the safety check as it
-- would involve an excessive hit to performance
................................................................................
me:flush()
me:txt(...)
end;
req = function(me, r)
me:flush()
table.insert(me.lines, '.'..r)
end;
sreq = function(me, r)
me:flush()
table.insert(me.lines, "'"..r)
end;
esc = function(me, e)
me:raw('\\' .. e)
end;
draw = function(me, args)
for _,v in ipairs(args) do
me:esc("D'" .. v .. "'")
end
end;
flush = function(me)
if me.linbuf ~= nil then
local line = me.linbuf:compile()
local first = line:sub(1,1)
-- make sure our lines aren't accidentally interpreted
-- as groff requests. groff is kinda hostile to script
-- generation, huh?
................................................................................
};
color = {'.color'};
insert = {};
footnote = {
'.de footnote-blank';
'. sp 0.25m';
'..';
'.ev footnote-env';
'. ps 8p';
'. in 0.5c';
'.ev';
'.de footnote-print';
-- '. sp |\\\\n[.p]u-\\\\n[footnote-pos]u';
'. sp 0.5c';
'. ev footnote-env';
'. blm footnote-blank';
'. fn';
'. blm np';
'. ev';
'. rm fn';
'. nr footnote-pos 0';
-- move the trap past the top of the page so it's not
-- invoked again until more footnotes have been assembled
'. ch footnote-print |-1000';
'. bp';
'..';
'.wh |\\n[.p]u footnote-print';
};
root = {
-- these are macros included in all documents
-- page offset is hideously broken and unusable; we
-- zero it out so we can use .in to control indents
-- instead. note that the upshot of this is we need
-- to manually specify the indent in every other
-- environment from now on, .evc doesn't seem to cut it
-- set up the page title environment & trap
"'in 2c";
"'ll 19.5c";
"'po 0";
"'ps 13p";
"'vs 15p";
".ev pgti";
". evc 0";
". fam H";
". ps 10pt";
................................................................................
'. lt 19c';
". tl '\\\\*[doctitle]'\\fB\\\\*[title]\\f[]'%'";
'. po 0';
". br";
'. ev';
'. sp 1.2c';
'..';
'.de np';
'. sp 0.6m';
'..';
'.blm np';
'.wh 0 ph';
};
}
rs.macsNeeded = {
order = {};
map = {};
count = 0;
................................................................................
elseif spanRenderers[v.kind] then
spanRenderers[v.kind](rc, v, b, sec)
end
end
end
local blockRenderers = {}
blockRenderers['horiz-rule'] = function(rc, b, sec)
rc.prop.margin = { top = 0.3 }
rc.prop.underline = 0.1
end
function blockRenderers.label(rc, b, sec)
if ct.sec.is(b.captions) then
local sizes = {36,24,12,8,4,2}
local margins = {0,3}
local dedents = {2.5,1.3,0.8,0.4}
local uls = {3,1.5,0.5,0.25}
rc.prop.dsz = sizes[b.captions.depth] or 10
rc.prop.underline = uls[b.captions.depth]
rc.prop.bold = b.captions.depth > 3
rc.prop.margin = {
top = margins[b.captions.depth] or 1;
bottom = 0.1;
}
rc.prop.vassure = rc.prop.dsz+70;
rc.prop.indent = -(dedents[b.captions.depth] or 0)
rc.prop.chtitle = collectText(rc, b.spans, b.spec):compile()
if b.captions.depth == 1 then
rc.prop.breakBefore = true
end
rs.renderSpans(rc, b.spans, b, sec)
else
ss.bug 'tried to render label for an unknown object type':throw()
................................................................................
local skippedFirstPagebreak = doc.secorder[1]:visible()
local deferrer = ss.declare {
ident = 'groff-deferrer';
mk = function(buf) return {ops={}, tgt=buf} end;
fns = {
esc = function(me, str) table.insert(me.ops, {0, str}) end;
req = function(me, str) table.insert(me.ops, {1, str}) end;
draw = function(me, lst) table.insert(me.ops,{2, lst}) end;
flush = function(me)
for i=#me.ops,1,-1 do
local d = me.ops[i]
if d[1] == 0 then
me.tgt:esc(d[2])
elseif d[1] == 1 then
me.tgt:req(d[2])
elseif d[1] == 2 then
me.tgt:draw(d[2])
end
end
me.ops = {}
end;
};
}
function rs.emitSpan(gtxt, s)
................................................................................
else
gtxt:txt(s.txt)
end
defer:flush()
if s.div then
for div, body in pairs(s.div) do
if div == 'fn' then
gtxt:sreq 'ev footnote-env'
end
gtxt:sreq('boxa '..div)
gtxt:txt(body)
gtxt:raw '\n'
gtxt:sreq 'boxa'
if div == 'fn' then
gtxt:sreq 'ev'
gtxt:sreq 'nr footnote-pos (\\n[footnote-pos]u+\\n[dn]u)'
gtxt:sreq 'ch footnote-print -(\\n[footnote-pos]u+1.5c)'
end
end
end
end
function rs.emitBlock(gtxt, b)
local didfinalbreak = false
local defer = deferrer(gtxt)
................................................................................
end
if ln.breakBefore then
if skippedFirstPagebreak then
gtxt:req 'bp'
else
skippedFirstPagebreak = true
end
elseif ln.vassure then
gtxt:req(string.format('if (\\n[.t]u < %sp) .bp',ln.vassure))
end
if ln.indent then
if ln.indent < 0 then
gtxt:req('in '..tostring(ln.indent)..'m')
defer:req 'in'
gtxt:req('ll +'..tostring(-ln.indent)..'m')
defer:req 'll'
................................................................................
if ln.margin then
if ln.margin.top then
gtxt:req(string.format('sp %sm', ln.margin.top))
end
end
if ln.underline then
defer:req'br'
defer:draw {
"t "..tostring(ln.underline).."p";
"l \\n[.ll]u-\\n[.in]u 0";
}
defer:esc("h'-" .. tostring(ln.underline) .. "p'")
defer:esc"v'-0.5'"
end
if ln.dsz and ln.dsz > 0 then
gtxt:req('ps +' .. tostring(ln.dsz) .. 'p')
defer:req('ps -' .. tostring(ln.dsz) .. 'p')
elseif ln.sz or ln.dsz then
if ln.sz and ln.sz <= 0 then
|