Skip to content

Commit

Permalink
No longer generates csproj file, but takes the runtimes and exports t…
Browse files Browse the repository at this point in the history
…hem to the PDFiumCore project in the src directory.

Added RenderFlags.
Added ignores to prevent committing of binary or generated files.
  • Loading branch information
DJGosnell committed Sep 27, 2020
1 parent eb548e8 commit 33e556e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 53 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/src/PDFiumCore/PDFiumCore.cs
PDFium-LICENSE
/output
PDFium.cs
pdfium.so
pdfium.dylib
pdfium.dll
7 changes: 1 addition & 6 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,4 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

PDFium.cs
pdfium.so
pdfium.dylib
pdfium.dll
*.pyc
6 changes: 6 additions & 0 deletions src/PDFiumCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDFiumCoreBindingsGenerator", "PDFiumCoreBindingsGenerator\PDFiumCoreBindingsGenerator.csproj", "{E7E472C6-A024-4CA9-BB40-90538B6D9781}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDFiumCore", "PDFiumCore\PDFiumCore.csproj", "{95F93950-EFB7-47DA-B539-DFB28155F39B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{E7E472C6-A024-4CA9-BB40-90538B6D9781}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7E472C6-A024-4CA9-BB40-90538B6D9781}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7E472C6-A024-4CA9-BB40-90538B6D9781}.Release|Any CPU.Build.0 = Release|Any CPU
{95F93950-EFB7-47DA-B539-DFB28155F39B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95F93950-EFB7-47DA-B539-DFB28155F39B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95F93950-EFB7-47DA-B539-DFB28155F39B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95F93950-EFB7-47DA-B539-DFB28155F39B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions src/PDFiumCore/PDFiumCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Dtronix/PDFiumCore</PackageProjectUrl>
<Description>PDFiumCore is a wrapper to generate pinvoke bindings to allow for usage in all languages which support .NET Standard 2.1. Includes the runtime native binary files for Linux, OSX &amp; Windows.</Description>
<PackageTags>pinvoke dotnet interop pdf pdfium</PackageTags>
<RepositoryUrl>https://github.com/Dtronix/PDFiumCore</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Authors>DJGosnell</Authors>
</PropertyGroup>
<ItemGroup>
<Content Include="runtimes/**" PackagePath="runtimes" />
</ItemGroup>
</Project>
59 changes: 59 additions & 0 deletions src/PDFiumCore/RenderFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;

namespace PDFiumCore
{
[Flags]
public enum RenderFlags
{
/// <summary>
/// FPDF_ANNOT: Set if annotations are to be rendered.
/// </summary>
RenderAnnotations = 0x01,

/// <summary>
/// FPDF_LCD_TEXT: Set if using text rendering optimized for LCD display. This flag will only take effect if anti-aliasing is enabled for text.
/// </summary>
OptimizeTextForLcd = 0x02,

/// <summary>
/// FPDF_NO_NATIVETEXT: Don't use the native text output available on some platforms
/// </summary>
NoNativeText = 0x04,

/// <summary>
/// FPDF_GRAYSCALE: Grayscale output
/// </summary>
Grayscale = 0x08,

/// <summary>
/// // FPDF_RENDER_LIMITEDIMAGECACHE: Limit image cache size
/// </summary>
LimitImageCacheSize = 0x200,

/// <summary>
/// FPDF_RENDER_FORCEHALFTONE: Always use halftone for image stretching
/// </summary>
ForceHalftone = 0x400,

/// <summary>
/// FPDF_PRINTING: Render for printing
/// </summary>
RenderForPrinting = 0x800,

/// <summary>
/// FPDF_RENDER_NO_SMOOTHTEXT: Set to disable anti-aliasing on text. This flag will also disable LCD optimization for text rendering
/// </summary>
DisableTextAntialiasing = 0x1000,


/// <summary>
/// FPDF_RENDER_NO_SMOOTHIMAGE: Set to disable anti-aliasing on images.
/// </summary>
DisableImageAntialiasing = 0x2000,

/// <summary>
/// FPDF_RENDER_NO_SMOOTHPATH: Set to disable anti-aliasing on paths.
/// </summary>
DisablePathAntialiasing = 0x4000
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PDFiumCoreBindingsGenerator.exe "https://api.github.com/repos/bblanchon/pdfium-binaries/releases/latest" "0" >> build.log
PDFiumCoreBindingsGenerator.exe "https://api.github.com/repos/bblanchon/pdfium-binaries/releases/latest" "0"
pause
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<None Remove="build.bat" />
</ItemGroup>
<ItemGroup>
<Content Include="build.bat">
<Content Include="CreatePackage.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
59 changes: 17 additions & 42 deletions src/PDFiumCoreBindingsGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ static void Main(string[] args)
// Build PDFium.cs from the windows x64 build header files.
ConsoleDriver.Run(new PDFiumCoreLibrary("pdfium-windows-x64"));

if (Directory.Exists("PDFiumCore"))
Directory.Delete("PDFiumCore", true);

Directory.CreateDirectory("PDFiumCore");
if (Directory.Exists("../../../../PDFiumCore/runtimes"))
Directory.Delete("../../../../PDFiumCore/runtimes", true);

// Add the additional build information in the header.
var fileContents = File.ReadAllText("PDFiumCore.cs");

using (var fs = new FileStream("PDFiumCore/PDFiumCore.cs", FileMode.Create, FileAccess.ReadWrite,
using (var fs = new FileStream("../../../../PDFiumCore/PDFiumCore.cs", FileMode.Create, FileAccess.ReadWrite,
FileShare.None))
using (var sw = new StreamWriter(fs))
{
Expand All @@ -63,42 +61,21 @@ static void Main(string[] args)
}

// Copy the binary files.
Directory.CreateDirectory("PDFiumCore/runtimes/win-x86/native/");
File.Copy("pdfium-windows-x86/x86/bin/pdfium.dll", "PDFiumCore/runtimes/win-x86/native/pdfium.dll");
File.Copy("pdfium-windows-x86/LICENSE", "PDFiumCore/runtimes/win-x86/native/PDFium-LICENSE");
Directory.CreateDirectory("../../../../PDFiumCore/runtimes/win-x86/native/");
File.Copy("pdfium-windows-x86/x86/bin/pdfium.dll", "../../../../PDFiumCore/runtimes/win-x86/native/pdfium.dll");
File.Copy("pdfium-windows-x86/LICENSE", "../../../../PDFiumCore/runtimes/win-x86/native/PDFium-LICENSE");

Directory.CreateDirectory("PDFiumCore/runtimes/win-x64/native/");
File.Copy("pdfium-windows-x64/x64/bin/pdfium.dll", "PDFiumCore/runtimes/win-x64/native/pdfium.dll");
File.Copy("pdfium-windows-x64/LICENSE", "PDFiumCore/runtimes/win-x64/native/PDFium-LICENSE");
Directory.CreateDirectory("../../../../PDFiumCore/runtimes/win-x64/native/");
File.Copy("pdfium-windows-x64/x64/bin/pdfium.dll", "../../../../PDFiumCore/runtimes/win-x64/native/pdfium.dll");
File.Copy("pdfium-windows-x64/LICENSE", "../../../../PDFiumCore/runtimes/win-x64/native/PDFium-LICENSE");

Directory.CreateDirectory("PDFiumCore/runtimes/linux/native/");
File.Copy("pdfium-linux/lib/libpdfium.so", "PDFiumCore/runtimes/linux/native/pdfium.so");
File.Copy("pdfium-linux/LICENSE", "PDFiumCore/runtimes/linux/native/PDFium-LICENSE");

Directory.CreateDirectory("PDFiumCore/runtimes/osx/native/");
File.Copy("pdfium-darwin/lib/libpdfium.dylib", "PDFiumCore/runtimes/osx/native/pdfium.dylib");
File.Copy("pdfium-darwin/LICENSE", "PDFiumCore/runtimes/osx/native/PDFium-LICENSE");


using (var fs = new FileStream("PDFiumCore/PDFiumCore.csproj", FileMode.Create, FileAccess.ReadWrite,
FileShare.None))
using (var sw = new StreamWriter(fs))
{
sw.WriteLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
sw.WriteLine(" <PropertyGroup>");
sw.WriteLine(" <TargetFramework>netstandard2.1</TargetFramework>");
sw.WriteLine(" <AllowUnsafeBlocks>true</AllowUnsafeBlocks>");

var versionParts = releaseInfo.TagName.Split('/');
sw.WriteLine($" <Version>{versionParts[1]}.{minorBuild}.0</Version>");
sw.WriteLine(" <PackageLicenseExpression>MIT</PackageLicenseExpression>");
sw.WriteLine(" </PropertyGroup>");
sw.WriteLine(" <ItemGroup>");
sw.WriteLine(" <Content Include=\"runtimes/**\" PackagePath=\"runtimes\" />");
sw.WriteLine(" </ItemGroup>");
sw.WriteLine("</Project>");
}
Directory.CreateDirectory("../../../../PDFiumCore/runtimes/linux/native/");
File.Copy("pdfium-linux/lib/libpdfium.so", "../../../../PDFiumCore/runtimes/linux/native/pdfium.so");
File.Copy("pdfium-linux/LICENSE", "../../../../PDFiumCore/runtimes/linux/native/PDFium-LICENSE");

Directory.CreateDirectory("../../../../PDFiumCore/runtimes/osx/native/");
File.Copy("pdfium-darwin/lib/libpdfium.dylib", "../../../../PDFiumCore/runtimes/osx/native/pdfium.dylib");
File.Copy("pdfium-darwin/LICENSE", "../../../../PDFiumCore/runtimes/osx/native/PDFium-LICENSE");

Process cmd = new Process
{
Expand All @@ -112,10 +89,8 @@ static void Main(string[] args)
};
cmd.Start();

cmd.StandardInput.WriteLine("dotnet build PDFiumCore/PDFiumCore.csproj -c Release");
cmd.StandardInput.Flush();

cmd.StandardInput.WriteLine("dotnet pack PDFiumCore/PDFiumCore.csproj -c Release");
var versionParts = releaseInfo.TagName.Split('/');
cmd.StandardInput.WriteLine($"dotnet pack \"../../../../PDFiumCore/PDFiumCore.csproj\" -p:Version=\"{versionParts[1]}.{minorBuild}.0.0\" -c Release -o \"../../../../../output/\"");
cmd.StandardInput.Flush();

cmd.StandardInput.Close();
Expand Down

0 comments on commit 33e556e

Please sign in to comment.