ESC-POS-.NET icon indicating copy to clipboard operation
ESC-POS-.NET copied to clipboard

Add a command for printing rasterized text

Open nickcharlton opened this issue 2 years ago • 5 comments

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 than ImageSharp 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.

nickcharlton avatar Feb 09 '22 12:02 nickcharlton

@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?

lukevp avatar Jul 08 '22 23:07 lukevp

I've just rebased to get up with those changes. I also added a commit to bump ImageSharp.Drawing to the latest beta as there were a few changes there too.

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?

nickcharlton avatar Jul 21 '22 11:07 nickcharlton

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.

lukevp avatar Aug 18 '22 00:08 lukevp

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).

lukevp avatar Aug 18 '22 00:08 lukevp

Do you use this for a line of text at a time, and wrap it manually somehow? or don't wrap?

lukevp avatar Aug 18 '22 00:08 lukevp