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

'' このサンプルでは、テキスト描画における各種(アンチ)エイリアシングモードの違いを示します。
'' -アンチエイリアスなし:非常に高速ですが、品質が低いため推奨されません。
'' -高速アンチエイリアス:高品質かつ高速な描画を実現する既定のモードです。
'' -低速アンチエイリアス:最も高品質ですが、既定のモードより描画速度が低下します。
Public Class Antialiasing
    Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
        Using g = bmp.CreateGraphics(Color.FromArgb(&HFFCCF2FF))
            g.Renderer.Multithreaded = True

            Dim text = Util.LoremIpsum()
            Dim tsize = New SizeF(bmp.Width / 2, bmp.Height / 2)
            Dim pad = 96.0F / 4

            Dim tfcap = New TextFormat() With
                {
                    .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Bold.ttf")),
                    .FontSize = 16
                }

            Dim tl = g.CreateTextLayout()
            tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf"))
            tl.DefaultFormat.FontSize = 14
            tl.TextAlignment = TextAlignment.Justified
            tl.FirstLineIndent = 96 / 2
            tl.ParagraphSpacing = 96 / 8
            tl.MaxWidth = tsize.Width
            tl.MaxHeight = tsize.Height
            tl.MarginAll = pad

            Dim tloc = PointF.Empty
            Using g.PushClip(New RectangleF(tloc, tsize))
                bmp.Renderer.Aliased = True
                tl.AppendLine("No anti-aliasing (worst quality)", tfcap)
                tl.Append(text)
                tl.PerformLayout(True)
                g.DrawTextLayout(tl, tloc)
            End Using
            tloc.X += tsize.Width
            Using g.PushClip(New RectangleF(tloc, tsize))
                bmp.Renderer.Aliased = False
                bmp.Renderer.SlowAntialiasing = False
                tl.Clear()
                tl.AppendLine("Fast anti-aliasing (default quality)", tfcap)
                tl.Append(text)
                tl.PerformLayout(True)
                g.DrawTextLayout(tl, tloc)
            End Using
            tloc.X = 0
            tloc.Y += tsize.Height
            Using g.PushClip(New RectangleF(tloc, tsize))
                bmp.Renderer.Aliased = False
                bmp.Renderer.SlowAntialiasing = True
                tl.Clear()
                tl.AppendLine("Slow anti-aliasing (highest quality)", tfcap)
                tl.Append(text)
                tl.PerformLayout(True)
                g.DrawTextLayout(tl, tloc)
            End Using
        End Using
        Return bmp
    End Function
End Class