summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/x-res-04.tex
blob: b5032f5503f27d7cb7544fa147510858d98977f8 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
%D \module
%D   [      file=x-fig-04,
%D        version=2001.03.21,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Figure Base Loading,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% hele base laden

\setXMLfallbackmode3

% icon        : preview
% caption     : \figurebasevariable{caption}
% background  : rgb cmyk gray name
% dimensions  : width height offset (l,r,t,b) area
% alternative : tag label / evt list
%
% movie
% sound
% applet
% application

\usemodule[res-00] % basic element definitions

%D This module implements an interface to a figure database
%D and file. The database is formatted in \XML\ conforming
%D the following \DTD:
%D
%D \typefile{x-fig-00.dtd}
%D
%D A figure base coded this way looks like:
%D
%D \starttyping
%D <!-- texexec --pdf --use=fig-01 figtest.xml -->
%D
%D <?xml version='1.0'?>
%D
%D <rl:library language="nl">
%D
%D   <rl:description>
%D     <organization>PRAGMA Advanced Document Engineering</rl:organization>
%D     <project>Manuals</rl:project>
%D     <product>Beginners Manual</rl:product>
%D     <comment>A bunch of figures.</rl:comment>
%D   </rl:description>
%D
%D   <rl:figure>
%D     <rl:file>koe.pdf</rl:file>
%D     <rl:label>a dutch cow</rl:label>
%D     <rl:copyright>Corel Draw Suite</rl:copyright>
%D     <rl:comment>I bet that you've seen this cow before.</rl:comment>
%D   </rl:figure>
%D
%D   <rl:figure>
%D     <rl:dummy width="4cm" height="3cm">non existent</rl:dummy>
%D     <rl:label>a european cow</rl:label>
%D     <rl:copyright>Nobody</rl:copyright>
%D     <rl:comment>When will we talk about European cows?</rl:comment>
%D   </rl:figure>
%D
%D </rl:library>
%D \stoptyping
%D
%D You can convert this base into a \PDF\ file using
%D \TEXEXEC\ and another module in this suite.
%D
%D \starttyping
%D texexec --pdf --use=fig-make yourfile.xml
%D \stoptyping
%D
%D You can now select a graphic from this file using the
%D
%D \starttyping
%D \externalfigure[a dutch cow][width=4cm]
%D \stoptyping
%D
%D This module overloads this command so that a figure is
%D it first searched in the list of databases.
%D
%D \starttyping
%D \usemodule     [fig-base]
%D \usefigurebases[yourfile]
%D \stoptyping
%D
%D The special keyword \type {reset} can be used to reset
%D this list.

\startcommands      dutch                 english
                    german                czech
                    italian               romanian

     usefigurebase: gebruikfiguurbestand  usefigurebase
                    usefigurebase         usefigurebase
                    usefigurebase         usefigurebase

\stopcommands

\unprotect

\consultutilityfilefalse

% 0 = no loading
% 1 = selective loading
% 2 = full loading

\chardef\figurebasemode=1 % 2

\newcounter\figurefilepage

% loading a complete figure base

\startXMLmapping[rl:load]

\defineXMLenvironmentsave [rl:figure]
  {\bgroup}
  {\XMLflush{rl:figure}
   \doglobal\increment\figurefilepage
   \figbase@savedata{\XMLflush{rl:label}}\figurefilepage
   \egroup}

\stopXMLmapping

\def\loadfigurebase#1%
  {\doifnotflagged{rl:#1}
     {\writestatus{figbase}{loading #1 into memory}%
      \startnointerference
        \autoXMLnamespace[rl]
        \startXMLmapping[rl:load]
          \doglobal\newcounter\figurefilepage
          \processXMLfilegrouped{#1.xml}
        \stopXMLmapping
        \doglobal\setflag{rl:#1}
      \stopnointerference}}

\def\figbase@savedata#1#2%
  {%\writestatus{figbase}{data of #1 loaded}%
   \doglobal\saveXMLdatastructure{rl:rl:#1}{record}{page="#2"}{}{rl:figure}{}}

% locating and if needed loading one figure record

\startXMLmapping[rl:find]

\defineXMLenvironment[rl:instance]
  {\bgroup}
  {\doif\askedlabel{\XMLflush{rl:label}}
     {\doglobal\saveXMLdata{rl:g:manipulation}{rl:manipulation}%
      \doifXMLdata{rl:original}
        {\xdef\askedlabel{\XMLflush{rl:original}}}}%
   \egroup}

\defineXMLenvironmentsave [rl:figure]
  {\bgroup}
  {\XMLflush{rl:figure}
   \doglobal\increment\figurefilepage
   %\doshowfigurestate{base : comparing \askedlabel\space with \XMLflush{rl:label}}%
   \doif\askedlabel{\XMLflush{rl:label}}
     {\doshowfigurestate{base label : found \askedlabel}%
      \ifnum\figurebasemode=\plusone % load used ones
        \figbase@savedata\askedlabel\figurefilepage
      \fi
      \doglobal\saveXMLdata{rl:l:manipulation}{rl:manipulation}%
      \xdef\figurefilelabel   {\XMLflush{rl:label}}%
      \xdef\figurefilefile    {\XMLflush{rl:file}}%
      \xdef\figurefileoriginal{\XMLflush{rl:original}}%
      \xdef\figurefilename    {\XMLflush{rl:file}}
      \endinput}%
   \egroup}

\defineXMLenvironment [rl:record]
  {}
  {\xdef\figurefilename{\XMLpop{rl:file}}
   \xdef\figurefilepage{\XMLop {page}}}

\stopXMLmapping

\def\getfigurefilename#1#2%
  {\ifnum\figurebasemode=\plustwo \loadfigurebase{#1} \fi
   \startnointerference
     \traceXMLelementsfalse
     \resetfigurefilebase
     \doglobal\newcounter\figurefilepage
     \autoXMLnamespace[rl]
     \startXMLmapping[rl:find]
       \xdef\figurefilebase{#1}%
       \def\askedlabel{#2}%
       \doifelseXMLelement{rl:rl:\askedlabel}
         {\enableXMLelements\flushXMLelement{rl:rl:\askedlabel}}
         {\doshowfigurestate{base path : \figurepathlist}%
          \processcommacommand[\figurepathlist]\dogetfigurefilename}%
     \stopXMLmapping
   \stopnointerference}

% todo: niet toegekende naam doorgeven aan calculate en pad
% in padstring

\def\dogetfigurefilename#1%
  {\ifx\figurefilename\empty
     \bgroup
     \doglobal\newcounter\figurefilepage
     \globalletempty\figurefilelabel
     \globalletempty\figurefileoriginal
     \globalletempty\figurefilefile
     \xdef\figurefilebasepath{#1}%
     \assignfullfilename{#1}{\figurefilebase}\to\filename
     \doiffileelse{\filename.xml}
       {\doshowfigurestate{base file : \filename}%
        \expanded{\processXMLfilegrouped{\filename.xml}}}
       \donothing
     \ifx\figurefilename\empty \else
%        \global\let\figurefilebase\figurefilebase
       \globallet\figurefilebase\filename % hm, bad omen that this is needed
     \fi
     \egroup
   \fi}

\newtoks\figurebaseresets

\appendtoks
  \globalletempty\figurefilebase
  \globalletempty\figurefilename
  \globalletempty\figurefilebasepath
  \globalletempty\figurefilepage
  \globalletempty\figurefilelabel
 %\globalletempty\figurefileoriginal
 %\globalletempty\figurefilefile
\to\figurebaseresets

\def\resetfigurefilebase
  {\the\figurebaseresets}

\ifx\doshowfigurestate\undefined \let\doshowfigurestate\gobbleoneargument \fi

\def\doanalyzefiguredimensionsfromfile
  {\ifcase\figurestatus \ifx\figurebaselist\empty \else
     \resetfigurefilebase
     \doshowfigurestate{base list : \figurebaselist}%
     \processcommacommand[\figurebaselist]\dodoanalyzefiguredimensionsfromfile
     \ifx\figurefilename\empty
       \doshowfigurestate{base warning : no matching name found}%
     \else
       \doiffileelse{\figurefilebase.pdf}
         {\doshowfigurestate{base file : \figurefilebase.pdf}%
          \doshowfigurestate{base page : \figurefilepage}%
          \let\figurepathlist\figurefilebasepath
          \analyzefigurefilename{\figurefilebase.pdf}\wantedfigurelabel
          \let\wantedfigurepage\figurefilepage}
         {\doshowfigurestate{base missing : \figurefilebase.pdf}}
     \fi
     \ifcase\figurestatus
       \analyzefigurefilename\expandedfigurename\wantedfigurelabel
     \fi
   \fi \fi}

\def\dodoanalyzefiguredimensionsfromfile#1%
  {\doshowfigurestate{base check : \wantedfigurename\space in #1}%
   \getfigurefilename{#1}\wantedfigurename
   \ifx\figurefilename\empty\else
     \quitcommalist
   \fi}

% management

% will become \useresourcelibrary

\def\usefigurebase[#1]%
  {\doifelse{#1}\v!reset
     {\let\figurebaselist\empty}
     {\addtocommalist{#1}\figurebaselist}}

\let\figurebaselist\empty

\resetfigurefilebase

% manipulations / todo: fixed order

\defineXMLsave [rl:manipulation]

\defineXMLsingular [rl:background] [r=0,g=0,b=0,s=0,c=0,m=0,y=0,k=0]
  {\global\setbox\foundexternalfigure\vbox
     {\definecolor
        [XMLRLcolor]
        [r=\XMLop{r},g=\XMLop{g},b=\XMLop{b},s=\XMLop{s},%
         c=\XMLop{c},m=\XMLop{m},y=\XMLop{y},k=\XMLop{k}]%
       \framed
         [\c!frame=\v!off,\c!offset=\v!overlay,
          \c!background=\v!color,\c!backgroundcolor=XMLRLcolor]
         {\box\foundexternalfigure}}}

\defineXMLsingular [rl:viewport] [\??cp] % []
  {\global\setbox\foundexternalfigure\vbox
     {\expandXMLta \getXMLta
      \clip
        [\XMLta]
        {\box\foundexternalfigure}}%
   \global\setbox\foundexternalfigure\vbox
     {\scale
        [\c!width=\figurewidth,\c!height=\figureheight]
        {\box\foundexternalfigure}}}

\defineXMLsingular [rl:dimensions] [width=,height=]
  {}

\defineXMLsingular [rl:position] [offset=,width=,height=,hoffset=,voffset=]
  {}

\appendtoks
  \doglobal\eraseXMLelement{rl:l:manipulation}%
  \doglobal\eraseXMLelement{rl:g:manipulation}%
\to \figurebaseresets

\appendtoks
  \startnointerference
    \processXMLelement{rl:l:manipulation}%
    \processXMLelement{rl:g:manipulation}%
  \stopnointerference
\to \externalfigurepostprocessors

\protect \doifnotmode{demo}{\endinput}

\starttext

\setupcolors[state=start]

\usefigurebase[d-fig-01]

\externalfigure[part of a dutch cow][width=3cm,frame=on]
\externalfigure[a simple dutch cow][width=5cm,frame=on]
\externalfigure[another simple dutch cow][width=5cm,frame=on]

\stoptext