//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Collections.Generic;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text; namespaceDsPdfWeb.Demos.Basics{// Demonstrates rendering of vertical text in LTR and RTL modes.// Also shows how to have text flow around rectangular objects. // See also JapaneseColumns.publicclassVerticalText {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage();// Use Landscape orientation: page.Landscape = true;var g = page.Graphics;// Some sample texts in Japanese, English and Arabic:string text1 = "学校教育の「国語」で教えられる。";string text2 = " flow direction. ";string text3 = "النص العربي 12 + 34 = 46 مع الأرقام ";// Init font cache and get the required fonts:var fc = newFontCollection(); fc.RegisterDirectory(Path.Combine("Resources", "Fonts"));var fnt1 = fc.FindFamilyName("Noto Sans JP");var fnt2 = fc.FindFamilyName("Noto Sans");var fnt3 = fc.FindFamilyName("Noto Sans Arabic");// Create text formats:var tf1 = newTextFormat() { Font = fnt1 };var tf2 = newTextFormat() { Font = fnt2 };var tf3 = newTextFormat() { Font = fnt3 };// Create TextLayout and set some options on it:var tl = g.CreateTextLayout(); tl.FirstLineIndent = 36; tl.TextAlignment = TextAlignment.Justified;// This setting justifies the last line too: tl.LastLineIsEndOfParagraph = false;// Set all margins to 1": tl.MarginAll = tl.Resolution; tl.MaxWidth = page.Size.Width; tl.MaxHeight = page.Size.Height;// RTL layout: tl.RightToLeft = false;// Build a list of objects for the text to flow around: tl.ObjectRects = newList<ObjectRect>() {newObjectRect(540, 100, 120, 160),newObjectRect(100, 290, 170, 100),newObjectRect(500, 350, 170, 100) };// Fill corresponding rectangles on page so that we can see them:foreach (var or in tl.ObjectRects) g.FillRectangle(or.ToRectangleF(), Color.PaleVioletRed); // Add text to layout:for (int i = 0; i < 3; i++) { tl.Append(text1, tf1); tl.Append("Horizontal Top To Bottom" + text2, tf2); tl.AppendLine(text3, tf3); }// Perform and draw first layout: tl.PerformLayout(true); g.DrawTextLayout(tl, PointF.Empty); g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Red)); // Create 2nd layout - vertical rotated counter-clockwise:var t = tl.ContentHeight; tl.Clear(); tl.RotateSidewaysCounterclockwise = true; tl.FlowDirection = FlowDirection.VerticalLeftToRight; tl.MarginTop += t;// Add text to layout:for (int i = 0; i < 3; i++) { tl.Append(text1, tf1); tl.Append("Vertical Left To Right" + text2, tf2); tl.AppendLine(text3, tf3); }// Perform and draw second layout: tl.PerformLayout(true); g.DrawTextLayout(tl, PointF.Empty); g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Green)); // Create 3rd layout - vertical: tl.Clear(); tl.FlowDirection = FlowDirection.VerticalRightToLeft; tl.RotateSidewaysCounterclockwise = false;// Add text to layout:for (int i = 0; i < 3; i++) { tl.Append(text1, tf1); tl.Append("Vertical Right To Left" + text2, tf2); tl.AppendLine(text3, tf3); }// Perform and draw third layout: tl.PerformLayout(true); g.DrawTextLayout(tl, PointF.Empty); g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Blue));// Done: doc.Save(stream);return doc.Pages.Count; } }}