summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/6_2/spqr/boxfill.tex
blob: fbc02b579937c51bb90b8a94a402fa28c3db9f86 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
%% BEGIN boxfill.tex
%%
%% Defines the \psboxfill macro.
%% For use with PSTricks v0.94 (or perhaps later).
%%
\def\fileversion{0.94}
\def\filedate{94/06/08}
%%
%% COPYRIGHT 1994, by Timothy Van Zandt, tvz@Princeton.EDU
%% See pstricks.tex or pstricks.doc for copying restrictions.

% Preliminaries:

\message{ v\fileversion, \filedate}

\csname PSTboxfillLoaded\endcsname
\let\PSTboxfillLoaded\endinput

\ifx\PSTricksLoaded\endinput\else
  \def\next{\input pstricks.tex}
  \expandafter\next
\fi

\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

% The box:

\newbox\pst@fillbox
\def\psboxfill{\pst@killglue\pst@makebox\psboxfill@i}
\def\psboxfill@i{\setbox\pst@fillbox\box\pst@hbox\ignorespaces}

% Parameters:

\def\psset@boxfillsize#1{%
  \def\pst@tempg{#1}\def\pst@temph{auto}%
  \ifx\pst@tempg\pst@temph
    \let\psk@boxfillsize\relax
  \else
    \psset@@boxfillsize#1(\z@,\z@)\@empty(\z@,\z@)(\@nil
  \fi}
\def\psset@@boxfillsize#1(#2,#3)#4(#5,#6)#7(#8\@nil{%
  \begingroup
    \ifx\@empty#7\relax
      \pst@dima\z@
      \pst@dimb\z@
      \pssetxlength\pst@dimc{#2}%
      \pssetylength\pst@dimd{#3}%
    \else
      \pssetxlength\pst@dima{#2}%
      \pssetylength\pst@dimb{#3}%
      \pssetxlength\pst@dimc{#5}%
      \pssetylength\pst@dimd{#6}%
    \fi
    \xdef\pst@tempg{%
      \pst@dima=\number\pst@dima sp
      \pst@dimb=\number\pst@dimb sp
      \pst@dimc=\number\pst@dimc sp
      \pst@dimd=\number\pst@dimd sp }%
  \endgroup
  \let\psk@boxfillsize\pst@tempg}

\psset{boxfillsize={(-15cm,-15cm)(15cm,15cm)}}

\def\psset@boxfillcolor#1{\pst@getcolor{#1}\psboxfillcolor}
\psset@boxfillcolor{black}

\def\psset@boxfillangle#1{\pst@getangle{#1}\psk@boxfillangle}
\psset@boxfillangle{0}

\def\psset@fillsepx#1{\pst@getlength{#1}\psk@fillsepx}
\def\psset@fillsepy#1{\pst@getlength{#1}\psk@fillsepy}
\def\psset@fillsep#1{\psset@fillsepx{#1}\let\psk@fillsepy\psk@fillsepx}
\psset@fillsep{2pt}

\def\psset@fillcycle#1{\pst@getint{#1}\psk@fillcycle}
\psset@fillcycle{0}
  
% Main macro:

\def\psfs@boxfill{%
  \ifvoid\pst@fillbox
    \@pstrickserr{Fill box is empty. Use \string\psboxfill\space first.}\@ehpa
  \else
    \ifx\psk@boxfillsize\relax
      \pst@AutoBoxFill
    \else
      \pst@ManualBoxFill
    \fi
  \fi}

% Manual box fill:

\def\pst@ManualBoxFill{%
  \leavevmode
  \begingroup
    \pst@FlushCode
    \begin@psclip
    \pstVerb{clip}%
    \expandafter\pst@AddFillBox\psk@boxfillsize
    \end@psclip
  \endgroup}

\def\pst@FlushCode{%
  \pst@Verb{%
    /mtrxc CM def
    CP CP T
    \tx@STV
    \psk@origin
    \psk@swapaxes
    \pst@newpath
    \pst@code
    mtrxc setmatrix
    moveto
    0 setgray}%
  \gdef\pst@code{}}

\def\pst@AddFillBox#1 #2 #3 #4 {%
  \begingroup
    \setbox\pst@fillbox=\vbox{%
      \hbox{\unhcopy\pst@fillbox\kern\psk@fillsepx\p@}%
      \vskip\psk@fillsepy\p@}%
    \psk@boxfillsize
    \pst@cnta=\pst@dimc
    \advance\pst@cnta-\pst@dima
    \divide\pst@cnta\wd\pst@fillbox
    \pst@cntb=\pst@dimd
    \advance\pst@cntb-\pst@dimb
    \pst@dimd=\ht\pst@fillbox
    \divide\pst@cntb\pst@dimd
    \def\pst@tempa{%
      \pst@tempg
      \copy\pst@fillbox
      \advance\pst@cntc\@ne
      \ifnum\pst@cntc<\pst@cntd\expandafter\pst@tempa\fi}%
    \let\pst@tempg\relax
    \pst@cntc-\tw@
    \pst@cntd\pst@cnta
    \setbox\pst@fillbox=\hbox to \z@{%
      \kern\pst@dima
      \kern-\wd\pst@fillbox
      \pst@tempa
      \hss}%
    \pst@cntd\pst@cntb
    \ifnum\psk@fillcycle=\z@\pst@ManualFillCycle\fi
    \global\setbox\pst@boxg=\vbox to\z@{%
      \offinterlineskip
      \vss
      \pst@tempa
      \vskip\pst@dimb}%
  \endgroup
  \setbox\pst@fillbox\box\pst@boxg
  \pst@rotate\psk@boxfillangle\pst@fillbox
  \box\pst@fillbox}

\def\pst@ManualFillCycle{%
  \pst@cntg=\psk@fillcycle
  \pst@dimg=\wd\pst@fillbox
  \divide\pst@dimg\pst@cntg
  \ifnum\pst@cntg<\z@\pst@cntg=-\pst@cntg\fi
  \advance\pst@cntg\m@ne
  \pst@cnth=\pst@cntg
  \def\pst@tempg{%
    \ifnum\pst@cnth<\pst@cntg\advance\pst@cnth\@ne\else\pst@cnth\z@\fi
    \moveright\pst@cnth\pst@dimg}}

% Auto box fill:        !! Fix dictionary

\pst@def{AutoFillCycle}<%
  /c ED
  /n 0 def
  /s {
    /x x w c div n mul add def
    /n n c abs 1 sub lt { n 1 add } { 0 } ifelse def
  } def>

\pst@def{BoxFill}<%
  gsave
    gsave \tx@STV CM grestore dtransform CM idtransform
    abs /h ED abs /w ED
    pathbbox
    h div round 2 add cvi /y2 ED
    w div round 2 add cvi /x2 ED
    h div round 2 sub cvi /y1 ED
    w div round 2 sub cvi /x1 ED
    /y2 y2 y1 sub def
    /x2 x2 x1 sub def
    CP
    y1 h mul sub neg /y1 ED
    x1 w mul sub neg /x1 ED
    clip
    y2 {
      /x x1 def
      s
      x2 {
        save CP x y1 T moveto Box restore
        /x x w add def
      } repeat
      /y1 y1 h add def
    } repeat
    CP x y1 T moveto Box
  currentpoint currentfont grestore setfont moveto>

\def\pst@AutoBoxFill{%
  \leavevmode
  \begingroup
    \pst@FlushCode
    \pst@Verb{\psk@boxfillangle \tx@RotBegin}%
    \pstVerb{\pst@dict /Box \pslbrace end}%
    \hbox to \z@{\vbox to\z@{\vss\copy\pst@fillbox\vskip-\dp\pst@fillbox}\hss}%
    \pstVerb{%
        tx@Dict begin \psrbrace def
        \ifnum\psk@fillcycle=\z@
          /s {} def
        \else
          \psk@fillcycle \tx@AutoFillCycle
        \fi
        \pst@number{\wd\pst@fillbox}%
        \psk@fillsepx add
        \pst@number{\ht\pst@fillbox}%
        \pst@number{\dp\pst@fillbox}%
        \psk@fillsepy add add
        \tx@BoxFill
      end}%
    \pst@Verb{\tx@RotEnd}%
  \endgroup}

\catcode`\@=\TheAtCode\relax

\endinput

%% END boxfill.tex