Antialiasing.vb
''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) 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

'' This sample shows the different (anti)aliasing modes of rendering text:
'' - No anti-aliasing, very fast but poor quality (not recommended).
'' - Fast anti-aliasing. This is the default that provides good quality and fast rendering.
'' - Slow anti-aliasing. Highest quality but slower than the default.
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", "timesbd.ttf")),
                    .FontSize = 16
                }

            Dim tl = g.CreateTextLayout()
            tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.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