Changes

Jump to navigation Jump to search
1,487 bytes added ,  14:56, 5 June 2015
m
no edit summary
'''Layers''' are ConTeXt's mechanism for absolute positioning of elements and other advanced techniques like switching elements on and off.
There's There’s still no manual about them.
==My first Layer==
Define a layer that takes the whole page
<texcode>
\definelayer[mybg] % name of the layer [x=0mm, y=0mm, % from upper left corner of paper
width=\paperwidth, height=\paperheight] % let the layer cover the full paper
</texcode>
\setlayer[mybg] % name of the layer
[hoffset=1cm, voffset=1cm] % placement (from upper left corner of the layer)
{\framed[frame=on, width=3cm, height=2cm]{LAYER}} % the actual contents of the layer
</texcode>
\setupbackgrounds[page][background=mybg]
</texcode>
This command makes the contents of the layer appear only once after the background is activated. If you want to repeat the contents of the layer on each page, use the option <code>repeat=yes</code> in the <{{cmd>|definelayer</cmd> }} command. Then the contents of the layer will be shown on every page. You can add to these contents by a new <{{cmd>|setlayer</cmd>}}[mybg] command. To clear the accumulated contents use <{{cmd>|resetlayer</cmd>}}[mybg]. To make the layer appear on each page, so that it can be populated with different content, set the option<code>state=repeat</code> in <{{cmd>|setupbackgrounds</cmd>}}.
Now you can test the whole thing:
<context source=yes>
\setuppapersize[A10,portrait][A9,landscape] % A10 = 2.6x3.7cm -- compact example\setuparranging[2SIDE2UP] % show both two pagesside by side\showframe % So we can see the show entire pages
\definelayer[mybg] % name of the layer [x=0mm, y=0mm, % from upper left corner of paper
width=\paperwidth, height=\paperheight, % let the layer cover the full paper
state=continue] % on all pages but the first one
\setupbackgrounds[page][background=mybg]
\setlayer[mybg] % name of the layer [hoffset=0.3cm2cm, voffset=0.7cm2cm] % placement (from upper left corner of the layer) {\framed[frame=on, width=2cm, height=2cm1cm]{LAYER}} % the actual contents of the layer
\starttext
\dorecurse{2}{\page[empty]} % for testing, to get 2 pages, 2nd 1st with layer, 1st 2nd without
\stoptext
 
</context>
* preset : a named location, see below
There are some "presets" for paper egde edge placement:
<texcode>
% These four are defined by ConTeXt!
</texcode>
Similarly you can define your own presets.
 
===Understanding "location" and "corner"===
 
The layer is divided into a 2x2 matrix of squares, where 'x' is the center.
This gets you a total of 3x3=9 different corners.
o---o---o
| | |
o---x---o
| | |
o---o---o
 
Now you choose one 'corner' (the reference point) for the placement of the content. The content is placed in relation to this point.
The chosen 'corner' c is our new 'center point' (only for placement) now.
With 'location' you define where (in relation to 'corner') the content is placed.
Again you have nine different corners to choose from.
==== Example: to make this clear ====
Specifications <code>corner={top,right},location={bottom,right}</code> will place content in the area L (outside the original layer).
Think about the 'corner' c as a magnetic grid point, where the content snaps to.
The 'location' defines, from which direction we approach the point c.
* x = layer center point
* c = corner 'top,right'
* d = location 'bottom right'
* L = location (area)
o---o---o
| | |
----o---c---o
| | | L |
----x---o---d
| | |
---------
 
==== Example: placing a logo to the top right corner of the page ====
 
<context source=yes text="gives:">
\definelayer
[Logo]
[location={left,bottom},
x=\paperwidth,y=0mm,
hoffset=-5mm,voffset=5mm,
]
\setlayer[Logo]
{\framed[width=3cm,height=1cm,background=color,backgroundcolor=lightgray]{Logo...}}
\setupbackgrounds[page][background=Logo]
 
\starttext
%\showframe
 
Some text...
\stoptext
</context>
==State==
You may experience cases where the defined size of your layer is ignored and you can’t get linebreaking or multiple lines at all.
This is due to <cmd>setlayer</cmd> using <cmd>hbox</cmd> internally. You can work around the problem using <cmd>setlayerframed</cmd>:
This does not work:
<context source=yes>
\showframesetuppapersize[A6]
\definelayer[AddressBg][
x=0mm20mm, y=0mm30mm, width=65mm, height=30mm,
state=start] % size is ignored!
\setupbackgrounds[paper][
setups=ALayer, background=AddressBg,
state=start]
\starttext
 
\strut
\startsetups ALayer
\setlayer[AddressBg] % setlayer does not Change this to \setlayerframed to get it to work here [width=65mm, height=30mm, frame=off, hoffset=0mm, voffset=0mm, align=right] %You must set align to get multiple lines! { PRAGMA Advanced Document Engineering\crlf Mr. Hans Hagen (the wizard who wrote it all, \CONTEXT\ and everything else, with the help of his little elves)\crlf Ridderstraat 27\crlf 8061 GH 8061GH Hasselt\crlf THE NETHERLANDS }
\stopsetups
</context>
 
<context source=yes>
\definelayer[AddressBg][
x=0mm, y=0mm,
width=65mm, height=30mm,
state=start] % size is ignored!
\setupbackgrounds[paper][
setups=ALayer,
background=AddressBg,
state=start]
 
\startsetups ALayer
\setlayerframed[AddressBg] % setlayerframed does not work here
[width=65mm, height=30mm,
frame=off,
hoffset=0mm, voffset=0mm,
align=right]%
{
PRAGMA Advanced Document Engineering\crlf
Mr. Hans Hagen (the wizard who wrote it all, \CONTEXT\ and everything else,
with the help of his little elves)\crlf
Ridderstraat 27\crlf
8061 GH Hasselt\crlf
THE NETHERLANDS
}
\stopsetups
 
\stoptext
</context>
<context source="yes">
\setupexternalfigures[location={local,default}]
% (necessary for the Wiki's ConTeXt wiki conTeXt live processor)
\definelayer [figure][width=\overlaywidth,height=\overlayheight]
x=.25\layerwidth,
y=.25\layerheight]
{\green HERE}
\setlayerframed
x=.15\layerwidth,
y=.35\layerheight]
{\red THERE}
\stopsetups
\externalfigure[cow][background={foreground,figure},width=4cm,height=8cm] \startsetups figure \setlayerframed [figure] [preset=righttop, x=.25\layerwidth, y=.25\layerheight] {MORE} \setlayerframed [figure] [preset=middle, foregroundcolor=green] {EVEN MORE} \stopsetups \externalfigure[cow][background={foreground,figure},width=14cm,height=2cm] \defineexternalfigure[whatever][background={foreground,figure}] \startsetups figure \setlayerframed [figure] [preset=righttop, x=.25\layerwidth, y=.25\layerheight] {\red MORE} \setlayerframed [figure] [preset=middle, foregroundcolor=green] {EVEN MORE} \stopsetups \externalfigure[cow][whatever][width=14cm,height=4cm3cm]
\stoptext
</texcode>
== Layers and the delayed font mechanism ==
 
Until some years ago the Latin Modern font was always automatically
loaded, regardless of the users choice of font. Font loading takes a
considerable amount of time (check the stats at the end of a context
run to get an idea). This led to the question:
 
“Why start loading a big, complex font like Latin Modern before we
know which font the user actually wants to use and waste several
seconds on it, just to start loading the users choice afterwards?”
 
The answer was:
 
”We delay loading the font until we know which font the user wants
to use. If the user doesn't tell us, then we fall back to Latin
Modern.”
 
The body font is set up in the setup area (the part above
<code>\starttext</code>). That, in turn, means that when having reached
<code>\starttext</code>, the users choice of font is known and can be loaded. It
is more efficient if a font other then Latin Modern is used.
 
One drawback is that typeset text in the setup area has no font
setup and will fall back to Latin Modern Mono. Usually no text is
typeset in the setup area. However, layers are an exception and
a font needs to be set up beforehand.
==LinksSee Also ==
* Some applications in the [[manual:details.pdf|Details]] manual
* Source: [[source:pack-lyr.mkii|pack-lyr.mkii]] or [[source:pack-lyr.mkiv|pack-lyr.mkiv]]
* Example of [[Alternating backgrounds and repeating layers]] and [[Draft Watermark]]
* [http://www.ntg.nl/pipermail/ntg-context/2013/070935.html Layer vs. overlay] by Wolfgang
{{todo|We need a lot of documentation and samples for this complicated subject.}}
 
[[Category:Graphics]] [[Category:Layers]]
105

edits

Navigation menu