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

'' 此示例呈现各种有趣的 Unicode 字符
'' 包括代理对,类似于Surrogates示例。
'' 但与该示例不同的是,它不依赖于任何系统提供的
'' 后备措施。相反,在此示例中,我们有目的地限制后备
'' 字体查找到程序自己的字体集合,并提供
'' 我们自己的一套后备字体。
'' 这使得代码平台和系统独立,因此它产生
'' 在 Windows、Linux 或 Mac 上的结果完全相同。
Public Class SurrogatesPort
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim g = page.Graphics

        '' 在Surrogates示例中,我们指定了标准字体
        '' (它缺少我们将渲染的许多字形),
        '' 并将依赖 FontCollection 提供的字体后备支持:
        Dim font = StandardFonts.Helvetica

        '' 设置标题、“有趣的字符”和间距的文本格式:
        Dim tf = New TextFormat() With {.Font = font, .FontSize = 12}
        Dim tf1 = New TextFormat(tf) With {.FontSize = 14}
        Dim tfs = New TextFormat(tf) With {.FontSize = 6}

        '' 创建要使用的字体集合:
        Dim fc = New FontCollection()
        '' 添加我们自己的后备字体以使用(请注意,此处的顺序很重要,
        '' 先到先得):
        fc.AppendFallbackFonts(
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "arialuni.ttf")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "l_10646.ttf")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguisym.ttf")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "simsun.ttc")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf")),
            GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "YuGothR.ttc"))
        )

        '' 限制默认字体查找是在 TextLayout 中完成的,因此与
        '' {Surrogates}示例,这里我们不能使用DrawString,但必须使用
        '' 直接TextLayout和DrawTextLayout:
        '' - 指定要使用的字体集合;
        '' - 将默认字体/后备查找仅限于指定集合;
        '' - 设置其他道具来渲染文本。
        Dim tl = New TextLayout(72) With {
            .FontCollection = fc,
            .RestrictedFontLookup = True,
            .FontFallbackScope = FontFallbackScope.FontCollectionOnly,
            .MaxWidth = page.Size.Width,
            .MaxHeight = page.Size.Height,
            .MarginLeft = 72,
            .MarginRight = 72,
            .MarginTop = 36,
            .MarginBottom = 36,
            .TextAlignment = TextAlignment.Center
        }

        tl.Append("Some Interesting Unicode Characters (system-independent)",
                  New TextFormat(tf) With {.Underline = True, .FontSize = tf.FontSize + 2})
        tl.PerformLayout(True)
        g.DrawTextLayout(tl, PointF.Empty)

        tl.MarginTop = tl.ContentRectangle.Bottom + 20
        tl.Clear()
        tl.TextAlignment = TextAlignment.Leading

        '' 绘制字符串。
        tl.Append("Surrogate Pairs:" + vbCrLf, tf)
        tl.Append($"{ChrW(&HD867)}{ChrW(&HDEDB)} {ChrW(&HD840)}{ChrW(&HDC0B)} {ChrW(&HD834)}{ChrW(&HDD1E)} {ChrW(&HD834)}{ChrW(&HDD61)} {ChrW(&HD83D)}{ChrW(&HDC04)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Currency Symbols:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H24)} {ChrW(&H20A0)} {ChrW(&H20A1)} {ChrW(&H20A2)} {ChrW(&H20A3)} {ChrW(&H20A4)} {ChrW(&H20AC)} {ChrW(&H20B9)} {ChrW(&H20BD)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Mathematical Operators:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H221A)} {ChrW(&H222B)} {ChrW(&H2211)} {ChrW(&H2210)} {ChrW(&H2264)} {ChrW(&H2265)} {ChrW(&H2202)} {ChrW(&H2208)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("CJK Ideographs Extension A:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H3400)} {ChrW(&H3401)} {ChrW(&H3402)} {ChrW(&H3403)} {ChrW(&H3404)} {ChrW(&H3405)} {ChrW(&H3406)} {ChrW(&H3407)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Letterlike Symbols:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H2110)} {ChrW(&H2111)} {ChrW(&H2112)} {ChrW(&H2113)} {ChrW(&H2114)} {ChrW(&H2115)} {ChrW(&H211B)} {ChrW(&H211C)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Private Use Area:" + vbCrLf, tf)
        tl.Append($"{ChrW(&HE000)} {ChrW(&HE001)} {ChrW(&HE010)} {ChrW(&HE011)} {ChrW(&HE012)} {ChrW(&HE013)} {ChrW(&HE014)} {ChrW(&HE015)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Arrows:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H2190)} {ChrW(&H2191)} {ChrW(&H2192)} {ChrW(&H2193)} {ChrW(&H21B0)} {ChrW(&H21E6)} {ChrW(&H21CB)} {ChrW(&H21A9)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Dingbats:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H2714)} {ChrW(&H2717)} {ChrW(&H275B)} {ChrW(&H275C)} {ChrW(&H2706)} {ChrW(&H2707)} {ChrW(&H2708)} {ChrW(&H2709)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Braille Patterns:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H2830)} {ChrW(&H2831)} {ChrW(&H2832)} {ChrW(&H2833)} {ChrW(&H2834)} {ChrW(&H2835)} {ChrW(&H2836)} {ChrW(&H2837)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Geometric Shapes:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H25D0)} {ChrW(&H25D1)} {ChrW(&H25D2)} {ChrW(&H25D3)} {ChrW(&H25A4)} {ChrW(&H25F0)} {ChrW(&H25BC)} {ChrW(&H25CE)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Latin Extended A:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H100)} {ChrW(&H101)} {ChrW(&H102)} {ChrW(&H103)} {ChrW(&H104)} {ChrW(&H105)} {ChrW(&H106)} {ChrW(&H107)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.Append("Miscellaneous Symbols:" + vbCrLf, tf)
        tl.Append($"{ChrW(&H2600)} {ChrW(&H2601)} {ChrW(&H2602)} {ChrW(&H2603)} {ChrW(&H2604)} {ChrW(&H2605)} {ChrW(&H2606)} " +
                  $"{ChrW(&H2607)} {ChrW(&H2608)} {ChrW(&H2609)} {ChrW(&H2614)} {ChrW(&H2615)} {ChrW(&H26F0)}{vbCrLf}", tf1)
        tl.Append(vbCrLf, tfs)

        tl.PerformLayout(True)
        g.DrawTextLayout(tl, PointF.Empty)
        ''
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class