Skip to content

Commit 0797621

Browse files
Publish fonts category examples (#228)
1 parent 4fec08d commit 0797621

38 files changed

Lines changed: 705 additions & 726 deletions

File tree

fonts/AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Use the simplest workflow that satisfies the task.
243243
## Build and run contract
244244

245245
- Target framework: `net8.0`
246-
- Package: `Aspose.Words` `26.7.0`
246+
- Package: `Aspose.Words` `26.8.0`
247247
- Package: `Aspose.Drawing.Common` `25.11.0`
248248

249249
## Command reference
@@ -258,7 +258,7 @@ cd ExampleProject
258258
### Add required packages
259259

260260
```bash
261-
dotnet add package Aspose.Words --version 26.7.0
261+
dotnet add package Aspose.Words --version 26.8.0
262262
dotnet add package Aspose.Drawing.Common --version 25.11.0
263263
```
264264

fonts/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Fonts Examples for Aspose.Words for .NET
22

3-
This folder contains the live, publish-ready C# examples for the Fonts category. Each file is a standalone console example selected from the verified 26.7.0 run.
3+
This folder contains the live, publish-ready C# examples for the Fonts category. Each file is a standalone console example selected from the verified 26.8.0 run.
44

55
## Snapshot
66

77
- Category: Fonts
88
- Slug: fonts
99
- Total examples: 35
1010
- Publish-ready successful examples: 35 / 35
11-
- Source run: 20260802_190455_803b68
11+
- Source run: 20260830_195242_46e1a9
1212
- Document Formatting examples: 27
1313
- Font Settings And Sources examples: 4
1414
- Embedding And Rendering examples: 2
@@ -29,7 +29,7 @@ This folder contains the live, publish-ready C# examples for the Fonts category.
2929
## Prerequisites
3030

3131
- .NET SDK 8.0 or later
32-
- Aspose.Words 26.7.0
32+
- Aspose.Words 26.8.0
3333
- Aspose.Drawing.Common 25.11.0
3434

3535
## Running Examples
@@ -39,7 +39,7 @@ Each file in this folder is a single, standalone `.cs` console example. To run o
3939
```bash
4040
dotnet new console -n ExampleProject --framework net8.0
4141
cd ExampleProject
42-
dotnet add package Aspose.Words --version 26.7.0
42+
dotnet add package Aspose.Words --version 26.8.0
4343
dotnet add package Aspose.Drawing.Common --version 25.11.0
4444

4545
# Copy one example from this folder into the project as Program.cs
@@ -61,7 +61,7 @@ Example:
6161
# From the repository root
6262
dotnet new console -n ExampleProject --framework net8.0
6363
cd ExampleProject
64-
dotnet add package Aspose.Words --version 26.7.0
64+
dotnet add package Aspose.Words --version 26.8.0
6565
dotnet add package Aspose.Drawing.Common --version 25.11.0
6666

6767
# PowerShell example
@@ -149,6 +149,6 @@ dotnet run --configuration Release --no-build
149149
150150
## Notes for maintainers
151151

152-
- This category is 100% publish-ready for the 26.7.0 run.
152+
- This category is 100% publish-ready for the 26.8.0 run.
153153
- Preserve file-to-task traceability when updating this folder.
154154
- Keep examples standalone and bootstrap local inputs inside the example whenever external sources are mentioned.

fonts/adjust-a-paragraph-s-line-spacing-to-1-5-lines-by-assigning-font-linespacing-to-1-5.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,29 @@ public static void Main()
1212

1313
// Use DocumentBuilder to add content.
1414
DocumentBuilder builder = new DocumentBuilder(doc);
15-
builder.Writeln("This paragraph will have 1.5 line spacing.");
1615

17-
// Set the line spacing rule to Multiple (number of lines) and specify 1.5 lines.
18-
// One line equals 12 points, so 1.5 lines = 18 points.
16+
// Set the paragraph line spacing to 1.5 lines.
17+
// In Aspose.Words, 1 line = 12 points. 1.5 lines = 18 points.
1918
builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
20-
builder.ParagraphFormat.LineSpacing = 18.0;
19+
builder.ParagraphFormat.LineSpacing = 18; // points
2120

22-
// Validate that the line spacing was applied.
23-
double appliedSpacing = builder.ParagraphFormat.LineSpacing;
24-
if (Math.Abs(appliedSpacing - 18.0) > 0.001)
25-
{
26-
throw new InvalidOperationException("Line spacing was not set correctly.");
27-
}
21+
// Add a sample paragraph.
22+
builder.Writeln("This paragraph uses 1.5 line spacing.");
2823

29-
// Define output file path.
24+
// Define the output file path.
3025
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "ParagraphLineSpacing.docx");
3126

3227
// Save the document.
3328
doc.Save(outputPath);
3429

35-
// Ensure the file was created.
36-
if (!File.Exists(outputPath))
30+
// Validate that the file was created.
31+
if (File.Exists(outputPath))
32+
{
33+
Console.WriteLine("Document saved successfully: " + outputPath);
34+
}
35+
else
3736
{
38-
throw new FileNotFoundException("The document was not saved correctly.", outputPath);
37+
Console.WriteLine("Failed to save the document.");
3938
}
4039
}
4140
}
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.IO;
33
using Aspose.Words;
4-
using Aspose.Drawing; // Provides Aspose.Drawing.Color
4+
using Aspose.Drawing;
55

66
public class Program
77
{
@@ -11,43 +11,41 @@ public static void Main()
1111
Document doc = new Document();
1212
DocumentBuilder builder = new DocumentBuilder(doc);
1313

14-
// Define a few Aspose.Drawing colors to choose from.
15-
Aspose.Drawing.Color redAspose = Aspose.Drawing.Color.Red;
16-
Aspose.Drawing.Color greenAspose = Aspose.Drawing.Color.Green;
14+
// Define two colors using Aspose.Drawing.Color.
1715
Aspose.Drawing.Color blueAspose = Aspose.Drawing.Color.Blue;
16+
Aspose.Drawing.Color redAspose = Aspose.Drawing.Color.Red;
17+
18+
// Convert Aspose.Drawing.Color to System.Drawing.Color for the Font.Color property.
19+
System.Drawing.Color blue = System.Drawing.Color.FromArgb(blueAspose.ToArgb());
20+
System.Drawing.Color red = System.Drawing.Color.FromArgb(redAspose.ToArgb());
1821

1922
// Add several paragraphs, changing the font color based on the paragraph index.
2023
for (int i = 0; i < 5; i++)
2124
{
22-
// Select a color using conditional logic.
23-
Aspose.Drawing.Color selectedAsposeColor;
24-
if (i % 3 == 0)
25-
selectedAsposeColor = redAspose;
26-
else if (i % 3 == 1)
27-
selectedAsposeColor = greenAspose;
28-
else
29-
selectedAsposeColor = blueAspose;
25+
// Even index -> blue, odd index -> red.
26+
System.Drawing.Color currentColor = (i % 2 == 0) ? blue : red;
3027

31-
// Convert Aspose.Drawing.Color to System.Drawing.Color as required by Font.Color.
32-
System.Drawing.Color sysColor = System.Drawing.Color.FromArgb(selectedAsposeColor.ToArgb());
28+
// Apply the selected color to the builder's font.
29+
builder.Font.Color = currentColor;
3330

34-
// Apply the color to the current font.
35-
builder.Font.Color = sysColor;
36-
37-
// Write a paragraph.
38-
builder.Writeln($"Paragraph {i + 1} with dynamically set color.");
31+
// Write the paragraph text.
32+
builder.Writeln($"Paragraph {i + 1} with {(i % 2 == 0 ? "blue" : "red")} text.");
3933

4034
// Validate that the color was set correctly.
41-
if (builder.Font.Color.ToArgb() != sysColor.ToArgb())
42-
throw new InvalidOperationException("Font color was not applied as expected.");
35+
if (builder.Font.Color.ToArgb() != currentColor.ToArgb())
36+
throw new InvalidOperationException("Font color assignment validation failed.");
4337
}
4438

45-
// Save the document to the current directory.
46-
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "DynamicFontColors.docx");
39+
// Ensure the output directory exists.
40+
string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Output");
41+
Directory.CreateDirectory(outputDir);
42+
string outputPath = Path.Combine(outputDir, "DynamicFontColors.docx");
43+
44+
// Save the document.
4745
doc.Save(outputPath);
4846

49-
// Ensure the file was created.
47+
// Verify that the file was created.
5048
if (!File.Exists(outputPath))
51-
throw new FileNotFoundException("The document was not saved correctly.", outputPath);
49+
throw new FileNotFoundException("Document was not saved correctly.", outputPath);
5250
}
5351
}
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
using System;
22
using System.IO;
3-
using System.Diagnostics;
43
using Aspose.Words;
5-
using Aspose.Words.Fonts;
6-
using Aspose.Words.Drawing;
7-
using Aspose.Words.Themes;
8-
using Aspose.Words.Saving;
94
using Aspose.Drawing;
105

116
public class Program
@@ -16,42 +11,27 @@ public static void Main()
1611
Document doc = new Document();
1712
DocumentBuilder builder = new DocumentBuilder(doc);
1813

19-
// Create a custom paragraph style named "MyCustomStyle".
14+
// Define a custom paragraph style with specific font settings.
2015
Style customStyle = doc.Styles.Add(StyleType.Paragraph, "MyCustomStyle");
21-
22-
// Define specific font settings for the style.
2316
customStyle.Font.Name = "Arial";
2417
customStyle.Font.Size = 14;
25-
customStyle.Font.Bold = true;
26-
27-
// Create a color using Aspose.Drawing, then convert to System.Drawing.Color.
28-
Aspose.Drawing.Color aspColor = Aspose.Drawing.Color.Blue;
29-
System.Drawing.Color sysColor = System.Drawing.Color.FromArgb(aspColor.ToArgb());
3018

19+
// Create a color using Aspose.Drawing.Color and convert it to System.Drawing.Color.
20+
Aspose.Drawing.Color asposeColor = Aspose.Drawing.Color.Blue;
21+
System.Drawing.Color sysColor = System.Drawing.Color.FromArgb(asposeColor.ToArgb());
3122
customStyle.Font.Color = sysColor;
3223

3324
// Apply the custom style to a range of paragraphs.
3425
builder.ParagraphFormat.Style = customStyle;
35-
builder.Writeln("Paragraph 1 with custom style.");
36-
builder.Writeln("Paragraph 2 with custom style.");
37-
builder.Writeln("Paragraph 3 with custom style.");
26+
builder.Writeln("First paragraph with custom style.");
27+
builder.Writeln("Second paragraph with custom style.");
3828

39-
// Switch back to the default "Normal" style for subsequent paragraphs.
29+
// Add a normal paragraph without the custom style.
4030
builder.ParagraphFormat.Style = doc.Styles["Normal"];
41-
builder.Writeln("Paragraph 4 with normal style.");
31+
builder.Writeln("A normal paragraph without custom style.");
4232

43-
// Validate that the style's font properties are set correctly.
44-
Debug.Assert(customStyle.Font.Name == "Arial");
45-
Debug.Assert(customStyle.Font.Size == 14);
46-
Debug.Assert(customStyle.Font.Bold == true);
47-
Debug.Assert(customStyle.Font.Color.ToArgb() == sysColor.ToArgb());
48-
49-
// Save the document to a file.
50-
string outputPath = "StyledParagraphs.docx";
33+
// Save the document to the current directory.
34+
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "StyledParagraphs.docx");
5135
doc.Save(outputPath);
52-
53-
// Ensure the output file was created.
54-
if (!File.Exists(outputPath))
55-
throw new Exception("The document was not saved successfully.");
5636
}
5737
}

fonts/apply-a-semi-transparent-fill-to-text-by-setting-font-fill-color-and-font-fill-transparenc.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,49 @@
22
using System.IO;
33
using Aspose.Words;
44
using Aspose.Words.Drawing;
5-
using Aspose.Drawing;
5+
using Aspose.Drawing; // For Aspose.Drawing.Color
66

77
public class Program
88
{
99
public static void Main()
1010
{
1111
// Create a new blank document.
1212
Document doc = new Document();
13-
14-
// Use DocumentBuilder to add a paragraph with a run of text.
1513
DocumentBuilder builder = new DocumentBuilder(doc);
16-
builder.Writeln("This text has a semi‑transparent fill.");
1714

18-
// Access the Font of the last run (the one just added).
15+
// Insert a line of text.
16+
builder.Writeln("Hello, semi‑transparent fill!");
17+
18+
// Access the font of the last inserted run.
1919
Aspose.Words.Font font = builder.Font;
2020

21-
// Ensure the fill is a solid fill.
22-
font.Fill.Solid();
21+
// Define a solid fill color (red) using Aspose.Drawing.Color.
22+
Aspose.Drawing.Color fillColor = Aspose.Drawing.Color.Red;
2323

24-
// Create an Aspose.Drawing.Color and convert it to System.Drawing.Color for the Fill.
25-
Aspose.Drawing.Color aspColor = Aspose.Drawing.Color.Blue;
26-
System.Drawing.Color sysColor = System.Drawing.Color.FromArgb(aspColor.ToArgb());
24+
// Apply the fill color to the font. The Solid method expects System.Drawing.Color,
25+
// so convert the Aspose.Drawing.Color to System.Drawing.Color.
26+
font.Fill.Solid(System.Drawing.Color.FromArgb(fillColor.ToArgb()));
2727

28-
// Set the fill color and transparency.
29-
font.Fill.Color = sysColor;
28+
// Set the fill transparency to 50% (0.5).
3029
font.Fill.Transparency = 0.5;
3130

32-
// Validate the applied properties.
33-
if (Math.Abs(font.Fill.Transparency - 0.5) > 0.0001 ||
34-
font.Fill.Color.ToArgb() != sysColor.ToArgb())
31+
// Validate that the properties were set correctly.
32+
if (font.Fill.Color.ToArgb() != fillColor.ToArgb() ||
33+
Math.Abs(font.Fill.Transparency - 0.5) > 0.0001)
3534
{
36-
throw new InvalidOperationException("Font fill properties were not set correctly.");
35+
throw new InvalidOperationException("Fill properties were not applied as expected.");
3736
}
3837

39-
// Prepare output directory.
40-
string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Output");
38+
// Ensure the output directory exists.
39+
string outputDir = "Output";
4140
Directory.CreateDirectory(outputDir);
41+
string outputPath = Path.Combine(outputDir, "SemiTransparentFill.docx");
4242

4343
// Save the document.
44-
string outputPath = Path.Combine(outputDir, "SemiTransparentFill.docx");
4544
doc.Save(outputPath);
4645

4746
// Verify that the file was created.
4847
if (!File.Exists(outputPath))
49-
{
50-
throw new FileNotFoundException("The document was not saved correctly.", outputPath);
51-
}
48+
throw new FileNotFoundException("The document was not saved.", outputPath);
5249
}
5350
}
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.IO;
33
using Aspose.Words;
4-
using Aspose.Drawing;
5-
using Newtonsoft.Json;
64

75
public class Program
86
{
@@ -11,31 +9,29 @@ public static void Main()
119
// Create a new blank document.
1210
Document doc = new Document();
1311

14-
// Use DocumentBuilder to add content.
15-
DocumentBuilder builder = new DocumentBuilder(doc);
12+
// Create a Run containing the desired text.
13+
Run run = new Run(doc, "Bold and Italic text");
1614

17-
// Apply bold and italic formatting to the current font.
18-
Aspose.Words.Font font = builder.Font;
15+
// Access the Run's font and set Bold and Italic to true.
16+
Aspose.Words.Font font = run.Font;
1917
font.Bold = true;
2018
font.Italic = true;
2119

22-
// Insert a line of text that will inherit the formatting.
23-
builder.Writeln("This text is bold and italic.");
24-
25-
// Validate that the formatting was applied.
20+
// Validate that the properties were set correctly.
2621
if (!font.Bold || !font.Italic)
27-
{
28-
throw new InvalidOperationException("Failed to set font styles.");
29-
}
22+
throw new InvalidOperationException("Failed to apply bold or italic style to the run.");
23+
24+
// Append the Run to the first paragraph of the document.
25+
doc.FirstSection.Body.FirstParagraph.AppendChild(run);
3026

31-
// Save the document to the current directory.
27+
// Define the output file path.
3228
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "BoldItalicRun.docx");
29+
30+
// Save the document.
3331
doc.Save(outputPath);
3432

3533
// Verify that the file was created.
3634
if (!File.Exists(outputPath))
37-
{
38-
throw new FileNotFoundException("The document was not saved.", outputPath);
39-
}
35+
throw new FileNotFoundException("The document was not saved correctly.", outputPath);
4036
}
4137
}

0 commit comments

Comments
 (0)