Files
PdfPig/src/UglyToad.PdfPig/Graphics/Operations/InlineImages/BeginInlineImageData.cs
EliotJones 00ca268092 move last uncovered operators to switch statement
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
2025-07-20 20:33:46 +01:00

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;
}
}