'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystemImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.SvgImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCTEXT = GrapeCity.Documents.Text '' This example shows how to draw on GcSvgGraphics.'' It draws round rectangles using both dedicated DrawRoundRect/FillRoundRect'' methods and graphics paths.'' Note that the code in this sample is identical to the drawing code'' in the RoundRectangle sample, but creates a vector SVG image'' rather than a raster GcBitmap.PublicClassSvgGraphicsRoundRectanglePublicReadOnlyPropertyDefaultMimeAsStringGetReturn Util.MimeTypes.SVGEndGetEndProperty PublicFunctionGenerateImageStream(ByVal targetMime AsString,ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsStream If targetMime <> Util.MimeTypes.SVG ThenThrowNewException("This sample only supports SVG output format.")EndIf Dim Inch = dpiDim ms = NewMemoryStream()Using g AsNewGcSvgGraphics(pixelSize.Width, pixelSize.Height)If opaque Then g.FillRectangle(NewRectangleF(0, 0, g.Width, g.Height), Color.White)EndIf Dim rc = Util.AddNote("GcGraphics has dedicated methods to easily draw and fill rectangles with rounded corners. " &"This sample also shows how the same result may be achieved using graphics paths. " &"While they are not really needed for drawing round rectangles, graphics paths allow " &"to draw and fill arbitrary figures with complex geometries." & vbCrLf & vbCrLf &"Note that this version of the ""Round Rectangles"" sample draws on a GcSvgGraphics, " &"and produces a vector SVG image rather than a raster image (JPEG, PNG etc.).", g) '' Rounded rectangle's radii:Dim rx AsSingle = 36, ry AsSingle = 24 '' Using dedicated methods to draw and fill round rectangles:Dim rEasy = NewRectangleF(rc.Left, rc.Bottom + Inch / 2, Inch * 2, Inch) g.FillRoundRect(rEasy, rx, ry, Color.PaleGreen) g.DrawRoundRect(rEasy, rx, ry, Color.Blue, 4)'' Add a label:Dim tf = NewTextFormat() With { .Font = GCTEXT.Font.FromFile(System.IO.Path.Combine("Resources", "Fonts", "FreeSerif.ttf")), .FontSize = Inch / 6 } g.DrawString("The easy way.", tf, rEasy, TextAlignment.Center, ParagraphAlignment.Center, False) '' Using graphics path to achieve the same result:Dim rHard = rEasy rHard.Offset(0, rEasy.Height + Inch / 2)Dim path = MakeRoundRect(g, rHard, rx, ry) g.FillPath(path, Color.PaleVioletRed) g.DrawPath(path, Color.Purple, 4)'' Add a label: g.DrawString("The hard way.", tf, rHard, TextAlignment.Center, ParagraphAlignment.Center, False) '' Done:Dim svg = g.ToSvgDocument() svg.Save(ms) ms.Seek(0, SeekOrigin.Begin)Return msEndUsingEndFunction '' This method shows how to create a graphics path that may be used'' to fill or draw arbitrary shapes on a GcGraphics.PrivateFunctionMakeRoundRect(g AsGcGraphics, rc AsRectangleF, rx AsSingle, ry AsSingle) AsIPathDim path = g.CreatePath()Dim sz = NewSizeF(rx, ry)'' start from horizontal top left path.BeginFigure(NewPointF(rc.Left + rx, rc.Top)) path.AddLine(NewPointF(rc.Right - rx, rc.Top)) path.AddArc(NewArcSegment() With {.Point = NewPointF(rc.Right, rc.Top + ry), .SweepDirection = SweepDirection.Clockwise, .Size = sz}) path.AddLine(NewPointF(rc.Right, rc.Bottom - ry)) path.AddArc(NewArcSegment() With {.Point = NewPointF(rc.Right - rx, rc.Bottom), .SweepDirection = SweepDirection.Clockwise, .Size = sz}) path.AddLine(NewPointF(rc.Left + rx, rc.Bottom)) path.AddArc(NewArcSegment() With {.Point = NewPointF(rc.Left, rc.Bottom - ry), .SweepDirection = SweepDirection.Clockwise, .Size = sz}) path.AddLine(NewPointF(rc.Left, rc.Top + ry)) path.AddArc(NewArcSegment() With {.Point = NewPointF(rc.Left + rx, rc.Top), .SweepDirection = SweepDirection.Clockwise, .Size = sz}) path.EndFigure(FigureEnd.Closed)Return pathEndFunctionEndClass