Skip to content

Commit

Permalink
V2.3.0 Released
Browse files Browse the repository at this point in the history
  • Loading branch information
XceedBoucherS committed Sep 15, 2022
1 parent 21b11d7 commit 2591003
Show file tree
Hide file tree
Showing 73 changed files with 462 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Xceed.Document.NET/AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COMMUNITY LICENSE AGREEMENT (for non-commercial use) as published at
internal static class _XceedVersionInfo
{
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string BaseVersion = "2.2";
public const string BaseVersion = "2.3";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string Version = BaseVersion +
".0.0";
Expand Down
5 changes: 4 additions & 1 deletion Xceed.Document.NET/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ COMMUNITY LICENSE AGREEMENT (for non-commercial use) as published at

#pragma warning disable 1699
[assembly: AssemblyDelaySign( false )]
#if NETCORE || NET5
[assembly: AssemblyKeyFile( @"..\..\..\..\sn.snk" )]
#else
[assembly: AssemblyKeyFile( @"..\..\sn.snk" )]
#endif
[assembly: AssemblyKeyName( "" )]
#pragma warning restore 1699

Binary file added Xceed.Document.NET/Resources/theme.xml.gz
Binary file not shown.
21 changes: 13 additions & 8 deletions Xceed.Document.NET/Src/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ split[ 1 ]
);
}
this.SetParentContainer( p );
this.AddParagraphInCache( p, index );
this.AddParagraphInCache( p );

return p;
}
Expand Down Expand Up @@ -620,7 +620,7 @@ public virtual Paragraph InsertParagraph( Paragraph p )
var newParagraph = new Paragraph( Document, newXElement, index );
this.Document._paragraphLookup.Add( index, newParagraph );
this.SetParentContainer( newParagraph );
this.AddParagraphInCache( newParagraph, index );
this.AddParagraphInCache( newParagraph );

return newParagraph;
}
Expand Down Expand Up @@ -650,7 +650,7 @@ public virtual Paragraph InsertParagraph( int index, string text, bool trackChan
}

this.SetParentContainer( newParagraph );
this.AddParagraphInCache( newParagraph, index );
this.AddParagraphInCache( newParagraph );

return newParagraph;
}
Expand Down Expand Up @@ -720,6 +720,14 @@ public virtual Paragraph InsertParagraph( string text, bool trackChanges, Format
return newParagraphAdded;
}









/// <summary>
/// Removes paragraph at specified position
/// </summary>
Expand Down Expand Up @@ -1056,12 +1064,9 @@ private void RemoveParagraphFromCache( Paragraph paragraph )
}
}

private void AddParagraphInCache( Paragraph p, int? index = null )
private void AddParagraphInCache( Paragraph p )
{
if( !( index.HasValue ) )
_editableParagraphsCollection.Add( p );
else
_editableParagraphsCollection.Insert( index.Value, p );
_editableParagraphsCollection.Add( p );
}

private void GetListItemType( Paragraph p )
Expand Down
159 changes: 135 additions & 24 deletions Xceed.Document.NET/Src/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class Document : Container, IDisposable
#region Internal Constants

internal const string RelationshipImage = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
internal const string RelationshipChart = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
internal const string ContentTypeApplicationRelationShipXml = "application/vnd.openxmlformats-package.relationships+xml";

#endregion
Expand Down Expand Up @@ -1112,6 +1113,40 @@ public override Section InsertSectionPageBreak( bool trackChanges = false )
return this.InsertSection( trackChanges, true );
}

public override List<string> FindUniqueByPattern( string pattern, RegexOptions options )
{
// FindUniqueByPattern in the main body of document.
var items = base.FindUniqueByPattern( pattern, options );

// FindUniqueByPattern in Headers of the document.
foreach( var section in this.Sections )
{
var headerList = new List<Header>() { section.Headers.First, section.Headers.Even, section.Headers.Odd };
foreach( var h in headerList )
{
if( h != null )
{
items.AddRange( h.FindUniqueByPattern( pattern, options ) );
}
}
}

// FindUniqueByPattern in Footers of the document.
foreach( var section in this.Sections )
{
var footerList = new List<Footer> { section.Footers.First, section.Footers.Even, section.Footers.Odd };
foreach( var f in footerList )
{
if( f != null )
{
items.AddRange( f.FindUniqueByPattern( pattern, options ) );
}
}
}

return items;
}

public override void ReplaceText( string searchValue,
string newValue,
bool trackChanges = false,
Expand Down Expand Up @@ -2525,13 +2560,17 @@ public override Paragraph InsertParagraph( int index, string text, bool trackCha
var p = base.InsertParagraph( index, text, trackChanges );
p.PackagePart = this.PackagePart;

// Inserting a paragraph at a specific index needs an update of Paragraph cache.
this.ClearParagraphsCache();

return p;
}

public override Paragraph InsertParagraph( Paragraph p )
{
// copy paragraph's pictures.
// copy paragraph's pictures and styles.
this.InsertParagraphPictures( p );
this.InsertParagraphStyles( p );

p.PackagePart = this.PackagePart;

Expand All @@ -2540,19 +2579,28 @@ public override Paragraph InsertParagraph( Paragraph p )

public override Paragraph InsertParagraph( int index, Paragraph p )
{
// copy paragraph's pictures.
// copy paragraph's pictures and styles.
this.InsertParagraphPictures( p );
this.InsertParagraphStyles( p );

p.PackagePart = this.PackagePart;

return base.InsertParagraph( index, p );
var returnParagraph = base.InsertParagraph( index, p );

// Inserting a paragraph at a specific index needs an update of Paragraph cache.
this.ClearParagraphsCache();

return returnParagraph;
}

public override Paragraph InsertParagraph( int index, string text, bool trackChanges, Formatting formatting )
{
var p = base.InsertParagraph( index, text, trackChanges, formatting );
p.PackagePart = this.PackagePart;

// Inserting a paragraph at a specific index needs an update of Paragraph cache.
this.ClearParagraphsCache();

return p;
}

Expand Down Expand Up @@ -2893,19 +2941,11 @@ public void SetDefaultFont( Font fontFamily, double fontSize = 11d, Color? fontC











public T AddChart<T>() where T : Chart, new()
{
var chart = new T();
chart.PackagePart = CreateChartPackagePart();
chart.RelationPackage = CreateChartRelationShip(chart.PackagePart);
var chart = new T();
chart.PackagePart = this.CreateChartPackagePart();
chart.RelationPackage = this.CreateChartRelationShip( chart.PackagePart );
return chart;
}
#endregion
Expand Down Expand Up @@ -3791,7 +3831,7 @@ internal void UpdateCacheSections()
// Save Headers/Footers in case they were modified. GetSectionCaches() will create new Sections based on them.
this.SaveHeadersFooters();

ClearParagraphsCache();
this.ClearParagraphsCache();
_cachedSections = this.GetSections();
}

Expand Down Expand Up @@ -3828,17 +3868,17 @@ internal Paragraph GetPreviousParagraph( Paragraph refParagraph )
internal Paragraph CreateChartElement( Chart chart, Paragraph paragraph, float width, float height )
{

if ( chart.PackagePart == null )
if( chart.PackagePart == null )
{
chart.PackagePart = this.CreateChartPackagePart();
chart.RelationPackage = this.CreateChartRelationShip(chart.PackagePart);
chart.RelationPackage = this.CreateChartRelationShip( chart.PackagePart );
}
var relID = chart.RelationPackage.Id.ToString();

// Save a chart info the chartPackagePart
var p = ( paragraph == null ) ? InsertParagraph() : paragraph;

using ( TextWriter tw = new StreamWriter( chart.PackagePart.GetStream( FileMode.Create, FileAccess.Write ) ) )
using( TextWriter tw = new StreamWriter( chart.PackagePart.GetStream( FileMode.Create, FileAccess.Write ) ) )
{
chart.ExternalXml.Save( tw );
}
Expand All @@ -3860,7 +3900,7 @@ internal PackagePart CreateChartPackagePart()
{
chartPartUriPath = String.Format( "/word/charts/chart{0}.xml", chartIndex );
chartIndex++;
} while ( _package.PartExists( new Uri( chartPartUriPath, UriKind.Relative ) ) );
} while( _package.PartExists( new Uri( chartPartUriPath, UriKind.Relative ) ) );

// Create chart part.
var chartPackagePart = _package.CreatePart( new Uri( chartPartUriPath, UriKind.Relative ), "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", CompressionOption.Normal );
Expand All @@ -3873,7 +3913,7 @@ internal PackageRelationship CreateChartRelationShip( PackagePart chartPackagePa
{
// Create a new chart relationship
var relID = this.GetNextFreeRelationshipID();
return this.PackagePart.CreateRelationship( chartPackagePart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", relID );
return this.PackagePart.CreateRelationship( chartPackagePart.Uri, TargetMode.Internal, Document.RelationshipChart, relID );
}

#endregion
Expand Down Expand Up @@ -4099,7 +4139,12 @@ private void MergeDocumentsRelations( Document remote_document, XDocument remote
{
if( _imageContentTypes.Contains( remote_pp.ContentType ) )
{
merge_images( remote_pp, remote_document, remote_mainDoc, remote_pp.ContentType );
this.MergeImages( remote_pp, remote_document, remote_mainDoc, remote_pp.ContentType );
}

if( remote_pp.Uri.OriginalString.StartsWith( "/word/charts/" ) )
{
this.MergeCharts( remote_pp, remote_document, remote_mainDoc );
}
}

Expand Down Expand Up @@ -4209,13 +4254,39 @@ private void InsertParagraphPictures( Paragraph p )
{
if( _imageContentTypes.Contains( remote_pp.ContentType ) )
{
merge_images( remote_pp, p.Document, p.Document._mainDoc, remote_pp.ContentType );
this.MergeImages( remote_pp, p.Document, p.Document._mainDoc, remote_pp.ContentType );
}
}
}
}

private void merge_images( PackagePart remote_pp, Document remote_document, XDocument remote_mainDoc, String contentType )
private void InsertParagraphStyles( Paragraph p )
{
// Check if style is already present in document.
if( ( p != null ) && ( p.StyleId != this.GetNormalStyleId() ) )
{
var styleToFind = HelperFunctions.GetStyle( this, p.StyleId );

// style is not there, we need to add it.
if( styleToFind == null )
{
var styleIdToFind = p.StyleId;
while( ( styleIdToFind != null ) && ( styleIdToFind != this.GetNormalStyleId() ) )
{
var styleToAdd = HelperFunctions.GetStyle( p.Document, styleIdToFind );
if( styleToAdd != null )
{
_styles.Root.Add( styleToAdd );

var basedOn = styleToAdd.Element( XName.Get( "basedOn", Document.w.NamespaceName ) );
styleIdToFind = ( basedOn != null ) ? basedOn.Attribute( XName.Get( "val", Document.w.NamespaceName ) ).Value : null;
}
}
}
}
}

private void MergeImages( PackagePart remote_pp, Document remote_document, XDocument remote_mainDoc, String contentType )
{
// 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
Expand Down Expand Up @@ -4328,7 +4399,7 @@ private void MergeImagesCore( PackageRelationship relationship, PackagePart remo

private void CreateRelationshipForImage( Uri newUri, string remote_Id, XDocument remote_mainDoc, PackagePart packagePartToSaveTo )
{
var pr = packagePartToSaveTo.CreateRelationship( newUri, TargetMode.Internal, RelationshipImage );
var pr = packagePartToSaveTo.CreateRelationship( newUri, TargetMode.Internal, Document.RelationshipImage );
var new_Id = pr.Id;

//Check if the remote relationship id is a default rId from Word
Expand All @@ -4350,6 +4421,46 @@ private void CreateRelationshipForImage( Uri newUri, string remote_Id, XDocument
this.ReplaceAllRemoteID( remote_mainDoc, "imagedata", "id", v.NamespaceName, remote_Id, new_Id );
}

private void CreateRelationshipForChart( Uri newUri, string remote_Id, XDocument remote_mainDoc )
{
var relID = this.GetNextFreeRelationshipID();
var pr = this.PackagePart.CreateRelationship( newUri, TargetMode.Internal, Document.RelationshipChart, relID );

// Replace all instances of remote_Id in the local document with local_Id
this.ReplaceAllRemoteID( remote_mainDoc, "chart", "id", c.NamespaceName, remote_Id, pr.Id );
}

private void MergeCharts( PackagePart remote_pp, Document remote_document, XDocument remote_mainDoc )
{
var remote_rel = remote_document.PackagePart.GetRelationships().Where( r => r.TargetUri.OriginalString.Equals( remote_pp.Uri.OriginalString ) ).FirstOrDefault();

if( remote_rel != null )
{
var remote_Id = remote_rel.Id;

var new_uri = remote_pp.Uri.OriginalString;
new_uri = new_uri.Remove( new_uri.LastIndexOf( "/" ) );
new_uri += "/" + Guid.NewGuid();
if( !new_uri.StartsWith( "/" ) )
{
new_uri = "/" + new_uri;
}

var new_pp = _package.CreatePart( new Uri( new_uri, UriKind.Relative ), remote_pp.ContentType, CompressionOption.Normal );

using( Stream s_read = remote_pp.GetStream() )
{
using( Stream s_write = new PackagePartStream( new_pp.GetStream( FileMode.Create ) ) )
{
HelperFunctions.CopyStream( s_read, s_write );
}
}

this.CreateRelationshipForChart( new Uri( new_uri, UriKind.Relative ), remote_Id, remote_mainDoc );
}
}


private void ReplaceAllRemoteID( XDocument remote_mainDoc, string localName, string localNameAttribute, string namespaceName, string remote_Id, string new_Id )
{
// Replace all instances of remote_Id in the local document with local_Id
Expand Down
5 changes: 4 additions & 1 deletion Xceed.Document.NET/Src/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3681,7 +3681,10 @@ public void RemoveText( int index, int count, bool trackChanges = false, bool re
if( parentElement.Parent != null )
{
// Need to make sure there is another paragraph in the parent cell
canRemove &= parentElement.Parent.Name.LocalName == "tc" && parentElement.Parent.Elements( XName.Get( "p", Document.w.NamespaceName ) ).Count() > 1;
if( parentElement.Parent.Name.LocalName == "tc" )
{
canRemove &= parentElement.Parent.Elements( XName.Get( "p", Document.w.NamespaceName ) ).Count() > 1;
}

// Need to make sure there is no drawing element within the parent element.
// Picture elements contain no text length but they are still content.
Expand Down
6 changes: 6 additions & 0 deletions Xceed.Document.NET/Src/Picture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,10 @@ private void SetPictureShape( object shape )









}
Loading

0 comments on commit 2591003

Please sign in to comment.