CharsAndFonts.cs
//
// This code is part of GrapeCity Documents for Imaging samples.
// Copyright (c) GrapeCity, 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;

namespace GcImagingWeb.Samples
{
    // This sample shows how to draw text using different fonts (.ttf, .otf, .woff)
    // and characrters with codes greater than 0xFFFF.
    public class CharsAndFonts
    {
        public GcBitmap GenerateImage(int pixelWidth = 1024, int pixelHeight = 1024, bool opaque = true, float dpiX = 96, float dpiY = 96)
        {
            var garlicFont = Font.FromFile(Path.Combine("Resources", "Fonts", "Woff", "Garlicembrace.woff"));
            var foglihtenFont = Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"));
            var pericFont = Font.FromFile(Path.Combine("Resources", "Fonts", "peric.ttf"));
            var emojiFont = Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf"));
            var timesFont = Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"));
            var bmp = new GcBitmap(pixelWidth, pixelHeight, true, dpiX, dpiY);
            using (var g = bmp.CreateGraphics(Color.White))
            {
                TextFormat tf = new TextFormat
                {
                    Font = garlicFont,
                    FontSize = 40
                };
                g.DrawString("Garlicembrace.woff", tf, new RectangleF(4, 4, 500, 50));

                tf = new TextFormat
                {
                    Font = timesFont,
                    FontSize = 40
                };
                g.DrawString("Times New Roman @ ǖ", tf, new RectangleF(4, 64, 580, 50));

                var tl = g.CreateTextLayout();
                tf = new TextFormat
                {
                    Font = foglihtenFont,
                    FontSize = 40
                };
                tl.Append("FoglihtenNo07.otf", tf);
                g.DrawTextLayout(tl, new PointF(4, 139));

                tf = new TextFormat
                {
                    Font = pericFont,
                    FontSize = 40
                };
                g.DrawString("peric.ttf", tf, new RectangleF(4, 190, 500, 50));

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