CharsAndFonts.cs
//
// This code is part of Document Solutions for Imaging demos.
// Copyright (c) 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
{
    // This sample shows how to draw text using different fonts (.ttf, .otf, .woff)
    // and characters with codes greater than 0xFFFF.
    public class CharsAndFonts
    {
        public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
        {
            var garlicFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Woff", "Garlicembrace.woff"));
            var foglihtenFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"));
            var pericFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "peric.ttf"));
            var emojiFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf"));
            var timesFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"));
            var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
            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;
        }
    }
}