SvgSpecArt.vb
''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Linq
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GrapeCity.Documents.Svg
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' Use GcSvgDocument to render a few images used as illustrations
'' in the SVG spec.
Public Class SvgSpecArt
    Public Function GenerateImage(
            ByVal pixelSize As Size,
            ByVal dpi As Single,
            ByVal opaque As Boolean,
            Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        '' Load images from resources:
        Dim fnames As New List(Of String) From {
            "dash-path.svg", "opacity.svg", "paths.svg", "shadowstyle.svg", "units.svg"
        }
        Dim images As New List(Of Tuple(Of String, GcSvgDocument))()
        For Each f In fnames
            images.Add(Tuple.Create(f, GcSvgDocument.FromFile(Path.Combine("Resources", "SvgSpecArt", f))))
        Next

        Dim margin As Single = dpi / 2.0F
        Dim gapy As Single = dpi / 4.0F
        Dim ip As New PointF(margin, margin)

        '' Render the images:
        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
        Using g = bmp.CreateGraphics(Color.White)
            For i As Integer = 0 To images.Count() - 1
                Dim svg = images(i).Item2
                Dim s = svg.GetIntrinsicSize(SvgLengthUnits.Pixels)
                g.DrawSvg(svg, ip)
                ip.Y += s.Height + gapy
            Next
        End Using

        '' Dispose images after saving the result:
        images.ForEach(Sub(t_) t_.Item2.Dispose())

        '' Done:
        Return bmp
    End Function
End Class