Skip to content
H1Gdev edited this page Nov 3, 2024 · 88 revisions

SVG

Scalable Vector Graphics

  • svg
    • File extension is .svg.
    • MIME type is image/svg+xml.
  • svgz
    • File extension is .svgz.
    • MIME type is image/svg+xml.
    • Encoding is gzip.

W3C

Latest version

Combinator
|| Concat

MDN

SVG: Scalable Vector Graphics

Software

NuGet version

Svg

Elements

Class Element
SvgFragment <svg>
SvgRectangle <rect>
SvgCircle <circle>
SvgEllipse <ellipse>
SvgLine <line>
SvgPolygon <polygon>
SvgPolyline <polyline>
SvgPath <path>
SvgText <text>
SvgTextSpan <tspan>
SvgDefinitionList <defs>
SvgUnknownElement
NonSvgElement
SvgElement
SvgVisualElement
SvgPathBasedElement SvgTextBase
SvgMarkerElement

SvgElement

Attribute
protected internal virtual SvgAttributeCollection Attributes { get; }
// -> SVG attributes

public SvgCustomAttributeCollection CustomAttributes { get; }
// -> User custom attributes
SvgAttributeCollection
Method
GetAttribute
GetInheritedAttribute == Indexer

attributeValue > parentAttributeValue > defaultValue

SvgVisualElement

Boundary
public abstract GraphicsPath Path(ISvgRenderer renderer);
// renderer
//  null -> Boundary with stroke.
//  other -> Boundary without stroke.

public RectangleF Bounds { get; }
// -> Boundary with stroke.

SvgDocument

  • Load
    • Open
    • FromSvg
      • FlushStyles
  • Set
    • BaseUri (if needed.)
  • Render
    • Draw
      • Render
  • Save
    • Write

SvgElementFactory

SvgElementAttribute

Parameter Description
ElementName

Attributes

TypeConverter

TypeConverter

TypeConverterAttribute

Class Type
SvgUnitConverter length
SvgPaintServerFactory color
SvgPathBuilder path data

SvgPaintServer

SvgElement
SvgPaintServer
SvgColourServer SvgDeferredPaintServer SvgFallbackPaintServer SvgGradientServer SvgPatternServer
SvgLinearGradientServer SvgRadialGradientServer

SpecifyingPaint

SvgAttributeAttribute

Parameter Description
Name
NameSpace Namespace URI.(svg, xml, xlink)

Render

SvgRenderer

  • Implement IGraphicsProvider and ISvgRenderer.
  • Has Graphics.
Graphics settings
public static ISvgRenderer FromImage(Image image)
{
    g.PixelOffsetMode = PixelOffsetMode.Half;
    g.CompositingQuality = CompositingQuality.HighQuality; // for compositing.
    // for text.
    g.TextRenderingHint = TextRenderingHint.AntiAlias;
    g.TextContrast = 1;
}
g.SmoothingMode = SmoothingMode.AntiAlias;
// -> completely horizontal and one width lines are blurred...

Svg.Pathing

Class Command
SvgMoveToSegment M m
SvgClosePathSegment Z z
SvgLineSegment L l
H h
V v
SvgCubicCurveSegment C c
S s
SvgQuadraticCurveSegment Q q
T t
SvgArcSegment A a

Svg.FilterEffects

Elements

Class Element
SvgFilter <filter>
SvgGaussianBlur <feGaussianBlur>
SvgElement
SvgFilter SvgFilterPrimitive

Svg.Css

CSS

  • If destinationType is string, CanConvertTo always returns true and ConvertTo calls ToString.

GDI+(Graphics Device Interface +)

  • Draw
  • Fill
Class Interface .NET Framework SetCompatibleTextRenderingDefault UseCompatibleTextRendering
Graphics GDI+ 1.1 - true true
TextRenderer GDI 2.0 - false false
  • LightGray is LightGrey
  • Origin is Graphics (0, 0).
  • Graphics shape
  • GetBounds()
    • GetBounds() is readonly. (returns Bounds copied.)
    • Bounds is only draw area. (Whitespace character etc. at both ends are not included.)
  • AddPath()
    • AddPath() cannot set empty GraphicsPath(PointCount is zero). (ArgumentException is thrown.)

Remarks

Implements IDisposable

.NET

Download .NET

Target frameworks

microsoft/dotnet

Frameworks

.NET Framework

Assembly

Windows Application

Windows Form

Windows Presentation Foundation (WPF)

  • XAML(eXtensible Application Markup Language)
  • Latest version is WinUI 3.

Documentation

Nuget Nuget