Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+: Add new method for set character's size. #273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ESCPOS_NET/Emitters/BaseCommandEmitter/CharacterCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,36 @@ namespace ESCPOS_NET.Emitters
public abstract partial class BaseCommandEmitter : ICommandEmitter
{
/* Character Commands */
/// <summary>
/// Select print mode(s)
/// </summary>
/// <param name="style"></param>
/// <returns></returns>
public virtual byte[] SetStyles(PrintStyle style) => new byte[] { Cmd.ESC, Chars.StyleMode, (byte)style };

/// <summary>
/// Select character size. Please reference <see cref="https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=34"/>
/// Value from 0 to 7, 0 for normal size.
/// </summary>
/// <param name="widthMagnification">Enlargement in horizontal direction.</param>
/// <param name="heightMagnification">Enlargement in vertical direction.</param>
/// <returns></returns>
public virtual byte[] SetSize(byte widthMagnification, byte heightMagnification)
{
if (widthMagnification > 7) widthMagnification = 7;
if (heightMagnification > 7) heightMagnification = 7;
Comment on lines +22 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we actually have enums for the magnification parameters? I see 7 is the maximum, but what is the minimum acceptable value for magnification? Does magnification = 1 means it's a regular-sized print?

Perhaps we want to add some validation, like the ones that exist for Barcode commands, in order to prevent users to use out of range magnification values. What do you think?


return [Cmd.GS, Chars.SizeMode, (byte)(widthMagnification * 0x10 + heightMagnification)];
}

/// <summary>
/// Select character size. Please reference <see cref="https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=34"/>
/// Set both width and height magnification in same value.
/// </summary>
/// <param name="magnification">Enlargement in both horizontal and vertical direction.</param>
/// <returns></returns>
public virtual byte[] SetSize(byte magnification) => SetSize(magnification, magnification);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new commands are introduced we need new Unit Tests, or at least include them in the Console Test Suite


public virtual byte[] LeftAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Left };

public virtual byte[] CenterAlign() => new byte[] { Cmd.ESC, Chars.Alignment, (byte)Align.Center };
Expand Down
3 changes: 2 additions & 1 deletion ESCPOS_NET/Emitters/BaseCommandValues/Chars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
public static class Chars
{
public static readonly byte StyleMode = 0x21;
public static readonly byte StyleMode = 0x21;/**ASCII Char: !*/
public static readonly byte SizeMode = StyleMode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if they are always the same, I don't see why use a new one just for SizeMode, let's keep using the StyleMode char also for the Size command

public static readonly byte Alignment = 0x61;
public static readonly byte ReversePrintMode = 0x42;
public static readonly byte RightCharacterSpacing = 0x20;
Expand Down
4 changes: 4 additions & 0 deletions ESCPOS_NET/Emitters/ICommandEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public interface ICommandEmitter
/* Character Commands */
byte[] SetStyles(PrintStyle style);

byte[] SetSize(byte widthMagnification, byte heightMagnification);

byte[] SetSize(byte magnification);

byte[] LeftAlign();

byte[] RightAlign();
Expand Down