-
-
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
Add a command for printing rasterized text #165
base: master
Are you sure you want to change the base?
Conversation
@nickcharlton I merged another PR which bumped imagesharp, could you resolve the merge conflicts? This is really cool, are you able to set widths and auto-wrap text to ensure it doesn't overflow the printer? or do you just have to rasterize each line individually? |
This allows us to print a line with a custom font, sizes and weights which resolves problems with printing text of unsupported sizes (lukevp#132) and unsupported character sets/code pages (lukevp#116) We achieve this by rendering an image with text, sized to fit the text itself and returning `byte[]` to be compatible with other commands. Fixes lukevp#132, lukevp#116
5394789
to
b0b5719
Compare
I've just rebased to get up with those changes. I also added a commit to bump I think we probably could. Could you point me to where I could find out the widths available to us? I'm thinking the nicest solution here is to default to that but still allow overriding. Also, do you have any thoughts on how we could go about testing this too? |
I think everything you mentioned makes sense! There's not really any automated testing in this project, just a console test, since most of the tests require validation on physical hardware to interpret the commands anyway. I think that would be fine here as well, I don't think you need to have automated tests, just a print command in the console test that will print some rasterized stuff. For default widths, I don't know what the defaults are, I think it would depend on the printer DPI and how wide it can print. You could just have a conservative setting that works on most epson printers out of the box for a standard receipt size, and then another for the common smaller paper size. I have printers of both sizes that I could test this on. Regarding system.drawing.common, do you think we could use that instead of imagesharp? I know I picked imagesharp at the onset of the project instead of system.drawing.common for some compatibility reasons, but I'm not certain why. Is it in net standard 2.0? I've added immediate network printing support as it's an often-requested feature, and am releasing version 3.0, can you update this PR again? my apologies. I would love to bring this in to version 3.1. |
font wise, I think a public domain font would be best, if such a thing exists, since the MIT license may conflict with anything stricter than public domain (eg. I don't know how MIT and CC licenses play out together). |
Do you use this for a line of text at a time, and wrap it manually somehow? or don't wrap? |
var bytes = memoryStream.ToArray(); | ||
memoryStream.Dispose(); | ||
|
||
return PrintImage(bytes, true); |
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 would pass in the isHDPI.
This allows us to print a line with a custom font, sizes and weights
which resolves problems with printing text of unsupported sizes (#132)
and unsupported character sets/code pages (#116)
We achieve this by rendering an image with text, sized to fit the text
itself and returning
byte[]
to be compatible with other commands.Fixes #132, #116
I'm opening this as a draft, as I'm a bit stuck on testing and some feedback on the API itself would be great. I'm using this in production currently and it's working quite well.
On the project which this is extracted from, I'm comparing the rendered text to a fixture using a library I cobbled together from some example code. It uses
System.Drawing.Common
, rather thanImageSharp
so one option would be for me to refactor that then use it here, but I'm open to any thoughts on that.Another problem with testing is needing a
ttf
font. A good choice here might be to bundle an open source font for this purpose, but I'm open to ideas.Finally, it's in the command emitters for images, which felt the most appropriate for what it's doing but it could easily go somewhere else.