Skip to content

NoProof was added to Formatting and Paragraph #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion DocX/Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Formatting : IComparable
private double? spacing;

private CultureInfo language;
private bool? noProof;

/// <summary>
/// A text formatting.
Expand Down Expand Up @@ -65,6 +66,22 @@ public CultureInfo Language
}
}

/// <summary>
/// Text proofing
/// </summary>
public bool? NoProof
{
get
{
return noProof;
}

set
{
noProof = value;
}
}

/// <summary>
/// Returns a new identical instance of Formatting.
/// </summary>
Expand All @@ -81,6 +98,7 @@ public Formatting Clone()
newf.Italic = italic;
if (kerning.HasValue) { newf.Kerning = kerning; }
newf.Language = language;
newf.NoProof = noProof;
newf.Misc = misc;
if (percentageScale.HasValue) { newf.PercentageScale = percentageScale; }
if (position.HasValue) { newf.Position = position; }
Expand Down Expand Up @@ -108,6 +126,8 @@ public static Formatting Parse(XElement rPr)
option.GetAttribute(XName.Get("eastAsia", DocX.w.NamespaceName), null) ??
option.GetAttribute(XName.Get("bidi", DocX.w.NamespaceName)));
break;
case "noProof":
formatting.NoProof = true; break;
case "spacing":
formatting.Spacing = Double.Parse(
option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 20.0;
Expand Down Expand Up @@ -172,7 +192,10 @@ internal XElement Xml
if (language != null)
rPr.Add(new XElement(XName.Get("lang", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), language.Name)));

if(spacing.HasValue)
if (noProof.HasValue && noProof.Value)
rPr.Add(new XElement(XName.Get("noProof", DocX.w.NamespaceName)));

if(spacing.HasValue)
rPr.Add(new XElement(XName.Get("spacing", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), spacing.Value * 20)));

if(position.HasValue)
Expand Down Expand Up @@ -542,6 +565,9 @@ public int CompareTo(object obj)
if (!other.language.Equals(this.language))
return -1;

if (other.noProof != this.noProof)
return -1;

return 0;
}
}
Expand Down
24 changes: 24 additions & 0 deletions DocX/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,30 @@ public Paragraph Culture(CultureInfo culture)
return this;
}

/// <summary>
/// For use with Append() and AppendLine()
/// </summary>
/// <returns>This Paragraph with the last appended text with proofing disabled.</returns>
/// <example>
/// Add a new Paragraph to this document and then disable proofing on it.
/// <code>
/// // Load a document.
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph and disable proofing on it.
/// Paragraph p = document.InsertParagraph("Hello, мир!").NoProof();
///
/// // Save this document.
/// document.Save();
/// }
/// </code>
/// </example>
public Paragraph NoProof()
{
ApplyTextFormattingProperty(XName.Get("noProof", DocX.w.NamespaceName), string.Empty, null);
return this;
}

/// <summary>
/// Append text to this Paragraph.
/// </summary>
Expand Down