-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Added support for printing Aztec codes and setting left margin print position #217
Open
jwikberg
wants to merge
4
commits into
lukevp:master
Choose a base branch
from
jwikberg:feature/add-aztec-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using ESCPOS_NET.Emitters; | ||
|
||
namespace ESCPOS_NET.ConsoleTest | ||
{ | ||
public static partial class Tests | ||
{ | ||
public static byte[][] Position(ICommandEmitter e) => new byte[][] { | ||
e.SetLeftMargin(0), | ||
e.PrintLine("Left Margin: This is 0 left margin."), | ||
e.SetLeftMargin(10), | ||
e.PrintLine("Left Margin: This is 10 left margin."), | ||
e.SetLeftMargin(20), | ||
e.PrintLine("Left Margin: This is 20 left margin."), | ||
e.SetLeftMargin(30), | ||
e.PrintLine("Left Margin: This is 30 left margin."), | ||
e.SetLeftMargin(0), | ||
e.PrintLine("Left Margin: This is 0 left margin."), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
ESCPOS_NET/Emitters/BaseCommandEmitter/PrintPositionCommands.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using ESCPOS_NET.Emitters.BaseCommandValues; | ||
|
||
namespace ESCPOS_NET.Emitters | ||
{ | ||
public abstract partial class BaseCommandEmitter : ICommandEmitter | ||
{ | ||
public virtual byte[] SetLeftMargin(int leftMargin) => new byte[] { Cmd.GS, PrintPosition.LeftMargin, (byte)leftMargin, 0x0 }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ESCPOS_NET.Emitters.BaseCommandValues | ||
{ | ||
public static class PrintPosition | ||
{ | ||
public static readonly byte LeftMargin = 0x4C; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any validations we could do for this command? Perhaps regarding the size of data, or min/max on correction level and layers?
Take a look at DataValidator class and see if you can implement some similar guardrails for this command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igorocampos Hi, I finally had some time to look at this again.
I've added validation of the data size by using ZXing.Net.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you added a new dependency to the project in order to validate the data size, is there other way of validating it? I don't think we want to add external dependencies like that in the project. The empty catch is not helping much either, you are just re-throwing the very same without any friendly details to the library user, in that case, why have the try at all? As a library user, if I provide an invalid size for the data, I would like to receive a message saying at least:
1 - The data I used was not in an acceptable size
2 - What is the acceptable size
Similar to what you have done to Module Size, I guess. Other than that I would just keep the empty new lines in the end of the files, but I can open new suggestion regarding that in the review, so you can solve them as easy as a button click :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jwikberg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igorocampos If I'm not completely mistaken, the problem with validating the data length for an Aztec is that you need to start encoding it to see if it's too big when it's close to the maximum size.
It's not as simple as validating the length of a string or the number of bytes that translates to before encoding it.
I've tried to confirm this by generating random strings that are 3067 letters long, which is the maximum of an Aztec, and that will fail to print if I mix upper and lowercase letters but succeed if the string is either only upper or lowercase.
Encoding the strings with ZXing.Net matches the printer's behavior and throws an exception for the string that can't be printed.
So either I'd have to implement the entire logic for encoding the data or use a lib for it, unless there is something I'm missing of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, perhaps that one validation should not be implemented. I think the "price" is too high. @lukevp do you agree?