Ver código fonte

V1.3.0 Released

master
BoucherS 7 anos atrás
pai
commit
675a7d62c3
68 arquivos alterados com 11201 adições e 185 exclusões
  1. 1
    0
      Examples/Program.cs
  2. BIN
      Examples/Samples/Bookmark/Output/InsertBookmarks.docx
  3. BIN
      Examples/Samples/Bookmark/Output/ReplaceBookmarkText.docx
  4. BIN
      Examples/Samples/Chart/Output/3DChart.docx
  5. BIN
      Examples/Samples/Chart/Output/BarChart.docx
  6. BIN
      Examples/Samples/Chart/Output/LineChart.docx
  7. BIN
      Examples/Samples/Chart/Output/PieChart.docx
  8. BIN
      Examples/Samples/Document/Output/AddCustomProperties.docx
  9. BIN
      Examples/Samples/Document/Output/AppendDocument.docx
  10. BIN
      Examples/Samples/Document/Output/ApplyTemplate.docx
  11. BIN
      Examples/Samples/Equation/Output/EquationSample.docx
  12. BIN
      Examples/Samples/HeaderFooter/Output/HeadersFooters.docx
  13. BIN
      Examples/Samples/Hyperlink/Output/Hyperlinks.docx
  14. BIN
      Examples/Samples/Image/Output/AddPicture.docx
  15. BIN
      Examples/Samples/Image/Output/CopyPicture.docx
  16. BIN
      Examples/Samples/Image/Output/ModifyImage.docx
  17. BIN
      Examples/Samples/Line/Output/InsertHorizontalLine.docx
  18. BIN
      Examples/Samples/List/Output/AddList.docx
  19. BIN
      Examples/Samples/Margin/Output/Indentation.docx
  20. BIN
      Examples/Samples/Margin/Output/Margins.docx
  21. BIN
      Examples/Samples/Margin/Output/SetDirection.docx
  22. BIN
      Examples/Samples/Miscellaneous/Output/CompanyReport.docx
  23. BIN
      Examples/Samples/Miscellaneous/Output/CreateInvoice.docx
  24. BIN
      Examples/Samples/Miscellaneous/Output/CreateRecipe.docx
  25. BIN
      Examples/Samples/Paragraph/Output/ForceMultiParagraphsOnSinglePage.docx
  26. BIN
      Examples/Samples/Paragraph/Output/ForceParagraphOnSinglePage.docx
  27. BIN
      Examples/Samples/Paragraph/Output/Heading.docx
  28. BIN
      Examples/Samples/Paragraph/Output/SimpleFormattedParagraphs.docx
  29. BIN
      Examples/Samples/Paragraph/Output/TextActions.docx
  30. 2
    1
      Examples/Samples/Paragraph/ParagraphSample.cs
  31. BIN
      Examples/Samples/Parallel/Output/OutputDoc1.docx
  32. BIN
      Examples/Samples/Parallel/Output/OutputDoc2.docx
  33. BIN
      Examples/Samples/Parallel/Output/OutputDoc3.docx
  34. 47
    0
      Examples/Samples/Pdf/PdfSample.cs
  35. BIN
      Examples/Samples/Pdf/Resources/DocumentToConvert.docx
  36. BIN
      Examples/Samples/Protection/Output/AddPasswordProtection.docx
  37. BIN
      Examples/Samples/Protection/Output/AddProtection.docx
  38. BIN
      Examples/Samples/Section/Output/InsertSections.docx
  39. BIN
      Examples/Samples/Table/Output/ColumnsWidth.docx
  40. BIN
      Examples/Samples/Table/Output/CreateTableFromTemplate.docx
  41. BIN
      Examples/Samples/Table/Output/InsertRowAndImageTable.docx
  42. BIN
      Examples/Samples/Table/Output/MergeCells.docx
  43. BIN
      Examples/Samples/Table/Output/TextDirectionTable.docx
  44. BIN
      Examples/Samples/TableOfContent/Output/InsertTableOfContent.docx
  45. BIN
      Examples/Samples/TableOfContent/Output/InsertTableOfContentWithReference.docx
  46. 2
    0
      Examples/Xceed.Words.NET.Examples.csproj
  47. 0
    3
      Examples/bin/Debug/Examples.vshost.exe.config
  48. 0
    11
      Examples/bin/Debug/Examples.vshost.exe.manifest
  49. 5235
    0
      Examples/bin/Debug/Xceed.Words.NET.xml
  50. 0
    3
      Examples/bin/Release/Examples.exe.config
  51. 0
    3
      Examples/bin/Release/Examples.vshost.exe.config
  52. 0
    11
      Examples/bin/Release/Examples.vshost.exe.manifest
  53. 0
    0
      Examples/obj/x86/Debug/Xceed.Words.NET.Examples.csproj.CopyComplete
  54. 11
    1
      Examples/obj/x86/Debug/Xceed.Words.NET.Examples.csproj.FileListAbsolute.txt
  55. 0
    5
      Examples/obj/x86/Release/Xceed.Words.NET.Examples.csproj.FileListAbsolute.txt
  56. 1
    1
      Xceed.Words.NET/AssemblyVersionInfo.cs
  57. 5
    0
      Xceed.Words.NET/Src/Container.cs
  58. 21
    3
      Xceed.Words.NET/Src/DocX.cs
  59. 87
    7
      Xceed.Words.NET/Src/Formatting.cs
  60. 255
    105
      Xceed.Words.NET/Src/HelperFunctions.cs
  61. 7
    5
      Xceed.Words.NET/Src/List.cs
  62. 223
    14
      Xceed.Words.NET/Src/Paragraph.cs
  63. 45
    6
      Xceed.Words.NET/Src/Picture.cs
  64. 16
    2
      Xceed.Words.NET/Src/Table.cs
  65. 1
    1
      Xceed.Words.NET/Xceed.Words.NET.csproj
  66. 5235
    0
      Xceed.Words.NET/bin/Debug/Xceed.Words.NET.XML
  67. 7
    0
      Xceed.Words.NET/obj/Debug/Xceed.Words.NET.csproj.FileListAbsolute.txt
  68. 0
    3
      Xceed.Words.NET/obj/Release/Xceed.Words.NET.csproj.FileListAbsolute.txt

+ 1
- 0
Examples/Program.cs Ver arquivo

@@ -100,6 +100,7 @@ namespace Xceed.Words.NET.Examples
MiscellaneousSample.CompanyReport();
MiscellaneousSample.CreateInvoice();
Console.WriteLine( "\nPress any key to exit." );
Console.ReadKey();
}

BIN
Examples/Samples/Bookmark/Output/InsertBookmarks.docx Ver arquivo


BIN
Examples/Samples/Bookmark/Output/ReplaceBookmarkText.docx Ver arquivo


BIN
Examples/Samples/Chart/Output/3DChart.docx Ver arquivo


BIN
Examples/Samples/Chart/Output/BarChart.docx Ver arquivo


BIN
Examples/Samples/Chart/Output/LineChart.docx Ver arquivo


BIN
Examples/Samples/Chart/Output/PieChart.docx Ver arquivo


BIN
Examples/Samples/Document/Output/AddCustomProperties.docx Ver arquivo


BIN
Examples/Samples/Document/Output/AppendDocument.docx Ver arquivo


BIN
Examples/Samples/Document/Output/ApplyTemplate.docx Ver arquivo


BIN
Examples/Samples/Equation/Output/EquationSample.docx Ver arquivo


BIN
Examples/Samples/HeaderFooter/Output/HeadersFooters.docx Ver arquivo


BIN
Examples/Samples/Hyperlink/Output/Hyperlinks.docx Ver arquivo


BIN
Examples/Samples/Image/Output/AddPicture.docx Ver arquivo


BIN
Examples/Samples/Image/Output/CopyPicture.docx Ver arquivo


BIN
Examples/Samples/Image/Output/ModifyImage.docx Ver arquivo


BIN
Examples/Samples/Line/Output/InsertHorizontalLine.docx Ver arquivo


BIN
Examples/Samples/List/Output/AddList.docx Ver arquivo


BIN
Examples/Samples/Margin/Output/Indentation.docx Ver arquivo


BIN
Examples/Samples/Margin/Output/Margins.docx Ver arquivo


BIN
Examples/Samples/Margin/Output/SetDirection.docx Ver arquivo


BIN
Examples/Samples/Miscellaneous/Output/CompanyReport.docx Ver arquivo


BIN
Examples/Samples/Miscellaneous/Output/CreateInvoice.docx Ver arquivo


BIN
Examples/Samples/Miscellaneous/Output/CreateRecipe.docx Ver arquivo


BIN
Examples/Samples/Paragraph/Output/ForceMultiParagraphsOnSinglePage.docx Ver arquivo


BIN
Examples/Samples/Paragraph/Output/ForceParagraphOnSinglePage.docx Ver arquivo


BIN
Examples/Samples/Paragraph/Output/Heading.docx Ver arquivo


BIN
Examples/Samples/Paragraph/Output/SimpleFormattedParagraphs.docx Ver arquivo


BIN
Examples/Samples/Paragraph/Output/TextActions.docx Ver arquivo


+ 2
- 1
Examples/Samples/Paragraph/ParagraphSample.cs Ver arquivo

@@ -75,11 +75,12 @@ namespace Xceed.Words.NET.Examples
var p2 = document.InsertParagraph();

// Append some text and add formatting.
p2.Append( "This is a formatted paragraph using spacing," )
p2.Append( "This is a formatted paragraph using spacing, line spacing, " )
.Font( new Font( "Courier New" ) )
.FontSize( 10 )
.Italic()
.Spacing( 5 )
.SpacingLine( 22 )
.Append( "highlight" ).Highlight( Highlight.yellow ).UnderlineColor( Color.Blue ).CapsStyle( CapsStyle.caps )
.Append( " and strike through." ).StrikeThrough( StrikeThrough.strike )
.SpacingAfter( 40 );

BIN
Examples/Samples/Parallel/Output/OutputDoc1.docx Ver arquivo


BIN
Examples/Samples/Parallel/Output/OutputDoc2.docx Ver arquivo


BIN
Examples/Samples/Parallel/Output/OutputDoc3.docx Ver arquivo


+ 47
- 0
Examples/Samples/Pdf/PdfSample.cs Ver arquivo

@@ -0,0 +1,47 @@
/***************************************************************************************

DocX – DocX is the community edition of Xceed Words for .NET

Copyright (C) 2009-2017 Xceed Software Inc.

This program is provided to you under the terms of the Microsoft Public
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license

For more features and fast professional support,
pick up Xceed Words for .NET at https://xceed.com/xceed-words-for-net/

*************************************************************************************/
using System;
using System.IO;

namespace Xceed.Words.NET.Examples
{
public class PdfSample
{
#region Private Members


#endregion

#region Constructors

static PdfSample()
{
}

#endregion

#region Public Methods

/// <summary>
/// Load a document and convert it to PDF.
/// </summary>
public static void ConvertToPDF()
{

// This option is available when you buy Xceed Words for .NET from https://xceed.com/xceed-words-for-net/.
}

#endregion
}
}

BIN
Examples/Samples/Pdf/Resources/DocumentToConvert.docx Ver arquivo


BIN
Examples/Samples/Protection/Output/AddPasswordProtection.docx Ver arquivo


BIN
Examples/Samples/Protection/Output/AddProtection.docx Ver arquivo


BIN
Examples/Samples/Section/Output/InsertSections.docx Ver arquivo


BIN
Examples/Samples/Table/Output/ColumnsWidth.docx Ver arquivo


BIN
Examples/Samples/Table/Output/CreateTableFromTemplate.docx Ver arquivo


BIN
Examples/Samples/Table/Output/InsertRowAndImageTable.docx Ver arquivo


BIN
Examples/Samples/Table/Output/MergeCells.docx Ver arquivo


BIN
Examples/Samples/Table/Output/TextDirectionTable.docx Ver arquivo


BIN
Examples/Samples/TableOfContent/Output/InsertTableOfContent.docx Ver arquivo


BIN
Examples/Samples/TableOfContent/Output/InsertTableOfContentWithReference.docx Ver arquivo


+ 2
- 0
Examples/Xceed.Words.NET.Examples.csproj Ver arquivo

@@ -61,6 +61,7 @@
<Compile Include="Samples\Miscellaneous\MiscellaneousSample.cs" />
<Compile Include="Samples\Paragraph\ParagraphSample.cs" />
<Compile Include="Samples\Parallel\ParallelSample.cs" />
<Compile Include="Samples\Pdf\PdfSample.cs" />
<Compile Include="Samples\Protection\ProtectionSample.cs" />
<Compile Include="Samples\Section\SectionSample.cs" />
<Compile Include="Samples\TableOfContent\TableOfContentSample.cs" />
@@ -78,6 +79,7 @@
<None Include="Samples\Parallel\Resources\Doc1.docx" />
<None Include="Samples\Parallel\Resources\Doc2.docx" />
<None Include="Samples\Parallel\Resources\Doc3.docx" />
<None Include="Samples\Pdf\Resources\DocumentToConvert.docx" />
<None Include="Samples\Table\Resources\DocumentWithTemplateTable.docx" />
</ItemGroup>
<ItemGroup>

+ 0
- 3
Examples/bin/Debug/Examples.vshost.exe.config Ver arquivo

@@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

+ 0
- 11
Examples/bin/Debug/Examples.vshost.exe.manifest Ver arquivo

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

+ 5235
- 0
Examples/bin/Debug/Xceed.Words.NET.xml
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 0
- 3
Examples/bin/Release/Examples.exe.config Ver arquivo

@@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

+ 0
- 3
Examples/bin/Release/Examples.vshost.exe.config Ver arquivo

@@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

+ 0
- 11
Examples/bin/Release/Examples.vshost.exe.manifest Ver arquivo

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

+ 0
- 0
Examples/obj/x86/Debug/Xceed.Words.NET.Examples.csproj.CopyComplete Ver arquivo


+ 11
- 1
Examples/obj/x86/Debug/Xceed.Words.NET.Examples.csproj.FileListAbsolute.txt Ver arquivo

@@ -1 +1,11 @@
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\bin\Debug\Examples.exe.config
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Examples.exe.config
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Examples.exe
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Examples.pdb
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Xceed.Words.NET.dll
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Xceed.Words.NET.pdb
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\bin\Debug\Xceed.Words.NET.xml
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\obj\x86\Debug\Xceed.Words.NET.Examples.csprojAssemblyReference.cache
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\obj\x86\Debug\Xceed.Words.NET.Examples.csproj.CoreCompileInputs.cache
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\obj\x86\Debug\Xceed.Words.NET.Examples.csproj.CopyComplete
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\obj\x86\Debug\Examples.exe
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Examples\obj\x86\Debug\Examples.pdb

+ 0
- 5
Examples/obj/x86/Release/Xceed.Words.NET.Examples.csproj.FileListAbsolute.txt Ver arquivo

@@ -1,5 +0,0 @@
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\bin\Release\Examples.exe.config
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\bin\Release\Examples.exe
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\bin\Release\Xceed.Words.NET.dll
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\obj\x86\Release\Xceed.Words.NET.Examples.csprojResolveAssemblyReference.cache
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Examples\obj\x86\Release\Examples.exe

+ 1
- 1
Xceed.Words.NET/AssemblyVersionInfo.cs Ver arquivo

@@ -19,7 +19,7 @@
internal static class _XceedVersionInfo
{
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string BaseVersion = "1.2";
public const string BaseVersion = "1.3";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string Version = BaseVersion +
".0.0";

+ 5
- 0
Xceed.Words.NET/Src/Container.cs Ver arquivo

@@ -858,6 +858,11 @@ namespace Xceed.Words.NET
{
foreach( XElement xElement in p )
{
// Do not include inner paragraphs contained in a Fallback.
if( xElement.Ancestors().FirstOrDefault( x => x.Name.Equals( XName.Get( "Fallback", DocX.mc.NamespaceName ) ) ) != null )
{
continue;
}
var paragraph = new Paragraph( this.Document, xElement, index );
paragraphs.Add( paragraph );
index += HelperFunctions.GetText( xElement ).Length;

+ 21
- 3
Xceed.Words.NET/Src/DocX.cs Ver arquivo

@@ -46,6 +46,7 @@ namespace Xceed.Words.NET
static internal XNamespace c = "http://schemas.openxmlformats.org/drawingml/2006/chart";
internal static XNamespace n = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
static internal XNamespace v = "urn:schemas-microsoft-com:vml";
static internal XNamespace mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
#endregion

#region Private Members
@@ -1705,7 +1706,6 @@ namespace Xceed.Words.NET
/// Add an Image into this document from a fully qualified or relative filename.
/// </summary>
/// <param name="filename">The fully qualified or relative filename.</param>
/// <param name="contentType">MIME type of image, guessed if not given.</param>
/// <returns>An Image file.</returns>
/// <example>
/// Add an Image into this document from a fully qualified filename.
@@ -2365,7 +2365,7 @@ namespace Xceed.Words.NET

// If this document does not contain a coreFilePropertyPart create one.)
if( !_package.PartExists( new Uri( "/docProps/core.xml", UriKind.Relative ) ) )
throw new Exception( "Core properties part doesn't exist." );
HelperFunctions.CreateCorePropertiesPart( this );

XDocument corePropDoc;
var corePropPart = _package.GetPart( new Uri( "/docProps/core.xml", UriKind.Relative ) );
@@ -2925,6 +2925,8 @@ namespace Xceed.Words.NET
_settings.Root.AddFirst( documentProtection );
}



#endregion

#region Internal Methods
@@ -3659,6 +3661,11 @@ namespace Xceed.Words.NET
}
}

internal XElement GetDocDefaults()
{
return this._styles.Element( XName.Get( "styles", DocX.w.NamespaceName ) ).Element( XName.Get( "docDefaults", DocX.w.NamespaceName ) );
}

/// <summary>
/// Finds the next free Id for bookmarkStart/docPr.
/// </summary>
@@ -4407,7 +4414,18 @@ namespace Xceed.Words.NET
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
document._stylesPart = package.GetPart( new Uri( uriString, UriKind.Relative ) );
using( TextReader tr = new StreamReader( document._stylesPart.GetStream() ) )
{
document._styles = XDocument.Load( tr );
var pPrDefault = document._styles.Root.Element( XName.Get( "docDefaults", DocX.w.NamespaceName ) ).Element( XName.Get( "pPrDefault", DocX.w.NamespaceName ) );
if( pPrDefault != null )
{
var pPr = pPrDefault.Element( XName.Get( "pPr", DocX.w.NamespaceName ) );
if( pPr != null )
{
Paragraph.SetDefaultValues( pPr );
}
}
}
break;

case "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects":
@@ -4510,7 +4528,7 @@ namespace Xceed.Words.NET
internal DocX( DocX document, XElement xml )
: base( document, xml )
{
Paragraph.ResetDefaultValues();
}

#endregion

+ 87
- 7
Xceed.Words.NET/Src/Formatting.cs Ver arquivo

@@ -35,6 +35,7 @@ namespace Xceed.Words.NET
private Script? _script;
private Highlight? _highlight;
private Color? _shading;
private Border _border;
private double? _size;
private Color? _fontColor;
private Color? _underlineColor;
@@ -311,6 +312,18 @@ namespace Xceed.Words.NET
}
}

public Border Border
{
get
{
return _border;
}
set
{
_border = value;
}
}

public string StyleName
{
get
@@ -571,6 +584,16 @@ namespace Xceed.Words.NET
_rPr.Add( new XElement( XName.Get( "shd", DocX.w.NamespaceName ), new XAttribute( XName.Get( "fill", DocX.w.NamespaceName ), _shading.Value.ToHex() ) ) );
}

if( _border != null )
{
_rPr.Add( new XElement( XName.Get( "bdr", DocX.w.NamespaceName ),
new object[] { new XAttribute( XName.Get( "color", DocX.w.NamespaceName ), _border.Color ),
new XAttribute( XName.Get( "space", DocX.w.NamespaceName ), _border.Space ),
new XAttribute( XName.Get( "sz", DocX.w.NamespaceName ), _border.Size ),
new XAttribute( XName.Get( "val", DocX.w.NamespaceName ), _border.Tcbs )
} ) );
}

if( _capsStyle.HasValue )
{
switch( _capsStyle )
@@ -624,6 +647,7 @@ namespace Xceed.Words.NET
clone.Hidden = _hidden;
clone.Highlight = _highlight;
clone.Shading = _shading;
clone.Border = _border;
clone.Italic = _italic;
if( _kerning.HasValue )
{
@@ -691,15 +715,19 @@ namespace Xceed.Words.NET
formatting.PercentageScale = Int32.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)));
break;
case "sz":
formatting.Size = Int32.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 2;
formatting.Size = Double.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 2;
break;
case "rFonts":
var fontName = option.GetAttribute( XName.Get( "cs", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "ascii", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "hAnsi", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "hint", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "eastAsia", DocX.w.NamespaceName ), null );
formatting.FontFamily = new Font( fontName ?? "Calibri" );
var fontName = option.GetAttribute( XName.Get( "ascii", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "hAnsi", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "cs", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "hint", DocX.w.NamespaceName ), null )
?? option.GetAttribute( XName.Get( "eastAsia", DocX.w.NamespaceName ), null );

formatting.FontFamily = ( fontName != null )
? new Font( fontName )
: ( formatting.FontFamily == null ) ?
new Font( "Calibri" ) : formatting.FontFamily;
break;
case "color":
try
@@ -809,6 +837,55 @@ namespace Xceed.Words.NET
formatting.Shading = System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", fill ) );
}
break;
case "bdr":
var borderSize = BorderSize.one;
var borderColor = Color.Black;
var borderSpace = 0;
var borderStyle = BorderStyle.Tcbs_single;

var bdrColor = option.Attribute( XName.Get( "color", DocX.w.NamespaceName ) );
if( ( bdrColor != null ) && ( bdrColor.Value != "auto" ) )
{
borderColor = System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", bdrColor.Value ) );
}
var size = option.Attribute( XName.Get( "sz", DocX.w.NamespaceName ) );
if( size != null )
{
var sizeValue = System.Convert.ToSingle( size.Value );
if( sizeValue == 2 )
borderSize = BorderSize.one;
else if( sizeValue == 4 )
borderSize = BorderSize.two;
else if( sizeValue == 6 )
borderSize = BorderSize.three;
else if( sizeValue == 8 )
borderSize = BorderSize.four;
else if( sizeValue == 12 )
borderSize = BorderSize.five;
else if( sizeValue == 18 )
borderSize = BorderSize.six;
else if( sizeValue == 24 )
borderSize = BorderSize.seven;
else if( sizeValue == 36 )
borderSize = BorderSize.eight;
else if( sizeValue == 48 )
borderSize = BorderSize.nine;
else
borderSize = BorderSize.one;
}
var space = option.Attribute( XName.Get( "space", DocX.w.NamespaceName ) );
if( space != null )
{
borderSpace = System.Convert.ToInt32( space.Value );
}
var bdrStyle = option.Attribute( XName.Get( "val", DocX.w.NamespaceName ) );
if( bdrStyle != null )
{
borderStyle = (BorderStyle)Enum.Parse( typeof( BorderStyle ), "Tcbs_" + bdrStyle.Value );
}

formatting.Border = new Border( borderStyle, borderSize, borderSpace, borderColor );
break;
case "rStyle":
var style = option.GetAttribute( XName.Get( "val", DocX.w.NamespaceName ), null );
formatting.StyleName = style;
@@ -846,6 +923,9 @@ namespace Xceed.Words.NET
if( other._shading != _shading )
return -1;

if( other._border != _border )
return -1;

if( other._size != _size )
return -1;


+ 255
- 105
Xceed.Words.NET/Src/HelperFunctions.cs Ver arquivo

@@ -24,6 +24,7 @@ using System.IO.Compression;
using System.Security.Principal;
using System.Globalization;
using System.Xml;
using System.Diagnostics;

namespace Xceed.Words.NET
{
@@ -89,7 +90,11 @@ namespace Xceed.Words.NET
{
sb.Append( ToText( Xml ) );

if( Xml.HasElements )
// Do not read text from Fallback or drawing(a new paragraph will take care of drawing).
var fallbackValue = Xml.Name.Equals( XName.Get( "Fallback", DocX.mc.NamespaceName ) );
var drawingValue = Xml.Name.Equals( XName.Get( "drawing", DocX.w.NamespaceName ) );

if( Xml.HasElements && !fallbackValue && !drawingValue )
foreach( XElement e in Xml.Elements() )
GetTextRecursive( e, ref sb );
}
@@ -138,8 +143,13 @@ namespace Xceed.Words.NET
if( text == String.Empty )
return null;

// Do not read text from Fallback.
var fallbackValue = e.AncestorsAndSelf().FirstOrDefault( x => x.Name.Equals( XName.Get( "Fallback", DocX.mc.NamespaceName ) ) );
if( fallbackValue != null )
return null;

// e is a w:t element, it must exist inside a w:r element or a w:tabs, lets climb until we find it.
while( (e != null) && !e.Name.Equals( XName.Get( "r", DocX.w.NamespaceName ) ) && !e.Name.Equals( XName.Get( "tabs", DocX.w.NamespaceName ) ) )
while( ( e != null ) && !e.Name.Equals( XName.Get( "r", DocX.w.NamespaceName ) ) && !e.Name.Equals( XName.Get( "tabs", DocX.w.NamespaceName ) ) )
e = e.Parent;

FormattedText ft = new FormattedText();
@@ -166,9 +176,9 @@ namespace Xceed.Words.NET
{
case "tab":
// Do not add "\t" for TabStopPositions defined in "tabs".
return ((e.Parent != null) && e.Parent.Name.Equals( XName.Get( "tabs", DocX.w.NamespaceName ) )) ? "" : "\t";
case "br":
return "\n";
return ( ( e.Parent != null ) && e.Parent.Name.Equals( XName.Get( "tabs", DocX.w.NamespaceName ) ) ) ? "" : "\t";
//case "br":
// return "\n";
case "t":
goto case "delText";
case "delText":
@@ -178,9 +188,12 @@ namespace Xceed.Words.NET
return e.Value;
}
case "tr":
goto case "br";
//goto case "br";
return "\n";
case "tc":
goto case "tab";
case "ptab":
goto case "tab";
default:
return "";
}
@@ -282,6 +295,29 @@ namespace Xceed.Words.NET
return settingsPart;
}

internal static void CreateCorePropertiesPart(DocX document)
{
PackagePart corePropertiesPart = document._package.CreatePart( new Uri( "/docProps/core.xml", UriKind.Relative ), "application/vnd.openxmlformats-package.core-properties+xml", CompressionOption.Maximum );

XDocument corePropDoc = XDocument.Parse( @"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<cp:coreProperties xmlns:cp='http://schemas.openxmlformats.org/package/2006/metadata/core-properties' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:dcterms='http://purl.org/dc/terms/' xmlns:dcmitype='http://purl.org/dc/dcmitype/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<dc:title></dc:title>
<dc:subject></dc:subject>
<dc:creator></dc:creator>
<cp:keywords></cp:keywords>
<dc:description></dc:description>
<cp:lastModifiedBy></cp:lastModifiedBy>
<cp:revision>1</cp:revision>
<dcterms:created xsi:type='dcterms:W3CDTF'>" + DateTime.UtcNow.ToString( "s" ) + "Z" + @"</dcterms:created>
<dcterms:modified xsi:type='dcterms:W3CDTF'>" + DateTime.UtcNow.ToString( "s" ) + "Z" + @"</dcterms:modified>
</cp:coreProperties>" );

using( TextWriter tw = new StreamWriter( new PackagePartStream( corePropertiesPart.GetStream( FileMode.Create, FileAccess.Write ) ) ) )
corePropDoc.Save( tw, SaveOptions.None );

document._package.CreateRelationship( corePropertiesPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" );
}

internal static void CreateCustomPropertiesPart( DocX document )
{
var customPropertiesPart = document._package.CreatePart( new Uri( "/docProps/custom.xml", UriKind.Relative ), "application/vnd.openxmlformats-officedocument.custom-properties+xml", CompressionOption.Maximum );
@@ -393,12 +429,12 @@ namespace Xceed.Words.NET
throw new ArgumentOutOfRangeException( "Row and Column count must be greater than 0." );
}

int[] columnWidths = new int[columnCount];
for (int i = 0; i < columnCount; i++)
int[] columnWidths = new int[ columnCount ];
for( int i = 0; i < columnCount; i++ )
{
columnWidths[i] = 2310;
columnWidths[ i ] = 2310;
}
return CreateTable(rowCount, columnWidths);
return CreateTable( rowCount, columnWidths );
}

internal static XElement CreateTable( int rowCount, int[] columnWidths )
@@ -611,12 +647,12 @@ namespace Xceed.Words.NET
/// <summary>
/// Add the default numbering.xml if it is missing from this document
/// </summary>
internal static XDocument AddDefaultNumberingXml(Package package)
internal static XDocument AddDefaultNumberingXml( Package package )
{
XDocument numberingDoc;

var numberingPart = package.CreatePart(new Uri("/word/numbering.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", CompressionOption.Maximum);
numberingDoc = DecompressXMLResource("Xceed.Words.NET.Resources.numbering.xml.gz");
var numberingPart = package.CreatePart( new Uri( "/word/numbering.xml", UriKind.Relative ), "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", CompressionOption.Maximum );
numberingDoc = DecompressXMLResource( "Xceed.Words.NET.Resources.numbering.xml.gz" );

using( TextWriter tw = new StreamWriter( new PackagePartStream( numberingPart.GetStream( FileMode.Create, FileAccess.Write ) ) ) )
{
@@ -625,122 +661,124 @@ namespace Xceed.Words.NET

var mainDocPart = GetMainDocumentPart( package );

mainDocPart.CreateRelationship(numberingPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering");
mainDocPart.CreateRelationship( numberingPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" );
return numberingDoc;
}

internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int? startNumber = null, bool trackChanges = false, bool continueNumbering = false)
internal static List CreateItemInList( List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int? startNumber = null, bool trackChanges = false, bool continueNumbering = false )
{
if (list.NumId == 0)
{
list.CreateNewNumberingNumId(level, listType, startNumber, continueNumbering);
}
if( list.NumId == 0 )
{
list.CreateNewNumberingNumId( level, listType, startNumber, continueNumbering );
}

if (listText != null)
{
var newSection = new XElement
(
XName.Get("p", DocX.w.NamespaceName),
new XElement(XName.Get("pPr", DocX.w.NamespaceName),
new XElement(XName.Get("numPr", DocX.w.NamespaceName),
new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)),
new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))),
new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText))
);
if (trackChanges)
newSection = CreateEdit(EditType.ins, DateTime.Now, newSection);
if (startNumber == null)
list.AddItem(new Paragraph(list.Document, newSection, 0, ContainerType.Paragraph));
else
list.AddItemWithStartValue(new Paragraph(list.Document, newSection, 0, ContainerType.Paragraph), (int)startNumber);
}
return list;
if( listText != null )
{
var newSection = new XElement
(
XName.Get( "p", DocX.w.NamespaceName ),
new XElement( XName.Get( "pPr", DocX.w.NamespaceName ),
new XElement( XName.Get( "numPr", DocX.w.NamespaceName ),
new XElement( XName.Get( "ilvl", DocX.w.NamespaceName ), new XAttribute( DocX.w + "val", level ) ),
new XElement( XName.Get( "numId", DocX.w.NamespaceName ), new XAttribute( DocX.w + "val", list.NumId ) ) ) ),
new XElement( XName.Get( "r", DocX.w.NamespaceName ), new XElement( XName.Get( "t", DocX.w.NamespaceName ), listText ) )
);
if( trackChanges )
newSection = CreateEdit( EditType.ins, DateTime.Now, newSection );
if( startNumber == null )
list.AddItem( new Paragraph( list.Document, newSection, 0, ContainerType.Paragraph ) );
else
list.AddItemWithStartValue( new Paragraph( list.Document, newSection, 0, ContainerType.Paragraph ), ( int )startNumber );
}
return list;
}

internal static UnderlineStyle GetUnderlineStyle(string styleName)
internal static UnderlineStyle GetUnderlineStyle( string styleName )
{
switch (styleName)
{
case "single":
return UnderlineStyle.singleLine;
case "double":
return UnderlineStyle.doubleLine;
case "thick":
return UnderlineStyle.thick;
case "dotted":
return UnderlineStyle.dotted;
case "dottedHeavy":
return UnderlineStyle.dottedHeavy;
case "dash":
return UnderlineStyle.dash;
case "dashedHeavy":
return UnderlineStyle.dashedHeavy;
case "dashLong":
return UnderlineStyle.dashLong;
case "dashLongHeavy":
return UnderlineStyle.dashLongHeavy;
case "dotDash":
return UnderlineStyle.dotDash;
case "dashDotHeavy":
return UnderlineStyle.dashDotHeavy;
case "dotDotDash":
return UnderlineStyle.dotDotDash;
case "dashDotDotHeavy":
return UnderlineStyle.dashDotDotHeavy;
case "wave":
return UnderlineStyle.wave;
case "wavyHeavy":
return UnderlineStyle.wavyHeavy;
case "wavyDouble":
return UnderlineStyle.wavyDouble;
case "words":
return UnderlineStyle.words;
default:
return UnderlineStyle.none;
}
switch( styleName )
{
case "single":
return UnderlineStyle.singleLine;
case "double":
return UnderlineStyle.doubleLine;
case "thick":
return UnderlineStyle.thick;
case "dotted":
return UnderlineStyle.dotted;
case "dottedHeavy":
return UnderlineStyle.dottedHeavy;
case "dash":
return UnderlineStyle.dash;
case "dashedHeavy":
return UnderlineStyle.dashedHeavy;
case "dashLong":
return UnderlineStyle.dashLong;
case "dashLongHeavy":
return UnderlineStyle.dashLongHeavy;
case "dotDash":
return UnderlineStyle.dotDash;
case "dashDotHeavy":
return UnderlineStyle.dashDotHeavy;
case "dotDotDash":
return UnderlineStyle.dotDotDash;
case "dashDotDotHeavy":
return UnderlineStyle.dashDotDotHeavy;
case "wave":
return UnderlineStyle.wave;
case "wavyHeavy":
return UnderlineStyle.wavyHeavy;
case "wavyDouble":
return UnderlineStyle.wavyDouble;
case "words":
return UnderlineStyle.words;
default:
return UnderlineStyle.none;
}
}

internal static bool ContainsEveryChildOf(XElement elementWanted, XElement elementToValidate, MatchFormattingOptions formattingOptions)
internal static bool ContainsEveryChildOf( XElement elementWanted, XElement elementToValidate, MatchFormattingOptions formattingOptions )
{
foreach (XElement subElement in elementWanted.Elements())
{
if (!elementToValidate.Elements(subElement.Name).Where(bElement => bElement.GetAttribute(XName.Get("val", DocX.w.NamespaceName)) == subElement.GetAttribute(XName.Get("val", DocX.w.NamespaceName))).Any())
return false;
}
foreach( XElement subElement in elementWanted.Elements() )
{
if( !elementToValidate.Elements( subElement.Name ).Where( bElement => bElement.GetAttribute( XName.Get( "val", DocX.w.NamespaceName ) ) == subElement.GetAttribute( XName.Get( "val", DocX.w.NamespaceName ) ) ).Any() )
return false;
}

if (formattingOptions == MatchFormattingOptions.ExactMatch)
return elementWanted.Elements().Count() == elementToValidate.Elements().Count();
if( formattingOptions == MatchFormattingOptions.ExactMatch )
return elementWanted.Elements().Count() == elementToValidate.Elements().Count();

return true;
return true;
}

internal static string GetListItemType( Paragraph p, DocX document )
{
var paragraphNumberPropertiesDescendants = p.ParagraphNumberProperties.Descendants();
var ilvlNode = paragraphNumberPropertiesDescendants.FirstOrDefault( el => el.Name.LocalName == "ilvl" );
var ilvlValue = ( ilvlNode != null) ? ilvlNode.Attribute( DocX.w + "val" ).Value : null;
var ilvlValue = ( ilvlNode != null ) ? ilvlNode.Attribute( DocX.w + "val" ).Value : null;

var numIdNode = paragraphNumberPropertiesDescendants.FirstOrDefault( el => el.Name.LocalName == "numId" );
var numIdValue = ( numIdNode != null ) ? numIdNode.Attribute( DocX.w + "val" ).Value : null;

//find num node in numbering
var documentNumberingDescendants = document._numbering.Descendants();
var numNodes = documentNumberingDescendants.Where( n => n.Name.LocalName == "num" );
XElement numNode = numNodes.FirstOrDefault( node => node.Attribute( DocX.w + "numId" ).Value.Equals( numIdValue ) );

if( numNode != null )
var abstractNumNode = HelperFunctions.GetAbstractNum( document, numIdValue );
if( abstractNumNode != null )
{
//Get abstractNumId node and its value from numNode
var abstractNumIdNode = numNode.Descendants().First( n => n.Name.LocalName == "abstractNumId" );
var abstractNumNodeValue = abstractNumIdNode.Attribute( DocX.w + "val" ).Value;

var abstractNumNodes = documentNumberingDescendants.Where( n => n.Name.LocalName == "abstractNum" );
XElement abstractNumNode = abstractNumNodes.FirstOrDefault( node => node.Attribute( DocX.w + "abstractNumId" ).Value.Equals( abstractNumNodeValue ) );

//Find lvl node
// Find lvl node.
var lvlNodes = abstractNumNode.Descendants().Where( n => n.Name.LocalName == "lvl" );
// No lvl, check if a numStyleLink is used.
if( lvlNodes.Count() == 0 )
{
var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId( document, numIdValue );
if( linkedStyleNumId != -1 )
{
abstractNumNode = HelperFunctions.GetAbstractNum( document, linkedStyleNumId.ToString() );
if( abstractNumNode != null )
{
lvlNodes = abstractNumNode.Descendants().Where( n => n.Name.LocalName == "lvl" );
}
}
}
XElement lvlNode = null;
foreach( XElement node in lvlNodes )
{
@@ -752,7 +790,7 @@ namespace Xceed.Words.NET
else if( ilvlValue == null )
{
var numStyleNode = node.Descendants().FirstOrDefault( n => n.Name.LocalName == "pStyle" );
if( ( numStyleNode != null) && numStyleNode.GetAttribute( DocX.w + "val" ).Equals( p.StyleName ) )
if( ( numStyleNode != null ) && numStyleNode.GetAttribute( DocX.w + "val" ).Equals( p.StyleName ) )
{
lvlNode = node;
break;
@@ -770,6 +808,34 @@ namespace Xceed.Words.NET
return null;
}

internal static XElement GetAbstractNum( DocX document, string numId )
{
if( document == null )
return null;
if( numId == null )
return null;

// Find num node in numbering.
var documentNumberingDescendants = document._numbering.Descendants();
var numNodes = documentNumberingDescendants.Where( n => n.Name.LocalName == "num" );
var numNode = numNodes.FirstOrDefault( node => node.Attribute( DocX.w + "numId" ).Value.Equals( numId ) );
if( numNode == null )
return null;

// Get abstractNumId node and its value from numNode.
var abstractNumIdNode = numNode.Descendants().FirstOrDefault( n => n.Name.LocalName == "abstractNumId" );
if( abstractNumIdNode == null )
return null;
var abstractNumNodeValue = abstractNumIdNode.Attribute( DocX.w + "val" ).Value;
if( string.IsNullOrEmpty( abstractNumNodeValue ) )
return null;

var abstractNumNodes = documentNumberingDescendants.Where( n => n.Name.LocalName == "abstractNum" );
var abstractNumNode = abstractNumNodes.FirstOrDefault( node => node.Attribute( DocX.w + "abstractNumId" ).Value.Equals( abstractNumNodeValue ) );

return abstractNumNode;
}

internal static string GetListItemStartValue( List list, int level )
{
var abstractNumElement = list.GetAbstractNum( list.NumId );
@@ -777,6 +843,19 @@ namespace Xceed.Words.NET
//Find lvl node
var lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
var lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
// No ilvl, check if a numStyleLink is used.
if( lvlNode == null )
{
var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId( list.Document, list.NumId.ToString() );
if( linkedStyleNumId != -1 )
{
abstractNumElement = list.GetAbstractNum( linkedStyleNumId );
lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
}
if( lvlNode == null )
return "1";
}

var startNode = lvlNode.Descendants().First( n => n.Name.LocalName == "start" );
return startNode.GetAttribute( DocX.w + "val" );
@@ -789,6 +868,19 @@ namespace Xceed.Words.NET
//Find lvl node
var lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
var lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
// No ilvl, check if a numStyleLink is used.
if( lvlNode == null )
{
var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId( list.Document, list.NumId.ToString() );
if( linkedStyleNumId != -1 )
{
abstractNumElement = list.GetAbstractNum( linkedStyleNumId );
lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
}
if( lvlNode == null )
return "%1.";
}

var textFormatNode = lvlNode.Descendants().First( n => n.Name.LocalName == "lvlText" );
return textFormatNode.GetAttribute( DocX.w + "val" );
@@ -801,6 +893,19 @@ namespace Xceed.Words.NET
//Find lvl node
var lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
var lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
// No ilvl, check if a numStyleLink is used.
if( lvlNode == null )
{
var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId( list.Document, list.NumId.ToString() );
if( linkedStyleNumId != -1 )
{
abstractNumElement = list.GetAbstractNum( linkedStyleNumId );
lvlNodes = abstractNumElement.Descendants().Where( n => n.Name.LocalName == "lvl" );
lvlNode = lvlNodes.FirstOrDefault( n => n.GetAttribute( DocX.w + "ilvl" ).Equals( level.ToString() ) );
}
if( lvlNode == null )
return null;
}

var pPr = lvlNode.Descendants().FirstOrDefault( n => n.Name.LocalName == "pPr" );
if( pPr != null )
@@ -813,5 +918,50 @@ namespace Xceed.Words.NET
}
return null;
}

private static XElement GetStyle( DocX fileToConvert, string styleName )
{
if( fileToConvert == null )
throw new ArgumentNullException( "fileToConvert" );
if( string.IsNullOrEmpty( styleName ) )
throw new ArgumentNullException( "styleName" );

var styles = fileToConvert._styles.Element( XName.Get( "styles", DocX.w.NamespaceName ) );
return ( from e in styles.Descendants()
let styleId = e.Attribute( XName.Get( "styleId", DocX.w.NamespaceName ) )
where ( styleId != null && styleId.Value == styleName )
select e ).FirstOrDefault();
}

private static int GetLinkedStyleNumId( DocX document, string numId )
{
Debug.Assert( document != null, "document should not be null" );

var abstractNumElement = HelperFunctions.GetAbstractNum( document, numId );
if( abstractNumElement != null )
{
var numStyleLink = abstractNumElement.Element( XName.Get( "numStyleLink", DocX.w.NamespaceName ) );
if( numStyleLink != null )
{
var val = numStyleLink.Attribute( XName.Get( "val", DocX.w.NamespaceName ) );
if( !string.IsNullOrEmpty( val.Value ) )
{
var linkedStyle = HelperFunctions.GetStyle( document, val.Value );
if( linkedStyle != null )
{
var linkedNumId = linkedStyle.Descendants( XName.Get( "numId", DocX.w.NamespaceName ) ).FirstOrDefault();
if( linkedNumId != null )
{
var linkedNumIdVal = linkedNumId.Attribute( XName.Get( "val", DocX.w.NamespaceName ) );
if( !string.IsNullOrEmpty( linkedNumIdVal.Value ) )
return Int32.Parse( linkedNumIdVal.Value );
}
}
}
}
}

return -1;
}
}
}

+ 7
- 5
Xceed.Words.NET/Src/List.cs Ver arquivo

@@ -78,7 +78,9 @@ namespace Xceed.Words.NET
{
if( paragraph.IsListItem )
{
var numIdNode = paragraph.Xml.Descendants().First( s => s.Name.LocalName == "numId" );
var numIdNode = paragraph.Xml.Descendants().FirstOrDefault( s => s.Name.LocalName == "numId" );
if( numIdNode == null )
return;
var numId = Int32.Parse( numIdNode.Attribute( DocX.w + "val" ).Value );

if( CanAddListItem( paragraph ) )
@@ -112,7 +114,9 @@ namespace Xceed.Words.NET
if( paragraph.IsListItem )
{
//var lvlNode = paragraph.Xml.Descendants().First(s => s.Name.LocalName == "ilvl");
var numIdNode = paragraph.Xml.Descendants().First( s => s.Name.LocalName == "numId" );
var numIdNode = paragraph.Xml.Descendants().FirstOrDefault( s => s.Name.LocalName == "numId" );
if( numIdNode == null )
return false;
var numId = Int32.Parse( numIdNode.Attribute( DocX.w + "val" ).Value );

//Level = Int32.Parse(lvlNode.Attribute(DocX.w + "val").Value);
@@ -188,9 +192,7 @@ namespace Xceed.Words.NET
/// <returns>XElement representing the requested abstractNum</returns>
internal XElement GetAbstractNum( int numId )
{
var num = Document._numbering.Descendants().First( d => d.Name.LocalName == "num" && d.GetAttribute( DocX.w + "numId" ).Equals( numId.ToString() ) );
var abstractNumId = num.Descendants().First( d => d.Name.LocalName == "abstractNumId" ).GetAttribute( DocX.w + "val" );
return Document._numbering.Descendants().First( d => d.Name.LocalName == "abstractNum" && d.GetAttribute( DocX.w + "abstractNumId" ).Equals( abstractNumId ) );
return HelperFunctions.GetAbstractNum( this.Document, numId.ToString() );
}

#endregion

+ 223
- 14
Xceed.Words.NET/Src/Paragraph.cs Ver arquivo

@@ -38,7 +38,15 @@ namespace Xceed.Words.NET
internal int _startIndex, _endIndex;
internal List<XElement> _styles = new List<XElement>();

internal const float DefaultLineSpacing = 1.1f * 20.0f;
internal const float DefaultSingleLineSpacing = 12f;
private static float DefaultLineSpacing = Paragraph.DefaultSingleLineSpacing;
private static float DefaultLineSpacingAfter = 0f;
private static float DefaultLineSpacingBefore = 0f;

private static float DefaultIndentationFirstLine = 0f;
private static float DefaultIndentationHanging = 0f;
private static float DefaultIndentationBefore = 0f;
private static float DefaultIndentationAfter = 0f;

#endregion

@@ -346,7 +354,7 @@ namespace Xceed.Words.NET
if( firstLine != null )
return float.Parse( firstLine.Value ) / 570f;

return 0.0f;
return Paragraph.DefaultIndentationFirstLine;
}

set
@@ -403,7 +411,7 @@ namespace Xceed.Words.NET
if( hanging != null )
return float.Parse( hanging.Value ) / 570f;

return 0.0f;
return Paragraph.DefaultIndentationHanging;
}

set
@@ -469,7 +477,7 @@ namespace Xceed.Words.NET
if( left != null )
return float.Parse( left.Value ) / 570f;

return 0.0f;
return Paragraph.DefaultIndentationBefore;
}

set
@@ -531,7 +539,7 @@ namespace Xceed.Words.NET
if( right != null )
return float.Parse( right.Value ) / 570f;

return 0.0f;
return Paragraph.DefaultIndentationAfter;
}

set
@@ -707,7 +715,7 @@ namespace Xceed.Words.NET

set
{
Spacing( value );
SpacingLine( value );
}
}

@@ -716,11 +724,15 @@ namespace Xceed.Words.NET
get
{
XElement pPr = GetOrCreate_pPr();

XElement spacing = pPr.Element( XName.Get( "spacing", DocX.w.NamespaceName ) );

if( spacing != null )
{
XAttribute line = spacing.Attribute( XName.Get( "before", DocX.w.NamespaceName ) );
if( this.IsBeforeAutoSpacing() )
return 0f;

var line = spacing.Attribute( XName.Get( "before", DocX.w.NamespaceName ) );
if( line != null )
{
float f;
@@ -730,7 +742,7 @@ namespace Xceed.Words.NET
}
}

return 0.0f;
return Paragraph.DefaultLineSpacingBefore;
}

set
@@ -748,7 +760,10 @@ namespace Xceed.Words.NET

if( spacing != null )
{
XAttribute line = spacing.Attribute( XName.Get( "after", DocX.w.NamespaceName ) );
if( this.IsAfterAutoSpacing() )
return 0f;

var line = spacing.Attribute( XName.Get( "after", DocX.w.NamespaceName ) );
if( line != null )
{
float f;
@@ -758,16 +773,43 @@ namespace Xceed.Words.NET
}
}

return 0.0f;
return Paragraph.DefaultLineSpacingAfter;
}


set
{
SpacingAfter( value );
}
}

internal bool IsAfterAutoSpacing()
{
XElement pPr = GetOrCreate_pPr();
XElement spacing = pPr.Element( XName.Get( "spacing", DocX.w.NamespaceName ) );

if( spacing != null )
{
var afterAutoSpacing = spacing.Attribute( XName.Get( "afterAutospacing", DocX.w.NamespaceName ) );
if( ( afterAutoSpacing != null ) && ( afterAutoSpacing.Value == "1" ) )
return true;
}
return false;
}

internal bool IsBeforeAutoSpacing()
{
XElement pPr = GetOrCreate_pPr();
XElement spacing = pPr.Element( XName.Get( "spacing", DocX.w.NamespaceName ) );

if( spacing != null )
{
var beforeAutospacing = spacing.Attribute( XName.Get( "beforeAutospacing", DocX.w.NamespaceName ) );
if( ( beforeAutospacing != null ) && ( beforeAutospacing.Value == "1" ) )
return true;
}
return false;
}

public XElement ParagraphNumberProperties
{
get
@@ -1938,6 +1980,8 @@ namespace Xceed.Words.NET
}
}

_runs = Xml.Elements( XName.Get( "r", DocX.w.NamespaceName ) ).ToList();

HelperFunctions.RenumberIDs( Document );
}

@@ -2056,6 +2100,10 @@ namespace Xceed.Words.NET
if( format.Shading.HasValue )
Shading( format.Shading.Value );

// Border
if( format.Border != null )
Border( format.Border );

// Italic
if( format.Italic.HasValue && format.Italic.Value )
Italic();
@@ -2877,6 +2925,53 @@ namespace Xceed.Words.NET
return this;
}

public Paragraph Border( Border border )
{
var size = "2";
switch( border.Size )
{
case BorderSize.two:
size = "4";
break;
case BorderSize.three:
size = "6";
break;
case BorderSize.four:
size = "8";
break;
case BorderSize.five:
size = "12";
break;
case BorderSize.six:
size = "18";
break;
case BorderSize.seven:
size = "24";
break;
case BorderSize.eight:
size = "36";
break;
case BorderSize.nine:
size = "48";
break;
case BorderSize.one:
default:
size = "2";
break;
}

var style = border.Tcbs.ToString().Remove(0, 5);

this.ApplyTextFormattingProperty( XName.Get( "bdr", DocX.w.NamespaceName ),
string.Empty,
new List<XAttribute>() { new XAttribute( XName.Get( "color", DocX.w.NamespaceName ), border.Color.ToHex() ),
new XAttribute( XName.Get( "space", DocX.w.NamespaceName ), border.Space ),
new XAttribute( XName.Get( "sz", DocX.w.NamespaceName ), size ),
new XAttribute( XName.Get( "val", DocX.w.NamespaceName ), style ) } );

return this;
}

/// <summary>
/// For use with Append() and AppendLine()
/// </summary>
@@ -3139,6 +3234,40 @@ namespace Xceed.Words.NET
return this;
}

public Paragraph SpacingLine( double lineSpacing )
{
lineSpacing *= 20;

var pPr = GetOrCreate_pPr();
var spacing = pPr.Element( XName.Get( "spacing", DocX.w.NamespaceName ) );

if( lineSpacing > 0 )
{
if( spacing == null )
{
spacing = new XElement( XName.Get( "spacing", DocX.w.NamespaceName ) );
pPr.Add( spacing );
}

var lineAttribute = spacing.Attribute( XName.Get( "line", DocX.w.NamespaceName ) );

if( lineAttribute == null )
spacing.SetAttributeValue( XName.Get( "line", DocX.w.NamespaceName ), lineSpacing );
else
lineAttribute.SetValue( lineSpacing );
}

if( Math.Abs( lineSpacing ) < 0.1f && spacing != null )
{
var lineAttribute = spacing.Attribute( XName.Get( "line", DocX.w.NamespaceName ) );
lineAttribute.Remove();

if( !spacing.HasAttributes )
spacing.Remove();
}
return this;
}

public Paragraph Kerning( int kerning )
{
if( !new int?[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }.Contains( kerning ) )
@@ -3386,6 +3515,8 @@ namespace Xceed.Words.NET
}
while( processed < count );

_runs = Xml.Elements( XName.Get( "r", DocX.w.NamespaceName ) ).ToList();

HelperFunctions.RenumberIDs( Document );
}

@@ -4138,7 +4269,7 @@ namespace Xceed.Words.NET
{
var bookmarkStart = this.Xml.Descendants( XName.Get( "bookmarkStart", DocX.w.NamespaceName ) )
.Where( x => x.Attribute( XName.Get( "name", DocX.w.NamespaceName ) ).Value == bookmarkName )
.SingleOrDefault();
.FirstOrDefault();
if( bookmarkStart == null )
return;

@@ -4203,6 +4334,84 @@ namespace Xceed.Words.NET

#region Internal Methods

internal static void ResetDefaultValues()
{
Paragraph.DefaultLineSpacing = Paragraph.DefaultSingleLineSpacing;
Paragraph.DefaultLineSpacingAfter = 0f;
Paragraph.DefaultLineSpacingBefore = 0f;

Paragraph.DefaultIndentationFirstLine = 0f;
Paragraph.DefaultIndentationHanging = 0f;
Paragraph.DefaultIndentationBefore = 0f;
Paragraph.DefaultIndentationAfter = 0f;
}

internal static void SetDefaultValues( XElement pPr )
{
if( pPr == null )
return;

// Default line spacings.
var spacing = pPr.Element( XName.Get( "spacing", DocX.w.NamespaceName ) );
if( spacing != null )
{
var line = spacing.Attribute( XName.Get( "line", DocX.w.NamespaceName ) );
if( line != null )
{
float f;

if( float.TryParse( line.Value, out f ) )
{
Paragraph.DefaultLineSpacing = f / 20.0f;
}
}
var after = spacing.Attribute( XName.Get( "after", DocX.w.NamespaceName ) );
if( after != null )
{
float f;
if( float.TryParse( after.Value, out f ) )
{
Paragraph.DefaultLineSpacingAfter = f / 20.0f;
}
}
var before = spacing.Attribute( XName.Get( "before", DocX.w.NamespaceName ) );
if( before != null )
{
float f;
if( float.TryParse( before.Value, out f ) )
{
Paragraph.DefaultLineSpacingBefore = f / 20.0f;
}
}
}

// Default indentations.
var ind = pPr.Element( XName.Get( "ind", DocX.w.NamespaceName ) );
if( ind != null )
{
var firstLine = ind.Attribute( XName.Get( "firstLine", DocX.w.NamespaceName ) );
if( firstLine != null )
{
Paragraph.DefaultIndentationFirstLine = float.Parse( firstLine.Value ) / 570f;
}
var hanging = ind.Attribute( XName.Get( "hanging", DocX.w.NamespaceName ) );
if( hanging != null )
{
Paragraph.DefaultIndentationHanging = float.Parse( hanging.Value ) / 570f;
}
var before = ind.Attribute( XName.Get( "left", DocX.w.NamespaceName ) );
if( before != null )
{
Paragraph.DefaultIndentationBefore = float.Parse( before.Value ) / 570f;
}
var after = ind.Attribute( XName.Get( "right", DocX.w.NamespaceName ) );
if( after != null )
{
Paragraph.DefaultIndentationAfter = float.Parse( after.Value ) / 570f;
}
}
}

/// <summary>
/// If the pPr element doesent exist it is created, either way it is returned by this function.
/// </summary>
@@ -4292,8 +4501,8 @@ namespace Xceed.Words.NET
{
using( System.Drawing.Image img = System.Drawing.Image.FromStream( packagePartStream, useEmbeddedColorManagement: false, validateImageData: false ) )
{
cx = img.Width * 9526;
cy = img.Height * 9526;
cx = img.Width * 914400 / Convert.ToInt32( img.HorizontalResolution );
cy = img.Height * 914400 / Convert.ToInt32( img.VerticalResolution );
}
}


+ 45
- 6
Xceed.Words.NET/Src/Picture.cs Ver arquivo

@@ -26,8 +26,6 @@ namespace Xceed.Words.NET
{
#region Private Members

private const int EmusInPixel = 9525;

private string _id;
private string _name;
private string _descr;
@@ -38,10 +36,18 @@ namespace Xceed.Words.NET
private XElement _xfrm;
private XElement _prstGeom;

// Calculating Height & Width in Inches
// https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
// http://lcorneliussen.de/raw/dashboards/ooxml/
private const int InchToEmuFactor = 914400;
private const double EmuToInchFactor = 1d / InchToEmuFactor;

#endregion

#region Internal Members

internal const int EmusInPixel = 9525; // Result of : 914400 EMUs per inch / 96 pixel per inch.

internal Dictionary<PackagePart, PackageRelationship> _picture_rels;

internal Image _img;
@@ -191,7 +197,7 @@ namespace Xceed.Words.NET
}

/// <summary>
/// Get or sets the Width of this Image.
/// Gets or sets the Width of this Image.
/// </summary>
public int Width
{
@@ -210,7 +216,23 @@ namespace Xceed.Words.NET
}

/// <summary>
/// Get or sets the height of this Image.
/// Gets or sets the Width of this Image (in Inches)
/// </summary>
public double WidthInches
{
get
{
return Width * EmusInPixel * EmuToInchFactor;
}

set
{
Width = ( int )( value * InchToEmuFactor / EmusInPixel );
}
}

/// <summary>
/// Gets or sets the height of this Image.
/// </summary>
public int Height
{
@@ -228,6 +250,23 @@ namespace Xceed.Words.NET
}
}

/// <summary>
/// Gets or sets the Height of this Image (in Inches)
/// </summary>
public double HeightInches
{
get
{
return Height * EmusInPixel * EmuToInchFactor;
}

set
{
Height = ( int )( value * InchToEmuFactor / EmusInPixel );
}
}


#endregion

#region Constructors
@@ -306,7 +345,7 @@ namespace Xceed.Words.NET
{
var widthString = style.Value.Substring( style.Value.IndexOf( "width:" ) + 6 );
var widthValueString = widthString.Substring( 0, widthString.IndexOf( "pt" ) ).Replace( ".", "," );
var widthDouble = ( double.Parse( widthValueString ) / 72d ) * 914400;
var widthDouble = double.Parse( widthValueString ) * EmusInPixel;
_cx = System.Convert.ToInt32( widthDouble );
}
}
@@ -333,7 +372,7 @@ namespace Xceed.Words.NET
{
var heightString = style.Value.Substring( style.Value.IndexOf( "height:" ) + 7 );
var heightValueString = heightString.Substring( 0, heightString.IndexOf( "pt" ) ).Replace( ".", "," );
var heightDouble = ( double.Parse( heightValueString ) / 72d ) * 914400;
var heightDouble = double.Parse( heightValueString ) * EmusInPixel;
_cy = System.Convert.ToInt32( heightDouble );
}
}

+ 16
- 2
Xceed.Words.NET/Src/Table.cs Ver arquivo

@@ -2867,7 +2867,7 @@ namespace Xceed.Words.NET

// If val is null, this cell contains no vAlign information.
if( val == null )
return VerticalAlignment.Center;
return VerticalAlignment.Top;

// If val is not a VerticalAlign enum, something is wrong with this attributes value, so remove it and return VerticalAlignment.Center;
try
@@ -2878,7 +2878,7 @@ namespace Xceed.Words.NET
catch
{
val.Remove();
return VerticalAlignment.Center;
return VerticalAlignment.Top;
}
}

@@ -2993,6 +2993,7 @@ namespace Xceed.Words.NET
// If tcW is null, this cell contains no width information.
// Get the w attribute of the tcW element.
XAttribute w = tcW?.Attribute( XName.Get( "w", DocX.w.NamespaceName ) );
XAttribute type = tcW?.Attribute( XName.Get( "type", DocX.w.NamespaceName ) );

// If w is null, this cell contains no width information.
if( w == null )
@@ -3006,6 +3007,19 @@ namespace Xceed.Words.NET
return double.NaN;
}

if( type != null )
{
if( type.Value == "pct" )
{
return ( ( widthInWordUnits / 5000d ) * this._row._table.ColumnWidths.Sum() ) / 20;
}
else if( type.Value == "auto" )
{
var cellIndex = this._row.Cells.FindIndex( x => x.Xml == this.Xml );
if( cellIndex >= 0 )
return this._row._table.ColumnWidths[ cellIndex ] / 20;
}
}
// Using 20 to match DocX._pageSizeMultiplier.
return ( widthInWordUnits / 20 );
}

+ 1
- 1
Xceed.Words.NET/Xceed.Words.NET.csproj Ver arquivo

@@ -71,7 +71,7 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.XML" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>

+ 5235
- 0
Xceed.Words.NET/bin/Debug/Xceed.Words.NET.XML
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 7
- 0
Xceed.Words.NET/obj/Debug/Xceed.Words.NET.csproj.FileListAbsolute.txt Ver arquivo

@@ -0,0 +1,7 @@
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\bin\Debug\Xceed.Words.NET.XML
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\bin\Debug\Xceed.Words.NET.dll
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\bin\Debug\Xceed.Words.NET.pdb
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\obj\Debug\Xceed.Words.NET.csprojAssemblyReference.cache
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\obj\Debug\Xceed.Words.NET.csproj.CoreCompileInputs.cache
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\obj\Debug\Xceed.Words.NET.dll
D:\Dev\DocumentLibraries\Release\1.3.0\OpenSource\Generated\Xceed.Words.NET\obj\Debug\Xceed.Words.NET.pdb

+ 0
- 3
Xceed.Words.NET/obj/Release/Xceed.Words.NET.csproj.FileListAbsolute.txt Ver arquivo

@@ -1,3 +0,0 @@
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Xceed.Words.NET\bin\Release\Xceed.Words.NET.dll
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Xceed.Words.NET\obj\Release\Xceed.Words.NET.csprojResolveAssemblyReference.cache
D:\Dev\DocumentLibraries\Release\1.2.0\OpenSource\Generated\Xceed.Words.NET\obj\Release\Xceed.Words.NET.dll

Carregando…
Cancelar
Salvar