Skip to content

Commit d515322

Browse files
Merge pull request #160 from ArtifexSoftware/linux-dist
Updates to create linux distribution.
2 parents ad7d582 + a2a210a commit d515322

23 files changed

+4822
-1735
lines changed

Demo/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10+
Console.WriteLine("Hello World!");
1011
Document doc = new();
1112
Page page = doc.NewPage();
1213

MuPDF.NET/Document.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Text;
55
using mupdf;
6+
using Newtonsoft.Json.Linq;
67

78
namespace MuPDF.NET
89
{
@@ -720,17 +721,21 @@ public void InitDocument()
720721
Dictionary<string, string> values = new Dictionary<string, string>()
721722
{
722723
{ "format", "format" },
723-
{ "title", "info:Title" },
724-
{ "author", "info:Author" },
725-
{ "subject", "info:Subject" },
726-
{ "keywords", "info:Keywords" },
727-
{ "creator", "info:Creator" },
728-
{ "producer", "info:Producer" },
729-
{ "creationDate", "info:CreationDate" },
730-
{ "modDate", "info:ModDate" },
731-
{ "trapped", "info:Trapped" }
732724
};
733725

726+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
727+
{
728+
values.Add("title", "info:Title");
729+
values.Add("author", "info:Author");
730+
values.Add("subject", "info:Subject");
731+
values.Add("keywords", "info:Keywords");
732+
values.Add("creator", "info:Creator");
733+
values.Add("producer", "info:Producer");
734+
values.Add("creationDate", "info:CreationDate");
735+
values.Add("modDate", "info:ModDate");
736+
values.Add("trapped", "info:Trapped");
737+
}
738+
734739
foreach ((string key, string value) in values)
735740
{
736741
MetaData.Add(key, GetMetadata(value));
@@ -4029,7 +4034,8 @@ public void Select(List<int> list)
40294034
Marshal.Copy(list.ToArray(), 0, pNumbers, list.Count);
40304035
SWIGTYPE_p_int swigNumbers = new SWIGTYPE_p_int(pNumbers, true);
40314036

4032-
pdf.pdf_rearrange_pages(list.Count, swigNumbers);
4037+
pdf.pdf_rearrange_pages(list.Count, swigNumbers, pdf_clean_options_structure.PDF_CLEAN_STRUCTURE_DROP);
4038+
40334039
ResetPageRefs();
40344040
}
40354041

MuPDF.NET/MuPDF.NET.csproj

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net8.0</TargetFrameworks>
55
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
66
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
7-
<UseMaui>true</UseMaui>
7+
<UseMaui>false</UseMaui>
88
<SingleProject>true</SingleProject>
99
<ImplicitUsings>enable</ImplicitUsings>
1010

@@ -16,7 +16,7 @@
1616
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
1717
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1818
<Title>MuPDF.NET</Title>
19-
<Version>3.0.0</Version>
19+
<Version>3.1.2-rc.1</Version>
2020
<Authors>Maksym Tkachuk, Jamie Lemon, Chris Palman</Authors>
2121
<Company>Artifex</Company>
2222
<Description>A C# binding for MuPDF</Description>
@@ -29,6 +29,10 @@
2929
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
3030
</PropertyGroup>
3131

32+
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
33+
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
34+
</PropertyGroup>
35+
3236
<ItemGroup>
3337
<None Include="..\LICENSE.md">
3438
<Pack>True</Pack>
@@ -56,15 +60,28 @@
5660
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.14" />
5761
</ItemGroup>
5862

59-
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
60-
<EmbeddedResource Include="mupdfcsharp.dll">
63+
<ItemGroup>
64+
<EmbeddedResource Include="libs\mupdf\linux\libmupdf.so">
65+
<LogicalName>libmupdf.so</LogicalName>
66+
</EmbeddedResource>
67+
<EmbeddedResource Include="libs\mupdf\linux\libmupdf.so.26.0">
68+
<LogicalName>libmupdf.so.26.0</LogicalName>
69+
</EmbeddedResource>
70+
<EmbeddedResource Include="libs\mupdf\linux\libmupdfcpp.so">
71+
<LogicalName>libmupdfcpp.so</LogicalName>
72+
</EmbeddedResource>
73+
<EmbeddedResource Include="libs\mupdf\linux\libmupdfcpp.so.26.0">
74+
<LogicalName>libmupdfcpp.so.26.0</LogicalName>
75+
</EmbeddedResource>
76+
<EmbeddedResource Include="libs\mupdf\linux\mupdfcsharp.so">
77+
<LogicalName>mupdfcsharp.so</LogicalName>
78+
</EmbeddedResource>
79+
<EmbeddedResource Include="libs\mupdf\windows\mupdfcsharp.dll">
6180
<LogicalName>mupdfcsharp.dll</LogicalName>
6281
</EmbeddedResource>
63-
</ItemGroup>
64-
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
65-
<EmbeddedResource Include="mupdfcpp64.dll">
82+
<EmbeddedResource Include="libs\mupdf\windows\mupdfcpp64.dll">
6683
<LogicalName>mupdfcpp64.dll</LogicalName>
6784
</EmbeddedResource>
6885
</ItemGroup>
69-
86+
7087
</Project>

MuPDF.NET/Page.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44
using System.Text;
5-
using Microsoft.Maui;
65
using mupdf;
76
using static System.Net.Mime.MediaTypeNames;
87
using static MuPDF.NET.Global;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace MuPDF.NET
22
{
3+
#if ANDROID
34
// All the code in this file is only included on Android.
45
public class PlatformClass1
56
{
67
}
8+
#endif
79
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace MuPDF.NET
22
{
3+
#if MACCATALYST
34
// All the code in this file is only included on Mac Catalyst.
45
public class PlatformClass1
56
{
67
}
8+
#endif
79
}

MuPDF.NET/Platforms/Tizen/PlatformClass1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace MuPDF.NET
44
{
5+
#if TVOS
56
// All the code in this file is only included on Tizen.
67
public class PlatformClass1
78
{
89
}
10+
#endif
911
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace MuPDF.NET
22
{
3+
#if WINDOWS
34
// All the code in this file is only included on Windows.
45
public class PlatformClass1
56
{
67
}
8+
#endif
79
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace MuPDF.NET
22
{
3+
#if IOS
34
// All the code in this file is only included on iOS.
45
public class PlatformClass1
56
{
67
}
8+
#endif
79
}

MuPDF.NET/TextPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ internal void MakeTextPage2Dict(PageInfo pageDict, bool raw)
11711171
style.Font = GetFontName(
11721172
new FzFont(mupdf.mupdf.ll_fz_keep_font(ch.font))
11731173
);
1174-
style.Color = ch.color;
1174+
style.Color = (int)ch.argb;
11751175
style.Asc = (
11761176
new FzFont(mupdf.mupdf.ll_fz_keep_font(ch.font))
11771177
).fz_font_ascender();

MuPDF.NET/Utils.cs

Lines changed: 107 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Reflection;
66
using System.Runtime.InteropServices;
77
using System.Text;
8-
using Microsoft.Maui.Storage;
98
using mupdf;
109
using Newtonsoft.Json;
1110
using static MuPDF.NET.Global;
@@ -6792,22 +6791,99 @@ internal static string GetFontName(fz_font font)
67926791
return name.Substring(s + 1, name.Length - s - 1);
67936792
}
67946793

6795-
internal static void LoadEmbeddedDll()
6794+
internal static void LoadEmbeddedDllForWindows()
67966795
{
6797-
var assembly = Assembly.GetExecutingAssembly();
6798-
var resourceStream = assembly.GetManifestResourceStream("mupdfcpp64.dll");
6799-
var tempFile = File.Create("mupdfcpp64.dll");
6796+
string binaryDir = AppContext.BaseDirectory;
6797+
if (!File.Exists(binaryDir + "mupdfcpp64.dll"))
6798+
{
6799+
var assembly = Assembly.GetExecutingAssembly();
6800+
var resourceStream = assembly.GetManifestResourceStream("mupdfcpp64.dll");
6801+
var tempFile = File.Create(binaryDir + "mupdfcpp64.dll");
68006802

6801-
resourceStream?.CopyTo(tempFile);
6802-
resourceStream?.Dispose();
6803-
tempFile.Dispose();
6803+
resourceStream?.CopyTo(tempFile);
6804+
resourceStream?.Dispose();
6805+
tempFile.Dispose();
6806+
}
68046807

6805-
resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.dll");
6806-
tempFile = File.Create("mupdfcsharp.dll");
6808+
if (!File.Exists(binaryDir + "mupdfcsharp.dll"))
6809+
{
6810+
var assembly = Assembly.GetExecutingAssembly();
6811+
var resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.dll");
6812+
var tempFile = File.Create(binaryDir + "mupdfcsharp.dll");
68076813

6808-
resourceStream?.CopyTo(tempFile);
6809-
resourceStream?.Dispose();
6810-
tempFile.Dispose();
6814+
resourceStream?.CopyTo(tempFile);
6815+
resourceStream?.Dispose();
6816+
tempFile.Dispose();
6817+
}
6818+
}
6819+
6820+
internal static void LoadEmbeddedDllForLinux()
6821+
{
6822+
string binaryDir = AppContext.BaseDirectory;
6823+
if (!File.Exists(binaryDir + "libmupdf.so"))
6824+
{
6825+
var assembly = Assembly.GetExecutingAssembly();
6826+
var resourceStream = assembly.GetManifestResourceStream("libmupdf.so");
6827+
if (resourceStream != null)
6828+
{
6829+
var tempFile = File.Create(binaryDir + "libmupdf.so");
6830+
resourceStream.CopyTo(tempFile);
6831+
resourceStream.Dispose();
6832+
tempFile.Dispose();
6833+
}
6834+
}
6835+
6836+
if (!File.Exists(binaryDir + "libmupdf.so.26.0"))
6837+
{
6838+
var assembly = Assembly.GetExecutingAssembly();
6839+
var resourceStream = assembly.GetManifestResourceStream("libmupdf.so.26.0");
6840+
if (resourceStream != null)
6841+
{
6842+
var tempFile = File.Create(binaryDir + "libmupdf.so.26.0");
6843+
resourceStream.CopyTo(tempFile);
6844+
resourceStream.Dispose();
6845+
tempFile.Dispose();
6846+
}
6847+
}
6848+
6849+
if (!File.Exists(binaryDir + "libmupdfcpp.so"))
6850+
{
6851+
var assembly = Assembly.GetExecutingAssembly();
6852+
var resourceStream = assembly.GetManifestResourceStream("libmupdfcpp.so");
6853+
if (resourceStream != null)
6854+
{
6855+
var tempFile = File.Create(binaryDir + "libmupdfcpp.so");
6856+
resourceStream.CopyTo(tempFile);
6857+
resourceStream.Dispose();
6858+
tempFile.Dispose();
6859+
}
6860+
}
6861+
6862+
if (!File.Exists(binaryDir + "libmupdfcpp.so.26.0"))
6863+
{
6864+
var assembly = Assembly.GetExecutingAssembly();
6865+
var resourceStream = assembly.GetManifestResourceStream("libmupdfcpp.so.26.0");
6866+
if (resourceStream != null)
6867+
{
6868+
var tempFile = File.Create(binaryDir + "libmupdfcpp.so.26.0");
6869+
resourceStream.CopyTo(tempFile);
6870+
resourceStream.Dispose();
6871+
tempFile.Dispose();
6872+
}
6873+
}
6874+
6875+
if (!File.Exists(binaryDir + "mupdfcsharp.dll"))
6876+
{
6877+
var assembly = Assembly.GetExecutingAssembly();
6878+
var resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.so");
6879+
if (resourceStream != null)
6880+
{
6881+
var tempFile = File.Create(binaryDir + "mupdfcsharp.dll");
6882+
resourceStream.CopyTo(tempFile);
6883+
resourceStream.Dispose();
6884+
tempFile.Dispose();
6885+
}
6886+
}
68116887
}
68126888

68136889
internal static void AddLayerConfig(
@@ -6869,16 +6945,26 @@ internal static void SetDotCultureForNumber()
68696945

68706946
public static void InitApp()
68716947
{
6872-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
6873-
return;
6874-
6875-
if (Utils.IsInitialized)
6876-
return;
6948+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
6949+
{
6950+
if (Utils.IsInitialized)
6951+
return;
68776952

6878-
Utils.SetDotCultureForNumber();
6879-
if (!File.Exists("mupdfcsharp.dll"))
6880-
Utils.LoadEmbeddedDll();
6953+
Utils.SetDotCultureForNumber();
6954+
Utils.LoadEmbeddedDllForWindows();
6955+
}
6956+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
6957+
{
6958+
if (Utils.IsInitialized)
6959+
return;
68816960

6961+
Utils.SetDotCultureForNumber();
6962+
Utils.LoadEmbeddedDllForLinux();
6963+
}
6964+
else
6965+
{
6966+
return;
6967+
}
68826968
Utils.IsInitialized = true;
68836969
}
68846970

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libmupdf.so.26.0
50.4 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libmupdfcpp.so.26.0
2.78 MB
Binary file not shown.
4.65 MB
Binary file not shown.
41 MB
Binary file not shown.
1.75 MB
Binary file not shown.

0 commit comments

Comments
 (0)