This module draws drop shadows using ImageMagick.
Include the module using
\usemodule[shadow]
The module provides 9 pre-defined shadows and an interface to define new shadows. Each shadow consists of two shadowlayers: an umbra (dark part of the shadow) and a penumbra (light part of the shadow).
- Three umbras are pre-defined: soft, hard, and flat
- Three penumbras are pre-defined: light, medium, dark
The pre-defined shadows consist of all combinations of these, so
- soft:light, soft:medium, soft:dark
- hard:light, hard:medium, hard:dark
- flat:light, flat:medium, flat:dark
Behind the scenes, the module calls ImageMagick to generate the shadow as a PNG. Once the shadow is generated, it is cached and regenerated only when some parameter changes. You can force shadows to be regenerated by setting
\setupexternalshadow[force=yes]
The default value of force is no.
The generated PNGs are stored in the current directory. To store them in a different directory, say shadow-cache, set
\setupexternalshadow[directory=shadow-cache]
A shadow can be used anywhere an overlay is accepted (so any command which has a background key). The most common use case is a frame. To use a shadow behind a frame, use
\framed[background=soft:light, backgroundcolor=white]{...}
The backgroundcolor=white is needed as we rely on ConTeXt to fill the background color.
The shadow adapts to the corner of the frame; for instance, if we set
\framed[background=soft:light, backgroundcolor=white,
corner=round, radius=3mm]{...}
then, we will get a shadow which has the same shape as the frame (so rounded corners with a radius of 3mm).
The module defines a macro externalshadow[...] to draw a shadow behind closed paths in MetaPost. For example,
\startMPcode
newpath p ;
p := (fullcircle scaled 3cm) randomized 3bp;
draw externalshadow [
path = p,
preset = "soft:light",
fillcolor = "white",
];
\stopMPcode
If the fillcolor is omitted, then the path is not filled.
Currently, open paths are not supported, but it is possible to get the same effect by obtaining the envelope of the path using envelope and treating that as a closed path. For example:
\startMPcode
newpath p ;
p := (0,0) -- (1cm, 1cm) -- (0, 1cm) -- (1cm, 0) ;
draw externalshadow [
path = envelope (makepen fullcircle) scaled 1bp of p,
preset = soft:light,
fillcolor = "black",
];
\stopMPcode
Two things are worth noting. First, we create the envelope of the path using makepen fullcircle rather than pencircle (because envelope pencircle scaled 1bp of p is not implmeneted and gives an error). Second, we set fillcolor to "black"; filling the envelope of a path is effectively the same as drawing it.
A shadow consists of two shadowlayers: umbra and penumbra. Both are defined using
\defineshadowlayer[name][spread=, blur=, transparency=]
spreadis the amount by ...spreadcontrols how far the shadow extends out from the object.blurcontrols how soft the shadow edges look.transparencyis between0and1:0is solid shadow,1is very light shadow.
The default umbra layers are defined as
\defineshadowlayer [soft] [blur=0.85mm,spread=0mm,transparency=0.40]
\defineshadowlayer [hard] [blur=0.35mm,spread=0mm,transparency=0.40]
\defineshadowlayer [flat] [blur=0mm, spread=0mm,transparency=0.40]
And the default penumbra layers are defined as
\defineshadowlayer [light] [blur=1.35mm,spread=0.5mm,transparency=0.70]
\defineshadowlayer [medium] [blur=1.50mm,spread=0.5mm,transparency=0.60]
\defineshadowlayer [dark] [blur=1.85mm,spread=0.5mm,transparency=0.50]
A shadow is defined by combining an umbra and a penumbra. For example:
\defineexternalshadow[soft:light][umbra=soft, penumbra=light]
If you only want one layer, simply don't specify the other. For instance
\defineexternalshadow[umbraonly][umbra=soft, penumbra=]
Other parameters of the shadow are
\defineexternalshadow
[
direction=-45,
offset=1.7mm,
shadowcolor=shadowcolor,
]
Though these are defined as default values for all shadows, they can be changed for individual shadows well.
directionspecifies the angle (in degrees) at which the shadow is cast andoffsetis the distance of the shadow.shadowcoloris the color of the shadow. The default shadow color is a cool dark blue, which gives a softer shadow than pure black.