CharsAndFonts.vb
'' 
'' このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
'' © MESCIUS inc. All rights reserved.
'' 
Imports System.IO
Imports System.Drawing
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' このサンプルでは、異なるフォント(.ttf、.otf、.woff)を使用した
'' テキストの描画方法と、0xFFFF を超えるコードを持つ文字の描画方法を示します。
Public Class CharsAndFonts
    Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim fWoff = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMonoBoldOblique.woff"))
        Dim fSerif = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf"))
        Dim fFoglihten = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"))
        Dim fSega = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "SEGA.ttf"))
        Dim fEmoji = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FirefoxEmoji.ttf"))
        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
        Using g = bmp.CreateGraphics(Color.White)
            Dim tf = New TextFormat With
            {
                .Font = fWoff,
                .FontSize = 40
            }
            g.DrawString("FreeMonoBoldOblique.woff", tf, New RectangleF(4, 4, 500, 50))

            tf = New TextFormat With
            {
                .Font = fSerif,
                .FontSize = 40
            }
            g.DrawString("FreeSerif.ttf", tf, New RectangleF(4, 64, 580, 50))

            Dim tl = g.CreateTextLayout()
            tf = New TextFormat With
            {
                .Font = fFoglihten,
                .FontSize = 40
            }
            tl.Append("FoglihtenNo07.otf", tf)
            g.DrawTextLayout(tl, New PointF(4, 139))

            tf = New TextFormat With
            {
                .Font = fSega,
                .FontSize = 40
            }
            g.DrawString("SEGA.ttf", tf, New RectangleF(4, 190, 500, 50))

            Dim pals = fEmoji.CreateFontTables(TableTag.CpalDraw).GetPalettes()
            tf = New TextFormat With
            {
                .Font = fEmoji,
                .FontSize = 40,
                .Palette = pals(0)
            }
            Dim s1 As String = Char.ConvertFromUtf32(&H1F433)
            Dim s2 As String = Char.ConvertFromUtf32(&H1F349)
            Dim s3 As String = Char.ConvertFromUtf32(&H1F367)
            g.DrawString($"FirefoxEmoji.ttf {s1}{s2}{s3}", tf, New RectangleF(4, 240, 550, 50))
        End Using
        Return bmp
    End Function
End Class