Skip to content

Commit

Permalink
Merge pull request #68 from egonl/2.5-beta
Browse files Browse the repository at this point in the history
SharpDocx 2.4.1
  • Loading branch information
egonl authored Apr 18, 2024
2 parents 0ffcdc2 + bf9b6c5 commit 107db8f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
Binary file modified Samples/Documents/Tutorial.docx
Binary file not shown.
12 changes: 7 additions & 5 deletions SharpDocx/DocumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
using System;
using System.Collections.Generic;
using System.IO;
#if SUPPORT_MULTI_THREADING_AND_LARGE_DOCUMENTS_IN_NET35
using System.Threading;
#endif

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Drawing.Wordprocessing;
using SharpDocx.CodeBlocks;
using SharpDocx.Extensions;
using System.Diagnostics;
using SharpImage;

namespace SharpDocx
namespace SharpDocx
{
public abstract class DocumentBase
{
Expand Down Expand Up @@ -273,7 +275,7 @@ protected void ImageFromUrl(string url, int percentage = 100, string extension =

protected void ImageFromStream(Stream stream, int percentage = 100, string extension = null)
{
ImagePartType imagePartType;
PartTypeInfo imagePartType;

if (extension == null)
{
Expand All @@ -284,7 +286,7 @@ protected void ImageFromStream(Stream stream, int percentage = 100, string exten
return;
}

imagePartType = ImageHelper.GetImagePartType(info.Type);
imagePartType = ImageHelper.GetImagePartType(info.Type).GetValueOrDefault();
}
else
{
Expand All @@ -294,7 +296,7 @@ protected void ImageFromStream(Stream stream, int percentage = 100, string exten
ImageInternal(stream, imagePartType, percentage);
}

protected void ImageInternal(Stream stream, ImagePartType type, int percentage = 100)
protected void ImageInternal(Stream stream, PartTypeInfo type, int percentage = 100)
{
const long emusPerTwip = 635;
var maxWidthInEmus = GetPageContentWidthInTwips() * emusPerTwip;
Expand Down
24 changes: 12 additions & 12 deletions SharpDocx/ImageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class ImageHelper
public static Drawing CreateDrawing(
WordprocessingDocument package,
Stream imageStream,
ImagePartType imagePartType,
PartTypeInfo imagePartType,
int percentage, long maxWidthInEmus)
{
var imagePart = package.MainDocumentPart.AddImagePart(imagePartType);
Expand Down Expand Up @@ -61,14 +61,14 @@ public static Drawing CreateDrawing(
return drawing;
}

internal static ImagePartType GetImagePartType(string extension)
internal static PartTypeInfo GetImagePartType(string extension)
{
if (extension == null)
{
throw new ArgumentException("Unknown extension", nameof(extension));
}

ImagePartType? type = null;
PartTypeInfo? type = null;

extension = extension.Replace(".", "").ToLower();
switch (extension)
Expand Down Expand Up @@ -113,33 +113,33 @@ internal static ImagePartType GetImagePartType(string extension)
return type.Value;
}

internal static ImageType GetImageType(ImagePartType imagePartType)
internal static ImageType GetImageType(PartTypeInfo imagePartType)
{
switch (imagePartType)
{
case ImagePartType.Bmp:
case PartTypeInfo part when part == ImagePartType.Bmp:
return ImageType.Bmp;

case ImagePartType.Gif:
case PartTypeInfo part when part == ImagePartType.Gif:
return ImageType.Gif;

case ImagePartType.Jpeg:
case PartTypeInfo part when part == ImagePartType.Jpeg:
return ImageType.Jpeg;

case ImagePartType.Png:
case PartTypeInfo part when part == ImagePartType.Png:
return ImageType.Png;

case ImagePartType.Tiff:
case PartTypeInfo part when part == ImagePartType.Tiff:
return ImageType.Tiff;

case ImagePartType.Emf:
case PartTypeInfo part when part == ImagePartType.Emf:
return ImageType.Emf;
}

return ImageType.Unknown;
}

internal static ImagePartType GetImagePartType(ImageType imageType)
internal static PartTypeInfo? GetImagePartType(ImageType imageType)
{
switch (imageType)
{
Expand All @@ -162,7 +162,7 @@ internal static ImagePartType GetImagePartType(ImageType imageType)
return ImagePartType.Emf;
}

return (ImagePartType) (-1);
return null;
}

private static Drawing GetDrawing(string relationshipId, long widthEmus, long heightEmus)
Expand Down
10 changes: 5 additions & 5 deletions SharpDocx/SharpDocx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<!--<TargetFrameworks>net35;net40;net45;netstandard2.0</TargetFrameworks>-->
<RootNamespace>SharpDocx</RootNamespace>
<Version>2.4.0.0</Version>
<Version>2.4.1.0</Version>
<Authors>egonl</Authors>
<Product>SharpDocx</Product>
<PackageId>SharpDocx</PackageId>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<FileVersion>2.4.0.0</FileVersion>
<AssemblyVersion>2.4.1.0</AssemblyVersion>
<FileVersion>2.4.1.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
<Description>C# based template engine for generating Word documents</Description>
<Copyright>Copyright 2017-2023 egonl</Copyright>
<Copyright>Copyright 2017-2024 egonl</Copyright>
<PackageLicenseUrl>https://github.com/egonl/SharpDocx/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/egonl/SharpDocx</PackageProjectUrl>
<!-- <PackageIconUrl>Icon URL</PackageIconUrl> -->
Expand All @@ -37,7 +37,7 @@
<ItemGroup>
<ProjectReference Include="..\SharpImage\SharpImage.csproj" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
17 changes: 10 additions & 7 deletions SharpDocx/nupkg/SharpDocx.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>SharpDocx</id>
<version>2.4.0</version>
<version>2.4.1</version>
<authors>egonl</authors>
<owners>egonl</owners>
<license type="expression">MIT</license>
Expand All @@ -16,11 +16,14 @@
- Supports .NET Framework 3.5/4.5+, .NET Standard 2.0, .NET Core 3.1, .NET 5.0 and .NET 6.0.
- Based on Microsoft's Open XML SDK.
- Source code, tutorial and examples on GitHub.</description>
<releaseNotes>Version 2.4.0 - January 30, 2023
<releaseNotes>Version 2.4.1 - April 18, 2024
- Updated to DocumentFormat.OpenXml version 3.0.2.

Version 2.4.0 - January 30, 2023
- Added ImageFromBase64, ImageFromUrl and ImageFromStream methods.
- Added ImageFromBase64 and ImageFromUrl examples to the tutorial.

Version 2.3.0 - October 9, 2022
Version 2.3.0 - October 9, 2022
- Added support for EMF files (issue #51).
- The IDs of DocProperties are now always unique (issue #51).
- Changed the default for TargetFrameworks to net48 and net6.0 to better support Visual Studio 2022.
Expand Down Expand Up @@ -75,16 +78,16 @@ Version 1.0.0 - January 1, 2018
<tags>openxml office word document sharpdocx</tags>
<dependencies>
<group targetFramework="net35">
<dependency id="DocumentFormat.OpenXml" version="2.18.0" />
<dependency id="DocumentFormat.OpenXml" version="3.0.2" />
</group>
<group targetFramework="net40">
<dependency id="DocumentFormat.OpenXml" version="2.18.0" />
<dependency id="DocumentFormat.OpenXml" version="3.0.2" />
</group>
<group targetFramework="net45">
<dependency id="DocumentFormat.OpenXml" version="2.18.0" />
<dependency id="DocumentFormat.OpenXml" version="3.0.2" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="DocumentFormat.OpenXml" version="2.18.0" />
<dependency id="DocumentFormat.OpenXml" version="3.0.2" />
<dependency id="Microsoft.CodeAnalysis.CSharp" version="2.10.0" />
</group>
</dependencies>
Expand Down

0 comments on commit 107db8f

Please sign in to comment.