1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Graphic Macros Figure Export}
15
16\unprotect
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57\newinteger\nofexportedboxes
58
59\newconditional\c_grph_exported
60
61\definesystemconstant{exported}
62
63\def\grph_exported_discard#1
64 {\ctxlua{backends.codeinjections.discardpages(\ifcase#1\else true\fi)}}
65
66\permanent\protected\def\collectexported
67 {\grph_exported_discard\plusone
68 \c_grph_exported\conditionaltrue
69 \appendtoks
70 \grph_exported_flush
71 \to \everystoptext}
72
73\aliased\let\dotagexported\relax
74
75\appendtoks
76 \enforced\let\dotagexported\grph_exported_tag
77\to \everyenableelements
78
79\permanent\protected\def\grph_exported_tag
80 {\enforced\def \figurefileoriginal{\jobname\s!exported\the\nofexportedboxes.svg}
81 \enforced\let \figurefullname \figurefileoriginal
82 \enforced\let \figurefilepage \!!plusone
83 \enforced\let \figurelabel \empty
84 \enforced\edef\figurewidth {\the\wd\b_grph_image}
85 \enforced\edef\figureheight {\the\ht\b_grph_image}
86 \enforced\edef\figuredepth {\the\dp\b_grph_image}
87 \dotagfigure}
88
89\permanent\protected\def\grph_exported_flush
90 {\page
91
92 \grph_exported_discard\zerocount
93 \dorecurse \nofexportedboxes {
94 \startTEXpage
95 \dontleavehmode\directboxfromcache\s!exported{##1}
96 \stopTEXpage}
97 \writestatus\m!system\empty
98 \writestatus\m!system{if needed run: mtxrun script epub images \jobname}
99 \writestatus\m!system\empty}
100
101\newbox\b_grph_image
102
103\permanent\protected\def\grph_start_image_tagged
104 {\begingroup
105 \global\advanceby\nofexportedboxes\plusone
106 \dostarttagged\t!image{\the\nofexportedboxes}
107 \setbox\b_grph_image\hpack\bgroup
108 \ignorepars
109 \ignorespaces}
110
111\permanent\protected\def\grph_stop_image_tagged
112 {\removeunwantedspaces
113 \egroup
114 \dotagexported
115 \dostoptagged
116 \ifconditional\c_grph_exported
117 \setbox\scratchbox\box\b_grph_image
118 \putboxincache\s!exported{\the\nofexportedboxes}\scratchbox
119 \fi
120 \box\b_grph_image
121 \endgroup}
122
123
124
125\permanent\protected\def\grph_start_image_normal
126 {\hpack\bgroup
127 \ignorepars
128 \ignorespaces}
129
130\permanent\protected\def\grph_stop_image_normal
131 {\removeunwantedspaces
132 \egroup}
133
134\enforced\let\startimage\grph_start_image_normal
135\enforced\let\stopimage \grph_stop_image_normal
136
137\appendtoks
138 \enforced\let\startimage\grph_start_image_tagged
139 \enforced\let\stopimage \grph_stop_image_tagged
140\to \everyenableelements
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164\permanent\protected\def\startMPimage#1\stopMPimage
165 {\startimage
166 \startMPcode#1\stopMPcode
167 \stopimage}
168
169\permanent\protected\lettonothing\stopMPimage
170
171
172
173\newdimension\justimageoffset
174\newdimension\justimagetopoffset
175\newdimension\justimagebottomoffset
176\newdimension\justimageleftoffset
177\newdimension\justimagerightoffset
178
179\permanent\protected\def\grph_start_image_only
180 {\begingroup
181 \setbox\b_grph_image\hpack\bgroup
182 \ignorepars
183 \ignorespaces}
184
185\permanent\protected\def\grph_stop_image_only
186 {\removeunwantedspaces
187 \egroup
188 \global\advanceby\nofexportedboxes\plusone
189 \ifzeropt{
190 \justimageoffset
191 \justimageleftoffset
192 \justimagerightoffset
193 \justimagetopoffset
194 \justimagebottomoffset
195 }
196 \setbox\scratchbox\box\b_grph_image
197 \else
198 \setbox\scratchbox\hpack\bgroup
199 \kern{\justimageoffset\justimageleftoffset}
200 \box\b_grph_image
201 \kern{\justimageoffset\justimagerightoffset}
202 \egroup
203 \ht\scratchbox{\ht\scratchbox\justimageoffset\justimagetopoffset}
204 \dp\scratchbox{\dp\scratchbox\justimageoffset\justimagebottomoffset}
205 \fi
206 \putboxincache\s!exported{\the\nofexportedboxes}\scratchbox
207 \box\b_grph_image
208 \endgroup}
209
210\permanent\protected\def\justimages
211 {\exportingtrue
212 \ctxlua{backends.codeinjections.discardpages(true)}
213 \appendtoks
214 \grph_exported_flush
215 \to \everystoptext
216 \enforced\let\startimage\grph_start_image_only
217 \enforced\let\stopimage \grph_stop_image_only}
218
219\protect \endinput
220 |