mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
remove unused code and add writing support for more graphics operations
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
namespace UglyToad.PdfPig.Tests.ContentStream
|
||||
{
|
||||
using PdfPig.ContentStream;
|
||||
using Xunit;
|
||||
|
||||
public class IndirectReferenceTests
|
||||
|
@@ -1,129 +0,0 @@
|
||||
namespace UglyToad.PdfPig.Tests.ContentStream
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using PdfPig.ContentStream;
|
||||
using PdfPig.Util;
|
||||
using Xunit;
|
||||
|
||||
public class PdfBooleanTests
|
||||
{
|
||||
[Fact]
|
||||
public void TrueIsTrue()
|
||||
{
|
||||
Assert.True(PdfBoolean.True.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FalseIsFalse()
|
||||
{
|
||||
Assert.False(PdfBoolean.False.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImplicitTrueIsTrue()
|
||||
{
|
||||
Assert.True(PdfBoolean.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImplicitFalseIsFalse()
|
||||
{
|
||||
Assert.False(PdfBoolean.False);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CastNullThrows()
|
||||
{
|
||||
PdfBoolean boolean = null;
|
||||
|
||||
// ReSharper disable once ExpressionIsAlwaysNull
|
||||
Action action = () => Test(boolean);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(action);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringRepresentationTrueCorrect()
|
||||
{
|
||||
Assert.Equal("true", PdfBoolean.True.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringRepresentationFalseCorrect()
|
||||
{
|
||||
Assert.Equal("false", PdfBoolean.False.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OperatorEqualityWorksCorrectly()
|
||||
{
|
||||
// ReSharper disable once EqualExpressionComparison
|
||||
Assert.True(PdfBoolean.True == PdfBoolean.True);
|
||||
// ReSharper disable once EqualExpressionComparison
|
||||
Assert.True(PdfBoolean.False == PdfBoolean.False);
|
||||
|
||||
Assert.False(PdfBoolean.True == PdfBoolean.False);
|
||||
Assert.False(PdfBoolean.False == PdfBoolean.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualityWorksCorrectly()
|
||||
{
|
||||
var result = PdfBoolean.True.Equals(PdfBoolean.False);
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
result = PdfBoolean.False.Equals(PdfBoolean.True);
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
result = PdfBoolean.True.Equals(PdfBoolean.True);
|
||||
|
||||
Assert.True(result);
|
||||
|
||||
result = PdfBoolean.False.Equals(PdfBoolean.False);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ObjectEqualityWorksCorrectly()
|
||||
{
|
||||
var result = PdfBoolean.True.Equals(null);
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
result = PdfBoolean.False.Equals("happy");
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
result = PdfBoolean.False.Equals((object) PdfBoolean.False);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WritesToStreamCorrectly()
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
using (var write = new BinaryWriter(memoryStream))
|
||||
{
|
||||
PdfBoolean.True.WriteToPdfStream(write);
|
||||
PdfBoolean.False.WriteToPdfStream(write);
|
||||
|
||||
write.Flush();
|
||||
|
||||
var result = OtherEncodings.BytesAsLatin1String(memoryStream.ToArray());
|
||||
|
||||
Assert.Equal("truefalse", result);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool Test(bool input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Tests
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using PdfPig.ContentStream;
|
||||
using PdfPig.Tokenization.Scanner;
|
||||
using PdfPig.Tokens;
|
||||
|
||||
|
@@ -3,7 +3,6 @@ namespace UglyToad.PdfPig.Tests.Tokenization
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using PdfPig.ContentStream;
|
||||
using PdfPig.Tokenization;
|
||||
using PdfPig.Tokens;
|
||||
using Xunit;
|
||||
|
@@ -4,7 +4,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PdfPig.ContentStream;
|
||||
using PdfPig.IO;
|
||||
using PdfPig.Tokenization.Scanner;
|
||||
using PdfPig.Tokens;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ContentStream;
|
||||
using Fonts;
|
||||
using Parser.Parts;
|
||||
using Tokenization.Scanner;
|
||||
|
@@ -1,110 +0,0 @@
|
||||
namespace UglyToad.PdfPig.ContentStream
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
internal class PdfBoolean : IEquatable<PdfBoolean>
|
||||
{
|
||||
/// <summary>
|
||||
/// The bytes representing a true value in the PDF content.
|
||||
/// </summary>
|
||||
/// <remarks>Equivalent to the text "true".</remarks>
|
||||
private static readonly byte[] TrueBytes = {116, 114, 117, 101};
|
||||
|
||||
/// <summary>
|
||||
/// The bytes representing a false value in the PDF content.
|
||||
/// </summary>
|
||||
/// <remarks>Equivalent to the text "false".</remarks>
|
||||
private static readonly byte[] FalseBytes = {102, 97, 108, 115, 101};
|
||||
|
||||
/// <summary>
|
||||
/// The PDF boolean representing <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static PdfBoolean True { get; } = new PdfBoolean(true);
|
||||
|
||||
/// <summary>
|
||||
/// The PDF boolean representing <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static PdfBoolean False { get; } = new PdfBoolean(false);
|
||||
|
||||
/// <summary>
|
||||
/// The boolean value.
|
||||
/// </summary>
|
||||
public bool Value { get; }
|
||||
|
||||
private PdfBoolean(bool value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supports casting from <see cref="bool"/> to <see cref="PdfBoolean"/>.
|
||||
/// </summary>
|
||||
public static explicit operator PdfBoolean(bool value)
|
||||
{
|
||||
return value ? True : False;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supports treatment of <see cref="PdfBoolean"/> as a <see cref="bool"/>.
|
||||
/// </summary>
|
||||
public static implicit operator bool(PdfBoolean value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
public static bool operator ==(PdfBoolean boolean1, PdfBoolean boolean2)
|
||||
{
|
||||
return EqualityComparer<PdfBoolean>.Default.Equals(boolean1, boolean2);
|
||||
}
|
||||
|
||||
public static bool operator !=(PdfBoolean boolean1, PdfBoolean boolean2)
|
||||
{
|
||||
return !(boolean1 == boolean2);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value ? "true" : "false";
|
||||
}
|
||||
|
||||
public void WriteToPdfStream(BinaryWriter output)
|
||||
{
|
||||
if (output == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(output));
|
||||
}
|
||||
|
||||
if (Value)
|
||||
{
|
||||
output.Write(TrueBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Write(FalseBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as PdfBoolean);
|
||||
}
|
||||
|
||||
public bool Equals(PdfBoolean other)
|
||||
{
|
||||
return other != null &&
|
||||
Value == other.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return -1937169414 + Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@
|
||||
|
||||
public string Operator => Symbol;
|
||||
|
||||
public LineCapStyle Cap { get; set; }
|
||||
public LineCapStyle Cap { get; }
|
||||
|
||||
public SetLineCap(int cap) : this((LineCapStyle)cap) { }
|
||||
public SetLineCap(LineCapStyle cap)
|
||||
@@ -31,7 +31,10 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
stream.WriteDecimal((int)Cap);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
public string Operator => Symbol;
|
||||
|
||||
public LineJoinStyle Join { get; set; }
|
||||
public LineJoinStyle Join { get; }
|
||||
|
||||
public SetLineJoin(int join) : this((LineJoinStyle)join) { }
|
||||
public SetLineJoin(LineJoinStyle join)
|
||||
@@ -31,7 +31,10 @@
|
||||
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
stream.WriteDecimal((int)Join);
|
||||
stream.WriteWhiteSpace();
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -3,7 +3,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ContentStream;
|
||||
using IO;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
namespace UglyToad.PdfPig.Parser.Parts
|
||||
{
|
||||
using ContentStream;
|
||||
using Exceptions;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Tokens
|
||||
{
|
||||
using System;
|
||||
using ContentStream;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user