Antialiasing.cs
//
// このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
// © MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;
using GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;
namespace DsImagingWeb.Demos
{
// このサンプルでは、テキスト描画における各種(アンチ)エイリアシングモードの違いを示します。
// -アンチエイリアスなし:非常に高速ですが、品質が低いため推奨されません。
// -高速アンチエイリアス:高品質かつ高速な描画を実現する既定のモードです。
// -低速アンチエイリアス:最も高品質ですが、既定のモードより描画速度が低下します。
public class Antialiasing
{
public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
{
var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
using var g = bmp.CreateGraphics(Color.FromArgb(unchecked((int)0xffccf2ff)));
g.Renderer.Multithreaded = true;
var text = Common.Util.LoremIpsum();
var tsize = new SizeF(bmp.Width / 2, bmp.Height / 2);
var pad = 96f / 4;
var tfcap = new TextFormat()
{
Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Bold.ttf")),
FontSize = 16,
};
var 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;
var 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);
}
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);
}
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);
}
return bmp;
}
}
}