details-ornaments.tex /size: 16 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\environment details-environment
4
5\startcomponent details-ornaments
6
7\startchapter[title={Ornaments everywhere}]
8
9The background mechanisms present in \CONTEXT\ have evolved over time and with
10computers becoming faster, you can expect new functionality to show up and
11existing functionality to start using this technology. A simple background
12consist of a colored area. Many commands accept settings like:
13
14\starttyping
15...[background=color,backgroundcolor=red,backgroundoffset=3pt]
16\stoptyping
17
18Instead of such an area you can define one or more so called
19overlays:
20
21\starttyping
22\defineoverlay[one][...]
23\defineoverlay[two][...]
24
25...[background={one,two}]
26\stoptyping
27
28The name overlay comes from the fact that you stack them on top of each other. A
29special overlay is \type {foreground}, and deep down in \CONTEXT\ there are more
30predefined overlays.
31
32In the \METAFUN\ manual you will find example of usage, so here we stick to a
33simple code snippet for testing this functionality:
34
35\startbuffer
36\defineoverlay[one][\green A]
37\defineoverlay[two][\red   B]
38
39\framed[background=one]       {1}
40\framed[background={one,two}] {1---2}
41\stopbuffer
42
43\typebuffer
44
45The rather ugly result is:
46
47\startlinecorrection
48\hbox{\getbuffer}
49\stoplinecorrection
50
51You can construct overlays by using \TEX\ boxing primitives or commands like
52\type {\framed}. Alternatively you can use another mechanism: layers. Layers
53collect content and flush that when asked, for instance when an overlay is
54constructed. Layers can be independent of a page, or bound to a specific page
55number, left or right hand pages. Here we look at independent layers.
56
57All these mechanisms are fine tuned for cooperating with the output routine (the
58part of \TEX\ that deals with composing pages) and are well interact quite well
59with \METAPOST\ graphics. Details of usage and tricks are revealed in this manual
60as well as in styles that come with \CONTEXT. In this chapter we will apply
61layers to graphics. For this we need a few setups, like:
62
63\starttyping
64\setupbackgrounds
65  [page]
66  [background=pagegraphics]
67\stoptyping
68
69Here we have set up the page background to use an overlay called \type
70{pagegraphics}. However, instead of an overlay, we will use a layer. This layer
71will collect content that goes into the page background. Whenever a layer is
72defined, an overlay is automatically defined as well.
73
74\startbuffer
75\definelayer
76  [pagegraphics]
77  [x=-2mm,
78   y=-2mm,
79   width=\paperwidth,
80   height=\paperheight]
81\stopbuffer
82
83\typebuffer \getbuffer
84
85When you fill a layer with content, you can influence the placement with the
86\type {x} and \type {y} parameters as well as \type {hoffset} and \type
87{voffset}, whichever you prefer. The reference point and alignment are set with
88\type {corner} and \type {location}.
89
90Live can be made easier by using presets, especially for our intended usage. The
91following presets are predefined.
92
93\startbuffer
94\definelayerpreset
95  [lefttop]     [corner={left,top},    location={right,bottom}]
96\definelayerpreset
97  [righttop]    [corner={right,top},   location={left,bottom}]
98\definelayerpreset
99  [leftbottom]  [corner={left,bottom}, location={right,top}]
100\definelayerpreset
101  [rightbottom] [corner={right,bottom},location={left,top}]
102\stopbuffer
103
104\typebuffer \getbuffer
105
106Because for this layer we have also preset the \type {x} and \type {y}, those
107corners are laying a few millimeters outside the page area. We have preset the
108size as well, otherwise all corners would end up in the top left corner.
109
110We will now fill this layer. Because the layer is hooked into the page, it will
111be flushed when the page is constructed. After the page is written to the output
112file, the layer is emptied, unless its \type {state} is set to \type {repeat}.
113
114\startbuffer
115\setlayer [extras] [preset=lefttop]     {\externalfigure[hacker]}
116\setlayer [extras] [preset=righttop]    {\externalfigure[hacker]}
117\setlayer [extras] [preset=leftbottom]  {\externalfigure[hacker]}
118\setlayer [extras] [preset=rightbottom] {\externalfigure[hacker]}
119\stopbuffer
120
121\testpage[5] \typebuffer \getbuffer
122
123Once you got the picture of layering, you will start using this mechanism for all
124kind of tasks. Instead of putting layers in a background, you can also directly
125place them, by using one of the two (equivalent) commands:
126
127\starttyping
128\composedlayer{identifier}
129\placelayer[identifier]
130\stoptyping
131
132Layer are quite convenient for defining title pages, colophons, and special
133section heads, especially in combination with \type {\framed}.
134
135On top of the layer mechanism we have build a few more mechanisms, like
136ornaments. You can use ornaments to annotate graphics in such a way that the
137dimensions stay unchanged.
138
139\startbuffer
140\defineornament
141  [affiliation]
142  [rotation=90,corner={right,bottom},location={right,top},
143   hoffset=-.25ex]
144  [frame=on,background=color,backgroundcolor=red,offset=0pt]
145\stopbuffer
146
147\typebuffer \getbuffer
148
149The negative offset will overlay the text outside the graphic. The meaning of the
150sign of coordinates and offsets depends on the corner. \in {Figure} [fig:affi-1]
151shows the result. We have put the reference point in the right bottom corner. The
152ornament is anchored at the right top corner of the dot you can picture at the
153reference point. The ornament is shifted .25ex outwards.
154
155\starttyping
156\placefigure
157  {}
158  {\affiliation{graphic}{\externalfigure[hacker][width=3cm]}}
159\stoptyping
160
161\placefigure
162  [here] [fig:affi-1] {Number 1}
163  {\affiliation{graphic}{\externalfigure[hacker][width=3cm]}}
164
165There are two ways to handle the placement. Alternative \type {a} will change the
166dimensions of the graphic according to the size of the ornament, while
167alternative \type {b} acts as a pure overlay. In \in {figure} [fig:affi-2] the
168ornament is not taken into account when calculating the dimensions of the
169graphic. This is often the preferred placement, because this way the (often
170small) ornament will not it will not spoil visual alignment of similar graphics.
171
172\startbuffer
173\defineornament
174  [affiliation]
175  [rotation=90,corner={right,bottom},location={right,top},
176   hoffset=-.25ex,alternative=b]
177  [frame=on,background=color,backgroundcolor=red,offset=0pt]
178\stopbuffer
179
180\typebuffer \getbuffer
181
182\placefigure
183  [here] [fig:affi-2] {Number 2}
184  {\affiliation{graphic}{\externalfigure[hacker][width=3cm]}}
185
186A positive offset will place the ornament on top of the graphic (see \in {figure}
187[fig:affi-3]).
188
189\startbuffer
190\defineornament
191  [affiliation]
192  [rotation=90,corner={right,bottom},location={left,top},
193   hoffset=.25ex,voffset=.25ex,alternative=a]
194  [background=color,style=\ss\tfxx,backgroundcolor=white,offset=0pt]
195\stopbuffer
196
197\typebuffer \getbuffer
198
199\placefigure
200  [here] [fig:affi-3] {Number 3}
201  {\affiliation{graphic}{\externalfigure[hacker][width=3cm]}}
202
203You need to play a bit with this mechanism in order to get a feeling for what the
204parameters do.
205
206\startbuffer
207\defineornament
208  [affiliation]
209  [rotation=90,corner={right,bottom},location={left,top},
210   hoffset=.25ex,voffset=.25ex,alternative=b]
211  [background=color,style=\ss\tfxx,backgroundcolor=white,offset=0pt]
212\stopbuffer
213
214\typebuffer \getbuffer
215
216\placefigure
217  [here] [fig:affi-4] {Number 4}
218  {\affiliation{graphic}{\externalfigure[hacker][width=3cm]}}
219
220Because the text is normally typeset quite small, you'd better use a font that
221can be scaled down a lot.
222
223\startbuffer
224\definefont[AffiliationFont][Sans sa .25]
225
226\defineornament
227  [SomeAffiliation]
228  [rotation=90,corner={right,bottom},location={right,top},
229   hoffset=-.125ex,alternative=b]
230  [style=AffiliationFont,offset=0pt]
231\stopbuffer
232
233\typebuffer \getbuffer
234
235This affiliation is used as:
236
237\startbuffer
238\placefigure
239  {Affiliations normally are typeset pretty small.}
240  {\SomeAffiliation
241     {author: Hester De Weert}
242     {\externalfigure[hacker]}}
243\stopbuffer
244
245\typebuffer \getbuffer
246
247Ornaments are implemented in terms of layers and collectors. A few examples
248demonstrate how these can be used.
249
250\startbuffer
251\layeredtext
252  [corner={right,bottom},location={left,top}]
253  [background=color,backgroundcolor=white,offset=0pt]
254  {graphic}
255  {\externalfigure[hacker][width=3cm]}
256\stopbuffer
257
258\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
259
260\startbuffer
261\layeredtext
262  [rotation=90,corner={right,bottom},location={right,top}]
263  [frame=on,offset=0pt]
264  {graphic}
265  {\externalfigure[hacker][width=3cm]}
266\stopbuffer
267
268\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
269
270\startbuffer
271\layeredtext
272  [rotation=90,corner={left,bottom},location={left,top}]
273  [frame=on,offset=0pt]
274  {graphic}
275  {\externalfigure[hacker][width=3cm]}
276\stopbuffer
277
278\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
279
280\startbuffer
281\collectedtext
282  [corner={right,bottom},location={left,top}]
283  [background=color,backgroundcolor=white,offset=0pt]
284  {graphic}
285  {\externalfigure[hacker][width=3cm]}
286\stopbuffer
287
288\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
289
290\startbuffer
291\collectedtext
292  [rotation=90,corner={right,bottom},location={right,top}]
293  [frame=on,offset=0pt]
294  {graphic}
295  {\externalfigure[hacker][width=3cm]}
296\stopbuffer
297
298\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
299
300\startbuffer
301\collectedtext
302  [rotation=90,corner={left,bottom},location={left,top}]
303  [frame=on,offset=0pt]
304  {graphic}
305  {\externalfigure[hacker][width=3cm]}
306\stopbuffer
307
308\typebuffer \startlinecorrection \getbuffer \stoplinecorrection
309
310There are several methods to construct title pages, headers, and other
311compositions. Of course there are the low level box constructors like \type
312{\hbox}, \type {\vbox} and positioning primitives like \type {\hskip}, \type
313{\hfill} and alike.
314
315Another option is to fall back on the low level box macros in the \CONTEXT\
316support file \type {supp-box} or the higher level \type {\framed} macro. You can
317use \type {\framed} nested and by cleverly using the offsets and dimensions you
318can do a lot.
319
320Layers are another means. You can or instance construct a title page in the
321following way:
322
323\starttyping
324\definelayer
325  [titlepage]
326  [width=\textwidth,
327   height=\textheight]
328
329\setlayer
330  [titlepage]
331  [preset=righttop,location={left,bottom},y=1cm,x=1cm]
332  {\definedfont[Regular at 60pt]Welcome}
333
334\setlayer
335  [titlepage]
336  [preset=rightbottom,location={right,top},y=2cm,x=2cm]
337  {\definedfont[Regular at 30pt]By Me}
338\stoptyping
339
340This just fills the layer. Placement is done with:
341
342\starttyping
343\startstandardmakeup
344  \flushlayer[titlepage]
345\stopstandardmakeup
346\stoptyping
347
348or alternatively:
349
350\starttyping
351\setupbackgrounds[text][background=titlepage]
352\startstandardmakeup \stopstandardmakeup
353\setupbackgrounds[text][background=]
354\stoptyping
355
356Another way to collect content is to use a collector. A collector starts out
357empty with:
358
359\startbuffer
360\definecollector[test][state=repeat]
361\stopbuffer
362
363\typebuffer \getbuffer
364
365We can now stepwise fill this collector. For educational purposes we've turn of
366tracing so that you can see what the anchor points.
367
368\startbuffer
369\setcollector[test]
370  [location={right,bottom}]
371  {\externalfigure[detcow][frame=on,width=3cm]}
372\stopbuffer
373
374\typebuffer {\traceboxplacementtrue \getbuffer}
375
376\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
377
378\startbuffer
379\setcollector[test]
380  [corner={right,bottom},location={left,top}]
381  {\framed[background=color,backgroundcolor=tyellow]{this is a cow}}
382\stopbuffer
383
384\typebuffer {\traceboxplacementtrue \getbuffer}
385
386\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
387
388\startbuffer
389\setcollector[test]
390  [corner={right,bottom},location={right,bottom}]
391  {\framed[background=color,backgroundcolor=tblue]{that's for sure}}
392\stopbuffer
393
394\typebuffer {\traceboxplacementtrue \getbuffer}
395
396\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
397
398\startbuffer
399\setcollector[test]
400  [corner={left,top},location={left,top}]
401  {\framed[background=color,backgroundcolor=tgreen]{a dutch cow}}
402\stopbuffer
403
404\typebuffer {\traceboxplacementtrue \getbuffer}
405
406\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
407
408\startbuffer
409\setcollector[test]
410  [corner=middle,
411   location=middle]
412  {\framed[background=color,backgroundcolor=tred]{nearly done}}
413\stopbuffer
414
415\typebuffer {\traceboxplacementtrue \getbuffer}
416
417\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
418
419In addition to the parameters shown here, you can also provide additional ones:
420\type {x}, \type {y}, \type {offset}, \type {hoffset} and \type {voffset} for
421positioning and \type {rotation} for (as expected) rotating the content in steps
422of 90 degrees. As with layers, the coordinates and offsets can be used
423intermixed.
424
425\startbuffer
426\setcollector[test]
427  [hoffset=4cm,
428   voffset=-1cm,
429   corner=middle,
430   location=middle]
431  {\framed{now}}
432\stopbuffer
433
434\typebuffer {\traceboxplacementtrue \getbuffer}
435
436\startlinecorrection[blank] \flushcollector[test] \stoplinecorrection
437
438We can show the intermediate results because we have set the state of this
439collector to repeat. In this case you need to erase the content manually, using:
440
441\startbuffer
442\resetcollector[test]
443\stopbuffer
444
445\typebuffer \getbuffer
446
447The chapter titles of this document are (as usual in a \CONTEXT\ document)
448typeset by the \type {\chapter} macro. When thinking about implementing a non
449standard head, those familiar with \CONTEXT's head macros will probably first
450think of using one of the hooks, like:
451
452\starttyping
453\setuphead[chapter][command=\MyChapterHead]
454\stoptyping
455
456Here we have followed a different approach. First we set up the chapter head. The
457\type {empty} directive instructs \CONTEXT\ not to place the head itself, but
458still to include the associated data in the text stream. This means that we will
459not see a chapter title, but that there will be an entry in the table of
460contents, that references will be set up, that so called marks will be available,
461etc.
462
463\starttyping
464\setuphead
465  [chapter]
466  [placehead=empty,
467   header=chapter,
468   style=\BigText,
469   numberstyle=\BigNumber]
470\stoptyping
471
472The \type {header} parameters instructs the head handler to mark this page as
473special with regards to header texts. This text is set up as follows:
474
475\starttyping
476\definetext
477  [chapter]
478  [header]
479  [\setups{chapter}]
480  []
481\stoptyping
482
483The setups are just series of typesetting instructions. For the sake of
484readability, we have split them up.
485
486\starttyping
487\startsetups chapter
488  \setups[chapter:title]
489  \setups[chapter:number]
490  \setups[chapter:finish]
491\stopsetups
492\stoptyping
493
494The setups will use a dedicated layer for the chapter title:
495
496\starttyping
497\definelayer
498  [chapter]
499  [width=\dimexpr\makeupwidth+\cutspace\relax,
500   height=\headerheight]
501\stoptyping
502
503The following code uses a macro \type {\setlayerframed}. This is a combination
504between \type {\setlayer} and \type {\framed}. We use two placement macros to
505typeset the title and number. When doing so, we need to take care of both
506numbered chapters and unnumbered titles.
507
508\starttyping
509\startsetups chapter:title
510
511  \setlayerframed
512    [chapter]
513    [x=\dimexpr\makeupwidth+\cutspace\relax,location={left,bottom}]
514    [height=\headerheight,
515     foregroundcolor=white,
516     background=color,
517     backgroundcolor=blue,
518     frame=off,
519     offset=none,
520     align={right,lohi}]
521    {\hbox spread .5\cutspace
522       {\hss
523        \doiftextelse{\placeheadtext[chapter]}%
524          {\placeheadtext[chapter]}%
525          {\placeheadtext[title]}%
526        \hss}\space
527     \vskip.5cm}
528
529\stopsetups
530\stoptyping
531
532Definitions like these may look complicated but in practice you will construct
533them piece|-|wise.
534
535\starttyping
536\startsetups chapter:number
537
538  \setlayerframed
539    [chapter]
540    [x=\dimexpr\makeupwidth+\cutspace\relax,
541     y=\vsize,
542     location={left,bottom}]
543    [width=\dimexpr\cutspace-\rightmargindistance\relax,
544     height=\dimexpr\cutspace-\rightmargindistance\relax,
545     foregroundcolor=white,
546     background=color,
547     backgroundcolor=red,
548     frame=off,
549     offset=none,
550     align={middle,lohi}]
551    {\hbox to \hsize
552       {\hskip.5cm\hss
553        \doifmode{*bodypart}{\placeheadnumber[chapter]}%
554        \hss}}
555
556\stopsetups
557\stoptyping
558
559The finishing touch is just a dummy frame with the chapter background. We could
560have used the header text background instead.
561
562\starttyping
563\startsetups chapter:finish
564
565  \framed
566    [width=\makeupwidth,
567     height=\headerheight,
568     background=chapter,
569     frame=off]
570    {}
571
572\stopsetups
573\stoptyping
574
575As the title of this manual suggests: it's in the details. Most of our time is
576spent in optimizing spacing issues. If you're designing the layout yourself, for
577a large part you can fall back on the consistent spacing provided by \TEX, i.e.\
578think in terms of \type {em}'s, \type {ex}'s and fractions or multiples of \type
579{\bodyfontsize}, as well as base you're dimensions on those provided by the
580layout. When dealing with translating a \DTP\ layout into something \TEX,
581definitions like the above will often look more messy.
582
583\stopchapter
584
585\stopcomponent
586