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

'' This example shows how to draw a table with cells spanning multiple rows and columns,
'' using the GrapeCity.Documents.Drawing.TableRenderer and related classes.
Public Class TableCellSpans
    Public Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
        Using g = bmp.CreateGraphics(Color.White)
            DrawTable(g, pixelSize.Width, pixelSize.Height)
        End Using
        Return bmp
    End Function

    Private Shared Sub DrawTable(g As GcGraphics, pageWidth As Single, pageHeight As Single)
        Dim host = New LayoutHost()
        Dim view = host.CreateView(pageWidth, pageHeight)

        Dim rt = view.CreateRect()
        rt.AnchorTopLeftRight(Nothing, 30, 20, 20)

        Dim ta = New TableRenderer(g,
            rt, FixedTableSides.TopLeftRight,
            rowCount:=5,
            columnCount:=4,
            gridLineColor:=Color.CornflowerBlue,
            gridLineWidth:=5,
            rowMinHeight:=50,
            columnMinWidth:=120)

        '' We set a "star" (weighted) width for the third column so that the table
        '' can expand since both the left and right sides of the table are fixed.
        ta.ColumnRects(2).SetStarWidth(1F)

        ta.DefaultCellStyle = New CellStyle() With
            {
                .LineWidth = 1,
                .LineColor = Color.Coral,
                .LinePaddingAll = 2,
                .PaddingAll = 5,
                .TextFormat = New TextFormat() With
                    {
                        .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")),
                        .FontSizeInGraphicUnits = True,
                        .FontSize = 16
                    }
            }

        '' AddCell()'s first 4 arguments are rowIndex, columnIndex, rowSpan, columnSpan:
        ta.AddCell(0, 0, 1, 1, "1 2 3 4 5 6 7 8 9 0.")
        ta.AddCell(0, 1, 2, 2, "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " &
                "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 " &
                "4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0.")
        ta.AddCell(2, 2, 3, 1, "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " &
                "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 " &
                "4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 " &
                "7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0.")
        ta.AddCell(1, 3, 3, 1, "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " &
                "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0.")
        ta.AddCell(4, 1, 1, 1, "1 2 3 4 5.")
        ta.AddCell(3, 0, 2, 1)

        ta.AddMissingCells()

        ta.Render()
    End Sub
End Class