-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactoring and a first working .NET Standard 2.0 version.
- Loading branch information
Showing
355 changed files
with
2,430 additions
and
8,368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.