mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-12-21 19:29:51 +08:00
Use double for pdf version instead of decimal
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename()))
|
||||
{
|
||||
Assert.Equal(1.7m, document.Version);
|
||||
Assert.Equal(1.7, document.Version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename()))
|
||||
{
|
||||
Assert.Equal(1.4m, document.Version);
|
||||
Assert.Equal(1.4, document.Version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);
|
||||
|
||||
Assert.Equal(1.2m, result.Version);
|
||||
Assert.Equal(1.2, result.Version);
|
||||
Assert.Equal(TestEnvironment.IsSingleByteNewLine(input) ? 7 : 9, result.OffsetInFile);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);
|
||||
|
||||
Assert.Equal(1.2m, result.Version);
|
||||
Assert.Equal(1.2, result.Version);
|
||||
Assert.Equal(TestEnvironment.IsSingleByteNewLine(input) ? 12 : 13, result.OffsetInFile);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, true, log);
|
||||
|
||||
Assert.Equal(1.7m, result.Version);
|
||||
Assert.Equal(1.7, result.Version);
|
||||
Assert.Equal(TestEnvironment.IsSingleByteNewLine(input) ? 12 : 13, result.OffsetInFile);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ three %PDF-1.6";
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, true, log);
|
||||
|
||||
Assert.Equal(1.6m, result.Version);
|
||||
Assert.Equal(1.6, result.Version);
|
||||
Assert.Equal(TestEnvironment.IsSingleByteNewLine(s) ? 14 : 15, result.OffsetInFile);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ three %PDF-1.6";
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, true, log);
|
||||
|
||||
Assert.Equal(1.4m, result.Version);
|
||||
Assert.Equal(1.4, result.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -156,7 +156,7 @@ three %PDF-1.6";
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner, bytes, false, log);
|
||||
|
||||
Assert.Equal(1.7m, result.Version);
|
||||
Assert.Equal(1.7, result.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -175,7 +175,7 @@ three %PDF-1.6";
|
||||
|
||||
Assert.Equal(0, scanner.scanner.CurrentPosition);
|
||||
Assert.Equal(128, result.OffsetInFile);
|
||||
Assert.Equal(1.1m, result.Version);
|
||||
Assert.Equal(1.1, result.Version);
|
||||
Assert.Equal("PDF-1.1", result.VersionString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
Assert.Equal(2, document.NumberOfPages);
|
||||
if (checkVersion)
|
||||
{
|
||||
Assert.Equal(1.5m, document.Version);
|
||||
Assert.Equal(1.5, document.Version);
|
||||
}
|
||||
|
||||
var page1 = document.GetPage(1);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
internal class HeaderVersion
|
||||
{
|
||||
public decimal Version { get; }
|
||||
public double Version { get; }
|
||||
|
||||
public string VersionString { get; }
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
/// </summary>
|
||||
public long OffsetInFile { get; }
|
||||
|
||||
public HeaderVersion(decimal version, string versionString, long offsetInFile)
|
||||
public HeaderVersion(double version, string versionString, long offsetInFile)
|
||||
{
|
||||
Version = version;
|
||||
VersionString = versionString;
|
||||
|
||||
@@ -69,9 +69,9 @@
|
||||
return HandleMissingVersion(comment, isLenientParsing, log);
|
||||
}
|
||||
|
||||
const int toDecimalStartLength = 4;
|
||||
const int toDoubleStartLength = 4;
|
||||
|
||||
if (!decimal.TryParse(comment.Data.Substring(toDecimalStartLength),
|
||||
if (!double.TryParse(comment.Data.Substring(toDoubleStartLength),
|
||||
NumberStyles.Number,
|
||||
CultureInfo.InvariantCulture,
|
||||
out var version))
|
||||
@@ -120,7 +120,7 @@
|
||||
if (actualIndex >= 0 && content.Length - actualIndex >= versionLength)
|
||||
{
|
||||
var numberPart = content.Substring(actualIndex + 5, 3);
|
||||
if (decimal.TryParse(
|
||||
if (double.TryParse(
|
||||
numberPart,
|
||||
NumberStyles.Number,
|
||||
CultureInfo.InvariantCulture,
|
||||
@@ -152,7 +152,7 @@
|
||||
{
|
||||
log.Warn($"Did not find a version header of the correct format, defaulting to 1.4 since lenient. Header was: {comment.Data}.");
|
||||
|
||||
return new HeaderVersion(1.4m, "PDF-1.4", 0);
|
||||
return new HeaderVersion(1.4, "PDF-1.4", 0);
|
||||
}
|
||||
|
||||
throw new PdfDocumentFormatException($"The comment which should have provided the version was in the wrong format: {comment.Data}.");
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
/// <summary>
|
||||
/// The version number of the PDF specification which this file conforms to, for example 1.4.
|
||||
/// </summary>
|
||||
public decimal Version => version.Version;
|
||||
public double Version => version.Version;
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of pages in this document.
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
/// Initializes the PDF stream with pdf header.
|
||||
/// </summary>
|
||||
/// <param name="version">Version of PDF.</param>
|
||||
void InitializePdf(decimal version);
|
||||
void InitializePdf(double version);
|
||||
|
||||
/// <summary>
|
||||
/// Completes the PDF writing trailing PDF information.
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace UglyToad.PdfPig.Writer
|
||||
Func<IToken, IndirectReferenceToken> writerFunc,
|
||||
PdfDocumentBuilder.DocumentInformationBuilder documentInformationBuilder,
|
||||
PdfAStandard archiveStandard,
|
||||
decimal version,
|
||||
double version,
|
||||
XDocument xmpMetadata)
|
||||
{
|
||||
catalog[NameToken.OutputIntents] = OutputIntentsFactory.GetOutputIntentsArray(writerFunc);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
Stream stream,
|
||||
bool dispose,
|
||||
ITokenWriter tokenWriter = null,
|
||||
Action<decimal> recordVersion = null
|
||||
Action<double> recordVersion = null
|
||||
) : base(stream, dispose, tokenWriter, recordVersion)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace UglyToad.PdfPig.Writer
|
||||
private readonly Dictionary<Guid, FontStored> fonts = new Dictionary<Guid, FontStored>();
|
||||
private bool completed = false;
|
||||
private int fontId = 0;
|
||||
private decimal version = 1.7m;
|
||||
private double version = 1.7;
|
||||
|
||||
private readonly static ArrayToken DefaultProcSet = new ArrayToken(new List<NameToken>
|
||||
{
|
||||
@@ -85,14 +85,14 @@ namespace UglyToad.PdfPig.Writer
|
||||
public PdfDocumentBuilder()
|
||||
{
|
||||
context = new PdfStreamWriter(new MemoryStream(), true, recordVersion: x => version = x);
|
||||
context.InitializePdf(1.7m);
|
||||
context.InitializePdf(1.7);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document builder keeping resources in memory.
|
||||
/// </summary>
|
||||
/// <param name="version">Pdf version to use in header.</param>
|
||||
public PdfDocumentBuilder(decimal version)
|
||||
public PdfDocumentBuilder(double version)
|
||||
{
|
||||
context = new PdfStreamWriter(new MemoryStream(), true, recordVersion: x => version = x);
|
||||
context.InitializePdf(version);
|
||||
@@ -106,7 +106,7 @@ namespace UglyToad.PdfPig.Writer
|
||||
/// <param name="type">Type of pdf stream writer to use</param>
|
||||
/// <param name="version">Pdf version to use in header.</param>
|
||||
/// <param name="tokenWriter">Token writer to use</param>
|
||||
public PdfDocumentBuilder(Stream stream, bool disposeStream = false, PdfWriterType type = PdfWriterType.Default, decimal version = 1.7m, ITokenWriter tokenWriter = null)
|
||||
public PdfDocumentBuilder(Stream stream, bool disposeStream = false, PdfWriterType type = PdfWriterType.Default, double version = 1.7, ITokenWriter tokenWriter = null)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
|
||||
private static void Merge(IReadOnlyList<PdfDocument> files, Stream output, IReadOnlyList<IReadOnlyList<int>> pagesBundle, PdfAStandard archiveStandard = PdfAStandard.None, PdfDocumentBuilder.DocumentInformationBuilder docInfoBuilder = null)
|
||||
{
|
||||
var maxVersion = files.Select(x=>x.Version).Max();
|
||||
var maxVersion = files.Select(x => x.Version).Max();
|
||||
using (var document = new PdfDocumentBuilder(output, false, PdfWriterType.Default, maxVersion))
|
||||
{
|
||||
document.ArchiveStandard = archiveStandard;
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
/// </summary>
|
||||
internal class PdfStreamWriter : IPdfStreamWriter
|
||||
{
|
||||
private readonly Action<decimal> recordVersion;
|
||||
protected const decimal DefaultVersion = 1.2m;
|
||||
private readonly Action<double> recordVersion;
|
||||
protected const double DefaultVersion = 1.2;
|
||||
protected Dictionary<IndirectReference, long> offsets = new Dictionary<IndirectReference, long>();
|
||||
protected bool DisposeStream { get; set; }
|
||||
protected bool Initialized { get; set; }
|
||||
@@ -35,7 +35,7 @@
|
||||
Stream baseStream,
|
||||
bool disposeStream = true,
|
||||
ITokenWriter tokenWriter = null,
|
||||
Action<decimal> recordVersion = null)
|
||||
Action<double> recordVersion = null)
|
||||
{
|
||||
Stream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
return new IndirectReferenceToken(new IndirectReference(CurrentNumber++, 0));
|
||||
}
|
||||
|
||||
public void InitializePdf(decimal version)
|
||||
public void InitializePdf(double version)
|
||||
{
|
||||
recordVersion?.Invoke(version);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace UglyToad.PdfPig.Writer.Xmp
|
||||
private const string PdfAIdentificationExtensionPrefix = "pdfaid";
|
||||
private const string PdfAIdentificationExtensionNamespace = "http://www.aiim.org/pdfa/ns/id/";
|
||||
|
||||
public static StreamToken GenerateXmpStream(PdfDocumentBuilder.DocumentInformationBuilder builder, decimal version,
|
||||
public static StreamToken GenerateXmpStream(PdfDocumentBuilder.DocumentInformationBuilder builder, double version,
|
||||
PdfAStandard standard, XDocument additionalXmpMetadata)
|
||||
{
|
||||
XNamespace xmpMeta = XmpMetaNamespace;
|
||||
|
||||
Reference in New Issue
Block a user