1 # paperdoorknob: Print glowfic
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
7 from typing
import Any
, Iterable
9 from args
import spec_from_commandline_args
10 from glowfic
import makeChunk
, renderChunk
, Thread
14 def ilen(it
: Iterable
[Any
]) -> int:
15 return sum(1 for _
in it
)
18 def process(spec
: Spec
) -> None:
19 spec
.texout
.write(br
'''\documentclass{article}
22 \usepackage{longtable}
25 \usepackage{wrapstuff}
27 if spec
.geometry
is not None:
28 spec
.texout
.write(br
'\usepackage[' +
29 spec
.geometry
.encode('UTF-8') +
31 spec
.texout
.write(br
'''\begin{document}
32 \newcommand{\href}[2]{#2\footnote{\detokenize{#1}}}
33 \def\glowiconsize{%fmm}
34 \newcommand{\glowicon}[1]{\includegraphics[
35 width=\glowiconsize,height=\glowiconsize,keepaspectratio
37 \newcommand{\ifnotempty}[2]{\expandafter\ifx\expandafter\relax
38 \detokenize{#1}\relax\else #2\fi}
40 ''' % (spec
.icon_size
, spec
.layout
))
42 spec
.log('Counting chunks...\r')
43 num_chunks
= ilen(thread
.chunkDOMs())
44 title
= thread
.title() or "chunk"
45 for i
, r
in enumerate(thread
.chunkDOMs()):
46 percent
= 100.0 * i
/ num_chunks
47 spec
.log(f
'Processing {title} {i} of {num_chunks} ({percent:.1f}%)\r')
49 chunk
= makeChunk(r
, spec
.images
)
50 spec
.texout
.write(spec
.texfilter(renderChunk(spec
.texifier
, chunk
)))
52 spec
.texout
.write(b
'\\end{document}\n')
56 with spec_from_commandline_args() as spec
:
60 if __name__
== '__main__':