SVG geometry and raster filters

Clipping accepts paths, basic shapes, text and local use references. Child silhouettes are united, clip-rule is inherited, transforms are applied, and clipPathUnits="objectBoundingBox" maps normalized content to the target's geometric bounds. Empty clips hide their targets. Definitions and circular references do not paint.

Nested svg elements establish independent percentage-length contexts, viewport position/dimensions, viewBoxes, meet/slice/none aspect ratios and overflow clipping. Symbol viewBoxes also establish the percentage context for their content. Local use references preserve their target's parent after rendering and circular references are ignored.

textPath lays out glyph outlines along a referenced path, rotates them to the path tangent, and supports startOffset (including percentages), text anchoring and nested styled spans. Glyphs whose midpoints are outside the path are omitted. This does not implement text stretching/automatic spacing, vertical text-on-path or pathLength calibration.

Patterns support independent patternUnits and patternContentUnits, tile origin/dimensions, viewBox/aspect ratio, transforms, opacity and local href templates (including forward references). Brushes are constructed per target bounds, so sharing a pattern between differently sized objects is safe. Circular pattern painting returns transparent content. Pattern overflow is clipped to the tile.

feTurbulence and feDisplacementMap use a bounded CPU raster pipeline. Turbulence provides four seeded channels, turbulence/fractalNoise, one or two base frequencies, up to nine octaves and tile stitching, using the SVG 1.1 noise generator. Displacement uses unpremultiplied R/G/B/A selectors, signed scale and bilinear sampling with transparent pixels outside the input.

Standalone filters and chains support SourceGraphic/SourceAlpha, named results, primitive subregions, filter/primitive coordinate units, sRGB/linearRGB conversion, flood, offset, merge, composite, color matrices (including saturation, hue rotation and luminance-to-alpha), component transfer, blend, Gaussian blur, morphology, tile, convolution and drop shadows. Component transfer implements identity, linear, gamma, table and discrete functions on unpremultiplied channels. Blend implements separable and nonseparable CSS blend modes. Gaussian blur uses three separable box convolutions, keeping work linear in the image size even for large radii. Morphology uses sliding extrema for erosion/dilation. Tile repeats the input subregion, including its transparent pixels. Unsupported primitive types are currently passed through; this is not a complete SVG filter graph implementation. Single matrix/saturation filters retain a vector paint mapping when native animations are enabled to preserve child clocks.

Element opacity is applied after the filter; fill/stroke opacity is part of SourceGraphic. Radial gradients retain their focal point in the same coordinate space as the center, and gradient/pattern brushes preserve per-use opacity. CSS colors accept RGB/RGBA, HSL/HSLA, percentage channels and short/long RGBA hex notation. Gradient stops clamp offsets monotonically, and gradients honor pad/repeat/reflect spreading.

SVG path data is parsed segment by segment, including single-token adjacent arc flags and reflected curve controls. Invalid data stops the current path at its last complete segment instead of aborting the SVG. Polygon/polyline lists likewise retain valid pairs before invalid data and ignore an unmatched final coordinate. Empty paths and point lists are safe.

Raster filters sample the source at load time; animation of the filtered source or filter parameters does not update their bitmap. Rasterization uses up to four pixels per user unit and a maximum dimension of 2048 pixels. This bounds memory use but limits magnification quality. The geometry and animation features remain vector-based outside these raster filter chains.

Run the regression runner with RESVG_TEST_SUITE pointing to a local checkout of linebender/resvg-test-suite to additionally compare path, polygon/polyline and supported filter cases against its reference PNGs. The huge-blur, transformed-tile and two out-of-range saturation fixtures are checked for successful rendering only: the huge-blur reference has implementation-specific artifacts and the other fixtures are explicitly marked undefined behavior upstream. Image comparisons allow small rasterization differences, with a wider tolerance for repeated tile edges and fractional morphology radii. Reference SVGs/PNGs and downloaded animation examples are kept outside this repository.

Convolution supports rectangular kernels, 180-degree kernel rotation, target positions, divisors/bias, duplicate/wrap/transparent edges, optional kernel spacing and unpremultiplied RGB with preserveAlpha. Invalid orders/kernel counts pass through their input; a zero divisor uses the default kernel sum (or one for a zero sum), as specified by Filter Effects. Historical resvg malformed-input references differ from those rules and are not treated as portable pixel expectations. Without explicit kernel spacing, convolution samples the internal raster grid; its output can differ slightly between raster resolutions. Drop shadows blur SourceAlpha, color it with flood color/opacity, offset it and composite the source above the shadow.

Clip circle/ellipse center/radius and transform animations preserve native WPF clocks through clip unions and coordinate wrappers. clipping_css.svg is checked directly, including image visibility, repeated frames and a separately advancing live clip clock.

For a progressive preview, set SVGRender.UseFilters = false, load the SVG, then set UseFilters = true and call CreateDrawing(renderer.SVG). This reuses the parsed document. Clipping, mask compositing and opacity remain enabled, while filters inside masks follow the same setting. The sample car runs both passes on one background STA and freezes each drawing before handing it to the UI; the completed render replaces the preview rather than mutating it.

Lighting, images and backdrop inputs

Diffuse/specular lighting treats input alpha as a height map and derives Sobel normals, including edge and corner cases. Light sources support distant directions, point positions and spot direction/exponent/cone controls. Lighting honors sRGB/linearRGB, CSS lighting-color/currentColor, constants and kernel spacing. Diffuse output is opaque; specular alpha is the largest clamped RGB component. See Filter Effects lighting rules.

feImage can reference a local element using use-like coordinates, load a raster/SVG data URI, or request an external resource through IExternalFileLoader. External image placement supports meet/slice/none alignment. Relative files inside external SVGs keep their source base; embedded resources resolve beside their containing SVG. Missing/invalid images and cyclic references produce transparent input. SVG fragments use the document viewport; full defer and intrinsic-sizing behavior remains incomplete.

BackgroundImage and BackgroundAlpha implement the SVG 1.1 background-buffer model. enable-background:new starts/reset a buffer; optional four-number bounds clip it. Only earlier siblings enter a filter snapshot, and snapshots map into the target's local coordinates. Group opacity, filters, clipping and masks apply when that group is composited rather than being baked into its children's backdrop. Without an enabled buffer, background inputs are transparent. Background capture is skipped for documents without those inputs.

SVGRender.RasterizationScale controls pixels per user unit (default four, longest side capped at 2048). Default lighting normals use the filter pixel grid, so output depends on sampling resolution. All raster filter inputs remain load-time snapshots; animated lighting/image/background updates are not implemented.