CharsAndFonts.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
{
    // このサンプルでは、異なるフォント(.ttf、.otf、.woff)を使用した
    // テキストの描画方法と、0xFFFF を超えるコードを持つ文字の描画方法を示します。
    public class CharsAndFonts
    {
        public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
        {
            var fWoff = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMonoBoldOblique.woff"));
            var fSerif = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf"));
            var fFoglihten = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"));
            var fSega = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "SEGA.ttf"));
            var fEmoji = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FirefoxEmoji.ttf"));
            var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
            using var g = bmp.CreateGraphics(Color.White);
            TextFormat tf = new TextFormat
            {
                Font = fWoff,
                FontSize = 40
            };
            g.DrawString("FreeMonoBoldOblique.woff", tf, new RectangleF(4, 4, 800, 50));

            tf = new TextFormat
            {
                Font = fSerif,
                FontSize = 40
            };
            g.DrawString("FreeSerif.ttf", tf, new RectangleF(4, 64, 800, 50));

            tf = new TextFormat
            {
                Font = fFoglihten,
                FontSize = 40
            };
            g.DrawString("FoglihtenNo07.otf", tf, new RectangleF(4, 139, 800, 50));

            tf = new TextFormat
            {
                Font = fSega,
                FontSize = 40
            };
            g.DrawString("SEGA.ttf", tf, new RectangleF(4, 190, 800, 50));

            var pals = fEmoji.CreateFontTables(TableTag.CpalDraw).GetPalettes();
            tf = new TextFormat
            {
                Font = fEmoji,
                FontSize = 40,
                Palette = pals[0] ?? null
            };
            g.DrawString("FirefoxEmoji.ttf \U0001F433\U0001F349\U0001F367", tf, new RectangleF(4, 240, 800, 50));
            return bmp;
        }
    }
}