RoundRectangle.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing

'' 该示例演示了如何绘制圆角矩形
'' 使用专用的 DrawRoundRect/FillRoundRect 方法。
'' 它还显示了如何实现相同的结果
'' 图形路径。
Public Class RoundRectangle
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim g = page.Graphics

        Dim rc = Util.AddNote(
            "GcPdfGraphics 有专门的方法可以轻松绘制和填充圆角矩形。" +
            "",
            page)

        '' 圆角矩形的半径:
        Dim rx = 36, ry = 24

        '' 使用专用方法绘制和填充圆角矩形:
        Dim rEasy = New RectangleF(rc.Left, rc.Bottom + 36, 144, 72)
        g.FillRoundRect(rEasy, rx, ry, Color.PaleGreen)
        g.DrawRoundRect(rEasy, rx, ry, Color.Blue, 4)
        '' 添加标签:
        Dim tf = New TextFormat() With {.Font = StandardFonts.Times, .FontSize = 14}
        g.DrawString("最简单的方法。", tf, rEasy, TextAlignment.Center, ParagraphAlignment.Center, False)

        '' 使用图形路径达到相同的结果:
        Dim rHard = rEasy
        rHard.Offset(0, rEasy.Height + 36)
        Dim path = MakeRoundRect(g, rHard, rx, ry)
        g.FillPath(path, Color.PaleVioletRed)
        g.DrawPath(path, Color.Purple, 4)
        '' 添加标签:
        g.DrawString("艰难的方式。", tf, rHard, TextAlignment.Center, ParagraphAlignment.Center, False)

        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function

    '' 该方法展示了如何创建可能使用的图形路径
    '' 在 GcGraphics 上填充或绘制任意形状。
    Private Function MakeRoundRect(ByVal g As GcGraphics, ByVal rc As RectangleF, ByVal rx As Single, ByVal ry As Single) As IPath
        Dim path = g.CreatePath()
        Dim sz = New SizeF(rx, ry)
        '' 从水平左上角开始:
        path.BeginFigure(New PointF(rc.Left + rx, rc.Top))
        path.AddLine(New PointF(rc.Right - rx, rc.Top))
        path.AddArc(New ArcSegment() With {.Point = New PointF(rc.Right, rc.Top + ry), .SweepDirection = SweepDirection.Clockwise, .Size = sz})
        path.AddLine(New PointF(rc.Right, rc.Bottom - ry))
        path.AddArc(New ArcSegment() With {.Point = New PointF(rc.Right - rx, rc.Bottom), .SweepDirection = SweepDirection.Clockwise, .Size = sz})
        path.AddLine(New PointF(rc.Left + rx, rc.Bottom))
        path.AddArc(New ArcSegment() With {.Point = New PointF(rc.Left, rc.Bottom - ry), .SweepDirection = SweepDirection.Clockwise, .Size = sz})
        path.AddLine(New PointF(rc.Left, rc.Top + ry))
        path.AddArc(New ArcSegment() With {.Point = New PointF(rc.Left + rx, rc.Top), .SweepDirection = SweepDirection.Clockwise, .Size = sz})
        path.EndFigure(FigureEnd.Closed)
        Return path
    End Function
End Class