//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingSystem.Text.RegularExpressions;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text;usingGCTEXT = GrapeCity.Documents.Text;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsPdfWeb.Demos.Basics{// This sample shows how to render subscript and superscript text.publicclassSubSuperScript {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage();var g = page.Graphics; var rc = Common.Util.AddNote("Demo of the TextFormat.Subscript and TextFormat.Superscript properties. " +"We draw a random 'lorem ipsum' paragraph, rendering all instances of 'lorem' as subscript, " +"and all instances of 'ipsum' as superscript.", page); // Get a random 'lorem ipsum' paragraph:var para = Common.Util.LoremIpsum(1, 18, 20, 20, 20); // Split the paragraph into 'lorem', 'ipsum' and everything else:conststringsub = "lorem";conststringsuper = "ipsum";var frags = Regex.Split(para, $"({sub})|({super})"); var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf")); // Create text formats for subscript and superscript:var tfSub = newTextFormat() { Font = font, FontSize = 12, Subscript = true };var tfSuper = newTextFormat(tfSub) { Subscript = false, Superscript = true }; // Add text to a TextLayout using special formats for 'lorem' and 'ipsum':var tl = g.CreateTextLayout(); tl.DefaultFormat.Font = font; tl.DefaultFormat.FontSize = 12;foreach (var frag in frags) {if (frag == sub) tl.Append(frag, tfSub);elseif (frag == super) tl.Append(frag, tfSuper);else tl.Append(frag); } // Set layout properties and render the text: tl.MaxWidth = page.Size.Width; tl.MaxHeight = page.Size.Height - rc.Height; tl.MarginAll = 72; tl.MarginTop = rc.Bottom + 36; tl.PerformLayout(true); g.DrawTextLayout(tl, PointF.Empty); // Done: doc.Save(stream);return doc.Pages.Count; } }}