1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Graphic Macros Transformations}
15
16\unprotect
17
18
19
20
21
22
23
24
25
26
27\registerctxluafile{grphtrf}{autosuffix}
28
29
30
31\newdimension\d_grph_rotate_x_size
32\newdimension\d_grph_rotate_y_size
33\newdimension\d_grph_rotate_x_offset
34\newdimension\d_grph_rotate_y_offset
35\newdimension\d_grph_rotate_x_position
36\newdimension\d_grph_rotate_y_position
37
38\newdimension\d_grph_rotate_new_width
39\newdimension\d_grph_rotate_new_height
40\newdimension\d_grph_rotate_new_depth
41
42
43
44\newdimension\d_grph_scale_x_size
45\newdimension\d_grph_scale_y_size
46\newdimension\d_grph_scale_x_offset
47\newdimension\d_grph_scale_y_offset
48
49\newdimension\d_grph_scale_h_size
50\newdimension\d_grph_scale_v_size
51
52\newconditional\c_grph_scale_done
53\newconditional\c_grph_scale_scaling_done
54\newconditional\c_grph_scale_limit_factors \c_grph_scale_limit_factors\conditionaltrue
55
56\newdimension\d_grph_scale_wd
57\newdimension\d_grph_scale_ht
58\newdimension\d_grph_scale_dp
59
60\newconditional\c_grph_scale_swap_factor
61
62\newdimension\d_grph_scale_used_x_size
63\newdimension\d_grph_scale_used_y_size
64
65\newinteger\c_grph_scale_used_x_scale
66\newinteger\c_grph_scale_used_y_scale
67
68\let\m_grph_scale_used_x_scale\!!plusone
69\let\m_grph_scale_used_y_scale\!!plusone
70
71\newdimension\d_grph_scale_outer_v_size
72
73
74
75\lettonothing\m_grph_scale_temp
76\lettonothing\m_grph_scale_temp_x
77\lettonothing\m_grph_scale_temp_y
78
79
80
81\mutable\let\finalscaleboxxscale \!!plusone
82\mutable\let\finalscaleboxyscale \!!plusone
83\mutable\let\finalscaleboxwidth \!!zeropoint
84\mutable\let\finalscaleboxheight \!!zeropoint
85
86
87
88\installcorenamespace{scale}
89\installcorenamespace{scalegrid}
90\installcorenamespace{scalenorm}
91\installcorenamespace{scalefact}
92
93\installcommandhandler \??scale {scale} \??scale
94
95\setupscale
96 [\c!sx=\scaleparameter\c!s,
97 \c!sy=\scaleparameter\c!s,
98 \c!s=1,
99
100
101
102
103
104
105
106
107
108
109
110
111 \c!maxwidth=\scaleparameter\c!width,
112 \c!maxheight=\scaleparameter\c!height]
113
114\newinteger\c_grph_scale_nesting
115
116\def\grph_scale_set_nesting
117 {\advanceby\c_grph_scale_nesting\plusone
118 \letcsname\??scale>\the\c_grph_scale_nesting:\s!parent\endcsname\??scale
119 \cdef\currentscale{>\the\c_grph_scale_nesting}}
120
121\permanent\tolerant\protected\def\scale[#S#1]#*[#S#2]
122 {\bgroup
123 \ifarguments
124 \grph_scale_set_nesting
125 \or
126 \ifhastok={#1}
127 \grph_scale_set_nesting
128 \setupcurrentscale[#1]
129 \else
130 \cdef\currentscale{#1}
131 \ifempty\currentscale
132 \grph_scale_set_nesting
133 \fi
134 \fi
135 \or
136 \cdef\currentscale{#1}
137 \ifempty\currentscale
138 \grph_scale_set_nesting
139 \fi
140 \setupcurrentscale[#2]
141 \fi
142
143 \dowithnextboxcs\grph_scale_finish\naturalhbox}
144
145\def\grph_scale_finish
146 {
147 \edef\p_scale {\scaleparameter\c!scale }
148 \edef\p_xscale {\scaleparameter\c!xscale }
149 \edef\p_yscale {\scaleparameter\c!yscale }
150 \edef\p_width {\scaleparameter\c!width }
151 \edef\p_height {\scaleparameter\c!height }
152
153 \edef\p_lines {\scaleparameter\c!lines }
154 \edef\p_factor {\scaleparameter\c!factor }
155 \edef\p_hfactor {\scaleparameter\c!hfactor }
156 \edef\p_wfactor {\scaleparameter\c!wfactor }
157
158 \edef\p_maxwidth {\scaleparameter\c!maxwidth }
159 \edef\p_maxheight {\scaleparameter\c!maxheight }
160 \edef\p_sx {\scaleparameter\c!sx }
161 \edef\p_sy {\scaleparameter\c!sy }
162 \edef\p_equalwidth {\scaleparameter\c!equalwidth }
163 \edef\p_equalheight{\scaleparameter\c!equalheight}
164
165 \d_grph_scale_dp\dp\nextbox
166 \ifzeropt\d_grph_scale_dp
167
168 \orelse\ifcstok{\scaleparameter\c!depth}\v!no
169 \setbox\nextbox\naturalhpack{\raise\d_grph_scale_dp\box\nextbox}
170
171 \fi
172 \d_grph_scale_wd\wd\nextbox
173 \d_grph_scale_ht\ht\nextbox
174 \d_grph_scale_dp\dp\nextbox
175
176 \glet\finalscaleboxxscale \!!plusone
177 \glet\finalscaleboxyscale \!!plusone
178 \xdef\finalscaleboxwidth {\the\d_grph_scale_wd}
179 \xdef\finalscaleboxheight{\the\d_grph_scale_ht}
180
181 \forgetall
182 \dontcomplain
183
184 \c_grph_scale_done\conditionalfalse
185 \grph_scale_calculate
186 \ifconditional\c_grph_scale_done
187 \grph_scale_apply
188 \fi
189 \grph_scale_position
190
191 \box\nextbox
192 \egroup}
193
194\def\grph_scale_apply
195 {\d_grph_scale_wd\finalscaleboxxscale\d_grph_scale_wd
196 \d_grph_scale_ht\finalscaleboxyscale\d_grph_scale_ht
197 \d_grph_scale_dp\finalscaleboxyscale\d_grph_scale_dp
198 \ifdim\d_grph_scale_wd=\wd\nextbox
199 \ifdim\d_grph_scale_ht=\ht\nextbox
200 \ifdim\d_grph_scale_dp=\dp\nextbox
201
202 \else
203 \grph_scale_apply_yes
204 \fi
205 \else
206 \grph_scale_apply_yes
207 \fi
208 \else
209 \grph_scale_apply_yes
210 \fi}
211
212\def\grph_scale_apply_yes
213 {\setbox\nextbox\hcontainer
214 {\dostartscaling \finalscaleboxxscale \finalscaleboxyscale
215 \smashedbox\nextbox
216 \dostopscaling}
217 \wd\nextbox\d_grph_scale_wd
218 \ht\nextbox\d_grph_scale_ht
219 \dp\nextbox\d_grph_scale_dp}
220
221\def\m_grph_scale_stamp_c{11}
222
223\def\grph_scale_calculate
224 {\ifdim\d_grph_scale_ht>\zeropoint \ifdim\d_grph_scale_wd>\zeropoint
225 \edef\m_grph_scale_stamp_a{\p_scale\p_xscale\p_yscale\p_factor\p_wfactor\p_hfactor\p_lines\p_width\p_height}
226 \edef\m_grph_scale_stamp_b{\p_sx\p_sy}
227 \ifempty\m_grph_scale_stamp_a
228 \ifx\m_grph_scale_stamp_b\m_grph_scale_stamp_c
229
230 \insidefloattrue
231 \grph_scale_calculations_yes
232 \else
233 \grph_scale_check_sx_sy
234 \grph_scale_calculations_nop
235 \fi
236 \else
237 \ifempty\m_grph_scale_stamp_b
238
239 \else
240 \grph_scale_check_sx_sy
241 \fi
242 \grph_scale_calculations_yes
243 \fi
244 \fi \fi}
245
246\def\grph_scale_check_sx_sy
247 {\ifdim\p_sx\onepoint=\onepoint\else\edef\p_width {\todimension{\p_sx\d_grph_scale_wd}}\fi
248 \ifdim\p_sy\onepoint=\onepoint\else\edef\p_height{\todimension{\p_sy\d_grph_scale_ht}}\fi}
249
250\def\grph_scale_rounded#1
251 {\thewithoutunit\dimexpr#1\points*10032768\scaledpoint\relax}
252
253\def\grph_scale_calculations_nop
254 {\c_grph_scale_done\conditionaltrue
255 \xdef\finalscaleboxwidth {\todimension{\p_sx\d_grph_scale_wd}}
256 \xdef\finalscaleboxheight{\todimension{\p_sy\d_grph_scale_ht}}
257 \glet\finalscaleboxxscale\p_sx
258 \glet\finalscaleboxyscale\p_sy
259 \ifempty\finalscaleboxxscale\let\finalscaleboxxscale\!!plusone\fi
260 \ifempty\finalscaleboxyscale\let\finalscaleboxyscale\!!plusone\fi}
261
262\let\grph_scale_calculations_report\relax
263
264\def\grph_scale_calculations_yes
265 {\c_grph_scale_done\conditionaltrue
266
267 \d_grph_scale_x_offset\zeropoint
268 \d_grph_scale_y_offset\zeropoint
269 \d_grph_scale_x_size \d_grph_scale_wd
270 \d_grph_scale_y_size \d_grph_scale_ht
271
272 \global\d_grph_scale_used_x_size \zeropoint
273 \global\d_grph_scale_used_y_size \zeropoint
274 \c_grph_scale_used_x_scale \plusone
275 \c_grph_scale_used_y_scale \plusone
276 \let\m_grph_scale_used_x_scale \!!plusone
277 \let\m_grph_scale_used_y_scale \!!plusone
278
279 \c_grph_scale_scaling_done\conditionalfalse
280 \grph_scale_check_parameters
281
282
283
284 \ifconditional\c_grph_scale_scaling_done\else\grph_scale_by_factor \fi
285 \ifconditional\c_grph_scale_scaling_done\else\grph_scale_by_scale \fi
286 \ifconditional\c_grph_scale_scaling_done\else\grph_scale_by_dimension\fi
287
288 \xdef\finalscaleboxwidth {\the\d_grph_scale_used_x_size}
289 \xdef\finalscaleboxheight {\the\d_grph_scale_used_y_size}
290 \glet\finalscaleboxxscale \m_grph_scale_used_x_scale
291 \glet\finalscaleboxyscale \m_grph_scale_used_y_scale
292 \grph_scale_calculations_report}
293
294\defcsname\??scalegrid\v!yes \endcsname{\getnoflines \d_grph_scale_used_y_size\edef\p_height{\tointeger{\noflines\lineheight}}}
295\defcsname\??scalegrid\v!height \endcsname{\getrawnoflines\d_grph_scale_used_y_size\edef\p_height{\todimension{\noflines\lineheight\strutdepth}}}
296\defcsname\??scalegrid\v!depth \endcsname{\getrawnoflines\d_grph_scale_used_y_size\edef\p_height{\todimension{\noflines\lineheight\strutdepth}}}
297\defcsname\??scalegrid\v!halfline\endcsname{\getrawnoflines\d_grph_scale_used_y_size\edef\p_height{\todimension{\noflines\lineheight.5\lineheight}}}
298\defcsname\??scalegrid\v!fit \endcsname{\getrawnoflines\d_grph_scale_used_y_size\edef\p_height{\tointeger{\noflines\lineheight}}}
299\letcsname\??scalegrid\empty \endcsname\donothing
300
301\def\grph_scale_check_parameters
302 {\ifempty\p_maxwidth \else \edef\p_maxwidth {\todimension{\p_maxwidth }}\fi
303 \ifempty\p_maxheight\else \edef\p_maxheight{\todimension{\p_maxheight }}\fi
304 \ifempty\p_lines \else \edef\p_height {\todimension{\p_lines\lineheight}}\fi
305 \begincsname\??scalegrid\scaleparameter\c!grid\endcsname}
306
307\def\grph_scale_by_nature
308 {\ifempty\p_width \else \global\d_grph_scale_used_x_size{\p_width }\fi
309 \ifempty\p_height\else \global\d_grph_scale_used_y_size{\p_height}\fi
310 \ifempty\p_scale \else \c_grph_scale_used_x_scale\p_scale
311 \c_grph_scale_used_y_scale\p_scale \fi
312 \ifempty\p_xscale\else \c_grph_scale_used_x_scale\p_xscale\fi
313 \ifempty\p_yscale\else \c_grph_scale_used_y_scale\p_yscale\fi}
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334\def\m_grph_scale_factor_set{\v!min,\v!max,\v!fit,\v!broad,\v!auto}
335
336\def\grph_scale_by_factor
337 {\ifinset\p_factor\m_grph_scale_factor_set
338 \grph_scale_by_factor_a
339 \orelse\ifinset\p_hfactor\m_grph_scale_factor_set
340 \grph_scale_by_factor_b
341 \orelse\ifinset\p_wfactor\m_grph_scale_factor_set
342 \grph_scale_by_factor_c
343 \else
344 \grph_scale_by_factor_d
345 \fi}
346
347\def\grph_scale_by_factor_a
348 {\grph_scale_apply_size
349 \ifdim\d_grph_scale_x_size >\d_grph_scale_y_size
350 \grph_scale_calculate_norm \d_grph_scale_used_x_size\p_factor\p_maxwidth\hsize\d_grph_scale_h_size
351 \grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
352 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size
353 \else
354 \grph_scale_calculate_norm \d_grph_scale_used_y_size\p_factor\p_maxheight\d_grph_scale_outer_v_size\d_grph_scale_v_size
355 \grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
356 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size
357 \fi
358 \grph_scale_by_factor_indeed}
359
360\def\grph_scale_by_factor_b
361 {\grph_scale_apply_size
362 \grph_scale_calculate_norm \d_grph_scale_used_y_size\p_hfactor\p_maxheight\d_grph_scale_outer_v_size\d_grph_scale_v_size
363 \grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
364 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size
365 \grph_scale_by_factor_indeed}
366
367\def\grph_scale_by_factor_c
368 {\grph_scale_apply_size
369 \grph_scale_calculate_norm \d_grph_scale_used_x_size\p_wfactor\p_maxwidth\hsize\d_grph_scale_h_size
370 \grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
371 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size
372 \grph_scale_by_factor_indeed}
373
374\def\grph_scale_by_factor_d
375 {\grph_scale_calculate_norm\d_grph_scale_used_y_size\p_factor \p_height \textheight\d_grph_scale_v_size
376 \grph_scale_calculate_norm\d_grph_scale_used_y_size\p_hfactor\p_height \textheight\d_grph_scale_v_size
377 \grph_scale_calculate_norm\d_grph_scale_used_x_size\p_wfactor\p_width \hsize \hsize}
378
379\def\grph_scale_by_factor_indeed
380 {\grph_scale_calculate_fact\p_factor
381 \c_grph_scale_scaling_done\conditionaltrue
382 \ifconditional\c_grph_scale_limit_factors
383 \ifdim\d_grph_scale_used_x_size\ifconditional\c_grph_scale_swap_factor<\else>\fi\d_grph_scale_h_size
384 \global\d_grph_scale_used_y_size\zeropoint
385 \global\d_grph_scale_used_x_size\d_grph_scale_h_size
386 \orelse\ifdim\d_grph_scale_used_y_size\ifconditional\c_grph_scale_swap_factor<\else>\fi\d_grph_scale_v_size
387 \global\d_grph_scale_used_x_size\zeropoint
388 \global\d_grph_scale_used_y_size\d_grph_scale_v_size
389 \fi
390 \fi
391 \grph_scale_by_dimension}
392
393\def\grph_scale_by_scale
394 {\edef\m_grph_scale_temp{\p_scale\p_xscale\p_yscale}
395 \ifempty\m_grph_scale_temp \else
396 \grph_scale_apply_scale\m_grph_scale_used_x_scale\p_xscale
397 \grph_scale_apply_scale\m_grph_scale_used_y_scale\p_yscale
398
399
400
401 \global\d_grph_scale_used_x_size\zeropoint
402 \global\d_grph_scale_used_y_size\zeropoint
403
404 \ifempty\p_maxwidth
405 \ifempty\p_maxheight\orelse\ifdim\d_grph_scale_y_size>\p_maxheight\relax
406 \global\d_grph_scale_used_y_size\p_maxheight
407 \fi
408 \orelse\ifdim\d_grph_scale_x_size>\p_maxwidth\relax
409 \global\d_grph_scale_used_x_size\p_maxwidth
410 \fi
411 \fi}
412
413\def\grph_scale_by_dimension
414 {\ifdim\d_grph_scale_used_x_size>\zeropoint
415 \ifdim\d_grph_scale_used_y_size>\zeropoint
416 \grph_scale_by_dimension_a
417 \else
418 \grph_scale_by_dimension_b
419 \fi
420 \else
421 \ifdim\d_grph_scale_used_y_size>\zeropoint
422 \grph_scale_by_dimension_c
423 \else
424 \grph_scale_by_dimension_d
425 \fi
426 \fi}
427
428\def\grph_scale_by_dimension_a
429 {\grph_scale_by_dimension_indeed
430 {\grph_scale_calculate_scale\m_grph_scale_used_y_scale\d_grph_scale_used_y_size\d_grph_scale_y_size
431 \grph_scale_calculate_scale\m_grph_scale_used_x_scale\d_grph_scale_used_x_size\d_grph_scale_x_size}
432 {\grph_scale_calculate_scale\m_grph_scale_used_y_scale\d_grph_scale_used_y_size\d_grph_scale_y_size
433 \grph_scale_calculate_scale\m_grph_scale_used_x_scale\d_grph_scale_used_x_size\d_grph_scale_x_size}
434 {\grph_scale_calculate_scale\m_grph_scale_used_y_scale\d_grph_scale_used_y_size\d_grph_scale_y_size
435 \grph_scale_calculate_scale\m_grph_scale_used_x_scale\d_grph_scale_used_x_size\d_grph_scale_x_size}}
436
437\def\grph_scale_by_dimension_b
438 {\grph_scale_by_dimension_indeed
439 {\grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
440 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size}
441 {\grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
442 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size}
443 {\grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
444 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size}}
445
446\def\grph_scale_by_dimension_c
447 {\grph_scale_by_dimension_indeed
448 {\grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
449 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size}
450 {\grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
451 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size}
452 {\grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
453 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size}}
454
455\def\grph_scale_by_dimension_d
456 {\grph_scale_by_dimension_indeed
457 {\grph_scale_apply_scale\m_grph_scale_used_x_scale\p_xscale
458 \grph_scale_apply_scale\m_grph_scale_used_y_scale\p_yscale
459 \global\d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size
460 \global\d_grph_scale_used_y_size\m_grph_scale_used_y_scale\d_grph_scale_y_size}
461 {\grph_scale_calculate_scales\d_grph_scale_used_x_size\d_grph_scale_x_size
462 \d_grph_scale_used_y_size\m_grph_scale_used_x_scale\d_grph_scale_y_size}
463 {\grph_scale_calculate_scales\d_grph_scale_used_y_size\d_grph_scale_y_size
464 \d_grph_scale_used_x_size\m_grph_scale_used_x_scale\d_grph_scale_x_size}}
465
466\def\grph_scale_by_dimension_indeed#1#2#3
467 {#1\relax
468 \ifempty\p_maxwidth\orelse\ifdim\d_grph_scale_used_x_size>\p_maxwidth\relax
469 \global\d_grph_scale_used_x_size\p_maxwidth
470 #2\relax
471 \fi
472 \ifempty\p_maxheight\orelse\ifdim\d_grph_scale_used_y_size>\p_maxheight\relax
473 \global\d_grph_scale_used_y_size\p_maxheight
474 #3\relax
475 \fi}
476
477
478
479\def\grph_scale_calculate_norm#1#2
480 {\csname\??scalenorm\ifcsname\??scalenorm#2\endcsname#2\else\s!unknown\fi\endcsname#1#2}
481
482\def\grph_scale_calculate_fact#1
483 {\csname\??scalefact\ifcsname\??scalefact#1\endcsname#1\else\s!unknown\fi\endcsname}
484
485\defcsname\??scalenorm\v!max \endcsname#1###2#{\global#1{#2}}
486\defcsname\??scalenorm\v!fit \endcsname#1####2{\global#1{#2}}
487\defcsname\??scalenorm\v!broad \endcsname#1####2{\global#1{#2(\externalfigureparameter\c!bodyfont\c!bodyfont)*4}}
488\defcsname\??scalenorm\s!unknown\endcsname#1#2###{\global#1{#2\dimexpr\externalfigureparameter\c!bodyfont10\relax}}
489\defcsname\??scalenorm\v!auto \endcsname#1##2##{\ifempty#2\else\global#1{#2}\fi}
490\defcsname\??scalenorm\empty \endcsname#1##2##{\ifempty#2\else\global#1{#2}\fi}
491\defcsname\??scalenorm\s!default\endcsname#1##2##{\ifempty#2\else\global#1{#2}\fi}
492
493\defcsname\??scalefact\v!min \endcsname{\global\c_grph_scale_swap_factor\conditionaltrue}
494\defcsname\??scalefact\s!unknown\endcsname{\global\c_grph_scale_swap_factor\conditionalfalse}
495
496\defcsname\??scalenorm\v!min\endcsname#####
497 {\d_grph_scale_used_x_size\hsize
498 \d_grph_scale_used_y_size\vsize}
499
500\def\grph_scale_calculate_scales#1#2
501 {\edef\m_grph_scale_used_x_scale{\luaexpr{\number#1/\number#2}}
502 \let\m_grph_scale_used_y_scale\m_grph_scale_used_x_scale}
503
504\def\grph_scale_calculate_scale#1#2#3
505 {\edef#1{\luaexpr{\number#2/\number#3}}}
506
507\def\grph_scale_apply_scale#1#2
508 {
509 \edef#1{\luaexpr
510 {\number
511 \ifempty#2
512 \ifempty\p_scale \plusthousand \else
513 \ifnum \p_scale=\zerocount \plusthousand \else
514 \p_scale \fi\fi
515 \orelse\ifnum#2=\zerocount
516 \ifempty\p_scale \plusthousand \else
517 \ifnum \p_scale=\zerocount \plusthousand \else
518 \p_scale \fi\fi
519 \else
520 #2
521 \fi
522 /1000}}}
523
524\def\grph_scale_apply_size
525 {\ifempty\p_maxheight
526 \d_grph_scale_outer_v_size\textheight
527 \ifinner
528 \d_grph_scale_outer_v_size \vsize
529 \scratchdimen\vsize
530 \orelse\ifinsidefloat
531 \d_grph_scale_outer_v_size \vsize
532 \scratchdimen\vsize
533 \orelse\ifinpagebody
534 \d_grph_scale_outer_v_size \vsize
535 \scratchdimen\vsize
536 \orelse\ifdim\pagegoal<\maxdimen
537 \ifdim\pagetotal<\pagegoal
538 \scratchdimen{\pagegoal\pagetotal}
539 \else
540 \scratchdimen\d_grph_scale_outer_v_size
541 \fi
542 \else
543 \scratchdimen\d_grph_scale_outer_v_size
544 \fi
545 \else
546 \scratchdimen\p_maxheight
547 \d_grph_scale_outer_v_size\scratchdimen
548 \fi
549 \ifempty\p_height
550 \d_grph_scale_v_size\scratchdimen
551 \else
552 \d_grph_scale_v_size{\p_height}
553 \fi
554 \ifempty\p_width
555 \d_grph_scale_h_size\hsize
556 \else
557 \d_grph_scale_h_size{\p_width}
558 \fi}
559
560
561
562
563
564
565\def\grph_scale_position
566 {\ifempty\p_equalwidth \else
567 \scratchdimen\p_equalwidth\relax
568 \ifdim\d_grph_scale_wd<\scratchdimen
569 \setbox\nextbox\naturalhpack to \scratchdimen{\hss\box\nextbox\hss}
570 \fi
571 \fi
572 \ifempty\p_equalheight \else
573 \scratchdimen\p_equalheight\relax
574 \ifdim\d_grph_scale_ht<\scratchdimen
575 \setbox\nextbox\naturalvpack to \scratchdimen{\vss\box\nextbox\vss}
576 \fi
577 \fi}
578
579\permanent\protected\def\fastscale#1
580 {\ifnum#1=1000\relax
581 \expandafter\grph_scale_fast_nop
582 \else
583 \expandafter\grph_scale_fast_yes
584 \fi{#1}}
585
586\def\grph_scale_fast_nop#1
587 {\hbox}
588
589\def\grph_scale_fast_yes#1
590 {\edef\finalscaleboxxscale{\toscaled\dimexpr#1\onepoint1000\relax}
591 \let\finalscaleboxyscale\finalscaleboxxscale
592 \dowithnextboxcs\grph_scale_fast_finish\hbox}
593
594\def\grph_scale_fast_finish
595 {\grph_scale_apply
596 \box\nextbox
597 \endgroup}
598
599\permanent\protected\def\fastsxsy#1#2
600 {\bgroup
601 \edef\p_sx{#1}
602 \edef\p_sy{#2}
603 \dowithnextboxcs\grph_scale_fast_sx_xy_finish\hbox}
604
605\def\grph_scale_fast_sx_xy_finish
606 {\grph_scale_check_sx_sy
607 \d_grph_scale_wd\wd\nextbox
608 \d_grph_scale_ht\ht\nextbox
609 \d_grph_scale_dp\dp\nextbox
610 \grph_scale_calculations_nop
611 \grph_scale_apply
612 \box\nextbox
613 \egroup}
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644\installcorenamespace{clipping}
645
646\installdirectcommandhandler \??clipping {clipping}
647
648\permanent\tolerant\protected\def\clip[#S#1]
649 {\bgroup
650 \ifparameter#1\or
651 \setupcurrentclipping[#1]
652 \fi
653 \dowithnextboxcs\grph_clip_finish\hbox}
654
655\def\grph_clip_finish
656 {\ifcstok{\clippingparameter\c!state}\v!start
657 \grph_clip_yes_finish
658 \else
659 \grph_clip_nop_finish
660 \fi}
661
662\def\grph_clip_yes_finish
663 {\scratchwidth{\clippingparameter\c!width}
664 \ifdim\scratchwidth>\zeropoint
665 \scratchxoffset{\clippingparameter\c!hoffset}
666 \else
667 \scratchwidth{\wd\nextbox(\clippingparameter\c!nx)}
668 \scratchxoffset{\scratchwidth*(\clippingparameter\c!x)\scratchwidth}
669 \scratchwidth\clippingparameter\c!sx\scratchwidth
670 \fi
671 \relax
672 \scratchheight{\clippingparameter\c!height}
673 \ifdim\scratchheight>\zeropoint
674 \scratchyoffset{\ht\nextbox(\clippingparameter\c!voffset)\scratchheight}
675 \else
676 \scratchheight{\ht\nextbox(\clippingparameter\c!ny)}
677 \scratchyoffset{\scratchheight*(\clippingparameter\c!y)\clippingparameter\c!sy\scratchheight\scratchheight}
678 \scratchheight\clippingparameter\c!sy\scratchheight
679 \advanceby\scratchyoffset\ht\nextbox
680 \fi
681 \scratchleftoffset {\clippingparameter\c!leftoffset}
682 \scratchrightoffset {\clippingparameter\c!rightoffset}
683 \scratchtopoffset {\clippingparameter\c!topoffset}
684 \scratchbottomoffset{\clippingparameter\c!bottomoffset}
685 \setbox\nextbox\naturalhpack
686 {\advanceby\scratchxoffset\scratchleftoffset
687 \advanceby\scratchyoffset\scratchbottomoffset
688 \hskip\scratchxoffset
689 \lower\scratchyoffset
690 \box\nextbox}
691 \wd\nextbox\zeropoint
692 \ht\nextbox\zeropoint
693 \dp\nextbox\zeropoint
694 \setbox\nextbox\naturalhpack
695 {\advanceby\scratchwidth {\scratchleftoffset \scratchrightoffset}
696 \advanceby\scratchheight{\scratchbottomoffset\scratchtopoffset}
697 \dostartclipping{\clippingparameter\c!mp}\scratchwidth\scratchheight
698 \box\nextbox
699 \dostopclipping}
700 \setbox\nextbox\hcontainer
701 {\hskip\scratchleftoffset
702 \lower \scratchbottomoffset
703 \box\nextbox}
704 \wd\nextbox\scratchwidth
705 \ht\nextbox\scratchheight
706 \dp\nextbox\zeropoint
707 \box\nextbox
708 \egroup}
709
710\def\grph_clip_nop_finish
711 {\box\nextbox
712 \egroup}
713
714\setupclipping
715 [\c!state=\v!start,
716 \c!n=\plusone,
717 \c!nx=\clippingparameter\c!n,\c!x=\plusone,\c!sx=\plusone,
718 \c!ny=\clippingparameter\c!n,\c!y=\plusone,\c!sy=\plusone,
719 \c!width=\zeropoint,
720 \c!height=\zeropoint,
721 \c!hoffset=\zeropoint,
722 \c!voffset=\zeropoint,
723 \c!offset=\zeropoint,
724 \c!leftoffset=\clippingparameter\c!offset,
725 \c!rightoffset=\clippingparameter\c!offset,
726 \c!topoffset=\clippingparameter\c!offset,
727 \c!bottomoffset=\clippingparameter\c!offset,
728 \c!mp=]
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750\permanent\protected\def\mirror
751 {\bgroup
752 \dowithnextboxcs\grph_mirror_finish\hbox}
753
754\def\grph_mirror_finish
755 {\scratchdimen\wd\nextbox
756
757
758 \setbox\nextbox\naturalhpack
759 {\dostartmirroring
760 \hskip\wd\nextbox
761 \box\nextbox
762 \dostopmirroring}
763 \wd\nextbox\scratchdimen
764 \box\nextbox
765 \egroup}
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788\installcorenamespace {rotate}
789\installcorenamespace {rotatelocation}
790\installcorenamespace {rotatepreset}
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809\newdimension\d_grph_rotate_used_height
810
811\newdimension\d_grph_rotate_width
812\newdimension\d_grph_rotate_height
813\newdimension\d_grph_rotate_depth
814
815\newdimension\d_grph_rotate_saved_width
816\newdimension\d_grph_rotate_saved_height
817\newdimension\d_grph_rotate_saved_depth
818
819\newconditional\c_grph_rotate_obey_depth
820\newconditional\c_grph_rotate_not_fit
821\newconditional\c_grph_rotate_center
822
823\installframedcommandhandler \??rotate {rotate} \??rotate
824
825\setuprotate
826 [\c!rotation=90,
827 \c!location=\v!normal,
828 \c!width=\v!fit,
829 \c!height=\v!fit,
830 \c!offset=\v!overlay,
831 \c!frame=\v!off]
832
833\lettonothing\p_rotation_location
834\lettonothing\p_rotation_rotation
835
836\permanent\tolerant\protected\def\rotate[#S#1]
837 {\bgroup
838 \ifparameter#1\or
839 \setupcurrentrotate[#1]
840 \fi
841 \edef\p_rotation_location{\rotateparameter\c!location}
842 \edef\p_rotation_rotation{\rotateparameter\c!rotation}
843 \ifcsname\??rotatelocation\p_rotation_location\endcsname
844 \expandafter\lastnamedcs
845 \else
846 \expandafter\grph_rotate_default
847 \fi}
848
849\def\grph_rotate_framed
850 {\resetrotateparameter\c!location
851 \dowithnextboxcs\grph_rotate_finish\vbox
852 \inheritedrotateframed}
853
854\def\grph_rotate_normal
855 {\dowithnextboxcs\grph_rotate_finish\vbox}
856
857\def\grph_rotate_finish
858 {\grph_rotate_finish_indeed
859 \egroup}
860
861\def\grph_rotate_default
862 {\c_grph_rotate_not_fit\conditionalfalse
863 \c_grph_rotate_center\conditionalfalse
864 \c_grph_rotate_obey_depth\conditionaltrue
865 \grph_rotate_framed}
866
867\letcsname\??rotatelocation\v!default\endcsname\grph_rotate_default
868
869\defcsname\??rotatelocation\v!depth\endcsname
870 {\c_grph_rotate_not_fit\conditionalfalse
871 \c_grph_rotate_center\conditionalfalse
872 \c_grph_rotate_obey_depth\conditionaltrue
873 \grph_rotate_normal}
874
875\defcsname\??rotatelocation\v!fit\endcsname
876 {\c_grph_rotate_not_fit\conditionaltrue
877 \c_grph_rotate_center\conditionalfalse
878 \c_grph_rotate_obey_depth\conditionaltrue
879 \grph_rotate_normal}
880
881\defcsname\??rotatelocation\v!broad\endcsname
882 {\c_grph_rotate_not_fit\conditionalfalse
883 \c_grph_rotate_center\conditionalfalse
884 \c_grph_rotate_obey_depth\conditionalfalse
885 \grph_rotate_normal}
886
887\defcsname\??rotatelocation\v!high\endcsname
888 {\c_grph_rotate_not_fit\conditionalfalse
889 \c_grph_rotate_center\conditionalfalse
890 \c_grph_rotate_obey_depth\conditionalfalse
891 \grph_rotate_framed}
892
893\defcsname\??rotatelocation\v!middle\endcsname
894 {\c_grph_rotate_not_fit\conditionalfalse
895 \c_grph_rotate_center\conditionaltrue
896 \c_grph_rotate_obey_depth\conditionalfalse
897 \grph_rotate_normal}
898
899\permanent\protected\def\dorotatebox#1
900 {\ifcase#1\relax
901 \expandafter\gobbleoneargument
902 \else
903 \expandafter\grph_rotate_box
904 \fi{#1}}
905
906\def\grph_rotate_box#1
907 {\bgroup
908 \hbox\bgroup
909 \edef\p_rotation_rotation{#1}
910 \dowithnextboxcs\grph_rotate_finish_box}
911
912\def\grph_rotate_finish_box
913 {\c_grph_rotate_not_fit\conditionalfalse
914 \c_grph_rotate_center\conditionalfalse
915 \c_grph_rotate_obey_depth\conditionalfalse
916 \grph_rotate_finish_indeed
917 \egroup
918 \egroup}
919
920\def\grph_rotate_finish_indeed
921 {\naturalhpack\bgroup
922 \ifempty\p_rotation_rotation
923 \grph_rotate_finish_nop
924 \else
925 \grph_rotate_finish_yes
926 \fi
927 \egroup}
928
929\def\grph_rotate_finish_nop
930 {\boxcursor\box\nextbox}
931
932\defcsname\??rotatepreset\v!left\endcsname
933 {\edef\p_rotation_rotation{90}}
934
935\defcsname\??rotatepreset\v!right\endcsname
936 {\edef\p_rotation_rotation{270}}
937
938\defcsname\??rotatepreset\v!inner\endcsname
939 {\signalrightpage
940 \doifelserightpage{\def\p_rotation_rotation{270}}{\def\p_rotation_rotation{90}}}
941
942\defcsname\??rotatepreset\v!outer\endcsname
943 {\signalrightpage
944 \doifelserightpage{\def\p_rotation_rotation{90}}{\def\p_rotation_rotation{270}}}
945
946\letcsname\??rotatepreset\v!default\endcsname\empty
947
948\def\grph_rotate_finish_yes
949 {\begincsname\??rotatepreset\p_rotation_rotation\endcsname
950 \setbox\nextbox\naturalvpack{\box\nextbox}
951 \dontcomplain
952 \ifconditional\c_grph_rotate_center
953 \d_grph_rotate_saved_width \wd\nextbox
954 \d_grph_rotate_saved_height\ht\nextbox
955 \d_grph_rotate_saved_depth \dp\nextbox
956 \setbox\nextbox\naturalhpack{\hskip.5\wd\nextbox\lower.5\ht\nextbox\box\nextbox}
957 \smashbox\nextbox
958 \fi
959
960 \d_grph_rotate_width \wd\nextbox
961 \d_grph_rotate_height\ht\nextbox
962 \d_grph_rotate_depth \dp\nextbox
963
964 \setbox\nextbox\naturalvpack{\naturalhpack{\raise\dp\nextbox\box\nextbox}}
965
966 \d_grph_rotate_used_height\ht\nextbox
967
968 \clf_analyzerotate
969 \p_rotation_rotation\relaxedspace
970 \d_grph_rotate_width
971 \d_grph_rotate_height
972 \d_grph_rotate_depth
973 \d_grph_rotate_used_height
974 \c_grph_rotate_not_fit
975 \c_grph_rotate_obey_depth
976 \relax
977
978 \setbox\nextbox\naturalvpack to \d_grph_rotate_y_size
979 {\vfilll
980 \hcontainer to \d_grph_rotate_x_size
981 {\dostartrotation\p_rotation_rotation
982 \wd\nextbox\zeropoint
983 \ht\nextbox\zeropoint
984 \box\nextbox
985 \dostoprotation
986 \hfill}
987 \kern\d_grph_rotate_y_position}
988
989 \setbox\nextbox\naturalhpack
990 {\kern{\d_grph_rotate_x_position\d_grph_rotate_x_offset}
991 \lower\d_grph_rotate_y_offset
992 \box\nextbox}
993
994 \ifconditional\c_grph_rotate_center
995 \setbox\nextbox\naturalhpack{\hskip.5\d_grph_rotate_saved_width\lower.5\d_grph_rotate_saved_height\box\nextbox}
996 \wd\nextbox\d_grph_rotate_saved_width
997 \ht\nextbox\d_grph_rotate_saved_height
998 \dp\nextbox\d_grph_rotate_saved_depth
999 \else
1000 \wd\nextbox\d_grph_rotate_new_width
1001 \ht\nextbox\d_grph_rotate_new_height
1002 \dp\nextbox\d_grph_rotate_new_depth
1003 \fi
1004
1005 \boxcursor\box\nextbox}
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040\def\grph_with_group
1041 {\d_grph_scale_wd\wd\nextbox
1042 \d_grph_scale_ht\ht\nextbox
1043 \d_grph_scale_dp\dp\nextbox
1044 \setbox\nextbox\hcontainer
1045 {\clf_startgraphicgroup
1046 \smashedbox\nextbox
1047 \clf_stopgraphicgroup}
1048 \wd\nextbox\d_grph_scale_wd
1049 \ht\nextbox\d_grph_scale_ht
1050 \dp\nextbox\d_grph_scale_dp
1051 \box\nextbox}
1052
1053\permanent\protected\def\startgraphicgroup
1054 {\dontleavehmode
1055 \begingroup
1056 \dowithnextboxcs\grph_with_group
1057 \hbox\bgroup}
1058
1059\permanent\protected\def\stopgraphicgroup
1060 {\egroup
1061 \endgroup}
1062
1063
1064
1065\permanent\protected\def\startclipeffect
1066 {\begingroup
1067 \dowithnextbox
1068 {\stopeffect
1069 \setbox\scratchboxone\box\nextbox
1070 \dowithnextbox
1071 {\setbox\scratchboxtwo\box\nextbox
1072 \startgraphicgroup
1073 \startoverlay
1074 {\box\scratchboxone}
1075 {\box\scratchboxtwo}
1076 \stopoverlay
1077 \stopgraphicgroup}
1078 \hbox}
1079 \hbox\bgroup\starteffect[\v!clip]\let\next}
1080
1081\permanent\protected\def\stopclipeffect
1082 {\endgroup}
1083
1084\setbox0\hbox{\strut\starteffect[clip]mikael\stopeffect}
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108\protect \endinput
1109 |