mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
in order to remove reflection from the core content stream operators construction we ensure all types covered by the operations dictionary have corresponding switch statement support. this moves the remaining 2 operators to the switch statement. fix for #1062
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
namespace UglyToad.PdfPig.Graphics.Operations.InlineImages;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Tokens;
|
|
using Writer;
|
|
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Begin the image data for an inline image object.
|
|
/// </summary>
|
|
public class BeginInlineImageData : IGraphicsStateOperation
|
|
{
|
|
/// <summary>
|
|
/// The symbol for this operation in a stream.
|
|
/// </summary>
|
|
public const string Symbol = "ID";
|
|
|
|
/// <inheritdoc />
|
|
public string Operator => Symbol;
|
|
|
|
/// <summary>
|
|
/// The key-value pairs which specify attributes of the following image.
|
|
/// </summary>
|
|
public IReadOnlyDictionary<NameToken, IToken> Dictionary { get; }
|
|
|
|
/// <summary>
|
|
/// Create a new <see cref="BeginInlineImageData"/>.
|
|
/// </summary>
|
|
public BeginInlineImageData(IReadOnlyDictionary<NameToken, IToken> dictionary)
|
|
{
|
|
Dictionary = dictionary ?? throw new ArgumentNullException(nameof(dictionary));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Run(IOperationContext operationContext)
|
|
{
|
|
operationContext.SetInlineImageProperties(Dictionary);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Write(Stream stream)
|
|
{
|
|
var tokenWriter = TokenWriter.Instance;
|
|
foreach (var item in Dictionary)
|
|
{
|
|
var name = item.Key;
|
|
var value = item.Value;
|
|
|
|
stream.WriteText($"{name} ");
|
|
tokenWriter.WriteToken(value, stream);
|
|
stream.WriteNewLine();
|
|
}
|
|
stream.WriteText(Symbol);
|
|
stream.WriteNewLine();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string ToString()
|
|
{
|
|
return Symbol;
|
|
}
|
|
} |