summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/pack-pos.mkiv
blob: fab73bc4a3b0a2839f8d6cc63eac048d9d0788bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
58
59
60
61
62
63
64
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
%D \module
%D   [       file=pack-pos,
%D        version=2010.11.17 % real old code, updated a bit
%D          title=\CONTEXT\ Packaging Macros,
%D       subtitle=Positioning,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Packaging Macros / Positioning}

\unprotect

% An old but still usefull mechanism:
%
% \ruledvbox{\startpositioning
%     \position(1,1){test}
%     \position[xstep=relative](1,1){test}
%     \position[ystep=relative](3,-1){test}
%     \position(10,10){test}
% \stoppositioning}

\newdimen\positioningxposition  \newdimen\positioningyposition
\newdimen\positioningxdimension \newdimen\positioningydimension
\newdimen\positioningxoffset    \newdimen\positioningyoffset

\newbox\positioningbox

\unexpanded\def\startpositioning
  {\dosingleempty\dostartpositioning}

\def\dostartpositioning[#1]%
  {\bgroup
   \getparameters[\??ps][#1]%
   \positioningxposition \zeropoint  \positioningyposition \zeropoint
   \positioningxdimension\zeropoint  \positioningydimension\zeropoint
   \positioningxoffset   \zeropoint  \positioningyoffset   \zeropoint
   \hfuzz                \paperwidth \vfuzz                \paperheight
   \setbox\positioningbox\hbox\bgroup
   \ignorespaces}

\unexpanded\def\stoppositioning
  {\removeunwantedspaces
   \doifnot\@@psoffset\v!yes
     {\global\positioningxoffset\zeropoint
      \global\positioningyoffset\zeropoint}%
   \global\advance\positioningxdimension \positioningxoffset
   \global\advance\positioningydimension \positioningyoffset
   \egroup
   \vbox to \positioningydimension
     {\vskip\positioningyoffset
      \hbox to \positioningxdimension
        {\hskip\positioningxoffset
         \box\positioningbox
         \hfill}
      \vfill}%
   \egroup}

\def\resetpositioning
  {\let\@@psstate   \v!start
   \let\@@psunit    \s!cm
   \let\@@psfactor  \plusone
   \let\@@psscale   \plusone
   \def\@@psxfactor{\@@psfactor}%
   \def\@@psyfactor{\@@psfactor}%
   \def\@@psxscale {\@@psscale}%
   \def\@@psyscale {\@@psscale}%
   \let\@@psxstep   \v!absolute
   \let\@@psystep   \v!absolute
   \let\@@psxoffset \zeropoint
   \let\@@psyoffset \zeropoint}

\resetpositioning

\unexpanded\def\setuppositioning
  {\resetpositioning
   \dodoubleargument\getparameters[\??ps]}

\def\calculateposition#1#2#3#4#5#6#7#8#9%
  {\setdimensionwithunit\scratchdimen{#1}\@@psunit
   \scratchdimen#8\scratchdimen
   \scratchdimen#9\scratchdimen
   \advance\scratchdimen #4\relax
   % == \scratchdimen\dimexpr#8\dimexpr#9\scratchdimen\relax+#4\relax
   \doif{#2}\v!relative
     {\advance\scratchdimen#3%
      \let#4\zeropoint}%
   #3\scratchdimen
   \doifnot\@@psstate\v!overlay
     {\scratchdimen\dimexpr#5+#3\relax
      \ifdim           #3<-#7\relax \global#7-#3\relax    \fi
      \ifdim\scratchdimen> #6\relax \global#6\scratchdimen\fi}}

\def\position
  {\dosingleempty\doposition}

\def\doposition[#1]#2(#3,#4)%
  {\removeunwantedspaces
   \dowithnextbox{\dodoposition{#1}{#2}{#3}{#4}}\hbox}

\def\dodoposition#1#2#3#4%
  {\bgroup
   \dontcomplain
   \getparameters[\??ps][#1]%
   \calculateposition{#3}\@@psxstep\positioningxposition\@@psxoffset\nextboxwd  \positioningxdimension\positioningxoffset\@@psxscale\@@psxfactor
   \calculateposition{#4}\@@psystep\positioningyposition\@@psyoffset\nextboxhtdp\positioningydimension\positioningyoffset\@@psyscale\@@psyfactor
   \vbox to \zeropoint
     {\vskip\positioningyposition
      \hbox to \zeropoint
        {\hskip\positioningxposition
         \flushnextbox
         \hss}
      \vss}%
   \normalexpanded
     {\egroup
      \positioningxposition\the\positioningxposition
      \positioningyposition\the\positioningyposition
      \def\noexpand\@@psxoffset{\the\dimexpr\@@psxoffset}%
      \def\noexpand\@@psyoffset{\the\dimexpr\@@psyoffset}}%
   \ignorespaces}

\setuppositioning
  [\c!unit=\s!cm,
   \c!factor=\plusone,
   \c!scale=\plusone,
   \c!xstep=\v!absolute,
   \c!ystep=\v!absolute,
   \c!offset=\v!yes,
   \c!xoffset=\zeropoint,
   \c!yoffset=\zeropoint]

\protect \endinput