How svg-net/svg works
This project is an SVG library for .NET that provides functionality to parse, create, edit, and render SVG 1.1 images. It is designed as a standalone library (with a NuGet package available) that can be used by any .NET application. In addition to the core library code (found in the Source folder), the project contains sample applications (in the Samples directory), code generators (in the Generators folder), comprehensive test suites (in the Tests directory), and detailed documentation (in the Docs directory).
Main Components
• Core SVG.NET Library:
– This is the heart of the project found under the Source folder. It contains multiple subcomponents such as:
▪ SVG DOM & Document Structure (Document Structure, SvgElement, non-SVG elements, etc.)
▪ Data Types and Converters (found in the DataTypes folder for handling measurement units, aspect ratios, etc.)
▪ CSS Integration (modules under the Css folder)
▪ Filter Effects and Painting (the Filter Effects and Painting directories reveal modules to render gradients, blur, displacement, and other SVG effects)
▪ Transformations (such as translation, rotation, scaling, and skewing located in the Transforms directory)
▪ Text and Font Handling (under the Text folder)
▪ Rendering and Graphics Provider (in the Rendering folder)
▪ Extensions and Helpers (extension methods, helper utilities, and linking features)
• Generators:
– The code in the Generators folder (like AvailableElementsGenerator.cs and related files) is likely used to dynamically generate code or element lists based on the SVG specification.
• Samples:
– Several sample projects (e.g., SVGBuilder, SVGViewer, SvgConsole) demonstrate how an application might consume this library.
• Tests:
– Test suites (unit, benchmark, and web test runners) ensure the library works correctly across diverse scenarios.
• Documentation & CI:
– A Docs folder containing markdown files, API docs, and doc generation scripts; in addition, GitHub workflows and CI tools (build and test workflows) support continuous integration and documentation building.
Out Component Relationships and Interactions
• The Core Library acts as the engine. At its center, the SVG Document Parser produces an internal representation (DOM) of an SVG file. This representation is then used by various modules:
• The Rendering Engine picks the parsed elements and applies styling, transforms, and filter effects before outputting the final rendered image.
• The Element Factory (or SVG Element Creation logic) constructs and manages individual SVG elements.
• Data Type modules and Converters enforce consistency and help parse numeric values, units, etc.
• Extensions and Helpers provide additional operations (e.g., string parsing, linking elements) used across the library.
• The Generators module interacts with the core by providing auto-generated code which may help in updating or extending available SVG elements dynamically.
• Sample applications demonstrate how external client applications call into the library’s APIs to load or render SVG files.
• The Test suites verify components in isolation (unit tests), as well as end-to-end behavior (benchmark, rendering accuracy, and web compliance tests).
• CI/CD (via GitHub workflows) ensures that tests run on each commit and documentation is built automatically.
Architectural Patterns/Design Principles
• Modularity & Separation of Concerns: Each responsibility—parsing, rendering, path building, etc.—resides in separate submodules.
• Layered Abstraction: There is a clear separation between the SVG DOM model, business logic of rendering, and the interfaces that client applications use.
• Extensibility: There are designated extension points (e.g., in the ExtensionMethods and Extensibility directories) which foster customization.
• Testability: Presence of multiple test projects and a robust CI pipeline underscores a focus on maintainability.
Technologies, Frameworks, and Tools
• The project is built using C# for .NET (compatible with .NET Standard 2.0).
• It leverages MSBuild (.csproj files) and includes GitHub workflows for CI.
• NuGet is used for dependencies such as ExCSS.
• Documentation is generated using DocFX (indicated by the docfx.json file in Docs).
Putting It All Together
– SVG Parsing & DOM Building
– Element Factories and Document Structure Management
– Data Types / Converters
– Rendering Pipeline (includes Painting, CSS, and Transformations)
– Filter Effects Processing
– Text and Font Handling
3. Complement this with Sample Applications consuming the library.
4. External layers for Automated Testing, CI/CD, and Documentation, which feed into quality assurance and developer knowledge.
– How SVG files are parsed and converted into an internal DOM,
– How this DOM is manipulated (through modules such as CSS and Transformation),
– And finally, how rendering is performed.