'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
'' 演示在 LTR 和 RTL 模式下垂直文本的渲染。
'' 还展示了如何让文本围绕矩形对象流动。
'' 另请参阅JapaneseColumns。
Public Class VerticalText
Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
'' 使用横向:
page.Landscape = True
Dim g = page.Graphics
'' 一些日语、英语和阿拉伯语示例文本:
Dim text1 = "学校教育の「国語」で教えられる。"
Dim text2 = " flow direction. "
Dim text3 = "النص العربي 12 + 34 = 46 مع الأرقام "
'' 初始化字体缓存并获取所需的字体:
Dim fc = New FontCollection()
fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
Dim fYuMin = fc.FindFamilyName("Yu Mincho")
Dim fTimes = fc.FindFamilyName("Times New Roman")
Dim fArial = fc.FindFamilyName("Arial")
'' 创建文本格式:
Dim tf1 = New TextFormat() With {.Font = fYuMin}
Dim tf2 = New TextFormat() With {.Font = fTimes}
Dim tf3 = New TextFormat() With {.Font = fArial}
'' 创建 TextLayout 并在其上设置一些选项:
Dim tl = g.CreateTextLayout()
tl.FirstLineIndent = 36
tl.TextAlignment = TextAlignment.Justified
'' 此设置也证明了最后一行的合理性:
tl.LastLineIsEndOfParagraph = False
'' 将所有边距设置为 1":
tl.MarginAll = tl.Resolution
tl.MaxWidth = page.Size.Width
tl.MaxHeight = page.Size.Height
'' RTL 布局:
tl.RightToLeft = False
'' 构建一个对象列表以使文本流动:
tl.ObjectRects = New List(Of ObjectRect) From {
New ObjectRect(540, 100, 120, 160),
New ObjectRect(100, 290, 170, 100),
New ObjectRect(500, 350, 170, 100)
}
'' 在页面上填充相应的矩形,以便我们可以看到它们:
For Each objRect In tl.ObjectRects
g.FillRectangle(objRect.ToRectangleF(), Color.PaleVioletRed)
Next
'' 将文本添加到布局:
For i = 1 To 3
tl.Append(text1, tf1)
tl.Append("Horizontal Top To Bottom" + text2, tf2)
tl.AppendLine(text3, tf3)
Next
'' 执行并绘制第一个布局:
tl.PerformLayout(True)
g.DrawTextLayout(tl, PointF.Empty)
g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Red))
'' 创建第二个布局 - 垂直逆时针旋转:
Dim t = tl.ContentHeight
tl.Clear()
tl.RotateSidewaysCounterclockwise = True
tl.FlowDirection = FlowDirection.VerticalLeftToRight
tl.MarginTop += t
'' 将文本添加到布局:
For i = 1 To 3
tl.Append(text1, tf1)
tl.Append("Vertical Left To Right" + text2, tf2)
tl.AppendLine(text3, tf3)
Next
'' 执行并绘制第二个布局:
tl.PerformLayout(True)
g.DrawTextLayout(tl, PointF.Empty)
g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Green))
'' 创建第三个布局 - 垂直:
tl.Clear()
tl.FlowDirection = FlowDirection.VerticalRightToLeft
tl.RotateSidewaysCounterclockwise = False
'' 将文本添加到布局:
For i = 1 To 3
tl.Append(text1, tf1)
tl.Append("Vertical Right To Left" + text2, tf2)
tl.AppendLine(text3, tf3)
Next
'' 执行并绘制第三个布局:
tl.PerformLayout(True)
g.DrawTextLayout(tl, PointF.Empty)
g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Blue))
''
'' 完毕:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class