1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Packaging Macros Positioning}
15
16\unprotect
17
18
19
20
21
22
23
24
25
26
27
28
29\installcorenamespace {positioning}
30
31\installcommandhandler \??positioning {positioning} \??positioning
32
33\setuppositioning
34 [\c!state=\v!start,
35 \c!unit=\s!cm,
36 \c!factor=\plusone,
37 \c!scale =\plusone,
38 \c!xfactor=\positioningparameter\c!factor,
39 \c!yfactor=\positioningparameter\c!factor,
40 \c!xscale=\positioningparameter\c!scale,
41 \c!yscale=\positioningparameter\c!scale,
42 \c!xstep=\v!absolute,
43 \c!ystep=\v!absolute,
44 \c!xoffset=\zeropoint,
45 \c!yoffset=\zeropoint]
46
47\newdimen\d_pack_positioning_x_position
48\newdimen\d_pack_positioning_y_position
49\newdimen\d_pack_positioning_x_dimension
50\newdimen\d_pack_positioning_y_dimension
51\newdimen\d_pack_positioning_x_offset
52\newdimen\d_pack_positioning_y_offset
53
54\newbox\b_pack_positioning
55
56\unexpanded\def\startpositioning
57 {\bgroup
58 \dodoubleempty\pack_positioning_start}
59
60\def\pack_positioning_start[#1][#2]
61 {\ifsecondargument
62 \edef\currentpositioning{#1}
63 \setupcurrentpositioning[#2]
64 \else\iffirstargument
65 \doifelseassignment{#1}
66 {\let\currentpositioning\empty
67 \setupcurrentpositioning[#1]}
68 {\edef\currentpositioning{#1}}
69 \else
70 \let\currentpositioning\empty
71 \fi\fi
72 \d_pack_positioning_x_position \zeropoint
73 \d_pack_positioning_y_position \zeropoint
74 \d_pack_positioning_x_dimension\zeropoint
75 \d_pack_positioning_y_dimension\zeropoint
76 \d_pack_positioning_x_offset \zeropoint
77 \d_pack_positioning_y_offset \zeropoint
78 \hfuzz\paperwidth
79 \vfuzz\paperheight
80 \setbox\b_pack_positioning\hbox\bgroup
81 \ignorespaces}
82
83\unexpanded\def\stoppositioning
84 {\removeunwantedspaces
85 \doifnot{\positioningparameter\c!offset}\v!yes
86 {\global\d_pack_positioning_x_offset\zeropoint
87 \global\d_pack_positioning_y_offset\zeropoint}
88 \global\advance\d_pack_positioning_x_dimension\d_pack_positioning_x_offset
89 \global\advance\d_pack_positioning_y_dimension\d_pack_positioning_y_offset
90 \egroup
91 \vbox to \d_pack_positioning_y_dimension
92 {\vskip\d_pack_positioning_y_offset
93 \hbox to \d_pack_positioning_x_dimension
94 {\hskip\d_pack_positioning_x_offset
95 \box\b_pack_positioning
96 \hfill}
97 \vfill}
98 \egroup}
99
100\unexpanded\def\pack_positioning_calculate#1#2#3#4#5#6#7#8#9
101 {\setdimensionwithunit\scratchdimen{#1}{\positioningparameter\c!unit}
102 \scratchdimen\positioningparameter#8\scratchdimen
103 \scratchdimen\positioningparameter#9\scratchdimen
104 \advance\scratchdimen\positioningparameter#4\relax
105
106 \doif{\positioningparameter#2}\v!relative
107 {\advance\scratchdimen#3
108 \letpositioningparameter#4\zeropoint}
109 #3\scratchdimen
110 \doifnot{\positioningparameter\c!state}\v!overlay
111 {\scratchdimen\dimexpr#5\nextbox#3\relax
112 \ifdim #3<#7\relax \global#7#3\relax \fi
113 \ifdim\scratchdimen> #6\relax \global#6\scratchdimen\fi}}
114
115\unexpanded\def\position
116 {\bgroup
117 \dosingleempty\pack_positioning_position}
118
119\def\pack_positioning_position[#1]#2(#3,#4)
120 {\iffirstargument
121 \setupcurrentpositioning[#1]
122 \fi
123 \removeunwantedspaces
124 \dowithnextbox{\pack_positioning_position_indeed{#3}{#4}}\hbox}
125
126\def\pack_positioning_position_indeed#1#2
127 {\dontcomplain
128 \pack_positioning_calculate
129 {#1}
130 \c!xstep
131 \d_pack_positioning_x_position
132 \c!xoffset
133 \wd
134 \d_pack_positioning_x_dimension
135 \d_pack_positioning_x_offset
136 \c!xscale
137 \c!xfactor
138 \pack_positioning_calculate
139 {#2}
140 \c!ystep
141 \d_pack_positioning_y_position
142 \c!yoffset
143 \htdp
144 \d_pack_positioning_y_dimension
145 \d_pack_positioning_y_offset
146 \c!yscale
147 \c!yfactor
148 \vbox to \zeropoint
149 {\offinterlineskip
150 \vskip\d_pack_positioning_y_position
151 \hbox to \zeropoint
152 {\hskip\d_pack_positioning_x_position
153 \box\nextbox
154 \hss}
155 \vss}
156 \normalexpanded
157 {\egroup
158 \d_pack_positioning_x_position\the\d_pack_positioning_x_position
159 \d_pack_positioning_y_position\the\d_pack_positioning_y_position
160 \setexpandedpositioningparameter\c!xoffset{\the\dimexpr\positioningparameter\c!xoffset}
161 \setexpandedpositioningparameter\c!yoffset{\the\dimexpr\positioningparameter\c!yoffset}}
162 \ignorespaces}
163
164\protect \endinput
165 |