namespace UglyToad.PdfPig.Graphics.Operations.TextState { using System; using System.Globalization; using System.IO; using Tokens; /// /// /// Set the font and the font size. /// Font is the name of a font resource in the Font subdictionary of the current resource dictionary. /// Size is a number representing a scale factor. /// public class SetFontAndSize : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. /// public const string Symbol = "Tf"; /// public string Operator => Symbol; /// /// The name of the font as defined in the resource dictionary. /// public NameToken Font { get; } /// /// The font program defines glyphs for a standard size. This standard size is set so that each line of text will occupy 1 unit in user space. /// The size is the scale factor used to scale glyphs from the standard size to the display size rather than the font size in points. /// public double Size { get; } /// /// Create a new . /// /// The font name. /// The font size. public SetFontAndSize(NameToken font, double size) { Font = font ?? throw new ArgumentNullException(nameof(font)); Size = size; } /// public void Run(IOperationContext operationContext) { operationContext.SetFontAndSize(Font, Size); } /// public void Write(Stream stream) { stream.WriteText(Font.ToString()); stream.WriteWhiteSpace(); stream.WriteNumberText(Size, Symbol); } /// public override string ToString() { return $"{Font} {Size.ToString("G", CultureInfo.InvariantCulture)} {Symbol}"; } } }