'' This code is part of GrapeCity Documents for PDF samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text

'' This sample renders a variety of interesting Unicode characters
'' including surrogate pairs. It also implicitly uses the automatic
'' font fallback (font substitution) feature built into GcPdf.
'' Note that this sample may produce different results on different
'' systems, as it relies on system-provided fallback fonts.
'' For a platform- and system-independent version of this sample see SurrogatesPort.
'' See also FontFallbacks.
Public Class Surrogates
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim g = doc.NewPage().Graphics
        '' For most of the 'interesting' chars demoed in this sample,
        '' fallback fonts (see FontFallbacks) will be automatically used,
        '' so we can just use a standard font for the captions:
        Dim font = StandardFonts.Helvetica
        Dim tf = New TextFormat() With {.Font = font, .FontSize = 12}
        Dim tf1 = New TextFormat(tf) With {.FontSize = 14}

        g.DrawString("Some Interesting Unicode Characters (relies on system fallbacks)",
            New TextFormat(tf) With {.Underline = True, .FontSize = tf.FontSize + 2},
            New RectangleF(0, 36, doc.PageSize.Width, Single.MaxValue),

        '' Set up text insertion point and its advance function:
        Dim ip = New PointF(72, 54)
        Dim nextIp As Func(Of Boolean, PointF) =
            Function(caption_ As Boolean)
                ip.Y += If(caption_, 30, 20)
                Return ip
            End Function

        '' Draw the strings:
        g.DrawString("Surrogate Pairs:", tf, nextIp(True))
        g.DrawString($"{ChrW(&HD867)}{ChrW(&HDEDB)} {ChrW(&HD840)}{ChrW(&HDC0B)} {ChrW(&HD834)}{ChrW(&HDD1E)} {ChrW(&HD834)}{ChrW(&HDD61)} {ChrW(&HD83D)}{ChrW(&HDC04)}", tf1, nextIp(False))

        g.DrawString("Currency Symbols:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H24)} {ChrW(&H20A0)} {ChrW(&H20A1)} {ChrW(&H20A2)} {ChrW(&H20A3)} {ChrW(&H20A4)} {ChrW(&H20AC)} {ChrW(&H20B9)} {ChrW(&H20BD)}", tf1, nextIp(False))

        g.DrawString("Mathematical Operators:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H221A)} {ChrW(&H222B)} {ChrW(&H2211)} {ChrW(&H2210)} {ChrW(&H2264)} {ChrW(&H2265)} {ChrW(&H2202)} {ChrW(&H2208)}", tf1, nextIp(False))

        g.DrawString("CJK Ideographs Extension A:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H3400)} {ChrW(&H3401)} {ChrW(&H3402)} {ChrW(&H3403)} {ChrW(&H3404)} {ChrW(&H3405)} {ChrW(&H3406)} {ChrW(&H3407)}", tf1, nextIp(False))

        g.DrawString("Letterlike Symbols:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H2110)} {ChrW(&H2111)} {ChrW(&H2112)} {ChrW(&H2113)} {ChrW(&H2114)} {ChrW(&H2115)} {ChrW(&H211B)} {ChrW(&H211C)}", tf1, nextIp(False))

        g.DrawString("Private Use Area:", tf, nextIp(True))
        g.DrawString($"{ChrW(&HE000)} {ChrW(&HE001)} {ChrW(&HE010)} {ChrW(&HE011)} {ChrW(&HE012)} {ChrW(&HE013)} {ChrW(&HE014)} {ChrW(&HE015)}", tf1, nextIp(False))

        g.DrawString("Arrows:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H2190)} {ChrW(&H2191)} {ChrW(&H2192)} {ChrW(&H2193)} {ChrW(&H21B0)} {ChrW(&H21E6)} {ChrW(&H21CB)} {ChrW(&H21A9)}", tf1, nextIp(False))

        g.DrawString("Dingbats:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H2714)} {ChrW(&H2717)} {ChrW(&H275B)} {ChrW(&H275C)} {ChrW(&H2706)} {ChrW(&H2707)} {ChrW(&H2708)} {ChrW(&H2709)}", tf1, nextIp(False))

        g.DrawString("Braille Patterns:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H2830)} {ChrW(&H2831)} {ChrW(&H2832)} {ChrW(&H2833)} {ChrW(&H2834)} {ChrW(&H2835)} {ChrW(&H2836)} {ChrW(&H2837)}", tf1, nextIp(False))

        g.DrawString($"Geometric Shapes:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H25D0)} {ChrW(&H25D1)} {ChrW(&H25D2)} {ChrW(&H25D3)} {ChrW(&H25A4)} {ChrW(&H25F0)} {ChrW(&H25BC)} {ChrW(&H25CE)}", tf1, nextIp(False))

        g.DrawString("Latin Extended A:", tf, nextIp(True))
        g.DrawString($"{ChrW(&H100)} {ChrW(&H101)} {ChrW(&H102)} {ChrW(&H103)} {ChrW(&H104)} {ChrW(&H105)} {ChrW(&H106)} {ChrW(&H107)}", tf1, nextIp(False))

        g.DrawString("Miscellaneous Symbols:", tf, nextIp(True))
        g.DrawString($"{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)}", tf1, nextIp(False))
        '' Done:
        Return doc.Pages.Count
    End Function
End Class