Skip to content

Commit 71ed174

Browse files
committed
Support paragraph formatting (except lists and borders) in RTF to DOCX converter
1 parent 04bb3cb commit 71ed174

6 files changed

Lines changed: 583 additions & 220 deletions

File tree

src/DocSharp.Docx/DocxToRtf/DocxToRtfConverter.Paragraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ internal void ProcessParagraphFormatting(Paragraph paragraph, RtfStringWriter sb
314314
sb.Write(@"\nosnaplinegrid");
315315
}
316316
var outlineLevel = paragraph.GetEffectiveProperty<OutlineLevel>();
317-
if (outlineLevel?.Val != null && outlineLevel.Val.HasValue)
317+
if (outlineLevel?.Val != null && outlineLevel.Val.HasValue)
318318
{
319319
sb.Write($"\\outline{outlineLevel.Val.Value}");
320320
}

src/DocSharp.Docx/Rtf/RtfControlWord.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ public RtfControlWord(string name)
1010
{
1111
Name = name;
1212
}
13+
14+
public RtfControlWord(string name, int value)
15+
{
16+
Name = name;
17+
Value = value;
18+
}
1319
}
1420

src/DocSharp.Docx/Rtf/RtfDestination.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class RtfDestination : RtfGroup
1111
public int? Value { get; set; }
1212
public bool HasValue { get; set; }
1313

14-
public RtfDestination(string name, bool isIgnorable = false)
14+
public RtfDestination(string name, bool isIgnorable = false)
1515
{
1616
Name = name ?? string.Empty;
1717
IsIgnorable = isIgnorable;

src/DocSharp.Docx/Rtf/RtfShadingMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace DocSharp.Rtf;
1010

1111
internal static class RtfShadingMapper
1212
{
13-
internal static EnumValue<ShadingPatternValues> GetShadingType(string word, int? value)
13+
internal static EnumValue<ShadingPatternValues>? GetShadingType(string word, int? value)
1414
{
1515
switch (word)
1616
{
@@ -133,6 +133,6 @@ internal static EnumValue<ShadingPatternValues> GetShadingType(string word, int?
133133
}
134134
break;
135135
}
136-
return ShadingPatternValues.Clear;
136+
return null;
137137
}
138138
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using DocumentFormat.OpenXml.Wordprocessing;
2+
3+
namespace DocSharp.Docx;
4+
5+
internal class FormattingState
6+
{
7+
public bool Bold { get; set; }
8+
public bool Italic { get; set; }
9+
public bool Strike { get; set; }
10+
public bool DoubleStrike { get; set; }
11+
public bool Subscript { get; set; }
12+
public bool Superscript { get; set; }
13+
public bool SmallCaps { get; set; }
14+
public bool AllCaps { get; set; }
15+
public bool Hidden { get; set; }
16+
public bool Emboss { get; set; }
17+
public bool Imprint { get; set; }
18+
public bool Outline { get; set; }
19+
public bool Shadow { get; set; }
20+
21+
public UnderlineValues? Underline { get; set; }
22+
public EmphasisMarkValues? Emphasis { get; set; }
23+
24+
public Border? CharacterBorder { get; set; }
25+
public Shading? CharacterShading { get; set; }
26+
27+
public int? FontIndex { get; set; }
28+
public int? FontColorIndex { get; set; }
29+
public int? HighlightColorIndex { get; set; }
30+
public int? UnderlineColorIndex { get; set; }
31+
32+
public int? FontSize { get; set; }
33+
public int? FontScaling { get; set; }
34+
public int? FontSpacing { get; set; }
35+
public int? FitText { get; set; }
36+
public int? Kerning { get; set; }
37+
public int? VerticalOffset { get; set; }
38+
39+
public int? CharacterStyleIndex { get; set; }
40+
41+
public FormattingState Clone()
42+
{
43+
return new FormattingState
44+
{
45+
Bold = this.Bold,
46+
Italic = this.Italic,
47+
Strike = this.Strike,
48+
DoubleStrike = this.DoubleStrike,
49+
Subscript = this.Subscript,
50+
Superscript = this.Superscript,
51+
SmallCaps = this.SmallCaps,
52+
AllCaps = this.AllCaps,
53+
Hidden = this.Hidden,
54+
Emboss = this.Emboss,
55+
Imprint = this.Imprint,
56+
Outline = this.Outline,
57+
Shadow = this.Shadow,
58+
59+
Underline = this.Underline,
60+
Emphasis = this.Emphasis,
61+
62+
CharacterBorder = this.CharacterBorder,
63+
CharacterShading = this.CharacterShading,
64+
65+
FontIndex = this.FontIndex,
66+
FontColorIndex = this.FontColorIndex,
67+
HighlightColorIndex = this.HighlightColorIndex,
68+
UnderlineColorIndex = this.UnderlineColorIndex,
69+
70+
FontSize = this.FontSize,
71+
FontScaling = this.FontScaling,
72+
FontSpacing = this.FontSpacing,
73+
FitText = this.FitText,
74+
Kerning = this.Kerning,
75+
VerticalOffset = this.VerticalOffset,
76+
77+
CharacterStyleIndex = this.CharacterStyleIndex
78+
};
79+
}
80+
81+
public void Clear()
82+
{
83+
Bold = false;
84+
Italic = false;
85+
Strike = false;
86+
DoubleStrike = false;
87+
Subscript = false;
88+
Superscript = false;
89+
SmallCaps = false;
90+
AllCaps = false;
91+
Hidden = false;
92+
Emboss = false;
93+
Imprint = false;
94+
Outline = false;
95+
Shadow = false;
96+
Underline = null;
97+
Emphasis = null;
98+
CharacterBorder = null;
99+
CharacterShading = null;
100+
FontIndex = null;
101+
FontColorIndex = null;
102+
HighlightColorIndex = null;
103+
UnderlineColorIndex = null;
104+
FontSize = null;
105+
FontScaling = null;
106+
FontSpacing = null;
107+
FitText = null;
108+
Kerning = null;
109+
VerticalOffset = null;
110+
CharacterStyleIndex = null;
111+
}
112+
}

0 commit comments

Comments
 (0)