mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-22 20:13:58 +08:00
add multi targeting frameworks in the same project for net 4.5 through net 7.0 and net standard 2.0
This commit is contained in:
@@ -229,7 +229,7 @@
|
|||||||
|
|
||||||
private AcroFieldBase GetChoiceField(DictionaryToken fieldDictionary, NameToken fieldType, uint fieldFlags, AcroFieldCommonInformation information)
|
private AcroFieldBase GetChoiceField(DictionaryToken fieldDictionary, NameToken fieldType, uint fieldFlags, AcroFieldCommonInformation information)
|
||||||
{
|
{
|
||||||
var selectedOptions = Array.Empty<string>();
|
var selectedOptions = EmptyArray<string>.Instance;
|
||||||
if (fieldDictionary.TryGet(NameToken.V, out var valueToken))
|
if (fieldDictionary.TryGet(NameToken.V, out var valueToken))
|
||||||
{
|
{
|
||||||
if (DirectObjectFinder.TryGet(valueToken, tokenScanner, out StringToken valueString))
|
if (DirectObjectFinder.TryGet(valueToken, tokenScanner, out StringToken valueString))
|
||||||
|
@@ -91,7 +91,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Identifier = Array.Empty<string>();
|
Identifier = EmptyArray<string>.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dictionary.TryGet(NameToken.Encrypt, out var encryptionToken))
|
if (dictionary.TryGet(NameToken.Encrypt, out var encryptionToken))
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Util;
|
||||||
using Util.JetBrains.Annotations;
|
using Util.JetBrains.Annotations;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -150,17 +151,17 @@
|
|||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
BlueValues = builder.BlueValues ?? Array.Empty<int>();
|
BlueValues = builder.BlueValues ?? EmptyArray<int>.Instance;
|
||||||
OtherBlues = builder.OtherBlues ?? Array.Empty<int>();
|
OtherBlues = builder.OtherBlues ?? EmptyArray<int>.Instance;
|
||||||
FamilyBlues = builder.FamilyBlues ?? Array.Empty<int>();
|
FamilyBlues = builder.FamilyBlues ?? EmptyArray<int>.Instance;
|
||||||
FamilyOtherBlues = builder.FamilyOtherBlues ?? Array.Empty<int>();
|
FamilyOtherBlues = builder.FamilyOtherBlues ?? EmptyArray<int>.Instance;
|
||||||
BlueScale = builder.BlueScale ?? DefaultBlueScale;
|
BlueScale = builder.BlueScale ?? DefaultBlueScale;
|
||||||
BlueFuzz = builder.BlueFuzz ?? DefaultBlueFuzz;
|
BlueFuzz = builder.BlueFuzz ?? DefaultBlueFuzz;
|
||||||
BlueShift = builder.BlueShift ?? DefaultBlueShift;
|
BlueShift = builder.BlueShift ?? DefaultBlueShift;
|
||||||
StandardHorizontalWidth = builder.StandardHorizontalWidth;
|
StandardHorizontalWidth = builder.StandardHorizontalWidth;
|
||||||
StandardVerticalWidth = builder.StandardVerticalWidth;
|
StandardVerticalWidth = builder.StandardVerticalWidth;
|
||||||
StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? Array.Empty<decimal>();
|
StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? EmptyArray<decimal>.Instance;
|
||||||
StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? Array.Empty<decimal>();
|
StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? EmptyArray<decimal>.Instance;
|
||||||
ForceBold = builder.ForceBold ?? false;
|
ForceBold = builder.ForceBold ?? false;
|
||||||
LanguageGroup = builder.LanguageGroup ?? DefaultLanguageGroup;
|
LanguageGroup = builder.LanguageGroup ?? DefaultLanguageGroup;
|
||||||
ExpansionFactor = builder.ExpansionFactor ?? DefaultExpansionFactor;
|
ExpansionFactor = builder.ExpansionFactor ?? DefaultExpansionFactor;
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
||||||
{
|
{
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Util;
|
||||||
using Util.JetBrains.Annotations;
|
using Util.JetBrains.Annotations;
|
||||||
|
|
||||||
internal class CompactFontFormatIndex : IReadOnlyList<IReadOnlyList<byte>>
|
internal class CompactFontFormatIndex : IReadOnlyList<IReadOnlyList<byte>>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
public CompactFontFormatIndex(byte[][] bytes)
|
public CompactFontFormatIndex(byte[][] bytes)
|
||||||
{
|
{
|
||||||
this.bytes = bytes ?? Array.Empty<IReadOnlyList<byte>>();
|
this.bytes = bytes ?? EmptyArray<IReadOnlyList<byte>>.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<IReadOnlyList<byte>> GetEnumerator()
|
public IEnumerator<IReadOnlyList<byte>> GetEnumerator()
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
||||||
{
|
{
|
||||||
|
using Util;
|
||||||
|
|
||||||
internal class CompactFontFormatIndexReader
|
internal class CompactFontFormatIndexReader
|
||||||
{
|
{
|
||||||
public CompactFontFormatIndex ReadDictionaryData(CompactFontFormatData data)
|
public CompactFontFormatIndex ReadDictionaryData(CompactFontFormatData data)
|
||||||
@@ -43,7 +45,7 @@ namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
|||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
return Array.Empty<int>();
|
return EmptyArray<int>.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
var offsetSize = data.ReadOffsize();
|
var offsetSize = data.ReadOffsize();
|
||||||
|
@@ -0,0 +1,9 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
internal interface ISystemFontLister
|
||||||
|
{
|
||||||
|
IEnumerable<SystemFontRecord> GetAllFonts();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,68 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
internal class LinuxSystemFontLister : ISystemFontLister
|
||||||
|
{
|
||||||
|
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||||
|
{
|
||||||
|
var directories = new List<string>
|
||||||
|
{
|
||||||
|
"/usr/local/fonts", // local
|
||||||
|
"/usr/local/share/fonts", // local shared
|
||||||
|
"/usr/share/fonts", // system
|
||||||
|
"/usr/X11R6/lib/X11/fonts" // X
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var folder = Environment.GetEnvironmentVariable("$HOME");
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(folder))
|
||||||
|
{
|
||||||
|
directories.Add($"{folder}/.fonts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var directory in directories)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] files;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
files = Directory.GetFiles(directory);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if (SystemFontRecord.TryCreate(file, out var record))
|
||||||
|
{
|
||||||
|
yield return record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
src/UglyToad.PdfPig/Fonts/SystemFonts/MacSystemFontLister.cs
Normal file
67
src/UglyToad.PdfPig/Fonts/SystemFonts/MacSystemFontLister.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
internal class MacSystemFontLister : ISystemFontLister
|
||||||
|
{
|
||||||
|
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||||
|
{
|
||||||
|
var directories = new List<string>
|
||||||
|
{
|
||||||
|
"/Library/Fonts/", // local
|
||||||
|
"/System/Library/Fonts/", // system
|
||||||
|
"/Network/Library/Fonts/" // network
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var folder = Environment.GetEnvironmentVariable("$HOME");
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(folder))
|
||||||
|
{
|
||||||
|
directories.Add($"{folder}/Library/Fonts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var directory in directories)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] files;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
files = Directory.GetFiles(directory);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if (SystemFontRecord.TryCreate(file, out var record))
|
||||||
|
{
|
||||||
|
yield return record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -19,7 +19,9 @@
|
|||||||
public SystemFontFinder(TrueTypeFontParser trueTypeFontParser)
|
public SystemFontFinder(TrueTypeFontParser trueTypeFontParser)
|
||||||
{
|
{
|
||||||
this.trueTypeFontParser = trueTypeFontParser;
|
this.trueTypeFontParser = trueTypeFontParser;
|
||||||
|
|
||||||
ISystemFontLister lister;
|
ISystemFontLister lister;
|
||||||
|
#if NETSTANDARD2_0
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
lister = new WindowsSystemFontLister();
|
lister = new WindowsSystemFontLister();
|
||||||
@@ -36,6 +38,9 @@
|
|||||||
{
|
{
|
||||||
throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");
|
throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
lister = new WindowsSystemFontLister();
|
||||||
|
#endif
|
||||||
|
|
||||||
availableFonts = new Lazy<IReadOnlyList<SystemFontRecord>>(() => lister.GetAllFonts().ToList());
|
availableFonts = new Lazy<IReadOnlyList<SystemFontRecord>>(() => lister.GetAllFonts().ToList());
|
||||||
}
|
}
|
||||||
@@ -75,230 +80,4 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal interface ISystemFontLister
|
|
||||||
{
|
|
||||||
IEnumerable<SystemFontRecord> GetAllFonts();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class WindowsSystemFontLister : ISystemFontLister
|
|
||||||
{
|
|
||||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
|
||||||
{
|
|
||||||
// TODO: Could use System.Drawing InstalledFontCollection to do this?
|
|
||||||
|
|
||||||
var winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
|
|
||||||
|
|
||||||
var fonts = Path.Combine(winDir, "Fonts");
|
|
||||||
|
|
||||||
if (Directory.Exists(fonts))
|
|
||||||
{
|
|
||||||
var files = Directory.GetFiles(fonts);
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
if (SystemFontRecord.TryCreate(file, out var record))
|
|
||||||
{
|
|
||||||
yield return record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var psFonts = Path.Combine(winDir, "PSFonts");
|
|
||||||
|
|
||||||
if (Directory.Exists(psFonts))
|
|
||||||
{
|
|
||||||
var files = Directory.GetFiles(fonts);
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
if (SystemFontRecord.TryCreate(file, out var record))
|
|
||||||
{
|
|
||||||
yield return record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class LinuxSystemFontLister : ISystemFontLister
|
|
||||||
{
|
|
||||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
|
||||||
{
|
|
||||||
var directories = new List<string>
|
|
||||||
{
|
|
||||||
"/usr/local/fonts", // local
|
|
||||||
"/usr/local/share/fonts", // local shared
|
|
||||||
"/usr/share/fonts", // system
|
|
||||||
"/usr/X11R6/lib/X11/fonts" // X
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var folder = Environment.GetEnvironmentVariable("$HOME");
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(folder))
|
|
||||||
{
|
|
||||||
directories.Add($"{folder}/.fonts");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var directory in directories)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] files;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
files = Directory.GetFiles(directory);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
if (SystemFontRecord.TryCreate(file, out var record))
|
|
||||||
{
|
|
||||||
yield return record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class MacSystemFontLister : ISystemFontLister
|
|
||||||
{
|
|
||||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
|
||||||
{
|
|
||||||
var directories = new List<string>
|
|
||||||
{
|
|
||||||
"/Library/Fonts/", // local
|
|
||||||
"/System/Library/Fonts/", // system
|
|
||||||
"/Network/Library/Fonts/" // network
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var folder = Environment.GetEnvironmentVariable("$HOME");
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(folder))
|
|
||||||
{
|
|
||||||
directories.Add($"{folder}/Library/Fonts");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var directory in directories)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] files;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
files = Directory.GetFiles(directory);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
if (SystemFontRecord.TryCreate(file, out var record))
|
|
||||||
{
|
|
||||||
yield return record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct SystemFontRecord
|
|
||||||
{
|
|
||||||
public string Path { get; }
|
|
||||||
|
|
||||||
public SystemFontType Type { get; }
|
|
||||||
|
|
||||||
public SystemFontRecord(string path, SystemFontType type)
|
|
||||||
{
|
|
||||||
Path = path ?? throw new ArgumentNullException(nameof(path));
|
|
||||||
Type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryCreate(string path, out SystemFontRecord type)
|
|
||||||
{
|
|
||||||
type = default(SystemFontRecord);
|
|
||||||
|
|
||||||
SystemFontType fontType;
|
|
||||||
if (path.EndsWith(".ttf"))
|
|
||||||
{
|
|
||||||
fontType = SystemFontType.TrueType;
|
|
||||||
}
|
|
||||||
else if (path.EndsWith(".otf"))
|
|
||||||
{
|
|
||||||
fontType = SystemFontType.OpenType;
|
|
||||||
}
|
|
||||||
else if (path.EndsWith(".ttc"))
|
|
||||||
{
|
|
||||||
fontType = SystemFontType.TrueTypeCollection;
|
|
||||||
}
|
|
||||||
else if (path.EndsWith(".otc"))
|
|
||||||
{
|
|
||||||
fontType = SystemFontType.OpenTypeCollection;
|
|
||||||
}
|
|
||||||
else if (path.EndsWith(".pfb"))
|
|
||||||
{
|
|
||||||
fontType = SystemFontType.Type1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
type = new SystemFontRecord(path, fontType);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal enum SystemFontType
|
|
||||||
{
|
|
||||||
Unknown = 0,
|
|
||||||
TrueType = 1,
|
|
||||||
OpenType = 2,
|
|
||||||
Type1 = 3,
|
|
||||||
TrueTypeCollection = 4,
|
|
||||||
OpenTypeCollection = 5
|
|
||||||
}
|
|
||||||
}
|
}
|
52
src/UglyToad.PdfPig/Fonts/SystemFonts/SystemFontRecord.cs
Normal file
52
src/UglyToad.PdfPig/Fonts/SystemFonts/SystemFontRecord.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
|
||||||
|
internal struct SystemFontRecord
|
||||||
|
{
|
||||||
|
public string Path { get; }
|
||||||
|
|
||||||
|
public SystemFontType Type { get; }
|
||||||
|
|
||||||
|
public SystemFontRecord(string path, SystemFontType type)
|
||||||
|
{
|
||||||
|
Path = path ?? throw new ArgumentNullException(nameof(path));
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryCreate(string path, out SystemFontRecord type)
|
||||||
|
{
|
||||||
|
type = default(SystemFontRecord);
|
||||||
|
|
||||||
|
SystemFontType fontType;
|
||||||
|
if (path.EndsWith(".ttf"))
|
||||||
|
{
|
||||||
|
fontType = SystemFontType.TrueType;
|
||||||
|
}
|
||||||
|
else if (path.EndsWith(".otf"))
|
||||||
|
{
|
||||||
|
fontType = SystemFontType.OpenType;
|
||||||
|
}
|
||||||
|
else if (path.EndsWith(".ttc"))
|
||||||
|
{
|
||||||
|
fontType = SystemFontType.TrueTypeCollection;
|
||||||
|
}
|
||||||
|
else if (path.EndsWith(".otc"))
|
||||||
|
{
|
||||||
|
fontType = SystemFontType.OpenTypeCollection;
|
||||||
|
}
|
||||||
|
else if (path.EndsWith(".pfb"))
|
||||||
|
{
|
||||||
|
fontType = SystemFontType.Type1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
type = new SystemFontRecord(path, fontType);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/UglyToad.PdfPig/Fonts/SystemFonts/SystemFontType.cs
Normal file
12
src/UglyToad.PdfPig/Fonts/SystemFonts/SystemFontType.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
internal enum SystemFontType
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
TrueType = 1,
|
||||||
|
OpenType = 2,
|
||||||
|
Type1 = 3,
|
||||||
|
TrueTypeCollection = 4,
|
||||||
|
OpenTypeCollection = 5
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
internal class WindowsSystemFontLister : ISystemFontLister
|
||||||
|
{
|
||||||
|
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||||
|
{
|
||||||
|
// TODO: Could use System.Drawing InstalledFontCollection to do this?
|
||||||
|
|
||||||
|
var winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
|
||||||
|
|
||||||
|
var fonts = Path.Combine(winDir, "Fonts");
|
||||||
|
|
||||||
|
if (Directory.Exists(fonts))
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(fonts);
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if (SystemFontRecord.TryCreate(file, out var record))
|
||||||
|
{
|
||||||
|
yield return record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var psFonts = Path.Combine(winDir, "PSFonts");
|
||||||
|
|
||||||
|
if (Directory.Exists(psFonts))
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(fonts);
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if (SystemFontRecord.TryCreate(file, out var record))
|
||||||
|
{
|
||||||
|
yield return record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47</TargetFrameworks>
|
||||||
<PackageId>PdfPig</PackageId>
|
<PackageId>PdfPig</PackageId>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Authors>UglyToad</Authors>
|
<Authors>UglyToad</Authors>
|
||||||
@@ -48,4 +48,14 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)'=='net45'
|
||||||
|
OR '$(TargetFramework)'=='net451'
|
||||||
|
OR '$(TargetFramework)'=='net452'
|
||||||
|
OR '$(TargetFramework)'=='net46'
|
||||||
|
OR '$(TargetFramework)'=='net461'
|
||||||
|
OR '$(TargetFramework)'=='net462'
|
||||||
|
OR '$(TargetFramework)'=='net47'">
|
||||||
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
13
src/UglyToad.PdfPig/Util/EmptyArray.cs
Normal file
13
src/UglyToad.PdfPig/Util/EmptyArray.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace UglyToad.PdfPig.Util
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// NET 4.5 compatible Array.Empty.
|
||||||
|
/// </summary>
|
||||||
|
internal static class EmptyArray<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An empty array.
|
||||||
|
/// </summary>
|
||||||
|
public static T[] Instance { get; } = new T[0];
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user