forked from UglyToad/PdfPig
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMoveToNextLineShowTextWithSpacing.cs
More file actions
107 lines (93 loc) · 3.45 KB
/
MoveToNextLineShowTextWithSpacing.cs
File metadata and controls
107 lines (93 loc) · 3.45 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
namespace UglyToad.PdfPig.Graphics.Operations.TextShowing
{
using System.IO;
using TextPositioning;
using TextState;
/// <inheritdoc />
/// <summary>
/// Move to the next line and show a text string, using the first number as the word spacing and the second as the character spacing.
/// </summary>
public class MoveToNextLineShowTextWithSpacing : IGraphicsStateOperation
{
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "\"";
/// <inheritdoc />
public string Operator => Symbol;
/// <summary>
/// The word spacing.
/// </summary>
public double WordSpacing { get; }
/// <summary>
/// The character spacing.
/// </summary>
public double CharacterSpacing { get; }
/// <summary>
/// The bytes of the text.
/// </summary>
public ReadOnlyMemory<byte> Bytes { get; }
/// <summary>
/// The text to show.
/// </summary>
public string? Text { get; }
/// <summary>
/// Create a new <see cref="MoveToNextLineShowTextWithSpacing"/>.
/// </summary>
/// <param name="wordSpacing">The word spacing.</param>
/// <param name="characterSpacing">The character spacing.</param>
/// <param name="text">The text to show.</param>
public MoveToNextLineShowTextWithSpacing(double wordSpacing, double characterSpacing, string text)
{
WordSpacing = wordSpacing;
CharacterSpacing = characterSpacing;
Text = text;
}
/// <summary>
/// Create a new <see cref="MoveToNextLineShowTextWithSpacing"/>.
/// </summary>
/// <param name="wordSpacing">The word spacing.</param>
/// <param name="characterSpacing">The character spacing.</param>
/// <param name="hexBytes">The bytes of the text to show.</param>
public MoveToNextLineShowTextWithSpacing(double wordSpacing, double characterSpacing, ReadOnlyMemory<byte> hexBytes)
{
WordSpacing = wordSpacing;
CharacterSpacing = characterSpacing;
Bytes = hexBytes;
}
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
var setWordSpacing = new SetWordSpacing(WordSpacing);
var setCharacterSpacing = new SetCharacterSpacing(CharacterSpacing);
var moveToNextLine = MoveToNextLine.Value;
var showText = Text != null ? new ShowText(Text) : new ShowText(Bytes!);
setWordSpacing.Run(operationContext);
setCharacterSpacing.Run(operationContext);
moveToNextLine.Run(operationContext);
showText.Run(operationContext);
}
/// <inheritdoc />
public void Write(Stream stream)
{
stream.WriteDouble(WordSpacing);
stream.WriteWhiteSpace();
stream.WriteDouble(CharacterSpacing);
stream.WriteWhiteSpace();
if (!Bytes.IsEmpty)
{
stream.WriteHex(Bytes.Span);
}
else
{
stream.WriteText($"({Text})");
}
stream.WriteNewLine();
}
/// <inheritdoc />
public override string ToString()
{
return $"{WordSpacing} {CharacterSpacing} {Text} {Symbol}";
}
}
}