2018-01-11 03:49:32 +08:00
|
|
|
|
namespace UglyToad.PdfPig.Graphics.Operations.TextState
|
2017-11-23 02:41:34 +08:00
|
|
|
|
{
|
2017-12-29 00:58:52 +08:00
|
|
|
|
using System;
|
2020-07-26 21:14:37 +08:00
|
|
|
|
using System.Globalization;
|
2018-12-03 00:14:55 +08:00
|
|
|
|
using System.IO;
|
2018-11-17 04:00:12 +08:00
|
|
|
|
using Tokens;
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
2024-01-30 23:11:12 +08:00
|
|
|
|
/// Set the font and the font size.
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SetFontAndSize : IGraphicsStateOperation
|
2017-11-23 02:41:34 +08:00
|
|
|
|
{
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The symbol for this operation in a stream.
|
|
|
|
|
/// </summary>
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public const string Symbol = "Tf";
|
|
|
|
|
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <inheritdoc />
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public string Operator => Symbol;
|
|
|
|
|
|
2017-12-29 00:58:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the font as defined in the resource dictionary.
|
|
|
|
|
/// </summary>
|
2018-01-19 08:35:04 +08:00
|
|
|
|
public NameToken Font { get; }
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2017-12-29 00:58:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
2024-01-30 23:11:12 +08:00
|
|
|
|
public double Size { get; }
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="SetFontAndSize"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="font">The font name.</param>
|
|
|
|
|
/// <param name="size">The font size.</param>
|
2024-01-30 23:11:12 +08:00
|
|
|
|
public SetFontAndSize(NameToken font, double size)
|
2017-11-23 02:41:34 +08:00
|
|
|
|
{
|
2017-12-29 00:58:52 +08:00
|
|
|
|
Font = font ?? throw new ArgumentNullException(nameof(font));
|
2017-11-23 02:41:34 +08:00
|
|
|
|
Size = size;
|
|
|
|
|
}
|
2019-01-04 06:20:53 +08:00
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Run(IOperationContext operationContext)
|
2017-11-30 06:55:53 +08:00
|
|
|
|
{
|
2024-01-30 23:11:12 +08:00
|
|
|
|
operationContext.SetFontAndSize(Font, Size);
|
2017-11-30 06:55:53 +08:00
|
|
|
|
}
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <inheritdoc />
|
2018-12-03 00:14:55 +08:00
|
|
|
|
public void Write(Stream stream)
|
|
|
|
|
{
|
|
|
|
|
stream.WriteText(Font.ToString());
|
|
|
|
|
stream.WriteWhiteSpace();
|
2019-01-04 06:20:53 +08:00
|
|
|
|
stream.WriteNumberText(Size, Symbol);
|
2018-12-03 00:14:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 06:20:53 +08:00
|
|
|
|
/// <inheritdoc />
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2020-07-26 21:14:37 +08:00
|
|
|
|
return $"{Font} {Size.ToString("G", CultureInfo.InvariantCulture)} {Symbol}";
|
2017-11-23 02:41:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|