<svg>
).<defs>
) - stored here are descriptions of gradients and objects that do not need to be output directly (immediately).<g>
) is the container for the elements to be drawn, which can be referenced if necessary.<path>
) is a set of rules for drawing ("go to a given point", "draw a segment from the current position to a given point"). Both straight line segments, 2nd and 3rd order Bezier curves, and circular arcs are supported.<text>
) - single-line text (in SVG there is no full support for multi-line texts).<linearGradient>
, <radialGradient>
).<clipPath>
region ( <clipPath>
) - sets the shape that can be used for clipping during output.<pattern>
) - sets the shape with which you can fill in closed areas.<mask>
) - specifies an object, alpha-values of which pixels can be used when displaying an arbitrary object.<filter>
) is one of the predefined ways of post-processing a given graphic element (for example, blurring it).<image>
). <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 100 100">
xmlns:xlink="http://www.w3.org/1999/xlink"
- without this attribute, we will not be able to refer to certain elements inside the file (and this is necessary, for example, if we want to print one and same shape or assign a gradient to the element for the fill);width/height
— rather important attributes — define the physical dimensions of the canvas on which the image will be displayed; almost always it is better to specify them (and better in pixels), otherwise some programs will not be able to understand what size the picture we expect to receive during rasterization;viewBox
- sets the coordinates and dimensions of the "vision window"; used by browsers to position the image in the rendering area (i.e., on the canvas), it can be ignored by other programs.<use>
tag is used). Below is an example of setting a group and using links to it. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100"> <defs> <g id="man"> <circle cx="16" cy="25" r="7"/> <path d="m7,44 a9,9 0,0,1 18,0 v20h-18z"/> </g> </defs> <use x="0" y="0" xlink:href="#man" /> <use x="50" y="-18" transform="rotate(15)" fill="blue" xlink:href="#man" /> </svg>
<path>
and private <polygon>
, <circle>
and <rect>
. The following points are interesting:fill-type="nonzero"
- a beam is fill-type="nonzero"
from a point inside the region and the number of its intersections with the lines going clockwise and counterclockwise is considered separately; the region is painted if the numbers do not match;fill-type="evenodd"
- a ray is fill-type="evenodd"
from a point inside the region and counted as the number of intersections with the lines defining the boundary; the region is filled if the number of intersections is odd.canvas
, then there is no problem at all: Context2D.fill()
supports both figures with self-intersections and an indication of the fill method. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="300"> <defs> <g id="g" fill="orange" stroke="black"> <polygon points="47.773,241.534 123.868,8.466 200.427,241.534 7.784,98.208 242.216,98.208" /> </g> </defs> <use x="0" y="0" xlink:href="#g" fill-rule="nonzero" /> <use x="250" y="0" xlink:href="#g" fill-rule="evenodd" /> </svg>
canvas
this is impossible: Context2D
supports the creation of Context2D
; however, it is proposed to use raster images rather than vector ones in their quality. A bypass maneuver here can be rasterization of a vector on a canvas in memory, followed by filling it with a specified area. However, in the general case, this will lead to a serious loss of performance (since it is impossible to rasterize the pattern in advance and use it everywhere because of the ignorance of the scale of the object to be poured). Therefore, remembering that the patterns are rarely used in real artistic vector images, it was decided to abandon their support in the NanoFL.canvas
related methods. Therefore, somewhere there is a sense in writing smart code that will do “like on SVG”, and somewhere, it may be worth refusing to support the functionality for the sake of performance.Source: https://habr.com/ru/post/276519/
All Articles