@nguyenphp/antigravity-marketing 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -78
- package/package.json +4 -3
- package/templates/.agent/skills/marketing-report-expert/SKILL.md +70 -0
- package/templates/.agent/skills/minimax-docx/LICENSE +21 -0
- package/templates/.agent/skills/minimax-docx/SKILL.md +274 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/academic_styles.xml +250 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/corporate_styles.xml +284 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/default_styles.xml +449 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/aesthetic-rules.xsd +470 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/business-rules.xsd +130 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/common-types.xsd +159 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/wml-subset.xsd +589 -0
- package/templates/.agent/skills/minimax-docx/references/cjk_typography.md +357 -0
- package/templates/.agent/skills/minimax-docx/references/cjk_university_template_guide.md +184 -0
- package/templates/.agent/skills/minimax-docx/references/comments_guide.md +191 -0
- package/templates/.agent/skills/minimax-docx/references/design_good_bad_examples.md +829 -0
- package/templates/.agent/skills/minimax-docx/references/design_principles.md +819 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_element_order.md +308 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part1.md +4061 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part2.md +2820 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part3.md +3381 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_namespaces.md +82 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_units.md +72 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_a_create.md +284 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_b_edit_content.md +295 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_c_apply_template.md +456 -0
- package/templates/.agent/skills/minimax-docx/references/track_changes_guide.md +200 -0
- package/templates/.agent/skills/minimax-docx/references/troubleshooting.md +506 -0
- package/templates/.agent/skills/minimax-docx/references/typography_guide.md +294 -0
- package/templates/.agent/skills/minimax-docx/references/xsd_validation_guide.md +158 -0
- package/templates/.agent/skills/minimax-docx/scripts/doc_to_docx.sh +40 -0
- package/templates/.agent/skills/minimax-docx/scripts/docx_preview.sh +37 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/MiniMaxAIDocx.Cli.csproj +19 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/Program.cs +18 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/AnalyzeCommand.cs +147 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ApplyTemplateCommand.cs +322 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/CreateCommand.cs +324 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/DiffCommand.cs +155 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/EditContentCommand.cs +487 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/FixOrderCommand.cs +108 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/MergeRunsCommand.cs +122 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ValidateCommand.cs +107 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/MiniMaxAIDocx.Core.csproj +15 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/CommentSynchronizer.cs +169 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/ElementOrder.cs +80 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/NamespaceConstants.cs +42 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/RunMerger.cs +81 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/StyleAnalyzer.cs +81 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/TrackChangesHelper.cs +99 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/UnitConverter.cs +23 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples.cs +1832 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch1.cs +910 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch2.cs +999 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch3.cs +1048 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch4.cs +1038 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/CharacterFormattingSamples.cs +1020 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/DocumentCreationSamples.cs +1121 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FieldAndTocSamples.cs +624 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FootnoteAndCommentSamples.cs +675 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/HeaderFooterSamples.cs +838 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ImageSamples.cs +917 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ListAndNumberingSamples.cs +826 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ParagraphFormattingSamples.cs +1199 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/StyleSystemSamples.cs +1487 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TableSamples.cs +1163 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TrackChangesSamples.cs +595 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/CjkHelper.cs +39 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/FontDefaults.cs +24 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/PageSizes.cs +20 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/BusinessRuleValidator.cs +224 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/GateCheckValidator.cs +148 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/ValidationResult.cs +23 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs +69 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.slnx +4 -0
- package/templates/.agent/skills/minimax-docx/scripts/env_check.sh +196 -0
- package/templates/.agent/skills/minimax-docx/scripts/setup.ps1 +274 -0
- package/templates/.agent/skills/minimax-docx/scripts/setup.sh +504 -0
- package/templates/.agent/skills/minimax-multimodal-toolkit/SKILL.md +359 -0
- package/templates/.agent/skills/minimax-pdf/README.md +222 -0
- package/templates/.agent/skills/minimax-pdf/SKILL.md +201 -0
- package/templates/.agent/skills/minimax-pdf/design/design.md +381 -0
- package/templates/.agent/skills/minimax-pdf/scripts/cover.py +1579 -0
- package/templates/.agent/skills/minimax-pdf/scripts/fill_inspect.py +200 -0
- package/templates/.agent/skills/minimax-pdf/scripts/fill_write.py +242 -0
- package/templates/.agent/skills/minimax-pdf/scripts/make.sh +491 -0
- package/templates/.agent/skills/minimax-pdf/scripts/merge.py +112 -0
- package/templates/.agent/skills/minimax-pdf/scripts/palette.py +559 -0
- package/templates/.agent/skills/minimax-pdf/scripts/reformat_parse.py +374 -0
- package/templates/.agent/skills/minimax-pdf/scripts/render_body.py +1055 -0
- package/templates/.agent/skills/minimax-pdf/scripts/render_cover.cjs +111 -0
- package/templates/.agent/skills/minimax-xlsx/SKILL.md +138 -0
- package/templates/.agent/skills/minimax-xlsx/references/create.md +691 -0
- package/templates/.agent/skills/minimax-xlsx/references/edit.md +684 -0
- package/templates/.agent/skills/minimax-xlsx/references/fix.md +37 -0
- package/templates/.agent/skills/minimax-xlsx/references/format.md +768 -0
- package/templates/.agent/skills/minimax-xlsx/references/ooxml-cheatsheet.md +231 -0
- package/templates/.agent/skills/minimax-xlsx/references/read-analyze.md +97 -0
- package/templates/.agent/skills/minimax-xlsx/references/validate.md +772 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/formula_check.py +422 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/libreoffice_recalc.py +248 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/shared_strings_builder.py +163 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/style_audit.py +575 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_add_column.py +395 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_insert_row.py +274 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_pack.py +87 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_reader.py +362 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_shift_rows.py +396 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_unpack.py +130 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/[Content_Types].xml +9 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/_rels/.rels +6 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/_rels/workbook.xml.rels +19 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/sharedStrings.xml +33 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/styles.xml +160 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/workbook.xml +30 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/worksheets/sheet1.xml +70 -0
- package/templates/.agent/skills/pptx-generator/SKILL.md +249 -0
- package/templates/.agent/skills/pptx-generator/references/design-system.md +392 -0
- package/templates/.agent/skills/pptx-generator/references/editing.md +162 -0
- package/templates/.agent/skills/pptx-generator/references/pitfalls.md +112 -0
- package/templates/.agent/skills/pptx-generator/references/pptxgenjs.md +420 -0
- package/templates/.agent/skills/pptx-generator/references/slide-types.md +413 -0
- package/templates/.agent/skills/tutorial-video-expert/SKILL.md +88 -0
- package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +170 -585
- package/templates/.agent/skills/vision-analysis/SKILL.md +174 -0
- package/templates/.agent/workflows/analyze.md +3 -0
- package/templates/.agent/workflows/brand-report.md +44 -0
- package/templates/.agent/workflows/report.md +49 -0
|
@@ -0,0 +1,1020 @@
|
|
|
1
|
+
using DocumentFormat.OpenXml;
|
|
2
|
+
using DocumentFormat.OpenXml.Wordprocessing;
|
|
3
|
+
|
|
4
|
+
namespace MiniMaxAIDocx.Core.Samples;
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Exhaustive reference for every RunProperties (w:rPr) child element in OpenXML.
|
|
8
|
+
/// Each method demonstrates one formatting category with full XML doc comments,
|
|
9
|
+
/// unit explanations, and gotchas. All code compiles against DocumentFormat.OpenXml 3.5.1.
|
|
10
|
+
/// </summary>
|
|
11
|
+
public static class CharacterFormattingSamples
|
|
12
|
+
{
|
|
13
|
+
// ──────────────────────────────────────────────────────────────────
|
|
14
|
+
// 1. Font Family (w:rFonts)
|
|
15
|
+
// ──────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Sets the font family on a run using all four font slots defined in OOXML.
|
|
19
|
+
/// <para>
|
|
20
|
+
/// <b>The four font slots:</b>
|
|
21
|
+
/// <list type="bullet">
|
|
22
|
+
/// <item><b>Ascii</b> — Used for characters in the Basic Latin range (U+0000–U+007F).
|
|
23
|
+
/// This is the primary slot for English text.</item>
|
|
24
|
+
/// <item><b>HighAnsi</b> — Used for characters above U+007F that are NOT East Asian
|
|
25
|
+
/// and NOT Complex Script. Covers Latin Extended, Greek, Cyrillic, etc.
|
|
26
|
+
/// Typically set to the same value as Ascii.</item>
|
|
27
|
+
/// <item><b>EastAsia</b> — Used for CJK Unified Ideographs (U+4E00–U+9FFF),
|
|
28
|
+
/// Hiragana, Katakana, Hangul, CJK Compatibility, etc.
|
|
29
|
+
/// Set this for Chinese / Japanese / Korean content.</item>
|
|
30
|
+
/// <item><b>ComplexScript</b> — Used for Complex Script (BiDi) ranges:
|
|
31
|
+
/// Arabic (U+0600–U+06FF), Hebrew (U+0590–U+05FF), Thai, Devanagari,
|
|
32
|
+
/// and other right-to-left or complex-shaping scripts.</item>
|
|
33
|
+
/// </list>
|
|
34
|
+
/// </para>
|
|
35
|
+
/// <para>
|
|
36
|
+
/// <b>Gotcha:</b> If HighAnsi is not set, Word may fall back to a different font
|
|
37
|
+
/// for characters like accented Latin (e.g., "e" uses Ascii, "e-acute" uses HighAnsi).
|
|
38
|
+
/// Always set both Ascii and HighAnsi together for consistent Western text rendering.
|
|
39
|
+
/// </para>
|
|
40
|
+
/// <para>
|
|
41
|
+
/// <b>Gotcha:</b> RunFonts also supports a <c>Hint</c> attribute
|
|
42
|
+
/// (<see cref="FontTypeHintValues"/>) that tells Word which slot to prefer when a
|
|
43
|
+
/// character could belong to multiple ranges. Values: Default, EastAsia, ComplexScript.
|
|
44
|
+
/// </para>
|
|
45
|
+
/// </summary>
|
|
46
|
+
public static void ApplyFontFamily(Run run)
|
|
47
|
+
{
|
|
48
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
49
|
+
|
|
50
|
+
rPr.RunFonts = new RunFonts
|
|
51
|
+
{
|
|
52
|
+
// Basic Latin characters (U+0000–U+007F)
|
|
53
|
+
Ascii = "Calibri",
|
|
54
|
+
|
|
55
|
+
// Non-CJK, non-complex characters above U+007F (Latin Extended, Greek, Cyrillic)
|
|
56
|
+
HighAnsi = "Calibri",
|
|
57
|
+
|
|
58
|
+
// CJK Ideographs, Hiragana, Katakana, Hangul
|
|
59
|
+
EastAsia = "SimSun",
|
|
60
|
+
|
|
61
|
+
// Arabic, Hebrew, Thai, Devanagari and other complex scripts
|
|
62
|
+
ComplexScript = "Arial",
|
|
63
|
+
|
|
64
|
+
// Hint tells Word which font slot to prefer for ambiguous characters.
|
|
65
|
+
// FontTypeHintValues.EastAsia makes Word prefer the EastAsia slot.
|
|
66
|
+
Hint = FontTypeHintValues.EastAsia
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ──────────────────────────────────────────────────────────────────
|
|
71
|
+
// 2. Font Size (w:sz, w:szCs)
|
|
72
|
+
// ──────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/// <summary>
|
|
75
|
+
/// Sets the font size on a run.
|
|
76
|
+
/// <para>
|
|
77
|
+
/// <b>Unit:</b> w:sz is in <b>half-points</b>. 12pt = 24 half-points, 10.5pt = 21 half-points.
|
|
78
|
+
/// </para>
|
|
79
|
+
/// <para>
|
|
80
|
+
/// <b>w:szCs</b> (FontSizeComplexScript) controls the size for Complex Script text
|
|
81
|
+
/// (Arabic, Hebrew, etc.). It must be set separately — it does NOT inherit from w:sz.
|
|
82
|
+
/// If you only set w:sz, Arabic/Hebrew text may render at a different size.
|
|
83
|
+
/// </para>
|
|
84
|
+
/// </summary>
|
|
85
|
+
/// <param name="run">The run to modify.</param>
|
|
86
|
+
/// <param name="points">Size in typographic points (e.g., 12.0 for 12pt).</param>
|
|
87
|
+
public static void ApplyFontSize(Run run, double points)
|
|
88
|
+
{
|
|
89
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
90
|
+
|
|
91
|
+
// Convert points to half-points: 12pt → "24"
|
|
92
|
+
var halfPoints = ((int)(points * 2)).ToString();
|
|
93
|
+
|
|
94
|
+
// w:sz — size for Latin / East Asian text
|
|
95
|
+
rPr.FontSize = new FontSize { Val = halfPoints };
|
|
96
|
+
|
|
97
|
+
// w:szCs — size for Complex Script text (Arabic, Hebrew, Thai, etc.)
|
|
98
|
+
// Must be set independently; does NOT inherit from w:sz.
|
|
99
|
+
rPr.FontSizeComplexScript = new FontSizeComplexScript { Val = halfPoints };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ──────────────────────────────────────────────────────────────────
|
|
103
|
+
// 3. Bold and Italic (w:b, w:bCs, w:i, w:iCs)
|
|
104
|
+
// ──────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/// <summary>
|
|
107
|
+
/// Applies bold and italic formatting to a run.
|
|
108
|
+
/// <para>
|
|
109
|
+
/// <b>Complex Script variants:</b> w:bCs and w:iCs control bold/italic for Complex
|
|
110
|
+
/// Script text (Arabic, Hebrew). They must be set independently.
|
|
111
|
+
/// </para>
|
|
112
|
+
/// <para>
|
|
113
|
+
/// <b>Gotcha:</b> <c>Bold</c> with no <c>Val</c> attribute means "true".
|
|
114
|
+
/// To explicitly disable bold (override a style), set <c>Val = false</c>.
|
|
115
|
+
/// An absent element means "inherit from style".
|
|
116
|
+
/// </para>
|
|
117
|
+
/// </summary>
|
|
118
|
+
public static void ApplyBoldItalic(Run run)
|
|
119
|
+
{
|
|
120
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
121
|
+
|
|
122
|
+
// Bold for Latin / East Asian text
|
|
123
|
+
// <w:b/> (no val) is equivalent to <w:b w:val="true"/>
|
|
124
|
+
rPr.Bold = new Bold();
|
|
125
|
+
|
|
126
|
+
// Bold for Complex Script (Arabic, Hebrew, etc.)
|
|
127
|
+
rPr.BoldComplexScript = new BoldComplexScript();
|
|
128
|
+
|
|
129
|
+
// Italic for Latin / East Asian text
|
|
130
|
+
rPr.Italic = new Italic();
|
|
131
|
+
|
|
132
|
+
// Italic for Complex Script
|
|
133
|
+
rPr.ItalicComplexScript = new ItalicComplexScript();
|
|
134
|
+
|
|
135
|
+
// To DISABLE bold (e.g., override a bold style), explicitly set Val = false:
|
|
136
|
+
// rPr.Bold = new Bold { Val = false };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ──────────────────────────────────────────────────────────────────
|
|
140
|
+
// 4. Underline (w:u) — ALL UnderlineValues
|
|
141
|
+
// ──────────────────────────────────────────────────────────────────
|
|
142
|
+
|
|
143
|
+
/// <summary>
|
|
144
|
+
/// Demonstrates every underline style available in OOXML.
|
|
145
|
+
/// <para>
|
|
146
|
+
/// <b>Underline color:</b> By default, the underline color matches the text color.
|
|
147
|
+
/// Override with <c>Color</c> (hex) and/or <c>ThemeColor</c>.
|
|
148
|
+
/// </para>
|
|
149
|
+
/// <para>
|
|
150
|
+
/// <b>All 18 styles:</b> Single, Words, Double, Thick, Dotted, DottedHeavy,
|
|
151
|
+
/// Dash, DashedHeavy, DashLong, DashLongHeavy, DotDash, DashDotHeavy,
|
|
152
|
+
/// DotDotDash, DashDotDotHeavy, Wave, WavyHeavy, WavyDouble, None.
|
|
153
|
+
/// </para>
|
|
154
|
+
/// </summary>
|
|
155
|
+
public static void ApplyAllUnderlineStyles(Run run)
|
|
156
|
+
{
|
|
157
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
158
|
+
|
|
159
|
+
// ── Standard underlines ──
|
|
160
|
+
// Single: standard single underline (most common)
|
|
161
|
+
rPr.Underline = new Underline { Val = UnderlineValues.Single };
|
|
162
|
+
|
|
163
|
+
// Words: underlines words only, not spaces
|
|
164
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Words };
|
|
165
|
+
|
|
166
|
+
// Double: two parallel lines
|
|
167
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Double };
|
|
168
|
+
|
|
169
|
+
// Thick: single thick line
|
|
170
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Thick };
|
|
171
|
+
|
|
172
|
+
// ── Dotted variants ──
|
|
173
|
+
// Dotted: dots
|
|
174
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Dotted };
|
|
175
|
+
|
|
176
|
+
// DottedHeavy: thick dots
|
|
177
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DottedHeavy };
|
|
178
|
+
|
|
179
|
+
// ── Dash variants ──
|
|
180
|
+
// Dash: short dashes
|
|
181
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Dash };
|
|
182
|
+
|
|
183
|
+
// DashedHeavy: thick short dashes
|
|
184
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DashedHeavy };
|
|
185
|
+
|
|
186
|
+
// DashLong: long dashes
|
|
187
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DashLong };
|
|
188
|
+
|
|
189
|
+
// DashLongHeavy: thick long dashes
|
|
190
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DashLongHeavy };
|
|
191
|
+
|
|
192
|
+
// ── Dash-dot combinations ──
|
|
193
|
+
// DotDash: alternating dot-dash (._._.)
|
|
194
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DotDash };
|
|
195
|
+
|
|
196
|
+
// DashDotHeavy: thick dot-dash
|
|
197
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DashDotHeavy };
|
|
198
|
+
|
|
199
|
+
// DotDotDash: dot-dot-dash (.._.._)
|
|
200
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DotDotDash };
|
|
201
|
+
|
|
202
|
+
// DashDotDotHeavy: thick dot-dot-dash
|
|
203
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.DashDotDotHeavy };
|
|
204
|
+
|
|
205
|
+
// ── Wave variants ──
|
|
206
|
+
// Wave: wavy line
|
|
207
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.Wave };
|
|
208
|
+
|
|
209
|
+
// WavyHeavy: thick wavy line
|
|
210
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.WavyHeavy };
|
|
211
|
+
|
|
212
|
+
// WavyDouble: double wavy line
|
|
213
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.WavyDouble };
|
|
214
|
+
|
|
215
|
+
// ── Remove underline ──
|
|
216
|
+
// None: explicitly remove underline (override style)
|
|
217
|
+
// rPr.Underline = new Underline { Val = UnderlineValues.None };
|
|
218
|
+
|
|
219
|
+
// ── Underline with custom color ──
|
|
220
|
+
// rPr.Underline = new Underline
|
|
221
|
+
// {
|
|
222
|
+
// Val = UnderlineValues.Single,
|
|
223
|
+
// Color = "FF0000", // Red underline, independent of text color
|
|
224
|
+
// ThemeColor = ThemeColorValues.Accent1 // Or use theme color
|
|
225
|
+
// };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ──────────────────────────────────────────────────────────────────
|
|
229
|
+
// 5. Text Color (w:color)
|
|
230
|
+
// ──────────────────────────────────────────────────────────────────
|
|
231
|
+
|
|
232
|
+
/// <summary>
|
|
233
|
+
/// Sets the text color on a run using hex value and/or theme colors.
|
|
234
|
+
/// <para>
|
|
235
|
+
/// <b>Val:</b> 6-digit hex RGB string WITHOUT the "#" prefix (e.g., "FF0000" for red).
|
|
236
|
+
/// The special value "auto" means the application decides (usually black).
|
|
237
|
+
/// </para>
|
|
238
|
+
/// <para>
|
|
239
|
+
/// <b>ThemeColor:</b> References a theme color slot. When set alongside Val, the
|
|
240
|
+
/// theme color takes precedence in theme-aware applications, but Val is the fallback.
|
|
241
|
+
/// </para>
|
|
242
|
+
/// <para>
|
|
243
|
+
/// <b>ThemeShade:</b> Darkens the theme color. Value is a 2-digit hex string (00–FF).
|
|
244
|
+
/// 00 = no change, FF = fully darkened. Applied as a multiplier.
|
|
245
|
+
/// </para>
|
|
246
|
+
/// <para>
|
|
247
|
+
/// <b>ThemeTint:</b> Lightens the theme color. Value is a 2-digit hex string (00–FF).
|
|
248
|
+
/// 00 = no change, FF = fully lightened (white). Applied as a multiplier.
|
|
249
|
+
/// </para>
|
|
250
|
+
/// <para>
|
|
251
|
+
/// <b>Gotcha:</b> ThemeShade and ThemeTint are mutually exclusive — only one should
|
|
252
|
+
/// be set. If both are present, behavior is undefined.
|
|
253
|
+
/// </para>
|
|
254
|
+
/// </summary>
|
|
255
|
+
public static void ApplyColor(Run run)
|
|
256
|
+
{
|
|
257
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
258
|
+
|
|
259
|
+
// Simple hex color (no theme)
|
|
260
|
+
rPr.Color = new Color { Val = "FF0000" }; // Red
|
|
261
|
+
|
|
262
|
+
// Theme-based color with fallback hex value
|
|
263
|
+
rPr.Color = new Color
|
|
264
|
+
{
|
|
265
|
+
Val = "2F5496", // Fallback hex for non-theme-aware renderers
|
|
266
|
+
ThemeColor = ThemeColorValues.Accent1, // Theme color slot
|
|
267
|
+
ThemeTint = "99" // Lighten: 99 hex → ~60% tint
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Theme color darkened
|
|
271
|
+
rPr.Color = new Color
|
|
272
|
+
{
|
|
273
|
+
Val = "1F3864",
|
|
274
|
+
ThemeColor = ThemeColorValues.Accent1,
|
|
275
|
+
ThemeShade = "BF" // Darken: BF hex → ~75% shade
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// Auto color (application-determined, typically black on white)
|
|
279
|
+
rPr.Color = new Color { Val = "auto" };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ──────────────────────────────────────────────────────────────────
|
|
283
|
+
// 6. Highlight (w:highlight)
|
|
284
|
+
// ──────────────────────────────────────────────────────────────────
|
|
285
|
+
|
|
286
|
+
/// <summary>
|
|
287
|
+
/// Applies text highlighting (the "marker pen" effect in Word's UI).
|
|
288
|
+
/// <para>
|
|
289
|
+
/// <b>All HighlightColorValues:</b> Yellow, Green, Cyan, Magenta, Blue, Red,
|
|
290
|
+
/// DarkBlue, DarkCyan, DarkGreen, DarkMagenta, DarkRed, DarkYellow,
|
|
291
|
+
/// DarkGray, LightGray, Black, White, None.
|
|
292
|
+
/// </para>
|
|
293
|
+
/// <para>
|
|
294
|
+
/// <b>Gotcha:</b> Highlighting is limited to the 17 preset colors above.
|
|
295
|
+
/// For arbitrary background colors, use <see cref="ApplyShading"/> on RunProperties
|
|
296
|
+
/// instead — it supports any hex color.
|
|
297
|
+
/// </para>
|
|
298
|
+
/// </summary>
|
|
299
|
+
public static void ApplyHighlight(Run run)
|
|
300
|
+
{
|
|
301
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
302
|
+
|
|
303
|
+
// Standard yellow highlight (most common for "tracked" or "review" marks)
|
|
304
|
+
rPr.Highlight = new Highlight { Val = HighlightColorValues.Yellow };
|
|
305
|
+
|
|
306
|
+
// All available highlight colors for reference:
|
|
307
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Green };
|
|
308
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Cyan };
|
|
309
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Magenta };
|
|
310
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Blue };
|
|
311
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Red };
|
|
312
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkBlue };
|
|
313
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkCyan };
|
|
314
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkGreen };
|
|
315
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkMagenta };
|
|
316
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkRed };
|
|
317
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkYellow };
|
|
318
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.DarkGray };
|
|
319
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.LightGray };
|
|
320
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Black };
|
|
321
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.White };
|
|
322
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.None }; // Remove
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// ──────────────────────────────────────────────────────────────────
|
|
326
|
+
// 7. Strikethrough (w:strike, w:dstrike)
|
|
327
|
+
// ──────────────────────────────────────────────────────────────────
|
|
328
|
+
|
|
329
|
+
/// <summary>
|
|
330
|
+
/// Applies strikethrough or double-strikethrough formatting.
|
|
331
|
+
/// <para>
|
|
332
|
+
/// <b>Gotcha:</b> w:strike and w:dstrike are mutually exclusive.
|
|
333
|
+
/// If both are present, behavior is undefined (Word typically uses the last one set).
|
|
334
|
+
/// </para>
|
|
335
|
+
/// </summary>
|
|
336
|
+
public static void ApplyStrikethrough(Run run)
|
|
337
|
+
{
|
|
338
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
339
|
+
|
|
340
|
+
// Single strikethrough: a single horizontal line through the text
|
|
341
|
+
rPr.Strike = new Strike(); // No Val = true
|
|
342
|
+
|
|
343
|
+
// Double strikethrough: two horizontal lines through the text
|
|
344
|
+
// rPr.DoubleStrike = new DoubleStrike();
|
|
345
|
+
|
|
346
|
+
// To explicitly disable (override a style that has strikethrough):
|
|
347
|
+
// rPr.Strike = new Strike { Val = false };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ──────────────────────────────────────────────────────────────────
|
|
351
|
+
// 8. Superscript / Subscript (w:vertAlign)
|
|
352
|
+
// ──────────────────────────────────────────────────────────────────
|
|
353
|
+
|
|
354
|
+
/// <summary>
|
|
355
|
+
/// Applies superscript or subscript vertical alignment.
|
|
356
|
+
/// <para>
|
|
357
|
+
/// <b>Values:</b>
|
|
358
|
+
/// <list type="bullet">
|
|
359
|
+
/// <item><b>Superscript</b> — raised text, reduced size (e.g., x²)</item>
|
|
360
|
+
/// <item><b>Subscript</b> — lowered text, reduced size (e.g., H₂O)</item>
|
|
361
|
+
/// <item><b>Baseline</b> — normal position (use to override style)</item>
|
|
362
|
+
/// </list>
|
|
363
|
+
/// </para>
|
|
364
|
+
/// <para>
|
|
365
|
+
/// <b>Gotcha:</b> This is NOT the same as <see cref="ApplyPosition"/>.
|
|
366
|
+
/// VerticalTextAlignment changes both position AND size (like Word's superscript button).
|
|
367
|
+
/// Position (w:position) only shifts the baseline without changing font size.
|
|
368
|
+
/// </para>
|
|
369
|
+
/// </summary>
|
|
370
|
+
public static void ApplySuperSubscript(Run run)
|
|
371
|
+
{
|
|
372
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
373
|
+
|
|
374
|
+
// Superscript (raised + smaller font)
|
|
375
|
+
rPr.VerticalTextAlignment = new VerticalTextAlignment
|
|
376
|
+
{
|
|
377
|
+
Val = VerticalPositionValues.Superscript
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Subscript (lowered + smaller font)
|
|
381
|
+
// rPr.VerticalTextAlignment = new VerticalTextAlignment
|
|
382
|
+
// {
|
|
383
|
+
// Val = VerticalPositionValues.Subscript
|
|
384
|
+
// };
|
|
385
|
+
|
|
386
|
+
// Baseline — explicitly reset to normal (override a style)
|
|
387
|
+
// rPr.VerticalTextAlignment = new VerticalTextAlignment
|
|
388
|
+
// {
|
|
389
|
+
// Val = VerticalPositionValues.Baseline
|
|
390
|
+
// };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ──────────────────────────────────────────────────────────────────
|
|
394
|
+
// 9. Caps / Small Caps (w:caps, w:smallCaps)
|
|
395
|
+
// ──────────────────────────────────────────────────────────────────
|
|
396
|
+
|
|
397
|
+
/// <summary>
|
|
398
|
+
/// Applies ALL CAPS or Small Caps display formatting.
|
|
399
|
+
/// <para>
|
|
400
|
+
/// <b>Caps (w:caps):</b> Displays all characters as uppercase. The underlying text
|
|
401
|
+
/// is NOT modified — it remains lowercase in the XML. This is a display-only transform.
|
|
402
|
+
/// </para>
|
|
403
|
+
/// <para>
|
|
404
|
+
/// <b>SmallCaps (w:smallCaps):</b> Displays lowercase letters as smaller uppercase
|
|
405
|
+
/// glyphs. Original uppercase letters remain full size. Common in legal and academic
|
|
406
|
+
/// documents for author names and section references.
|
|
407
|
+
/// </para>
|
|
408
|
+
/// <para>
|
|
409
|
+
/// <b>Gotcha:</b> w:caps and w:smallCaps are mutually exclusive.
|
|
410
|
+
/// If both are present, w:caps wins.
|
|
411
|
+
/// </para>
|
|
412
|
+
/// </summary>
|
|
413
|
+
public static void ApplyCapsSmallCaps(Run run)
|
|
414
|
+
{
|
|
415
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
416
|
+
|
|
417
|
+
// ALL CAPS display (text stored as-is, displayed uppercase)
|
|
418
|
+
rPr.Caps = new Caps();
|
|
419
|
+
|
|
420
|
+
// Small Caps display (lowercase → small uppercase glyphs)
|
|
421
|
+
// rPr.SmallCaps = new SmallCaps();
|
|
422
|
+
|
|
423
|
+
// Disable (override a style):
|
|
424
|
+
// rPr.Caps = new Caps { Val = false };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// ──────────────────────────────────────────────────────────────────
|
|
428
|
+
// 10. Character Spacing (w:spacing)
|
|
429
|
+
// ──────────────────────────────────────────────────────────────────
|
|
430
|
+
|
|
431
|
+
/// <summary>
|
|
432
|
+
/// Adjusts the spacing between characters (tracking / character spacing).
|
|
433
|
+
/// <para>
|
|
434
|
+
/// <b>Unit:</b> Value is in <b>twips</b> (1/20 of a point).
|
|
435
|
+
/// Positive values = expanded (letters spread apart).
|
|
436
|
+
/// Negative values = condensed (letters squeezed together).
|
|
437
|
+
/// </para>
|
|
438
|
+
/// <para>
|
|
439
|
+
/// Examples: 20 twips = 1pt expanded, -10 twips = 0.5pt condensed,
|
|
440
|
+
/// 40 twips = 2pt expanded.
|
|
441
|
+
/// </para>
|
|
442
|
+
/// <para>
|
|
443
|
+
/// <b>Gotcha:</b> This is NOT the same as kerning (w:kern).
|
|
444
|
+
/// Spacing applies a uniform offset between ALL characters.
|
|
445
|
+
/// Kerning adjusts spacing between specific character PAIRS based on font metrics.
|
|
446
|
+
/// </para>
|
|
447
|
+
/// </summary>
|
|
448
|
+
public static void ApplyCharacterSpacing(Run run)
|
|
449
|
+
{
|
|
450
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
451
|
+
|
|
452
|
+
// Expanded by 1pt (20 twips)
|
|
453
|
+
rPr.Spacing = new Spacing { Val = 20 };
|
|
454
|
+
|
|
455
|
+
// Condensed by 0.5pt (-10 twips)
|
|
456
|
+
// rPr.Spacing = new Spacing { Val = -10 };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ──────────────────────────────────────────────────────────────────
|
|
460
|
+
// 11. Position — raised/lowered baseline (w:position)
|
|
461
|
+
// ──────────────────────────────────────────────────────────────────
|
|
462
|
+
|
|
463
|
+
/// <summary>
|
|
464
|
+
/// Raises or lowers the text position relative to the baseline.
|
|
465
|
+
/// <para>
|
|
466
|
+
/// <b>Unit:</b> Value is in <b>half-points</b>.
|
|
467
|
+
/// Positive values = raised above baseline.
|
|
468
|
+
/// Negative values = lowered below baseline.
|
|
469
|
+
/// </para>
|
|
470
|
+
/// <para>
|
|
471
|
+
/// Examples: 6 half-points = 3pt raised, -4 half-points = 2pt lowered.
|
|
472
|
+
/// </para>
|
|
473
|
+
/// <para>
|
|
474
|
+
/// <b>Gotcha:</b> Unlike <see cref="ApplySuperSubscript"/>, Position does NOT change
|
|
475
|
+
/// the font size. It only shifts the vertical position. Use this for fine-tuning
|
|
476
|
+
/// baseline alignment (e.g., aligning inline images with text).
|
|
477
|
+
/// </para>
|
|
478
|
+
/// </summary>
|
|
479
|
+
public static void ApplyPosition(Run run)
|
|
480
|
+
{
|
|
481
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
482
|
+
|
|
483
|
+
// Raise text by 3pt (6 half-points)
|
|
484
|
+
rPr.Position = new Position { Val = "6" };
|
|
485
|
+
|
|
486
|
+
// Lower text by 2pt (-4 half-points)
|
|
487
|
+
// rPr.Position = new Position { Val = "-4" };
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ──────────────────────────────────────────────────────────────────
|
|
491
|
+
// 12. Run Shading (w:shd) — arbitrary background color on text
|
|
492
|
+
// ──────────────────────────────────────────────────────────────────
|
|
493
|
+
|
|
494
|
+
/// <summary>
|
|
495
|
+
/// Applies shading (background color) to a run.
|
|
496
|
+
/// <para>
|
|
497
|
+
/// <b>Use case:</b> When you need a background color that is NOT one of the 17
|
|
498
|
+
/// preset highlight colors. Shading supports any hex RGB value.
|
|
499
|
+
/// </para>
|
|
500
|
+
/// <para>
|
|
501
|
+
/// <b>Fill:</b> The background color (hex RGB, e.g., "FFFF00" for yellow).
|
|
502
|
+
/// <b>Val:</b> The shading pattern. Use <c>ShadingPatternValues.Clear</c> for a
|
|
503
|
+
/// solid background fill (most common). Other patterns overlay a foreground color.
|
|
504
|
+
/// <b>Color:</b> The foreground/pattern color (only meaningful for non-Clear patterns).
|
|
505
|
+
/// </para>
|
|
506
|
+
/// <para>
|
|
507
|
+
/// <b>Gotcha:</b> If Val is omitted or set to Nil, the shading may not render.
|
|
508
|
+
/// Always set Val = Clear for solid backgrounds.
|
|
509
|
+
/// </para>
|
|
510
|
+
/// </summary>
|
|
511
|
+
public static void ApplyShading(Run run)
|
|
512
|
+
{
|
|
513
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
514
|
+
|
|
515
|
+
// Solid light-blue background
|
|
516
|
+
rPr.Shading = new Shading
|
|
517
|
+
{
|
|
518
|
+
Val = ShadingPatternValues.Clear, // Solid fill (no pattern)
|
|
519
|
+
Fill = "DAEEF3", // Background color: light blue
|
|
520
|
+
Color = "auto" // Foreground/pattern color: auto
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// Theme-colored shading
|
|
524
|
+
// rPr.Shading = new Shading
|
|
525
|
+
// {
|
|
526
|
+
// Val = ShadingPatternValues.Clear,
|
|
527
|
+
// Fill = "auto",
|
|
528
|
+
// ThemeFill = ThemeColorValues.Accent1,
|
|
529
|
+
// ThemeFillTint = "33" // Light tint of accent1
|
|
530
|
+
// };
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ──────────────────────────────────────────────────────────────────
|
|
534
|
+
// 13. Text Border (w:bdr)
|
|
535
|
+
// ──────────────────────────────────────────────────────────────────
|
|
536
|
+
|
|
537
|
+
/// <summary>
|
|
538
|
+
/// Applies a border around a run of text.
|
|
539
|
+
/// <para>
|
|
540
|
+
/// <b>Val:</b> Border style — Single, Double, Dotted, Dashed, DotDash, DotDotDash,
|
|
541
|
+
/// Triple, ThickThinSmallGap, ThinThickSmallGap, ThickThinMediumGap, etc.
|
|
542
|
+
/// Use <c>BorderValues.None</c> to remove.
|
|
543
|
+
/// </para>
|
|
544
|
+
/// <para>
|
|
545
|
+
/// <b>Size:</b> Border width in <b>eighths of a point</b>. 4 = 0.5pt, 8 = 1pt, 12 = 1.5pt.
|
|
546
|
+
/// Valid range: 2–96 (0.25pt–12pt).
|
|
547
|
+
/// </para>
|
|
548
|
+
/// <para>
|
|
549
|
+
/// <b>Space:</b> Padding between text and border in <b>points</b>. Range: 0–31.
|
|
550
|
+
/// </para>
|
|
551
|
+
/// <para>
|
|
552
|
+
/// <b>Gotcha:</b> Run borders look like "boxed text" in Word. Adjacent runs with
|
|
553
|
+
/// borders will have separate boxes — they do NOT merge into one box.
|
|
554
|
+
/// </para>
|
|
555
|
+
/// </summary>
|
|
556
|
+
public static void ApplyBorder(Run run)
|
|
557
|
+
{
|
|
558
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
559
|
+
|
|
560
|
+
rPr.Border = new Border
|
|
561
|
+
{
|
|
562
|
+
Val = BorderValues.Single, // Single-line border
|
|
563
|
+
Size = 4, // 0.5pt wide (4 eighths of a point)
|
|
564
|
+
Space = 1, // 1pt padding between text and border
|
|
565
|
+
Color = "4472C4" // Border color (blue)
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// Double border
|
|
569
|
+
// rPr.Border = new Border
|
|
570
|
+
// {
|
|
571
|
+
// Val = BorderValues.Double,
|
|
572
|
+
// Size = 4,
|
|
573
|
+
// Space = 1,
|
|
574
|
+
// Color = "auto"
|
|
575
|
+
// };
|
|
576
|
+
|
|
577
|
+
// Theme-colored border
|
|
578
|
+
// rPr.Border = new Border
|
|
579
|
+
// {
|
|
580
|
+
// Val = BorderValues.Single,
|
|
581
|
+
// Size = 8,
|
|
582
|
+
// Space = 1,
|
|
583
|
+
// Color = "auto",
|
|
584
|
+
// ThemeColor = ThemeColorValues.Accent1
|
|
585
|
+
// };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// ──────────────────────────────────────────────────────────────────
|
|
589
|
+
// 14. Run Style Reference (w:rStyle)
|
|
590
|
+
// ──────────────────────────────────────────────────────────────────
|
|
591
|
+
|
|
592
|
+
/// <summary>
|
|
593
|
+
/// Applies a named character style to a run.
|
|
594
|
+
/// <para>
|
|
595
|
+
/// <b>Val:</b> The style ID (not the display name). For example, Word's built-in
|
|
596
|
+
/// "Strong" style has ID "Strong", "Emphasis" has ID "Emphasis".
|
|
597
|
+
/// Custom styles use their internal ID which may differ from the display name.
|
|
598
|
+
/// </para>
|
|
599
|
+
/// <para>
|
|
600
|
+
/// <b>Gotcha:</b> The style must exist in the document's styles.xml (StyleDefinitionsPart).
|
|
601
|
+
/// Referencing a non-existent style ID will not cause an error, but the formatting
|
|
602
|
+
/// defined by that style will not be applied — Word silently ignores unknown style IDs.
|
|
603
|
+
/// </para>
|
|
604
|
+
/// <para>
|
|
605
|
+
/// <b>Gotcha:</b> RunProperties set directly on the run override properties from the
|
|
606
|
+
/// style (direct formatting wins). To inherit everything from the style, do not set
|
|
607
|
+
/// additional properties on the RunProperties.
|
|
608
|
+
/// </para>
|
|
609
|
+
/// </summary>
|
|
610
|
+
public static void ApplyRunStyle(Run run)
|
|
611
|
+
{
|
|
612
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
613
|
+
|
|
614
|
+
// Reference the built-in "Strong" character style (bold)
|
|
615
|
+
rPr.RunStyle = new RunStyle { Val = "Strong" };
|
|
616
|
+
|
|
617
|
+
// Common built-in character style IDs:
|
|
618
|
+
// "Strong" — Bold
|
|
619
|
+
// "Emphasis" — Italic
|
|
620
|
+
// "IntenseEmphasis" — Bold + Italic + Accent color
|
|
621
|
+
// "SubtleEmphasis" — Italic + gray color
|
|
622
|
+
// "BookTitle" — Small caps + spacing
|
|
623
|
+
// "IntenseReference" — Bold + Small caps + Accent color + Underline
|
|
624
|
+
// "SubtleReference" — Small caps + Accent color
|
|
625
|
+
// "Hyperlink" — Blue + Underline
|
|
626
|
+
// "FollowedHyperlink" — Purple + Underline
|
|
627
|
+
// "FootnoteReference" — Superscript
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ──────────────────────────────────────────────────────────────────
|
|
631
|
+
// 15. Hidden Text (w:vanish)
|
|
632
|
+
// ──────────────────────────────────────────────────────────────────
|
|
633
|
+
|
|
634
|
+
/// <summary>
|
|
635
|
+
/// Makes text hidden (invisible in normal view, shown with dotted underline
|
|
636
|
+
/// when "Show/Hide" is toggled in Word).
|
|
637
|
+
/// <para>
|
|
638
|
+
/// <b>Use cases:</b> Hidden text for internal notes, index entries, TOC field codes.
|
|
639
|
+
/// Hidden text is NOT printed by default (controlled by Word's print settings).
|
|
640
|
+
/// </para>
|
|
641
|
+
/// <para>
|
|
642
|
+
/// <b>Gotcha:</b> Hidden text still participates in page layout calculations in some
|
|
643
|
+
/// modes. It can affect pagination when revealed.
|
|
644
|
+
/// </para>
|
|
645
|
+
/// </summary>
|
|
646
|
+
public static void ApplyHiddenText(Run run)
|
|
647
|
+
{
|
|
648
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
649
|
+
|
|
650
|
+
// Make text hidden
|
|
651
|
+
rPr.Vanish = new Vanish();
|
|
652
|
+
|
|
653
|
+
// Explicitly un-hide (override a style that hides text):
|
|
654
|
+
// rPr.Vanish = new Vanish { Val = false };
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// ──────────────────────────────────────────────────────────────────
|
|
658
|
+
// 16. Right-to-Left / Complex Script (w:rtl, w:cs)
|
|
659
|
+
// ──────────────────────────────────────────────────────────────────
|
|
660
|
+
|
|
661
|
+
/// <summary>
|
|
662
|
+
/// Marks a run as right-to-left and/or complex script.
|
|
663
|
+
/// <para>
|
|
664
|
+
/// <b>RightToLeft (w:rtl):</b> Indicates the run contains right-to-left text.
|
|
665
|
+
/// This affects character ordering and cursor movement. Required for Arabic/Hebrew text.
|
|
666
|
+
/// </para>
|
|
667
|
+
/// <para>
|
|
668
|
+
/// <b>ComplexScript (w:cs):</b> Marks the run as containing complex script text.
|
|
669
|
+
/// When set, Word uses the ComplexScript variants of font properties:
|
|
670
|
+
/// w:szCs instead of w:sz, w:bCs instead of w:b, rFonts@cs instead of rFonts@ascii.
|
|
671
|
+
/// </para>
|
|
672
|
+
/// <para>
|
|
673
|
+
/// <b>Gotcha:</b> For Arabic/Hebrew content, you typically need BOTH w:rtl and w:cs.
|
|
674
|
+
/// Thai text needs w:cs but NOT w:rtl (Thai is left-to-right but uses complex shaping).
|
|
675
|
+
/// </para>
|
|
676
|
+
/// </summary>
|
|
677
|
+
public static void ApplyRightToLeft(Run run)
|
|
678
|
+
{
|
|
679
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
680
|
+
|
|
681
|
+
// Mark as right-to-left (for Arabic/Hebrew)
|
|
682
|
+
rPr.RightToLeftText = new RightToLeftText();
|
|
683
|
+
|
|
684
|
+
// Mark as complex script (use CS font/size/bold/italic variants)
|
|
685
|
+
rPr.ComplexScript = new ComplexScript();
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// ──────────────────────────────────────────────────────────────────
|
|
689
|
+
// 17. Emphasis Mark (w:em) — CJK emphasis dots
|
|
690
|
+
// ──────────────────────────────────────────────────────────────────
|
|
691
|
+
|
|
692
|
+
/// <summary>
|
|
693
|
+
/// Applies emphasis marks (dots/circles above or below characters).
|
|
694
|
+
/// Primarily used in CJK (Chinese, Japanese, Korean) typography.
|
|
695
|
+
/// <para>
|
|
696
|
+
/// <b>Values:</b>
|
|
697
|
+
/// <list type="bullet">
|
|
698
|
+
/// <item><b>Dot</b> — small filled dot above each character (Japanese: 傍点)</item>
|
|
699
|
+
/// <item><b>Comma</b> — small comma-like mark above (used in some CJK styles)</item>
|
|
700
|
+
/// <item><b>Circle</b> — small open circle above each character</item>
|
|
701
|
+
/// <item><b>UnderDot</b> — small filled dot below each character (Chinese style)</item>
|
|
702
|
+
/// <item><b>None</b> — remove emphasis marks</item>
|
|
703
|
+
/// </list>
|
|
704
|
+
/// </para>
|
|
705
|
+
/// <para>
|
|
706
|
+
/// <b>Gotcha:</b> Emphasis marks are distinct from underlines. They appear as individual
|
|
707
|
+
/// marks above/below each character, not as a continuous line.
|
|
708
|
+
/// </para>
|
|
709
|
+
/// </summary>
|
|
710
|
+
public static void ApplyEmphasisMark(Run run)
|
|
711
|
+
{
|
|
712
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
713
|
+
|
|
714
|
+
// Dot emphasis (most common in Japanese)
|
|
715
|
+
rPr.Emphasis = new Emphasis { Val = EmphasisMarkValues.Dot };
|
|
716
|
+
|
|
717
|
+
// Other emphasis mark styles:
|
|
718
|
+
// rPr.Emphasis = new Emphasis { Val = EmphasisMarkValues.Comma };
|
|
719
|
+
// rPr.Emphasis = new Emphasis { Val = EmphasisMarkValues.Circle };
|
|
720
|
+
// rPr.Emphasis = new Emphasis { Val = EmphasisMarkValues.UnderDot };
|
|
721
|
+
// rPr.Emphasis = new Emphasis { Val = EmphasisMarkValues.None };
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ──────────────────────────────────────────────────────────────────
|
|
725
|
+
// 18. Kerning (w:kern)
|
|
726
|
+
// ──────────────────────────────────────────────────────────────────
|
|
727
|
+
|
|
728
|
+
/// <summary>
|
|
729
|
+
/// Sets the kerning threshold for automatic font-based kerning.
|
|
730
|
+
/// <para>
|
|
731
|
+
/// <b>Unit:</b> Value is in <b>half-points</b>. Characters at or above this size
|
|
732
|
+
/// will have kerning applied (the font's kern table adjusts spacing between
|
|
733
|
+
/// specific character pairs, e.g., "AV", "To", "WA").
|
|
734
|
+
/// </para>
|
|
735
|
+
/// <para>
|
|
736
|
+
/// <b>Common values:</b>
|
|
737
|
+
/// <list type="bullet">
|
|
738
|
+
/// <item>0 — Disable kerning entirely</item>
|
|
739
|
+
/// <item>2 (1pt) — Kern all text (including body text)</item>
|
|
740
|
+
/// <item>28 (14pt) — Kern only headings (Word's typical default threshold)</item>
|
|
741
|
+
/// </list>
|
|
742
|
+
/// </para>
|
|
743
|
+
/// <para>
|
|
744
|
+
/// <b>Gotcha:</b> Kerning only works if the font contains a kern table.
|
|
745
|
+
/// Most professional fonts (Times New Roman, Calibri, Arial) include kern data.
|
|
746
|
+
/// </para>
|
|
747
|
+
/// </summary>
|
|
748
|
+
public static void ApplyKerning(Run run)
|
|
749
|
+
{
|
|
750
|
+
var rPr = run.GetOrCreateRunProperties();
|
|
751
|
+
|
|
752
|
+
// Kern text at 14pt and above (28 half-points)
|
|
753
|
+
rPr.Kern = new Kern { Val = 28 };
|
|
754
|
+
|
|
755
|
+
// Kern all text regardless of size (0 half-points is "no threshold"
|
|
756
|
+
// but some renderers interpret 0 as "off". Use 1 or 2 to be safe.)
|
|
757
|
+
// rPr.Kern = new Kern { Val = 2 };
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// ──────────────────────────────────────────────────────────────────
|
|
761
|
+
// 19. Fully Formatted Run (combining multiple properties)
|
|
762
|
+
// ──────────────────────────────────────────────────────────────────
|
|
763
|
+
|
|
764
|
+
/// <summary>
|
|
765
|
+
/// Creates a fully formatted run combining multiple character properties.
|
|
766
|
+
/// Demonstrates the correct way to build a run with RunProperties.
|
|
767
|
+
/// <para>
|
|
768
|
+
/// <b>Key principle:</b> Create RunProperties first, add all child elements,
|
|
769
|
+
/// then set it on the run BEFORE adding text. The run's XML structure must be:
|
|
770
|
+
/// <c><w:r><w:rPr>...</w:rPr><w:t>text</w:t></w:r></c>
|
|
771
|
+
/// </para>
|
|
772
|
+
/// <para>
|
|
773
|
+
/// <b>Gotcha:</b> If you add RunProperties AFTER the Text element, it will appear
|
|
774
|
+
/// after w:t in the XML, which is technically invalid OOXML ordering. Word tolerates
|
|
775
|
+
/// it but some third-party parsers may not. Always add rPr first.
|
|
776
|
+
/// </para>
|
|
777
|
+
/// </summary>
|
|
778
|
+
public static Run CreateFullyFormattedRun()
|
|
779
|
+
{
|
|
780
|
+
// Build RunProperties with all desired formatting
|
|
781
|
+
var rPr = new RunProperties();
|
|
782
|
+
|
|
783
|
+
// 1. Style reference (must be first child per schema order)
|
|
784
|
+
rPr.RunStyle = new RunStyle { Val = "Strong" };
|
|
785
|
+
|
|
786
|
+
// 2. Font family
|
|
787
|
+
rPr.RunFonts = new RunFonts
|
|
788
|
+
{
|
|
789
|
+
Ascii = "Georgia",
|
|
790
|
+
HighAnsi = "Georgia",
|
|
791
|
+
EastAsia = "SimSun",
|
|
792
|
+
ComplexScript = "Times New Roman"
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
// 3. Bold
|
|
796
|
+
rPr.Bold = new Bold();
|
|
797
|
+
rPr.BoldComplexScript = new BoldComplexScript();
|
|
798
|
+
|
|
799
|
+
// 4. Italic
|
|
800
|
+
rPr.Italic = new Italic();
|
|
801
|
+
rPr.ItalicComplexScript = new ItalicComplexScript();
|
|
802
|
+
|
|
803
|
+
// 5. Caps — omitted here (mutually exclusive with SmallCaps)
|
|
804
|
+
// rPr.Caps = new Caps();
|
|
805
|
+
|
|
806
|
+
// 6. SmallCaps
|
|
807
|
+
rPr.SmallCaps = new SmallCaps();
|
|
808
|
+
|
|
809
|
+
// 7. Strikethrough
|
|
810
|
+
rPr.Strike = new Strike();
|
|
811
|
+
|
|
812
|
+
// 8. Hidden — typically NOT combined with visible formatting
|
|
813
|
+
// rPr.Vanish = new Vanish();
|
|
814
|
+
|
|
815
|
+
// 9. Color
|
|
816
|
+
rPr.Color = new Color { Val = "2F5496" };
|
|
817
|
+
|
|
818
|
+
// 10. Font size
|
|
819
|
+
rPr.FontSize = new FontSize { Val = "28" }; // 14pt
|
|
820
|
+
rPr.FontSizeComplexScript = new FontSizeComplexScript { Val = "28" };
|
|
821
|
+
|
|
822
|
+
// 11. Underline
|
|
823
|
+
rPr.Underline = new Underline { Val = UnderlineValues.Single };
|
|
824
|
+
|
|
825
|
+
// 12. Shading (text background)
|
|
826
|
+
rPr.Shading = new Shading
|
|
827
|
+
{
|
|
828
|
+
Val = ShadingPatternValues.Clear,
|
|
829
|
+
Fill = "FFFFCC"
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
// 13. Highlight (preset colors only)
|
|
833
|
+
// rPr.Highlight = new Highlight { Val = HighlightColorValues.Yellow };
|
|
834
|
+
|
|
835
|
+
// 14. Character spacing
|
|
836
|
+
rPr.Spacing = new Spacing { Val = 10 }; // 0.5pt expanded
|
|
837
|
+
|
|
838
|
+
// 15. Kerning threshold
|
|
839
|
+
rPr.Kern = new Kern { Val = 2 };
|
|
840
|
+
|
|
841
|
+
// 16. Position (raised/lowered)
|
|
842
|
+
// rPr.Position = new Position { Val = "4" }; // 2pt raised
|
|
843
|
+
|
|
844
|
+
// 17. Vertical alignment (super/subscript)
|
|
845
|
+
// rPr.VerticalTextAlignment = new VerticalTextAlignment
|
|
846
|
+
// {
|
|
847
|
+
// Val = VerticalPositionValues.Superscript
|
|
848
|
+
// };
|
|
849
|
+
|
|
850
|
+
// 18. Border
|
|
851
|
+
rPr.Border = new Border
|
|
852
|
+
{
|
|
853
|
+
Val = BorderValues.Single,
|
|
854
|
+
Size = 4,
|
|
855
|
+
Space = 1,
|
|
856
|
+
Color = "auto"
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
// Build the Run: RunProperties MUST come before Text content
|
|
860
|
+
var run = new Run();
|
|
861
|
+
run.RunProperties = rPr;
|
|
862
|
+
|
|
863
|
+
// Add text content
|
|
864
|
+
// PreserveSpace is needed when text has leading/trailing spaces
|
|
865
|
+
run.AppendChild(new Text("Fully formatted text")
|
|
866
|
+
{
|
|
867
|
+
Space = SpaceProcessingModeValues.Preserve
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
return run;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// ──────────────────────────────────────────────────────────────────
|
|
874
|
+
// 20. BuildRunProperties helper — recommended property order
|
|
875
|
+
// ──────────────────────────────────────────────────────────────────
|
|
876
|
+
|
|
877
|
+
/// <summary>
|
|
878
|
+
/// Helper that constructs a RunProperties with elements in the correct schema order.
|
|
879
|
+
/// <para>
|
|
880
|
+
/// <b>OOXML schema order for w:rPr children (ISO 29500-1, section 17.3.2.28):</b>
|
|
881
|
+
/// <list type="number">
|
|
882
|
+
/// <item>w:rStyle — Character style reference</item>
|
|
883
|
+
/// <item>w:rFonts — Font family</item>
|
|
884
|
+
/// <item>w:b — Bold</item>
|
|
885
|
+
/// <item>w:bCs — Bold Complex Script</item>
|
|
886
|
+
/// <item>w:i — Italic</item>
|
|
887
|
+
/// <item>w:iCs — Italic Complex Script</item>
|
|
888
|
+
/// <item>w:caps — All Caps</item>
|
|
889
|
+
/// <item>w:smallCaps — Small Caps</item>
|
|
890
|
+
/// <item>w:strike — Strikethrough</item>
|
|
891
|
+
/// <item>w:dstrike — Double Strikethrough</item>
|
|
892
|
+
/// <item>w:outline — Outline effect</item>
|
|
893
|
+
/// <item>w:shadow — Shadow effect</item>
|
|
894
|
+
/// <item>w:emboss — Emboss effect</item>
|
|
895
|
+
/// <item>w:imprint — Imprint/Engrave effect</item>
|
|
896
|
+
/// <item>w:noProof — Skip proofing</item>
|
|
897
|
+
/// <item>w:snapToGrid — Snap to document grid</item>
|
|
898
|
+
/// <item>w:vanish — Hidden text</item>
|
|
899
|
+
/// <item>w:webHidden — Hidden in web view</item>
|
|
900
|
+
/// <item>w:color — Text color</item>
|
|
901
|
+
/// <item>w:spacing — Character spacing</item>
|
|
902
|
+
/// <item>w:w — Character width scaling (%)</item>
|
|
903
|
+
/// <item>w:kern — Kerning threshold</item>
|
|
904
|
+
/// <item>w:position — Raised/lowered position</item>
|
|
905
|
+
/// <item>w:sz — Font size</item>
|
|
906
|
+
/// <item>w:szCs — Font size Complex Script</item>
|
|
907
|
+
/// <item>w:highlight — Highlight color</item>
|
|
908
|
+
/// <item>w:u — Underline</item>
|
|
909
|
+
/// <item>w:effect — Animation effect (deprecated)</item>
|
|
910
|
+
/// <item>w:bdr — Text border</item>
|
|
911
|
+
/// <item>w:shd — Shading</item>
|
|
912
|
+
/// <item>w:fitText — Fit text to width</item>
|
|
913
|
+
/// <item>w:vertAlign — Vertical alignment (super/subscript)</item>
|
|
914
|
+
/// <item>w:rtl — Right-to-left</item>
|
|
915
|
+
/// <item>w:cs — Complex Script</item>
|
|
916
|
+
/// <item>w:em — Emphasis mark</item>
|
|
917
|
+
/// <item>w:lang — Language</item>
|
|
918
|
+
/// <item>w:eastAsianLayout — East Asian typography</item>
|
|
919
|
+
/// <item>w:specVanish — Special vanish</item>
|
|
920
|
+
/// <item>w:oMath — Math formatting</item>
|
|
921
|
+
/// <item>w:rPrChange — Revision tracking for run properties</item>
|
|
922
|
+
/// </list>
|
|
923
|
+
/// </para>
|
|
924
|
+
/// <para>
|
|
925
|
+
/// <b>Gotcha:</b> When using the strongly-typed SDK (setting properties like
|
|
926
|
+
/// <c>rPr.Bold = new Bold()</c>), the SDK handles ordering automatically when
|
|
927
|
+
/// serializing. However, if you use <c>rPr.AppendChild()</c>, you must add
|
|
928
|
+
/// elements in the correct order yourself, or call
|
|
929
|
+
/// <c>rPr.SetElement()</c> which inserts at the correct position.
|
|
930
|
+
/// </para>
|
|
931
|
+
/// </summary>
|
|
932
|
+
/// <param name="fontFamily">Font name for Ascii and HighAnsi slots. Null to skip.</param>
|
|
933
|
+
/// <param name="sizePoints">Font size in points. Null to skip.</param>
|
|
934
|
+
/// <param name="bold">True to apply bold, false to explicitly disable, null to inherit.</param>
|
|
935
|
+
/// <param name="italic">True to apply italic, false to explicitly disable, null to inherit.</param>
|
|
936
|
+
/// <param name="colorHex">Six-digit hex color (e.g., "FF0000"). Null to skip.</param>
|
|
937
|
+
/// <param name="underline">Underline style. Null to skip.</param>
|
|
938
|
+
/// <returns>A well-ordered RunProperties element ready to attach to a Run.</returns>
|
|
939
|
+
public static RunProperties BuildRunProperties(
|
|
940
|
+
string? fontFamily = null,
|
|
941
|
+
double? sizePoints = null,
|
|
942
|
+
bool? bold = null,
|
|
943
|
+
bool? italic = null,
|
|
944
|
+
string? colorHex = null,
|
|
945
|
+
UnderlineValues? underline = null)
|
|
946
|
+
{
|
|
947
|
+
var rPr = new RunProperties();
|
|
948
|
+
|
|
949
|
+
// Using the strongly-typed properties ensures the SDK serializes
|
|
950
|
+
// child elements in the correct schema order automatically.
|
|
951
|
+
|
|
952
|
+
if (fontFamily is not null)
|
|
953
|
+
{
|
|
954
|
+
rPr.RunFonts = new RunFonts
|
|
955
|
+
{
|
|
956
|
+
Ascii = fontFamily,
|
|
957
|
+
HighAnsi = fontFamily
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if (bold == true)
|
|
962
|
+
{
|
|
963
|
+
rPr.Bold = new Bold();
|
|
964
|
+
rPr.BoldComplexScript = new BoldComplexScript();
|
|
965
|
+
}
|
|
966
|
+
else if (bold == false)
|
|
967
|
+
{
|
|
968
|
+
rPr.Bold = new Bold { Val = false };
|
|
969
|
+
rPr.BoldComplexScript = new BoldComplexScript { Val = false };
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
if (italic == true)
|
|
973
|
+
{
|
|
974
|
+
rPr.Italic = new Italic();
|
|
975
|
+
rPr.ItalicComplexScript = new ItalicComplexScript();
|
|
976
|
+
}
|
|
977
|
+
else if (italic == false)
|
|
978
|
+
{
|
|
979
|
+
rPr.Italic = new Italic { Val = false };
|
|
980
|
+
rPr.ItalicComplexScript = new ItalicComplexScript { Val = false };
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
if (colorHex is not null)
|
|
984
|
+
{
|
|
985
|
+
rPr.Color = new Color { Val = colorHex };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
if (sizePoints is not null)
|
|
989
|
+
{
|
|
990
|
+
var halfPts = ((int)(sizePoints.Value * 2)).ToString();
|
|
991
|
+
rPr.FontSize = new FontSize { Val = halfPts };
|
|
992
|
+
rPr.FontSizeComplexScript = new FontSizeComplexScript { Val = halfPts };
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (underline is not null)
|
|
996
|
+
{
|
|
997
|
+
rPr.Underline = new Underline { Val = underline };
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
return rPr;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// ──────────────────────────────────────────────────────────────────
|
|
1004
|
+
// Internal helper: get or create RunProperties on a Run
|
|
1005
|
+
// ──────────────────────────────────────────────────────────────────
|
|
1006
|
+
|
|
1007
|
+
/// <summary>
|
|
1008
|
+
/// Gets the existing RunProperties from a run or creates and attaches a new one.
|
|
1009
|
+
/// Ensures RunProperties is always the first child element of the run.
|
|
1010
|
+
/// </summary>
|
|
1011
|
+
private static RunProperties GetOrCreateRunProperties(this Run run)
|
|
1012
|
+
{
|
|
1013
|
+
if (run.RunProperties is not null)
|
|
1014
|
+
return run.RunProperties;
|
|
1015
|
+
|
|
1016
|
+
var rPr = new RunProperties();
|
|
1017
|
+
run.RunProperties = rPr;
|
|
1018
|
+
return rPr;
|
|
1019
|
+
}
|
|
1020
|
+
}
|