├── .editorconfig
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── dependabot.yml
└── workflows
│ ├── codeql.yml
│ └── dotnetcore.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Directory.Packages.props
├── LICENSE
├── README.md
├── SvgDocTest
├── .vs
│ └── SvgDocTest.csproj.dtbcache.json
├── App.ico
├── AssemblyInfo.cs
├── Assert.cs
├── DocForm.Designer.cs
├── DocForm.cs
├── DocForm.resx
├── Extensions.cs
├── StringExtensions.cs
├── SvgDocTest.csproj
├── SvgDocTest.csproj.user
└── app.config
├── SvgDotNetCoreTest
├── Program.cs
└── SvgDotNetCoreTest.csproj
├── SvgGdiTest
├── .vs
│ └── SvgGdiTest.csproj.dtbcache.json
├── App.ico
├── AssemblyInfo.cs
├── RectAlignedTextTest.cs
├── SvgGdiTest.csproj
├── SvgGdiTest.csproj.user
├── SvgGdiTestForm.Designer.cs
├── SvgGdiTestForm.cs
├── SvgGdiTestForm.resx
├── TestApp.ndoc
├── app.config
├── test.bmp
└── testdoc.xml
├── SvgNet.sln
├── SvgNet
├── Elements
│ ├── SvgBaseTextElement.cs
│ ├── SvgElement.cs
│ ├── SvgEllipseElement.cs
│ ├── SvgFilterElement.cs
│ ├── SvgGroupElement.cs
│ ├── SvgLineElement.cs
│ ├── SvgLinearGradientElement.cs
│ ├── SvgPathElement.cs
│ ├── SvgPatternElement.cs
│ ├── SvgPolygonElement.cs
│ ├── SvgPolylineElement.cs
│ ├── SvgRadialGradientElement.cs
│ ├── SvgRectElement.cs
│ ├── SvgStopElement.cs
│ ├── SvgStyledElement.cs
│ ├── SvgSvgElement.cs
│ ├── SvgSymbolElement.cs
│ ├── SvgTextElement.cs
│ ├── SvgTitleElement.cs
│ ├── SvgTrefElement.cs
│ ├── SvgTspanElement.cs
│ └── TextNode.cs
├── Exceptions
│ ├── EmfException.cs
│ ├── SvgException.cs
│ └── SvgGdiNotImplementedException.cs
├── Extensions
│ ├── FloatExtensions.cs
│ ├── MatrixExtensions.cs
│ ├── ObjectExtensions.cs
│ ├── StringExtensions.cs
│ └── StringExtensionsForOlderDotNet.cs
├── GlobalSuppressions.cs
├── ImplementedGraphics
│ ├── GDIGraphics.cs
│ ├── SVGGraphics.BitmapDrawer.cs
│ └── SVGGraphics.cs
├── Interfaces
│ ├── IElementWithText.cs
│ ├── IElementWithXRef.cs
│ └── IGraphics.cs
├── MetafileTools
│ ├── EmfTools.cs
│ └── MetafileParser.cs
├── SvgFactory.cs
├── SvgNet.csproj
├── Types
│ ├── PathSeg.cs
│ ├── SvgAngle.cs
│ ├── SvgAngleType.cs
│ ├── SvgColor.cs
│ ├── SvgHelpers.cs
│ ├── SvgLength.cs
│ ├── SvgLengthType.cs
│ ├── SvgNumList.cs
│ ├── SvgNumber.cs
│ ├── SvgPath.cs
│ ├── SvgPathSegType.cs
│ ├── SvgPoints.cs
│ ├── SvgStyle.cs
│ ├── SvgTransform.cs
│ ├── SvgTransformList.cs
│ ├── SvgUriReference.cs
│ └── SvgXRef.cs
└── svgnet.png
├── SvgNetUnitTests
├── Main.cs
├── SvgColorTests.cs
└── SvgNetUnitTests.csproj
├── TestShared
└── TestShared.cs
└── global.json
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "nuget" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "daily"
12 |
--------------------------------------------------------------------------------
/.github/workflows/codeql.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL Advanced"
13 |
14 | on:
15 | push:
16 | branches: [ "main" ]
17 | pull_request:
18 | branches: [ "main" ]
19 | schedule:
20 | - cron: '22 5 * * 3'
21 |
22 | jobs:
23 | analyze:
24 | name: Analyze (${{ matrix.language }})
25 | # Runner size impacts CodeQL analysis time. To learn more, please see:
26 | # - https://gh.io/recommended-hardware-resources-for-running-codeql
27 | # - https://gh.io/supported-runners-and-hardware-resources
28 | # - https://gh.io/using-larger-runners (GitHub.com only)
29 | # Consider using larger runners or machines with greater resources for possible analysis time improvements.
30 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31 | permissions:
32 | # required for all workflows
33 | security-events: write
34 |
35 | # required to fetch internal or private CodeQL packs
36 | packages: read
37 |
38 | # only required for workflows in private repositories
39 | actions: read
40 | contents: read
41 |
42 | strategy:
43 | fail-fast: false
44 | matrix:
45 | include:
46 | - language: csharp
47 | build-mode: manual
48 | # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
49 | # Use `c-cpp` to analyze code written in C, C++ or both
50 | # Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51 | # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52 | # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53 | # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54 | # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55 | # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56 | steps:
57 | - name: Checkout repository
58 | uses: actions/checkout@v4
59 |
60 | # Initializes the CodeQL tools for scanning.
61 | - name: Initialize CodeQL
62 | uses: github/codeql-action/init@v3
63 | with:
64 | languages: ${{ matrix.language }}
65 | build-mode: ${{ matrix.build-mode }}
66 | # If you wish to specify custom queries, you can do so here or in a config file.
67 | # By default, queries listed here will override any specified in a config file.
68 | # Prefix the list here with "+" to use these queries and those in the config file.
69 |
70 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
71 | # queries: security-extended,security-and-quality
72 |
73 | - name: Setup .NET 9.0
74 | uses: actions/setup-dotnet@v4
75 | with:
76 | dotnet-version: 9.0.201
77 |
78 | - shell: bash
79 | run: dotnet build --configuration Release -v:m
80 |
81 | - name: Perform CodeQL Analysis
82 | uses: github/codeql-action/analyze@v3
83 | with:
84 | category: "/language:${{matrix.language}}"
85 |
--------------------------------------------------------------------------------
/.github/workflows/dotnetcore.yml:
--------------------------------------------------------------------------------
1 | name: .NET Core
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v4
12 |
13 | - name: Setup .NET 9.0
14 | uses: actions/setup-dotnet@v4
15 | with:
16 | dotnet-version: 9.0.201
17 |
18 | - shell: bash
19 | run: dotnet build --configuration Release -v:m
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | *.user
4 | *.suo
5 | *.xml
6 | *.userprefs
7 | *.pidb
8 | *.nupkg
9 | test-results/
10 | /packages/
11 | /.vs
12 | InternalTrace.*.log
13 | SvgNet/svgnetdoc.xml
14 | /SvgNet/svgnetdoc.xml
15 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at monoman@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to SvgNet
2 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
3 |
4 | - Reporting a bug
5 | - Discussing the current state of the code
6 | - Submitting a fix
7 | - Proposing new features
8 | - Becoming a maintainer
9 |
10 | ## We Develop with Github
11 | We use github to host code, to track issues and feature requests, as well as accept pull requests.
12 |
13 | ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
14 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
15 |
16 | 1. Fork the repo and create your branch from `main`.
17 | 2. If you've added code that should be tested, add tests.
18 | 3. If you've changed APIs, update the documentation.
19 | 4. Ensure the test suite passes.
20 | 5. Make sure your code follows our standards.
21 | 6. Issue that pull request!
22 |
23 | ## Any contributions you make will be under the *BSD 3-Clause "New" or "Revised" License*
24 | In short, when you submit code changes, your submissions are understood to be under the same [BSD 3-Clause "New" or "Revised" License](https://opensource.org/licenses/BSD-3-Clause) that covers the project. Feel free to contact the maintainers if that's a concern.
25 |
26 | ## Report bugs using Github's [issues](https://github.com/managed-commons/SvgNet/issues)
27 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/managed-commons/SvgNet/issues); it's that easy!
28 |
29 | ## Write bug reports with detail, background, and sample code
30 |
31 | **Great Bug Reports** tend to have:
32 |
33 | - A quick summary and/or background
34 | - Steps to reproduce
35 | - Be specific!
36 | - Give sample code if you can.
37 | - What you expected would happen
38 | - What actually happens
39 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
40 | People *love* thorough bug reports. I'm not even kidding.
41 |
42 | *We have a template for bug reports, please use it.*
43 |
44 | ## Use a Consistent Coding Style
45 | * 4 spaces for indentation rather than tabs
46 | * use the 'dotnet format' following our .editorconfig settings
47 |
48 | ## License
49 | By contributing, you agree that your contributions will be licensed under its *BSD 3-Clause "New" or "Revised" License*.
50 |
51 | ## References
52 | This document was adapted from an adaptation of the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) done by @briandk.
53 |
--------------------------------------------------------------------------------
/Directory.Packages.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | true
5 | $(NoWarn);NU1507
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2003 RiskCare Ltd.
2 | Copyright (c) 2010 SvgNet & SvgGdi Bridge Project
3 | Copyright (c) 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of SvgNet nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SvgNet
2 |
3 | A fork of the SvgNet & SvgGdi bridge (http://www.codeproject.com/KB/cs/svgnet.aspx) to ressurrect it.
4 |
5 | __SvgNet is now available as a Nuget:__ [SvgNet](https://www.nuget.org/packages/SvgNet/).
6 |
7 | __Latest version 3.5.0 is .NET Standard 2.0 and 2.1 and also .NET 8.0/9.0 (base and Windows) compatible and works with .NET Core 2.x and 3.x and .NET 5.0/6.0/7.0/8.0/9.0, but now requires .NET Framework 4.6.2 or higher__
8 |
9 | To build this version properly you need .NET 8.0.404+ & 9.0.100 SDKs installed
10 |
11 | ## License: BSD
12 |
13 | Copyright © 2003 RiskCare Ltd. All rights reserved.
14 |
15 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
16 |
17 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
18 |
19 | Redistribution and use in source and binary forms, with or without
20 | modification, are permitted provided that the following conditions
21 | are met:
22 |
23 | 1. Redistributions of source code must retain the above copyright
24 | notice, this list of conditions and the following disclaimer.
25 | 2. Redistributions in binary form must reproduce the above copyright
26 | notice, this list of conditions and the following disclaimer in the
27 | documentation and/or other materials provided with the distribution.
28 | 3. The name of the author may not be used to endorse or promote products
29 | derived from this software without specific prior written permission.
30 |
31 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 |
--------------------------------------------------------------------------------
/SvgDocTest/.vs/SvgDocTest.csproj.dtbcache.json:
--------------------------------------------------------------------------------
1 | {"RootPath":"D:\\myrepos\\SvgNet\\SvgDocTest","ProjectFileName":"SvgDocTest.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"AssemblyInfo.cs"},{"SourceFile":"Assert.cs"},{"SourceFile":"DocForm.cs"},{"SourceFile":"DocForm.Designer.cs"},{"SourceFile":"StringExtensions.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.7.1.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"D:\\myrepos\\SvgNet\\SvgNet\\bin\\Debug\\net462\\SVG.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":true,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.Drawing.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.Windows.Forms.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.7.1\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"D:\\myrepos\\SvgNet\\SvgDocTest\\bin\\Debug\\SvgDocTest.exe","OutputItemRelativePath":"SvgDocTest.exe"},{"OutputItemFullPath":"D:\\myrepos\\SvgNet\\SvgDocTest\\bin\\Debug\\SvgDocTest.pdb","OutputItemRelativePath":"SvgDocTest.pdb"}],"CopyToOutputEntries":[]}
--------------------------------------------------------------------------------
/SvgDocTest/App.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/managed-commons/SvgNet/9aa368c6dafc05f61f97ad7b1c8ec5eda316ec1a/SvgDocTest/App.ico
--------------------------------------------------------------------------------
/SvgDocTest/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.Reflection;
10 |
11 | [assembly: AssemblyTitle("SvgNet Document Loading Test")]
12 | [assembly: AssemblyDescription("Testing the C# framework for creating SVG images")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("RiskCare Ltd, SvgNet and SvgGdi Bridge Project, Rafael Teixeira, Mojmír Němeček")]
15 | [assembly: AssemblyProduct("SvgNet")]
16 | [assembly: AssemblyCopyright("Copyright 2003, 2010, 2015-2024 RiskCare Ltd, SvgNet and SvgGdi Bridge Project, Rafael Teixeira, Mojmír Němeček, Benjamin Peterson")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 | [assembly: AssemblyVersion("1.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0")]
21 | [assembly: AssemblyInformationalVersion("1.0.0")]
22 | [assembly: AssemblyDelaySign(false)]
23 | [assembly: AssemblyKeyFile("")]
24 | [assembly: AssemblyKeyName("")]
25 |
--------------------------------------------------------------------------------
/SvgDocTest/Assert.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System;
10 |
11 | namespace SvgDocTest {
12 | public static class Assert {
13 | public static void Equals(float a, float b) {
14 | if (a != b) {
15 | throw new Exception("Assert.Equals");
16 | }
17 | }
18 |
19 | public static void Equals(bool a, bool b) {
20 | if (a != b) {
21 | throw new Exception("Assert.Equals");
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/SvgDocTest/DocForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Windows.Forms;
4 |
5 | using SvgNet;
6 | using SvgNet.Elements;
7 | using SvgNet.Types;
8 |
9 | namespace SvgDocTest {
10 | public partial class DocForm : Form {
11 | public DocForm() => InitializeComponent();
12 |
13 | private static readonly string _tempFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");
14 |
15 | ///
16 | /// The main entry point for the application.
17 | ///
18 | [STAThread]
19 | private static void Main() => Application.Run(new DocForm());
20 |
21 | private void Button1_Click(object sender, EventArgs e) {
22 | using (var dlg = new OpenFileDialog {
23 | AutoUpgradeEnabled = true,
24 | CheckFileExists = true,
25 | DefaultExt = ".svg",
26 | Filter = "Scalable Vector Graphics|*.svg",
27 | Multiselect = false,
28 | Title = "Choose one Scalable Vector Graphics file"
29 | }) {
30 | if (dlg.ShowDialog() == DialogResult.OK) {
31 | ProcessSvgFile(dlg.FileName);
32 | }
33 | }
34 | }
35 |
36 | private void Button2_Click(object sender, EventArgs e) {
37 | var root = new SvgSvgElement("4in", "4in", "-10,-10 250,250");
38 |
39 | //adding multiple children
40 |
41 | _ = root.AddChildren(
42 | new SvgRectElement(5, 5, 5, 5),
43 | new SvgEllipseElement(20, 20, 8, 12) {
44 | Style = "fill:yellow;stroke:red"
45 | },
46 |
47 | new SvgAElement("https://github.com/managed-commons/SvgNet").AddChildren(
48 | new SvgTextElement("Textastic!", "30px", "20px") {
49 | Style = "fill:midnightblue;stroke:navy;stroke-width:1px;font-size:30px;font-family:Calibri"
50 | })
51 | );
52 |
53 | //group and path
54 |
55 | var grp = new SvgGroupElement("green_group") {
56 | Style = "fill:green;stroke:black;"
57 | };
58 |
59 | grp.AddChild(new SvgRectElement(30, 30, 5, 20));
60 |
61 | var ell = new SvgEllipseElement {
62 | CX = 50,
63 | CY = 50,
64 | RX = 10,
65 | RY = 20
66 | };
67 |
68 | var pathy = new SvgPathElement {
69 | D = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z",
70 | Style = ell.Style
71 | };
72 |
73 | root.AddChild(grp);
74 |
75 | //cloning and style arithmetic
76 |
77 | _ = grp.AddChildren(ell, pathy);
78 |
79 | grp.Style.Set("fill", "blue");
80 |
81 | var grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);
82 |
83 | grp2.Id = "cloned_red_group";
84 |
85 | grp2.Style.Set("fill", "red");
86 |
87 | grp2.Style += "opacity:0.5";
88 |
89 | grp2.Transform = "scale (1.2, 1.2) translate(10)";
90 |
91 | root.AddChild(grp2);
92 |
93 | //output
94 | SvgFactory.ResetNamespaces();
95 | string s = root.WriteSVGString(true);
96 | tbIn.Text = s;
97 | tbOut.Text = s;
98 |
99 | string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");
100 |
101 | using (var tw = new StreamWriter(tempFile, false))
102 | tw.Write(s);
103 | panelTop.Text = $"Input: {tempFile}";
104 | svgOut.RefreshFrom(tempFile);
105 | svgIn.RefreshFrom(tempFile);
106 | }
107 |
108 | private void Button3_Click(object sender, EventArgs e) {
109 | SvgNumList a = "3, 5.6 901 -7 ";
110 | Assert.Equals(a[3], -7f);
111 |
112 | SvgTransformList b = "rotate ( 45 ), translate (11, 10)skewX(3)";
113 | Assert.Equals(b[1].Matrix.OffsetX, 11f);
114 |
115 | SvgColor c = "rgb( 100%, 100%, 50%)";
116 | Assert.Equals(c.Color.B, 0x7f);
117 |
118 | SvgColor d = "#abc";
119 | Assert.Equals(d.Color.G, 0xbb);
120 |
121 | SvgPath f = "M 5,5 L 1.1 -6 , Q 1,3 9,10 z";
122 | Assert.Equals(f.Count, 4f);
123 | Assert.Equals(f[1].Abs, true);
124 | Assert.Equals(f[2].Data[3], 10f);
125 |
126 | _ = MessageBox.Show("Tests completed Ok");
127 | }
128 | private void ProcessSvgFile(string svgFileName) {
129 | panelTop.Text = $"Input: {svgFileName}";
130 | tbIn.Text = svgFileName.LoadText();
131 | tbOut.Text = SvgFactory.LoadFromXML(svgFileName.LoadXml(), null).WriteSVGString(true);
132 | File.WriteAllText(_tempFileName, tbOut.Text);
133 | svgIn.RefreshFrom(svgFileName);
134 | svgOut.RefreshFrom(_tempFileName);
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/SvgDocTest/DocForm.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/SvgDocTest/Extensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace SvgDocTest {
5 | public static class Extensions {
6 | public static void RefreshFrom(this WebBrowser browser, string filename) {
7 | browser.Navigate(new Uri(filename));
8 | browser.Refresh(WebBrowserRefreshOption.Completely);
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SvgDocTest/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.IO;
10 | using System.Xml;
11 |
12 | namespace SvgDocTest {
13 | public static class StringExtensions {
14 | public static string LoadText(this string svgFileName) => File.ReadAllText(svgFileName);
15 |
16 | public static XmlDocument LoadXml(this string svgFileName) {
17 | var doc = new XmlDocument();
18 | doc.Load(svgFileName);
19 | return doc;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/SvgDocTest/SvgDocTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | net471
7 | Local
8 | App.ico
9 |
10 |
11 | JScript
12 | Grid
13 | IE50
14 | false
15 | WinExe
16 |
17 | false
18 | true
19 | true
20 |
21 |
22 | 285212672
23 |
24 | 4096
25 | false
26 | false
27 | CS1591
28 |
29 |
30 | 285212672
31 |
32 | 4096
33 | false
34 | false
35 | none
36 | CS1591
37 |
38 |
39 |
40 |
41 | System
42 |
43 |
44 | System.Data
45 |
46 |
47 | System.Drawing
48 |
49 |
50 | System.XML
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/SvgDocTest/SvgDocTest.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 |
7 |
8 |
9 | 0
10 | ProjectFiles
11 | 0
12 |
13 |
14 | false
15 | false
16 | false
17 | false
18 | false
19 |
20 | Project
21 |
22 |
23 |
24 |
25 |
26 | true
27 |
28 |
29 | false
30 | false
31 | false
32 | false
33 | false
34 |
35 | Project
36 |
37 |
38 |
39 |
40 |
41 | true
42 |
43 |
44 |
45 | Form
46 |
47 |
48 |
--------------------------------------------------------------------------------
/SvgDocTest/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SvgDotNetCoreTest/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 |
4 | using SvgNet;
5 | using SvgNet.Interfaces;
6 |
7 | namespace SvgDotNetCoreTest;
8 | public static class Program {
9 | public static void Main(string[] args) {
10 | foreach (System.Collections.Generic.KeyValuePair> pair in TestShared.Renderers) {
11 | using var ig = new SvgGraphics(Color.WhiteSmoke);
12 | Console.WriteLine($"=== Renderer {pair.Key}");
13 | pair.Value(ig);
14 | Console.WriteLine(ig.WriteSVGString(640, 480));
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/SvgDotNetCoreTest/SvgDotNetCoreTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | 12
5 | net8.0-windows;net9.0-windows
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/SvgGdiTest/.vs/SvgGdiTest.csproj.dtbcache.json:
--------------------------------------------------------------------------------
1 | {"RootPath":"D:\\myrepos\\SvgNet\\SvgGdiTest","ProjectFileName":"SvgGdiTest.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"RectAlignedTextTest.cs"},{"SourceFile":"..\\TestShared\\TestShared.cs"},{"SourceFile":"AssemblyInfo.cs"},{"SourceFile":"SvgGdiTestForm.Designer.cs"},{"SourceFile":"SvgGdiTestForm.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.6.2.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"D:\\myrepos\\SvgNet\\SvgNet\\bin\\Debug\\net462\\SVG.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":true,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.Drawing.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.Windows.Forms.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.6.2\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"D:\\myrepos\\SvgNet\\SvgGdiTest\\bin\\Debug\\SvgGdiTest.exe","OutputItemRelativePath":"SvgGdiTest.exe"},{"OutputItemFullPath":"D:\\myrepos\\SvgNet\\SvgGdiTest\\bin\\Debug\\SvgGdiTest.pdb","OutputItemRelativePath":"SvgGdiTest.pdb"}],"CopyToOutputEntries":[]}
--------------------------------------------------------------------------------
/SvgGdiTest/App.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/managed-commons/SvgNet/9aa368c6dafc05f61f97ad7b1c8ec5eda316ec1a/SvgGdiTest/App.ico
--------------------------------------------------------------------------------
/SvgGdiTest/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.Reflection;
10 |
11 | [assembly: AssemblyTitle("SvgNet Visual Test")]
12 | [assembly: AssemblyDescription("Testing the C# framework for creating SVG images")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("RiskCare Ltd, SvgNet and SvgGdi Bridge Project, Rafael Teixeira, Mojmír Němeček, Benjamin Peterson")]
15 | [assembly: AssemblyProduct("SvgNet")]
16 | [assembly: AssemblyCopyright("Copyright 2003, 2010, 2015-2024 RiskCare Ltd, SvgNet and SvgGdi Bridge Project, Rafael Teixeira, Mojmír Němeček, Benjamin Peterson")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 | [assembly: AssemblyVersion("1.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0")]
21 | [assembly: AssemblyInformationalVersion("1.0.0")]
22 | [assembly: AssemblyDelaySign(false)]
23 | [assembly: AssemblyKeyFile("")]
24 | [assembly: AssemblyKeyName("")]
25 |
--------------------------------------------------------------------------------
/SvgGdiTest/RectAlignedTextTest.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.Drawing;
10 |
11 | using SvgNet.Interfaces;
12 |
13 | namespace SvgGdiTest;
14 | public static class RectAlignedTextTest {
15 | public static void RenderRectAlignedText(IGraphics ig, float width, float height, Font baseFont) {
16 | ig.Clear(Color.White);
17 | ig.ScaleTransform(width / _canvasSize, height / _canvasSize);
18 | DrawTest(ig, baseFont);
19 | }
20 |
21 | private const int _canvasSize = (3 * _rectSize) + (4 * _rectGap);
22 | private const int _rectFontSize = 20;
23 | private const int _rectGap = 20;
24 | private const int _rectSize = 150;
25 |
26 | private static void DrawRect(IGraphics canvas, string id, Rectangle rect, StringAlignment horizontalAlignment, StringAlignment verticalAlignment, Font baseFont) {
27 | var format = new StringFormat {
28 | Alignment = horizontalAlignment,
29 | LineAlignment = verticalAlignment,
30 | FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip
31 | };
32 |
33 | var pen = new Pen(new SolidBrush(Color.Black), 1);
34 | canvas.DrawRectangle(pen, rect);
35 |
36 | var font = new Font(baseFont.Name, _rectFontSize, baseFont.Style, baseFont.Unit);
37 |
38 | {
39 | // Draw label
40 | var labelFormat = new StringFormat {
41 | Alignment = StringAlignment.Near,
42 | LineAlignment = StringAlignment.Center,
43 | FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip
44 | };
45 | var labelRect = new Rectangle(rect.X, rect.Y - _rectGap, _rectGap, _rectGap);
46 | var labelFont = new Font(baseFont.Name, _rectFontSize * 0.8f, baseFont.Style, baseFont.Unit);
47 | canvas.DrawString(id, labelFont, new SolidBrush(Color.Black), labelRect, labelFormat);
48 | }
49 |
50 | canvas.DrawString("Helloy", font, new SolidBrush(Color.Blue), rect, format);
51 | }
52 |
53 | private static void DrawTest(IGraphics canvas, Font baseFont) {
54 | canvas.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, _canvasSize, _canvasSize));
55 |
56 | var alignments = new StringAlignment[] { StringAlignment.Near, StringAlignment.Center, StringAlignment.Far };
57 |
58 | int id = 1;
59 | foreach (StringAlignment verticalAlignment in alignments)
60 | foreach (StringAlignment horizontalAlignment in alignments) {
61 | int x = _rectGap + ((int)horizontalAlignment * (_rectSize + _rectGap));
62 | int y = _rectGap + ((int)verticalAlignment * (_rectSize + _rectGap));
63 | var rect = new Rectangle(x, y, _rectSize, _rectSize);
64 | DrawRect(canvas, id.ToString(), rect, horizontalAlignment, verticalAlignment, baseFont);
65 | id++;
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/SvgGdiTest/SvgGdiTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | net471
7 | Local
8 | 12
9 | App.ico
10 |
11 |
12 | JScript
13 | Grid
14 | IE50
15 | false
16 | WinExe
17 |
18 | false
19 | true
20 | true
21 |
22 |
23 | 285212672
24 |
25 | testdoc.xml
26 | 4096
27 | false
28 | false
29 | CS1591
30 |
31 |
32 | 285212672
33 |
34 | 4096
35 | false
36 | false
37 | none
38 | CS1591
39 |
40 |
41 |
42 | System
43 |
44 |
45 | System.Data
46 |
47 |
48 | System.Drawing
49 |
50 |
51 | System.XML
52 |
53 |
54 |
55 |
56 | TestShared.cs
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/SvgGdiTest/SvgGdiTest.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 |
7 |
8 |
9 | 0
10 | ProjectFiles
11 | 0
12 |
13 |
14 | false
15 | false
16 | false
17 | false
18 | false
19 |
20 | Project
21 |
22 |
23 |
24 |
25 |
26 | true
27 |
28 |
29 | false
30 | false
31 | false
32 | false
33 | false
34 |
35 | Project
36 |
37 |
38 |
39 |
40 |
41 | true
42 |
43 |
44 |
45 | Form
46 |
47 |
48 |
--------------------------------------------------------------------------------
/SvgGdiTest/SvgGdiTestForm.Designer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.ComponentModel;
10 | using System.Windows.Forms;
11 |
12 | namespace SvgGdiTest {
13 | public partial class SvgGdiTestForm
14 | {
15 | public SvgGdiTestForm()
16 | {
17 | //
18 | // Required for Windows Form Designer support
19 | //
20 | InitializeComponent();
21 | }
22 |
23 | ///
24 | /// Clean up any resources being used.
25 | ///
26 | /// if should be disposing the components
27 | protected override void Dispose(bool disposing)
28 | {
29 | if (disposing)
30 | {
31 | if (components != null)
32 | {
33 | components.Dispose();
34 | }
35 | }
36 | base.Dispose(disposing);
37 | }
38 |
39 | private ComboBox cbWhat;
40 |
41 | ///
42 | /// Required designer variable.
43 | ///
44 | private Container components = null;
45 |
46 | private Label label1;
47 | private Label label2;
48 | private Panel panel1;
49 | private WebBrowser svgCtl;
50 | private TextBox tbSVG;
51 |
52 | ///
53 | /// Required method for Designer support - do not modify
54 | /// the contents of this method with the code editor.
55 | ///
56 | private void InitializeComponent()
57 | {
58 | this.panel1 = new System.Windows.Forms.Panel();
59 | this.tbSVG = new System.Windows.Forms.TextBox();
60 | this.cbWhat = new System.Windows.Forms.ComboBox();
61 | this.label1 = new System.Windows.Forms.Label();
62 | this.label2 = new System.Windows.Forms.Label();
63 | this.svgCtl = new System.Windows.Forms.WebBrowser();
64 | this.SuspendLayout();
65 | //
66 | // panel1
67 | //
68 | this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
69 | this.panel1.Location = new System.Drawing.Point(8, 46);
70 | this.panel1.Name = "panel1";
71 | this.panel1.Size = new System.Drawing.Size(426, 300);
72 | this.panel1.TabIndex = 2;
73 | this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.PanelPaint);
74 | //
75 | // tbSVG
76 | //
77 | this.tbSVG.BackColor = System.Drawing.SystemColors.Info;
78 | this.tbSVG.Font = new System.Drawing.Font("Cascadia Code", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
79 | this.tbSVG.Location = new System.Drawing.Point(440, 46);
80 | this.tbSVG.Multiline = true;
81 | this.tbSVG.Name = "tbSVG";
82 | this.tbSVG.ScrollBars = System.Windows.Forms.ScrollBars.Both;
83 | this.tbSVG.Size = new System.Drawing.Size(664, 643);
84 | this.tbSVG.TabIndex = 3;
85 | //
86 | // cbWhat
87 | //
88 | this.cbWhat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
89 | this.cbWhat.Items.AddRange(new object[] {
90 | "Clipping",
91 | "Transforms",
92 | "Arcs/Pies",
93 | "Lines",
94 | "Curves",
95 | "Transparency",
96 | "Images",
97 | "Text",
98 | "Rect-aligned Text",
99 | "Fills",
100 | "Path",
101 | "Path Polygon",
102 | "Path 2 (Slow)"});
103 | this.cbWhat.Location = new System.Drawing.Point(732, 12);
104 | this.cbWhat.MaxDropDownItems = 30;
105 | this.cbWhat.Name = "cbWhat";
106 | this.cbWhat.Size = new System.Drawing.Size(372, 22);
107 | this.cbWhat.TabIndex = 5;
108 | this.cbWhat.SelectedIndexChanged += new System.EventHandler(this.ComboWhat_SelectedIndexChanged);
109 | //
110 | // label1
111 | //
112 | this.label1.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
113 | this.label1.Location = new System.Drawing.Point(8, 26);
114 | this.label1.Name = "label1";
115 | this.label1.Size = new System.Drawing.Size(72, 17);
116 | this.label1.TabIndex = 6;
117 | this.label1.Text = "GDI:";
118 | //
119 | // label2
120 | //
121 | this.label2.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
122 | this.label2.Location = new System.Drawing.Point(8, 365);
123 | this.label2.Name = "label2";
124 | this.label2.Size = new System.Drawing.Size(72, 21);
125 | this.label2.TabIndex = 7;
126 | this.label2.Text = "SVG:";
127 | //
128 | // svgCtl
129 | //
130 | this.svgCtl.Location = new System.Drawing.Point(8, 389);
131 | this.svgCtl.MinimumSize = new System.Drawing.Size(20, 20);
132 | this.svgCtl.Name = "svgCtl";
133 | this.svgCtl.Size = new System.Drawing.Size(426, 300);
134 | this.svgCtl.TabIndex = 8;
135 | //
136 | // SvgGdiTestForm
137 | //
138 | this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
139 | this.ClientSize = new System.Drawing.Size(1116, 697);
140 | this.Controls.Add(this.svgCtl);
141 | this.Controls.Add(this.label2);
142 | this.Controls.Add(this.label1);
143 | this.Controls.Add(this.cbWhat);
144 | this.Controls.Add(this.tbSVG);
145 | this.Controls.Add(this.panel1);
146 | this.Font = new System.Drawing.Font("Calibri", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
147 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
148 | this.MaximizeBox = false;
149 | this.Name = "SvgGdiTestForm";
150 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
151 | this.Text = "SvgNet.SvgGdi demonstration/test app";
152 | this.Load += new System.EventHandler(this.SvgGdiTestForm_Load);
153 | this.ResumeLayout(false);
154 | this.PerformLayout();
155 |
156 | }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/SvgGdiTest/SvgGdiTestForm.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System;
10 | using System.Drawing;
11 | using System.Drawing.Drawing2D;
12 | using System.Globalization;
13 | using System.IO;
14 | using System.Linq;
15 | using System.Threading;
16 | using System.Windows.Forms;
17 |
18 | using SvgNet;
19 | using SvgNet.Interfaces;
20 |
21 | namespace SvgGdiTest;
22 | ///
23 | /// Summary description for Form1.
24 | ///
25 | public partial class SvgGdiTestForm : Form {
26 | ///
27 | /// The main entry point for the application.
28 | ///
29 | [STAThread]
30 | private static void Main() {
31 | Thread.CurrentThread.CurrentCulture = new CultureInfo("nb-NO"); // To catch culture formatting errors
32 | Application.Run(new SvgGdiTestForm());
33 | }
34 |
35 | private void ComboWhat_SelectedIndexChanged(object sender, EventArgs e) {
36 | using var ig = new SvgGraphics(Color.WhiteSmoke);
37 | Render(ig);
38 | string s = ig.WriteSVGString();
39 | tbSVG.Text = s;
40 | string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");
41 | var tw = new StreamWriter(tempFile, false);
42 | tw.Write(s);
43 | tw.Close();
44 |
45 | svgCtl.Navigate(new Uri(tempFile));
46 | svgCtl.Refresh(WebBrowserRefreshOption.Completely);
47 |
48 | panel1.Invalidate();
49 | }
50 |
51 | private void PanelPaint(object sender, PaintEventArgs e) {
52 | Graphics g = e.Graphics;
53 | Render(new GdiGraphics(g));
54 | g.Flush();
55 | }
56 |
57 | private void Render(IGraphics ig) {
58 | string s = cbWhat.Text;
59 | if (string.IsNullOrEmpty(s))
60 | return;
61 | if (TestShared.Renderers.ContainsKey(s))
62 | TestShared.Renderers[s](ig);
63 | else
64 | throw new NotImplementedException();
65 | }
66 |
67 | private void RenderImages(IGraphics ig) {
68 | var ike = new Icon(GetType(), "App.ico");
69 | ig.DrawIcon(ike, 10, 10);
70 | ig.DrawIcon(ike, new Rectangle(50, 10, ike.Width * 2, ike.Height * 3));
71 |
72 | var bmp = new Bitmap(GetType(), "test.bmp");
73 | ig.DrawImage(bmp, 100f, 150f);
74 | GraphicsContainer cnt = ig.BeginContainer();
75 | ig.RotateTransform(7.5f);
76 | ig.DrawImage(bmp, 160f, 50f, 120f, 70f);
77 | ig.EndContainer(cnt);
78 | //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20);
79 | }
80 |
81 | private void SvgGdiTestForm_Load(object sender, EventArgs e) {
82 | TestShared.Renderers.Add("Images", RenderImages);
83 | TestShared.Renderers.Add("Text Rect Aligned", ig => RectAlignedTextTest.RenderRectAlignedText(ig, panel1.ClientSize.Width, panel1.ClientSize.Height, Font));
84 | cbWhat.Items.Clear();
85 | cbWhat.Items.AddRange([.. TestShared.Renderers.Keys.OrderBy(s => s)]);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/SvgGdiTest/SvgGdiTestForm.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/SvgGdiTest/TestApp.ndoc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/SvgGdiTest/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SvgGdiTest/test.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/managed-commons/SvgNet/9aa368c6dafc05f61f97ad7b1c8ec5eda316ec1a/SvgGdiTest/test.bmp
--------------------------------------------------------------------------------
/SvgGdiTest/testdoc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SvgGdiTest
5 |
6 |
7 |
8 |
9 | Summary description for Form1.
10 |
11 |
12 |
13 |
14 | The main entry point for the application.
15 |
16 |
17 |
18 |
19 | Clean up any resources being used.
20 |
21 | if should be disposing the components
22 |
23 |
24 |
25 | Required designer variable.
26 |
27 |
28 |
29 |
30 | Required method for Designer support - do not modify
31 | the contents of this method with the code editor.
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/SvgNet.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 17
3 | VisualStudioVersion = 17.0.31825.309
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgNet", "SvgNet\SvgNet.csproj", "{BB4C8021-B5E1-4DE2-82CB-14BDFB9837E4}"
6 | EndProject
7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgDocTest", "SvgDocTest\SvgDocTest.csproj", "{6A203A21-673D-45E1-A7F5-D7112E114D6E}"
8 | EndProject
9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgGdiTest", "SvgGdiTest\SvgGdiTest.csproj", "{0C963EB6-C1B4-453D-B694-E81EC26D3AB9}"
10 | EndProject
11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{45898DE7-2090-4F7C-B198-A5D7A15447FF}"
12 | ProjectSection(SolutionItems) = preProject
13 | .editorconfig = .editorconfig
14 | .gitignore = .gitignore
15 | .github\workflows\codeql.yml = .github\workflows\codeql.yml
16 | .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
17 | global.json = global.json
18 | LICENSE = LICENSE
19 | README.md = README.md
20 | EndProjectSection
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgDotNetCoreTest", "SvgDotNetCoreTest\SvgDotNetCoreTest.csproj", "{0AE45FD9-68B8-4232-A8C0-7D9E446F73C9}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SvgNetUnitTests", "SvgNetUnitTests\SvgNetUnitTests.csproj", "{5510CC3E-821A-45F8-AE32-77B9E49BA0DE}"
25 | EndProject
26 | Global
27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
28 | Debug|Any CPU = Debug|Any CPU
29 | Release|Any CPU = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
32 | {BB4C8021-B5E1-4DE2-82CB-14BDFB9837E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {BB4C8021-B5E1-4DE2-82CB-14BDFB9837E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {BB4C8021-B5E1-4DE2-82CB-14BDFB9837E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {BB4C8021-B5E1-4DE2-82CB-14BDFB9837E4}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {6A203A21-673D-45E1-A7F5-D7112E114D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {6A203A21-673D-45E1-A7F5-D7112E114D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {6A203A21-673D-45E1-A7F5-D7112E114D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {6A203A21-673D-45E1-A7F5-D7112E114D6E}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {0C963EB6-C1B4-453D-B694-E81EC26D3AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {0C963EB6-C1B4-453D-B694-E81EC26D3AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {0C963EB6-C1B4-453D-B694-E81EC26D3AB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {0C963EB6-C1B4-453D-B694-E81EC26D3AB9}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {0AE45FD9-68B8-4232-A8C0-7D9E446F73C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {0AE45FD9-68B8-4232-A8C0-7D9E446F73C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {0AE45FD9-68B8-4232-A8C0-7D9E446F73C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {0AE45FD9-68B8-4232-A8C0-7D9E446F73C9}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {5510CC3E-821A-45F8-AE32-77B9E49BA0DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {5510CC3E-821A-45F8-AE32-77B9E49BA0DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {5510CC3E-821A-45F8-AE32-77B9E49BA0DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {5510CC3E-821A-45F8-AE32-77B9E49BA0DE}.Release|Any CPU.Build.0 = Release|Any CPU
52 | EndGlobalSection
53 | GlobalSection(SolutionProperties) = preSolution
54 | HideSolutionNode = FALSE
55 | EndGlobalSection
56 | GlobalSection(ExtensibilityGlobals) = postSolution
57 | SolutionGuid = {CFB59A8F-8484-428B-B69E-0FAADCD5CC77}
58 | EndGlobalSection
59 | EndGlobal
60 |
--------------------------------------------------------------------------------
/SvgNet/Elements/SvgBaseTextElement.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | namespace SvgNet.Elements;
10 | public abstract class SvgBaseTextElement : SvgStyledTransformedElement {
11 | public SvgLength DX {
12 | get => (SvgLength)_atts["dx"];
13 | set => _atts["dx"] = value;
14 | }
15 |
16 | public SvgLength DY {
17 | get => (SvgLength)_atts["dy"];
18 | set => _atts["dy"] = value;
19 | }
20 |
21 | public string LengthAdjust {
22 | get => (string)_atts["lengthAdjust"];
23 | set => _atts["lengthAdjust"] = value;
24 | }
25 |
26 | public SvgNumList Rotate {
27 | get => (SvgNumList)_atts["rotate"];
28 | set => _atts["rotate"] = value;
29 | }
30 |
31 | public SvgLength X {
32 | get => (SvgLength)_atts["x"];
33 | set => _atts["x"] = value;
34 | }
35 |
36 | public SvgLength Y {
37 | get => (SvgLength)_atts["y"];
38 | set => _atts["y"] = value;
39 | }
40 | }
--------------------------------------------------------------------------------
/SvgNet/Elements/SvgElement.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2003 RiskCare Ltd. All rights reserved.
3 | Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4 | Copyright © 2015-2024 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5 |
6 | Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7 | */
8 |
9 | using System.Xml;
10 |
11 | using SvgNet.Elements;
12 |
13 | namespace SvgNet.Elements;
14 | ///
15 | /// The base class for SVG elements. It represents some part of an SVG document, either an element (rect, circle etc) or a text item. Duties include:
16 | ///
17 | /// -
18 | ///
19 | /// Maintains a list of child elements and a list of attributes.
20 | ///
21 | ///
22 | /// -
23 | ///
24 | /// Writes itself and its children to an Xml document.
25 | ///
26 | ///
27 | /// -
28 | ///
29 | /// Reads itself and its children from an Xml document.
30 | ///
31 | ///
32 | ///
33 | ///
34 | public class SvgElement {
35 | public SvgElement() => Id = GenerateNewId();
36 |
37 | public SvgElement(string id) => Id = id;
38 |
39 | ///
40 | /// A hashtable containing this element's attributes. Keys are strings but values can be any type; they will only be
41 | /// reduced to strings when this element needs to convert itself to XML.
42 | ///
43 | public Hashtable Attributes => _atts;
44 |
45 | ///
46 | /// An ArrayList containing this element's children
47 | ///
48 | public ArrayList Children { get; protected set; } = [];
49 |
50 | public string Id {
51 | get => (string)_atts["id"];
52 | set => _atts["id"] = value;
53 | }
54 |
55 | ///
56 | /// The name of the XML element that this SVG element represents.
57 | ///
58 | public virtual string Name => "?";
59 |
60 | public SvgElement Parent { get; protected set; }
61 |
62 | ///
63 | /// The element whose child this element is; can be null, because SvgElements may only be inserted into a full SVG tree
64 | /// long after they are created.
65 | ///
66 | ///
67 | /// A quick way to get and set attributes.
68 | ///
69 | public object this[string attname] {
70 | get => _atts[attname];
71 | set => _atts[attname] = value;
72 | }
73 |
74 | ///
75 | /// Adds a child, and sets the child's parent to this element.
76 | ///
77 | ///
78 | public virtual void AddChild(SvgElement ch) {
79 | if (ch.Parent != null) throw new SvgException("Child already has a parent", ch.ToString());
80 |
81 | _ = Children.Add(ch);
82 | ch.Parent = this;
83 | }
84 |
85 | ///
86 | /// Adds a variable number of children
87 | ///
88 | ///
89 | public virtual SvgElement AddChildren(params SvgElement[] ch) {
90 | foreach (SvgElement el in ch) AddChild(el);
91 | return this;
92 | }
93 |
94 | ///
95 | /// Given a document and a current node, read this element from the node.
96 | ///
97 | ///
98 | ///
99 | public virtual void ReadXmlElement(XmlDocument doc, XmlElement el) {
100 | foreach (XmlAttribute att in el.Attributes)
101 | if (att.Name.StartsWith("xmlns", StringComparison.Ordinal))
102 | #if NET5_0_OR_GREATER
103 | SvgFactory._namespaces.TryAdd(att.Name, att.Value);
104 | #else
105 | {
106 | if (!SvgFactory._namespaces.ContainsKey(att.Name))
107 | SvgFactory._namespaces.Add(att.Name, att.Value);
108 | }
109 | #endif
110 | else
111 | this[att.Name] = att.Value;
112 | }
113 |
114 | ///
115 | /// A simple ToString() for use in debugging.
116 | ///
117 | ///
118 | public override string ToString() => "<" + Name + " id='" + Id + "'/>";
119 |
120 | ///
121 | /// Get a string that contains a complete SVG document. XML version, DOCTYPE etc are included.
122 | ///
123 | ///
124 | /// Should usually be set true. Causes the XML output to be optimized so that
125 | /// long attributes like styles and transformations are represented with entities.
126 | public string WriteSVGString(bool compressAttributes) =>
127 | WriteSVGString(compressAttributes, null);
128 |
129 | ///
130 | /// Get a string that contains a complete SVG document. XML version, DOCTYPE etc are included.
131 | ///
132 | ///
133 | /// Should usually be set true. Causes the XML output to be optimized so that
134 | /// long attributes like styles and transformations are represented with entities.
135 | /// Width/Height values to add as attributes to the svg element
136 | public string WriteSVGString(bool compressAttributes, SizeF? bounds) {
137 | var doc = new XmlDocument();
138 |
139 | XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, "yes");
140 | _ = doc.AppendChild(declaration);
141 |
142 | //write out our SVG tree to the new XmlDocument
143 | WriteXmlElements(doc, null);
144 |
145 | foreach (KeyValuePair pair in SvgFactory._namespaces)
146 | doc.DocumentElement.SetAttribute(pair.Key, pair.Value);
147 | string ents = string.Empty;
148 | if (compressAttributes)
149 | ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
150 | if (bounds != null) {
151 | doc.DocumentElement.SetAttribute("width", bounds.Value.Width.ToInvariantString());
152 | doc.DocumentElement.SetAttribute("height", bounds.Value.Height.ToInvariantString());
153 | }
154 | doc.XmlResolver = new DummyXmlResolver();
155 | _ = doc.InsertAfter(
156 | doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents),
157 | declaration
158 | );
159 | return ToXmlString(doc);
160 | }
161 |
162 | ///
163 | /// Given an XML document and a parent node, write out this node and its descendants as XmlElements.
164 | ///
165 | /// A document
166 | /// A node, or null if this element is to be the root element
167 | public virtual void WriteXmlElements(XmlDocument doc, XmlElement parent) {
168 | XmlElement me = doc.CreateElement("", Name, doc.NamespaceURI);
169 | foreach (string s in _atts.Keys) _ = _atts[s] switch {
170 | float singleValue => me.SetAttribute(s, doc.NamespaceURI, singleValue.ToString(CultureInfo.InvariantCulture)),
171 | double doubleValue => me.SetAttribute(s, doc.NamespaceURI, doubleValue.ToString(CultureInfo.InvariantCulture)),
172 | _ => SetAttribute(doc, me, s, _atts[s].ToString()),
173 | };
174 |
175 | foreach (SvgElement el in Children) el.WriteXmlElements(doc, me);
176 |
177 | _ = parent == null ? doc.AppendChild(me) : parent.AppendChild(me);
178 | }
179 |
180 | protected Hashtable _atts = [];
181 | protected object FirstChild => Children[0];
182 |
183 | protected T GetTypedAttribute(string attributeName, Func