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;
|
2017-11-30 06:55:53 +08:00
|
|
|
|
using Content;
|
2017-11-23 02:41:34 +08:00
|
|
|
|
using Cos;
|
2017-12-29 00:58:52 +08:00
|
|
|
|
using Util.JetBrains.Annotations;
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
2017-11-30 06:55:53 +08:00
|
|
|
|
internal class SetFontAndSize : IGraphicsStateOperation
|
2017-11-23 02:41:34 +08:00
|
|
|
|
{
|
|
|
|
|
public const string Symbol = "Tf";
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
[NotNull]
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public CosName Font { get; }
|
|
|
|
|
|
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>
|
2017-11-23 02:41:34 +08:00
|
|
|
|
public decimal Size { get; }
|
|
|
|
|
|
2017-11-30 06:55:53 +08:00
|
|
|
|
public SetFontAndSize(CosName font, decimal 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;
|
|
|
|
|
}
|
2017-11-30 06:55:53 +08:00
|
|
|
|
|
|
|
|
|
public void Run(IOperationContext operationContext, IResourceStore resourceStore)
|
|
|
|
|
{
|
|
|
|
|
var currentState = operationContext.GetCurrentState();
|
|
|
|
|
|
|
|
|
|
currentState.FontState.FontSize = Size;
|
|
|
|
|
currentState.FontState.FontName = Font;
|
|
|
|
|
}
|
2017-11-23 02:41:34 +08:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{Font} {Size} {Symbol}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|