Skip to content
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

Fixed broken DifferentOddAndEvenPages property #149

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
67 changes: 28 additions & 39 deletions DocX/DocX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,35 +706,21 @@ public bool DifferentOddAndEvenPages
{
get
{
XDocument settings;
using (TextReader tr = new StreamReader(settingsPart.GetStream()))
settings = XDocument.Load(tr);

XElement evenAndOddHeaders = settings.Root.Element(w + "evenAndOddHeaders");

return evenAndOddHeaders != null;
return settings.Root.Element(w + "evenAndOddHeaders") != null;
}

set
{
XDocument settings;
using (TextReader tr = new StreamReader(settingsPart.GetStream()))
settings = XDocument.Load(tr);

XElement evenAndOddHeaders = settings.Root.Element(w + "evenAndOddHeaders");
if (evenAndOddHeaders == null)
if (evenAndOddHeaders != null)
{
if (value)
settings.Root.AddFirst(new XElement(w + "evenAndOddHeaders"));
evenAndOddHeaders.Remove();
}
else
if (value)
{
if (!value)
evenAndOddHeaders.Remove();
evenAndOddHeaders = new XElement(XName.Get("evenAndOddHeaders", w.NamespaceName));
evenAndOddHeaders.Add(new XAttribute(XName.Get("val", w.NamespaceName), "1"));
settings.Root.AddFirst(evenAndOddHeaders);
}

using (TextWriter tw = new StreamWriter(new PackagePartStream(settingsPart.GetStream())))
settings.Save(tw);
}
}

Expand Down Expand Up @@ -1425,7 +1411,8 @@ private void merge_images(PackagePart remote_pp, DocX remote_document, XDocument
// Before doing any other work, check to see if this image is actually referenced in the document.
// In my testing I have found cases of Images inside documents that are not referenced
var remote_rel = remote_document.mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(remote_pp.Uri.OriginalString.Replace("/word/", ""))).FirstOrDefault();
if (remote_rel == null) {
if (remote_rel == null)
{
remote_rel = remote_document.mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(remote_pp.Uri.OriginalString)).FirstOrDefault();
if (remote_rel == null)
return;
Expand Down Expand Up @@ -3694,20 +3681,20 @@ select e.Attribute(r + "id").Value
{
using (FileStream fs = new FileStream(filename, FileMode.Create))
{
// Original code
// fs.Write( memoryStream.ToArray(), 0, (int)memoryStream.Length );
// was replaced by save using small buffer
// CopyStream( memoryStream, fs);
// Corection is to make position equal to 0
if(memoryStream.CanSeek)
{
// Write to the beginning of the stream
memoryStream.Position = 0;
CopyStream(memoryStream, fs);
}
else
fs.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
}
// Original code
// fs.Write( memoryStream.ToArray(), 0, (int)memoryStream.Length );
// was replaced by save using small buffer
// CopyStream( memoryStream, fs);
// Corection is to make position equal to 0
if (memoryStream.CanSeek)
{
// Write to the beginning of the stream
memoryStream.Position = 0;
CopyStream(memoryStream, fs);
}
else
fs.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
}
}
else
{
Expand Down Expand Up @@ -4409,11 +4396,13 @@ public void InsertChart(Chart chart)
/// <summary>
/// Insert a chart in document after paragraph
/// </summary>
public void InsertChartAfterParagraph(Chart chart, Paragraph paragraph) {
public void InsertChartAfterParagraph(Chart chart, Paragraph paragraph)
{
// Create a new chart part uri.
String chartPartUriPath = String.Empty;
Int32 chartIndex = 1;
do {
do
{
chartPartUriPath = String.Format
(
"/word/charts/chart{0}.xml",
Expand Down Expand Up @@ -4595,4 +4584,4 @@ public void Dispose()

#endregion
}
}
}
3 changes: 3 additions & 0 deletions DocX/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ public Direction Direction
if (direction == Direction.RightToLeft)
{
if (bidi == null)
{
pPr.Add(new XElement(XName.Get("bidi", DocX.w.NamespaceName)));
}
ApplyTextFormattingProperty(XName.Get("rtl", DocX.w.NamespaceName), string.Empty, null);
}
else
{
Expand Down