forked from UglyToad/PdfPig
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMoveToNextLineShowText.cs
More file actions
82 lines (71 loc) · 2.22 KB
/
MoveToNextLineShowText.cs
File metadata and controls
82 lines (71 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
namespace UglyToad.PdfPig.Graphics.Operations.TextShowing
{
using System.IO;
using TextPositioning;
/// <inheritdoc />
/// <summary>
/// Move to the next line and show a text string.
/// </summary>
public class MoveToNextLineShowText : IGraphicsStateOperation
{
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "'";
/// <inheritdoc />
public string Operator => Symbol;
/// <summary>
/// The text to show as a <see cref="string"/>.
/// </summary>
public string? Text { get; }
/// <summary>
/// The text to show as hex bytes.
/// </summary>
public ReadOnlyMemory<byte> Bytes { get; }
/// <summary>
/// Create a new <see cref="MoveToNextLineShowText"/>.
/// </summary>
/// <param name="text">The text to show.</param>
public MoveToNextLineShowText(string text)
{
Text = text;
}
/// <summary>
/// Create a new <see cref="MoveToNextLineShowText"/>.
/// </summary>
/// <param name="hexBytes">The bytes of the text to show.</param>
public MoveToNextLineShowText(ReadOnlyMemory<byte> hexBytes)
{
Bytes = hexBytes;
}
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
var move = MoveToNextLine.Value;
var showText = Text != null ? new ShowText(Text) : new ShowText(Bytes);
move.Run(operationContext);
showText.Run(operationContext);
}
/// <inheritdoc />
public void Write(Stream stream)
{
if (Bytes.IsEmpty)
{
stream.WriteText($"({Text}) {Symbol}");
stream.WriteNewLine();
}
else
{
stream.WriteHex(Bytes.Span);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
}
}
/// <inheritdoc />
public override string ToString()
{
return $"{Text} {Symbol}";
}
}
}