Ligatures.cs
// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;

namespace DsPdfWeb.Demos.Basics
{
    // GcDocs.Pdf 支持连字(将两个或多个字母连接成一个字形),
    // 前提是所选字体支持它们,并且相应的字体功能已打开。
    // 有关字体功能的完整列表,请参阅
    public class Ligatures
    {
        public int CreatePDF(Stream stream)
        {
            // 常见拉丁连字列表:
            const string latinLigatures = "fi, fj, fl, ff, ffi, ffl.";
            // 设置与连字相关的字体功能:
            // 全部开启:
            FontFeature[] allOn = new FontFeature[]
            {
                new FontFeature(FeatureTag.clig, true), // Contextual Ligatures
                new FontFeature(FeatureTag.dlig, true), // Discretionary Ligatures
                new FontFeature(FeatureTag.hlig, true), // Historical Ligatures
                new FontFeature(FeatureTag.liga, true), // Standard Ligatures
                new FontFeature(FeatureTag.rlig, true), // Required Ligatures
            };
            // 全部关闭:
            FontFeature[] allOff = new FontFeature[]
            {
                new FontFeature(FeatureTag.clig, false),
                new FontFeature(FeatureTag.dlig, false),
                new FontFeature(FeatureTag.hlig, false),
                new FontFeature(FeatureTag.liga, false),
                new FontFeature(FeatureTag.rlig, false),
            };
            var doc = new GcPdfDocument();
            var g = doc.NewPage().Graphics;
            // 文本插入点:
            var ip = new PointF(72, 72);
            var tf = new TextFormat();
            tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"));
            tf.FontSize = 20;
            g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip);
            ip.Y += 36;
            // 关闭所有连字功能:
            tf.FontFeatures = allOff;
            g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip);
            ip.Y += 36;
            // 打开所有连字功能:
            tf.FontFeatures = allOn;
            g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip);
            ip.Y += 72;
            // 使用不同的字体重复:
            tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"));
            g.DrawString($"Common Latin ligatures, font {tf.Font.FontFamilyName}", tf, ip);
            ip.Y += 36;
            // 关闭所有连字功能:
            tf.FontFeatures = allOff;
            g.DrawString($"All ligature features OFF: {latinLigatures}", tf, ip);
            ip.Y += 36;
            // 打开所有连字功能:
            tf.FontFeatures = allOn;
            g.DrawString($"All ligature features ON: {latinLigatures}", tf, ip);
            // 完毕:
            doc.Save(stream);
            return doc.Pages.Count;
        }
    }
}