Skip to content

Commit

Permalink
Major refactoring and a first working .NET Standard 2.0 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dids committed Jun 26, 2017
1 parent f8ece07 commit c387b23
Show file tree
Hide file tree
Showing 355 changed files with 2,430 additions and 8,368 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ script:
jobs:
include:
- stage: nuget.org
script: echo "Deploying to nuget.org.."
script: skip
env: BUILD_CONFIG="Release" DOTNET_CLI_TELEMETRY_OPTOUT=1
os: linux
deploy:
Expand All @@ -58,7 +58,7 @@ jobs:
repo: Didstopia/PDFSharp
tags: true
- stage: GitHub Release
script: echo "Deploying to GitHub Releases.."
script: skip
env: BUILD_CONFIG="Release" DOTNET_CLI_TELEMETRY_OPTOUT=1
os: linux
deploy:
Expand Down
63 changes: 63 additions & 0 deletions Didstopia.PDFSharp.Tests/Didstopia.PDFSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
<Description>A .NET Standard library for reading, writing and editing PDF files.

NOTE: This is a fork of PdfSharpCore by ststeiger:
https://github.com/ststeiger/PdfSharpCore</Description>
<ReleaseVersion>1.0.0-beta1</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<DefineConstants>TRACE;RELEASE;NETCOREAPP2_0;PORTABLE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;PORTABLE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170618-03" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Didstopia.PDFSharp\Didstopia.PDFSharp.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Fonts\" />
</ItemGroup>
<ItemGroup>
<None Remove="Fonts\Tinos-Bold.ttf" />
<None Remove="Fonts\Tinos-BoldItalic.ttf" />
<None Remove="Fonts\Tinos-Italic.ttf" />
<None Remove="Fonts\Tinos-Licence.txt" />
<None Remove="Fonts\Tinos-Regular.ttf" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Fonts\Tinos-Bold.ttf">
<LogicalName>Tinos-Bold.ttf</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Fonts\Tinos-BoldItalic.ttf">
<LogicalName>Tinos-BoldItalic.ttf</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Fonts\Tinos-Italic.ttf">
<LogicalName>Tinos-Italic.ttf</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Fonts\Tinos-Licence.txt">
<LogicalName>Tinos-Licence.txt</LogicalName>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Fonts\Tinos-Regular.ttf">
<LogicalName>Tinos-Regular.ttf</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Samples\Test.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
53 changes: 53 additions & 0 deletions Didstopia.PDFSharp.Tests/FontResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Didstopia.PDFSharp.Fonts;

namespace Didstopia.PDFSharp.Tests
{
public class FontResolver : IFontResolver
{
public string DefaultFontName => "Tinos";

public byte[] GetFont(string faceName)
{
using (var ms = new MemoryStream())
{
var assembly = typeof(FontResolver).GetTypeInfo().Assembly;
var resources = assembly.GetManifestResourceNames();
var resourceName = resources.First(x => x == faceName);
using (var rs = assembly.GetManifestResourceStream(resourceName))
{
rs.CopyTo(ms);
ms.Position = 0;
return ms.ToArray();
}
}
}

public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
{
if (familyName.Equals("Tinos", StringComparison.CurrentCultureIgnoreCase))
{
if (isBold && isItalic)
{
return new FontResolverInfo("Tinos-BoldItalic.ttf");
}
else if (isBold)
{
return new FontResolverInfo("Tinos-Bold.ttf");
}
else if (isItalic)
{
return new FontResolverInfo("Tinos-Italic.ttf");
}
else
{
return new FontResolverInfo("Tinos-Regular.ttf");
}
}
return null;
}
}
}
Binary file added Didstopia.PDFSharp.Tests/Fonts/Tinos-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added Didstopia.PDFSharp.Tests/Fonts/Tinos-Italic.ttf
Binary file not shown.
49 changes: 49 additions & 0 deletions Didstopia.PDFSharp.Tests/Fonts/Tinos-Licence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Designer
Steve Matteson

Copyright
Digitized data copyright (c) 2010 Google Corporation.

License
This Font Software is licensed under the SIL Open Font License, Version 1.1.

This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

SIL OPEN FONT LICENSE

Version 1.1 - 26 February 2007

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting — in part or in whole — any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added Didstopia.PDFSharp.Tests/Fonts/Tinos-Regular.ttf
Binary file not shown.
65 changes: 65 additions & 0 deletions Didstopia.PDFSharp.Tests/PDFSharpTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.IO;
using Didstopia.PDFSharp.Drawing;
using Didstopia.PDFSharp.Fonts;
using Didstopia.PDFSharp.Pdf;
using Didstopia.PDFSharp.Pdf.IO;
using Xunit;

namespace Didstopia.PDFSharp.Tests
{
public class PDFSharpTests
{
// TODO: Implement more tests, since these are VERY barebones
// and not in any way reliable as is

private const string TitleString = "Unit Test PDF";
private const string FontName = "Tinos";
private const int FontSize = 16;

[Fact]
public void TestBasicFunctionality()
{
// Create a new PDF
var pdfDocument = new PdfDocument();
Assert.True(pdfDocument != null, "PDF should not be null");

// Set the PDF title
pdfDocument.Info.Title = TitleString;
Assert.True(pdfDocument.Info.Title.Equals(TitleString), $"PDF title should equal { TitleString }");

// Add a new page to the PDF
PdfPage pdfPage = pdfDocument.AddPage();
Assert.True(pdfPage != null, "PDF page should not be null");

// Draw text on the newly created page
GlobalFontSettings.FontResolver = new FontResolver();
XGraphics pdfGraphics = XGraphics.FromPdfPage(pdfPage);
XFont pdfFont = new XFont(FontName, FontSize, XFontStyle.Regular);
pdfGraphics.DrawString(TitleString, pdfFont, XBrushes.Black, new XRect(0, 0, pdfPage.Width, pdfPage.Height), XStringFormats.Center);

// Save the PDF to a temporary path
var tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf");
Assert.False(File.Exists(tempFilePath), "Temporary file should not exist before saving");
Assert.True(pdfDocument.CanSave(ref tempFilePath), $"PDF should be able to be saved to path: { tempFilePath }");
pdfDocument.Save(tempFilePath);
Assert.True(File.Exists(tempFilePath), "Temporary file should exist after saving");
var tempFileLength = new FileInfo(tempFilePath).Length;
Assert.True(tempFileLength > 0, $"Temporary file length should be greater than 0 after saving, but was { tempFileLength } instead");

// Close and dispose of the saved PDF
pdfDocument.Close();
pdfDocument.Dispose();

// Load the PDF from the temporary path
var loadedPdfDocument = PdfReader.Open(tempFilePath, PdfDocumentOpenMode.ReadOnly);
Assert.True(loadedPdfDocument != null, "PDF should not be null");
Assert.True(loadedPdfDocument.Info != null, "PDF info should not be null");
Assert.True(loadedPdfDocument.Info.Title.Equals(TitleString), $"PDF title should equal { TitleString }");

// Close and dispose of the loaded PDF
loadedPdfDocument.Close();
loadedPdfDocument.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.pdfsharp.com
// http://www.PdfSharpCore.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -29,7 +29,7 @@

using System;

namespace PdfSharp
namespace Didstopia.PDFSharp
{
/// <summary>
/// Floating point formatting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NETStandardImplicitPackageVersion>2.0.0-preview1-25301-01</NETStandardImplicitPackageVersion>
<PackageId>Didstopia.PDFSharp</PackageId>
<PackageVersion>1.0.0-beta1</PackageVersion>
<Authors>Didstopia</Authors>
<Description>A .NET Standard library for reading, writing and editing PDF files.

NOTE: This is a fork of PDFsharp by empira.</Description>
NOTE: This is a fork of PdfSharpCore by ststeiger:
https://github.com/ststeiger/PdfSharpCore</Description>
<ReleaseVersion>1.0.0-beta1</ReleaseVersion>
<PackageVersion>1.0.0-beta1</PackageVersion>
<Authors>Didstopia</Authors>
<DevelopmentDependency>true</DevelopmentDependency>
<NeutralLanguage>en-US</NeutralLanguage>
<PackageLicenseUrl>https://github.com/Didstopia/PDFSharp/blob/master/LICENSE.md</PackageLicenseUrl>
<Owners>Didstopia</Owners>
<PackageProjectUrl>https://github.com/Didstopia/PDFSharp</PackageProjectUrl>
<PackageReleaseNotes>Initial beta release.</PackageReleaseNotes>
<Summary>A .NET Standard library for reading, writing and editing PDF files.</Summary>
<PackageTags>pdfsharp pdf extract read edit modify parse</PackageTags>
<Title>PDFSharp</Title>
<PackageLicenseUrl>https://github.com/Didstopia/PDFSharp/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/Didstopia/PDFSharp</PackageProjectUrl>
<PackageId>Didstopia.PDFSharp</PackageId>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>TRACE;DEBUG;NETSTANDARD2_0;CORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<DefineConstants>TRACE;RELEASE;NETSTANDARD2_0;CORE</DefineConstants>
<DefineConstants>TRACE;PORTABLE;RELEASE;NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>TRACE;PORTABLE;DEBUG;NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Packaging" Version="0.1.323" />
<PackageReference Include="CoreCompat.System.Drawing" Version="1.0.0-beta006" />
</ItemGroup>

<ItemGroup>
<Folder Include="!internal\" />
<Folder Include="!JetBrains\" />
<Folder Include="Drawing\" />
<Folder Include="Drawing.BarCodes\" />
<Folder Include="Drawing.Internal\" />
Expand All @@ -56,21 +56,8 @@ NOTE: This is a fork of PDFsharp by empira.</Description>
<Folder Include="Pdf.IO\" />
<Folder Include="Pdf.Printing\" />
<Folder Include="Pdf.Security\" />
<Folder Include="Properties\" />
<Folder Include="Resources\" />
<Folder Include="root\" />
<Folder Include="SharpZipLib\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Pdf\PdfOutlineCollection.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Messages.de.restext" />
<EmbeddedResource Include="Resources\Messages.restext" />
</ItemGroup>
<ItemGroup>
<Content Include="SharpZipLib\ReadMe.txt" />
<Folder Include="SilverlightInternals\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.pdfsharp.com
// http://www.PdfSharpCore.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -30,7 +30,7 @@
using System;
using System.ComponentModel;

namespace PdfSharp.Drawing.BarCodes
namespace Didstopia.PDFSharp.Drawing.BarCodes
{
/// <summary>
/// Represents the base class of all bar codes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.pdfsharp.com
// http://www.PdfSharpCore.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand All @@ -27,7 +27,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace PdfSharp.Drawing.BarCodes
namespace Didstopia.PDFSharp.Drawing.BarCodes
{
/// <summary>
/// Holds all temporary information needed during rendering.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Copyright (c) 2005-2016 empira Software GmbH, Cologne Area (Germany)
//
// http://www.pdfsharp.com
// http://www.PdfSharpCore.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -27,7 +27,7 @@
// DEALINGS IN THE SOFTWARE.
#endregion

namespace PdfSharp.Drawing.BarCodes
namespace Didstopia.PDFSharp.Drawing.BarCodes
{
// TODO: Mere with PDFsharp strings table
/// <summary>
Expand Down
Loading

0 comments on commit c387b23

Please sign in to comment.