Ligatures.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' GcDocs.Pdf 支持连字(将两个或多个字母连接成一个字形),
'' 前提是所选字体支持它们,并且相应的字体功能已打开。
'' 有关字体功能的完整列表,请参阅
Public Class Ligatures
Function CreatePDF(ByVal stream As Stream) As Integer
'' 常见拉丁连字列表:
Const latinLigatures = "fi, fj, fl, ff, ffi, ffl."
'' 设置与连字相关的字体功能:
'' 全部开启:
Dim allOn As FontFeature() = {
New FontFeature(FeatureTag.clig, True), '' Contextual Ligatures
New FontFeature(FeatureTag.dlig, True), '' Discretionary Ligatures
New FontFeature(FeatureTag.hlig, True), '' Historical Ligatures
New FontFeature(FeatureTag.liga, True), '' Standard Ligatures
New FontFeature(FeatureTag.rlig, True) '' Required Ligatures
}
'' 全部关闭:
Dim allOff As FontFeature() = {
New FontFeature(FeatureTag.clig, False),
New FontFeature(FeatureTag.dlig, False),
New FontFeature(FeatureTag.hlig, False),
New FontFeature(FeatureTag.liga, False),
New FontFeature(FeatureTag.rlig, False)
}
Dim doc = New GcPdfDocument()
Dim g = doc.NewPage().Graphics
'' 文本插入点:
Dim ip = New PointF(72, 72)
Dim tf = New TextFormat()
tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
tf.FontSize = 20
g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip)
ip.Y += 36
'' 关闭所有连字功能:
tf.FontFeatures = allOff
g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip)
ip.Y += 36
'' 打开所有连字功能:
tf.FontFeatures = allOn
g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip)
ip.Y += 72
'' 使用不同的字体重复:
tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"))
g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip)
ip.Y += 36
'' 关闭所有连字功能:
tf.FontFeatures = allOff
g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip)
ip.Y += 36
'' 打开所有连字功能:
tf.FontFeatures = allOn
g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip)
''
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class