BoldItalicEmulation.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

'' 示例展示了如何在使用普通字体时控制粗体和/或斜体模拟。
Public Class BoldItalicEmulation
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim fc = New FontCollection()
        fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
        Dim doc = New GcPdfDocument()
        Dim g = doc.NewPage().Graphics
        Dim rc = Util.AddNote(
            "TextFormat.FontStyle 允许使用粗体和/或斜体模拟" + vbLf +
            "", doc.Pages.Last)
        '' 文本插入点:
        Dim ip = New PointF(rc.Left, rc.Bottom + 36)
        Dim tf = New TextFormat()
        '' 我们特别获得了该字体的非粗体/非斜体版本:
        tf.Font = fc.FindFamilyName("Times New Roman", False, False)
        tf.FontSize = 16
        g.DrawString($"Regular Times font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        '' 使用相同(常规)字体但模拟粗体和斜体绘制一些字符串:
        tf.FontStyle = GCTEXT.FontStyle.Bold
        g.DrawString($"Bold emulation using font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        tf.FontStyle = GCTEXT.FontStyle.Italic
        g.DrawString($"Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        tf.FontStyle = GCTEXT.FontStyle.BoldItalic
        g.DrawString($"Bold+Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        ''
        '' 现在我们使用字体的“真正的”粗体/斜体变体渲染一些字符串:
        tf.FontStyle = GCTEXT.FontStyle.Regular
        tf.Font = fc.FindFamilyName("Times New Roman", True, False)
        g.DrawString($"Using real bold font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        tf.Font = fc.FindFamilyName("Times New Roman", False, True)
        g.DrawString($"Using real italic font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        tf.Font = fc.FindFamilyName("Times New Roman", True, True)
        g.DrawString($"Using real bold italic font: {tf.Font.FullFontName}", tf, ip)
        ip.Y += 36
        ''
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class