การทำงานกับแบบอักษร

แบบอักษรคือชุดอักขระที่มีขนาด สี และการออกแบบที่แน่นอน Aspose.Words ช่วยให้คุณทำงานกับแบบอักษรโดยใช้เนมสเปซ Fonts และคลาส Font

การจัดรูปแบบตัวอักษร

การจัดรูปแบบแบบอักษรปัจจุบันแสดงโดยออบเจ็กต์ Font ที่ส่งคืนโดยคุณสมบัติ Font คลาส Font มีคุณสมบัติแบบอักษรที่หลากหลาย โดยจำลองคุณสมบัติที่มีอยู่ใน Microsoft Word

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการตั้งค่าการจัดรูปแบบแบบอักษร:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set font formatting properties
Font font = builder.Font;
font.Bold = true;
font.Color = System.Drawing.Color.DarkBlue;
font.Italic = true;
font.Name = "Arial";
font.Size = 24;
font.Spacing = 5;
font.Underline = Underline.Double;
// Output formatted text
builder.Writeln("I'm a very nice formatted string.");
dataDir = dataDir + "DocumentBuilderSetFontFormatting_out.doc";
doc.Save(dataDir);

คุณสมบัติการเติมยังมีให้ใช้สำหรับแบบอักษรเพื่อตั้งค่าการจัดรูปแบบการเติมข้อความ ซึ่งทำให้สามารถเปลี่ยนแปลงได้ เช่น สีพื้นหน้าหรือความโปร่งใสของการเติมข้อความ

รับระยะห่างระหว่างบรรทัดแบบอักษร

ระยะห่างระหว่างบรรทัดแบบอักษรคือระยะห่างแนวตั้งระหว่างเส้นฐานของข้อความสองบรรทัดที่ต่อเนื่องกัน ดังนั้นระยะห่างระหว่างบรรทัดจึงรวมถึงช่องว่างระหว่างบรรทัดพร้อมกับความสูงของอักขระด้วย

คุณสมบัติ LineSpacing ได้รับการแนะนำในคลาส Font เพื่อรับค่านี้ ดังแสดงในตัวอย่างด้านล่าง:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Calibri";
builder.Writeln("qText");
// Obtain line spacing.
Font font = builder.Document.FirstSection.Body.FirstParagraph.Runs[0].Font;
Console.WriteLine($"lineSpacing = {font.LineSpacing}");

แบบอักษรเน้นเครื่องหมาย

ภาษาเอเชียตะวันออกบางภาษาใช้เครื่องหมายเน้นพิเศษเพื่อระบุการเน้น คลาส Font จัดเตรียมคุณสมบัติ EmphasisMark เพื่อรับหรือตั้งค่าการแจงนับ EmphasisMark ที่จะใช้เมื่อจัดรูปแบบ

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการตั้งค่าคุณสมบัติ EphasisMark:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.Font.EmphasisMark = EmphasisMark.UnderSolidCircle;
builder.Write("Emphasis text");
builder.Writeln();
builder.Font.ClearFormatting();
builder.Write("Simple text");
document.Save(dataDir + "FontEmphasisMark_out.doc");