''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.Drawing
Imports System.IO
Imports System.Numerics
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 rotated table using an angle constraint.
'' An angle constraint is similar to rotation with a transformation matrix,
'' but unlike transformation, using angle constraint makes it easier to add
'' other visual elements to the view.
Public Class RotatedTable
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 Class ItemLine
Public ReadOnly Property Text As String
Public ReadOnly Property Sales As Double
Public ReadOnly Property MarginNumber As Double
Public ReadOnly Property MarginPercent As Double
Public ReadOnly Property TotalCustomers As Integer
Public Sub New(text As String, sales As Double, marginNumber As Double, marginPercent As Double, totalCustomers As Integer)
Me.Text = text
Me.Sales = sales
Me.MarginNumber = marginNumber
Me.MarginPercent = marginPercent
Me.TotalCustomers = totalCustomers
End Sub
End Class
Private Shared Sub DrawTable(g As GcGraphics, pageWidth As Integer, pageHeight As Integer)
Dim marginX As Single = 20, marginY As Single = 20
Dim host = New LayoutHost()
Dim view = host.CreateView(0, 0)
'' Note that the table rectangle is rotated using an AngleConstraint.
'' We don't need a separate View with a transformation matrix.
Dim rt = view.CreateRect()
rt.SetAngle(Nothing, 270)
rt.SetTop(Nothing, AnchorParam.Left, marginX)
rt.SetRight(Nothing, AnchorParam.Top, -marginY)
Dim ta = New TableRenderer(g,
rt, FixedTableSides.TopRight,
rowCount:=9,
columnCount:=5,
gridLineColor:=Color.Black,
gridLineWidth:=1,
paddingLeft:=20,
paddingRight:=20,
paddingBottom:=20,
paddingTop:=12)
Dim lgb = New LinearGradientBrush(Color.FromArgb(240, 234, 249), New PointF(0, 0), Color.FromArgb(201, 181, 232), New PointF(0, 1))
ta.TableFrameStyle = New FrameStyle() With
{
.LineColor = Color.FromArgb(126, 96, 160),
.LineWidth = 1,
.FillBrush = lgb
}
Dim columns = ta.ColumnRects
columns(0).SetWidth(80)
columns(1).SetWidth(125)
columns(2).SetWidth(110)
columns(3).SetWidth(80)
columns(4).SetWidth(80)
Dim fmt = New TextFormat() With
{
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")),
.FontSize = 16,
.FontSizeInGraphicUnits = True,
.FontFeatures = New FontFeature() {New FontFeature(FeatureTag.liga, False)}
}
Dim fmtHeader = New TextFormat(fmt) With
{
.ForeColor = Color.White,
.FontBold = True
}
Dim csTitle = New CellStyle() With
{
.Background = True,
.TextFormat = New TextFormat(fmt) With
{
.FontBold = True,
.FontSize = 20
},
.TextAlignment = TextAlignment.Center,
.PaddingBottom = 8
}
ta.AddCell(csTitle, 0, 0, 1, 5, "Class Schedule")
Dim csHeader = New CellStyle() With
{
.TextFormat = fmtHeader,
.TextAlignment = TextAlignment.Center,
.PaddingTop = 5,
.PaddingBottom = 6
}
ta.AddCell(csHeader, 1, 0, "LESSON")
ta.AddCell(csHeader, 1, 1, "TOPIC")
ta.AddCell(csHeader, 1, 2, "ASSIGNMENT")
ta.AddCell(csHeader, 1, 3, "POINTS")
ta.AddCell(csHeader, 1, 4, "DUE")
Dim csCenter = New CellStyle(csHeader) With
{
.TextFormat = fmt,
.PaddingLeftRight = 6
}
Dim csLeft = New CellStyle(csCenter) With
{
.TextAlignment = TextAlignment.Leading
}
ta.AddCell(csCenter, 2, 0, 2, 1, "1")
ta.AddCell(csLeft, 2, 1, 2, 1, "What is Distance Learning?")
ta.AddCell(csLeft, 2, 2, "Wiki #1")
ta.AddCell(csCenter, 2, 3, "10")
ta.AddCell(csCenter, 2, 4, "March 10")
ta.AddCell(csLeft, 3, 2, "Presentation")
ta.AddCell(csCenter, 3, 3, "20")
ta.AddCell(csCenter, 3, 4)
ta.AddCell(csCenter, 4, 0, "2")
ta.AddCell(csLeft, 4, 1, "History & Theories")
ta.AddCell(csLeft, 4, 2, "Brief Paper")
ta.AddCell(csCenter, 4, 3, "20")
ta.AddCell(csCenter, 4, 4, "March 24")
ta.AddCell(csCenter, 5, 0, 1, 5, "Spring Break")
ta.AddCell(csCenter, 6, 0, 2, 1, "3")
ta.AddCell(csLeft, 6, 1, 2, 1, "Distance Learners")
ta.AddCell(csLeft, 6, 2, "Discussion #1")
ta.AddCell(csCenter, 6, 3, "10")
ta.AddCell(csCenter, 6, 4, "April 7")
ta.AddCell(csLeft, 7, 2, "Group Project")
ta.AddCell(csCenter, 7, 3, "50")
ta.AddCell(csCenter, 7, 4, "April 14")
ta.AddCell(csCenter, 8, 0, "4")
ta.AddCell(csLeft, 8, 1, "Media Selection")
ta.AddCell(csLeft, 8, 2, "Blog #1")
ta.AddCell(csCenter, 8, 3, "10")
ta.AddCell(csCenter, 8, 4, "April 21")
ta.AddCell(New CellStyle() With
{
.Background = True,
.FillColor = Color.FromArgb(79, 129, 189)
}, 1, 0, 1, 5)
ta.AddCell(New CellStyle() With
{
.Background = True,
.FillColor = Color.FromArgb(208, 216, 232)
}, 2, 0, 7, 5)
Dim bkHighlight = New CellStyle() With
{
.Background = True,
.FillColor = Color.FromArgb(233, 237, 244)
}
ta.AddCell(bkHighlight, 3, 2, 1, 3)
ta.AddCell(bkHighlight, 5, 0, 1, 5)
ta.AddCell(bkHighlight, 7, 2, 1, 3)
ta.ApplyCellConstraints()
g.Transform = Matrix3x2.CreateScale(1.8F)
ta.Render(g)
End Sub
End Class