XML technologies / SVG / Filters, transformations and gradients / Solutions
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
Use the following tag to create and format the text:
<text x="10" y="60" style="font-size:46px;font-weight:bolder;fill:none;stroke:black">Text</text>Define the gradient with the tag
<linearGradient>, then assign it with thefillproperty:
<defs>
<linearGradient id="weissrot">
<stop offset="5%" style="stop-color:white"/>
<stop offset="100%" style="stop-color:red"/>
</linearGradient>
</defs>
<text x="10" y="60" style="font-size:46px;font-weight:bolder;fill:url(#weissrot); stroke:black">Text</text>
For example, a 3D effect can be obtained with the filter
<feComposite>. Alternatives exist, so the following code is only one possible solution.
<filter id="out">
<feOffset dx="+2" dy="+2" in="SourceGraphic" result="3d"/>
<feComposite in2="SourceGraphic" in="3d" operator="out"/>
</filter>
<text x="10" y="60" style="font-size:46px;font-weight:bolder;filter:url(#out);fill:url(#weissrot);stroke:black">Text</text>
To add the shadow, adjust the filter as follows. Several solutions are possible here too.
<filter id="out">
<feGaussianBlur in="SourceAlpha" stdDeviation="3" result="Schatten"/>
<feOffset dx="+2" dy="+2" in="SourceGraphic" result="3d"/>
<feComposite in2="Schatten" in="3d" operator="over" result="3dBild"/>
<feComposite in="3dBild" in2="SourceGraphic" operator="out" result="3dBild"/>
</filter>
To produce the lighting effect, extend the filters as follows:
<filter id="out">
...
<feDiffuseLighting in="3dBild" diffuseConstant="1" surfaceScale="10" style="lighting-color:yellow" result="licht">
<feSpotLight x="0" y="0" z="25" pointsAtX="10" pointsAtY="60" pointsAtZ="0" specularExponent="0.01"/>
</feDiffuseLighting>
</filter>
To create the pattern, use another filter, assigning it to the rectangle with the
styleattribute. Define the rectangle before the text, or it will lie over the text instead of behind it.
<filter id="muster">
<feTurbulence in="SourceGraphic" baseFrequency="0.02" numOctaves="1" seed="2" type="turbulence"/>
</filter>
...
<rect x="0" y="10" width="120" height="70" style="filter:url(#muster)"/>
Group the elements with the
<g>tag; skew them using the instructionskewXof thetransformtag:
<g transform="skewX(30)">
...
</g>
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de
back to top