RotatedTableText.vb
C# VB
'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.DrawingImports System.IOImports GrapeCity.Documents.DrawingImports GrapeCity.Documents.TextImports GrapeCity.Documents.ImagingImports GrapeCity.Documents.LayoutImports GCTEXT = GrapeCity.Documents.Text
'' This example shows how to draw a table with cells containing rotated texts,'' using the GrapeCity.Documents.Drawing.TableRenderer and related classes.Public Class RotatedTableText 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:=9, columnCount:=7, gridLineColor:=Color.Transparent, gridLineWidth:=1, rowMinHeight:=20, columnMinWidth:=20)
'' We set a "star" (weighted) width for the seventh column so that the table '' can expand since both the left and right sides of the table are fixed. ta.ColumnRects(6).SetStarWidth(1F)
ta.RowRects(8).AppendMinHeight(70)
Dim fmtNorm = New TextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")), .FontSize = 16F, .FontSizeInGraphicUnits = True }
Dim cs = New CellStyle() With { .LineWidth = 1, .LineColor = Color.Coral, .LinePaddingAll = 1, .CornerRadius = 5, .FillColor = Color.Snow, .PaddingLeftRight = 10, .PaddingTop = 2, .PaddingBottom = 5, .TextAlignment = TextAlignment.Center, .TextFormat = fmtNorm } ta.DefaultCellStyle = cs
ta.TableFrameStyle = New FrameStyle() With { .LineWidth = 1, .LineColor = Color.CornflowerBlue, .LinePaddingAll = -3, .CornerRadius = 5, .FillColor = Color.MistyRose }
'' To adjust a column width automatically we need to set '' the FixedWidth property the CellStyle to false. Dim csFlexW = New CellStyle(cs) With { .FixedWidth = False } Dim cs270 = New CellStyle(cs) With { .RotationAngle = 270 } '' A rotated cell also has a fixed width (which is actually a height) by default. '' If we set FixedWidth to false, the row height will be adjusted automatically. Dim cs270FlexH = New CellStyle(cs) With { .RotationAngle = 270, .ParagraphAlignment = ParagraphAlignment.Center, .FixedWidth = False, .MaxWidth = 120 }
ta.AddCell(0, 1, 1, 3, "Title 1 with a long text") ta.AddCell(New CellStyle(cs) With {.ParagraphAlignment = ParagraphAlignment.Center}, 0, 4, 1, 3, "Title 2")
ta.AddCell(cs270, 1, 1, 2, 1, "Vertical Title 1") ta.AddCell(cs270, 1, 2, 2, 1, "Vertical Title 2 with additional text") ta.AddCell(cs270, 1, 3, 2, 1, "Vertical Title 3")
ta.AddCell(1, 4, 1, 2, "Subtitle 2.1")
ta.AddCell(cs270FlexH, 2, 4, "Vertical Subtitle 2.1.1") ta.AddCell(cs270FlexH, 2, 5, "Vertical Subtitle 2.1.2 with a long, long, long, and even longer text")
ta.AddCell(cs270, 3, 0, 3, 1, "Side Title 1") ta.AddCell(cs270, 6, 0, 2, 1, "Side Title 2")
For r = 3 To 7 For c = 1 To 3 ta.AddCell(csFlexW, r, c, (r * c).ToString()) Next Next
For r = 3 To 7 For c = 4 To 5 ta.AddCell(csFlexW, r, c, $"row {r} column {c}") Next Next
ta.AddCell(New CellStyle(cs) With { .RotationAngle = 90, .ParagraphAlignment = ParagraphAlignment.Far, .TextAlignment = TextAlignment.Leading }, 1, 6, 7, 1, "Other Side") ta.AddCell(New CellStyle(cs) With { .TextAlignment = TextAlignment.Trailing, .ParagraphAlignment = ParagraphAlignment.Far }, 8, 0, 1, 7, "Bottom Side")
ta.Render() End SubEnd Class