feat(escpos): add graphics base64 image printing and autoencoding for printer code tables#56
Merged
feat(escpos): add graphics base64 image printing and autoencoding for printer code tables#56
Conversation
- Implement LoadFromBase64 function to decode base64-encoded strings into image.Image objects. - Update existing image loading functions for consistency. - Enhance the ESC/POS protocol with character code table selection. This change improves the flexibility of image handling for printing tasks, allowing images to be loaded from base64 encoded data. Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
- Introduced a new encoding mechanism for ESC/POS character tables - Added a mapping of code tables to Go encodings - Implemented methods for encoding strings and selecting code tables - Updated printer methods to utilize the new encoding functionality Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
- Bump version to 2.1.0 to reflect new features - Document base64 image loading functionality in CHANGELOG Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Contributor
|
👋 Thanks for opening this PR, @adcondev! Here's what will happen next:
Please make sure:
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds character encoding support to the POS printer library, enabling proper text encoding based on configurable code tables. The implementation leverages the golang.org/x/text package to convert UTF-8 strings to various character encodings supported by ESC/POS printers.
Key changes:
- Introduced character encoding functionality with support for multiple code pages (CP437, CP850, Windows-1252, etc.)
- Refactored printer initialization and text printing methods to use profile-based code table configuration
- Renamed
DefaultCharSettoCodeTableacross profiles for consistency
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/profile/escpos_encoding.go | New file implementing encoding logic with mappings from ESC/POS code tables to Go encodings |
| pkg/service/escpos_registry.go | Updated Initialize(), Print(), PrintLine() to use encoding; added SetCodeTable() method |
| pkg/profile/escpos_profile.go | Renamed DefaultCharSet to CodeTable; added Dithering field; removed unused helper methods |
| go.mod, go.sum | Added golang.org/x/text v0.30.0 dependency |
| examples/graphics/base64/base64_example.go | Updated example text to demonstrate special character printing |
| CHANGELOG.md | Formatting change to feature entry |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Refactor EncodeString to return a string instead of bytes - Improve error messages for unsupported code tables - Add IsSupported method to check code table support - Update GetEncoding to log warnings for unsupported encodings Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Descripción
Tipo de cambio
¿Cómo se ha probado?
Checklist
Notas adicionales
This pull request introduces improved character encoding support for ESC/POS printers, refactoring how code tables are managed and adding support for more encodings. It also updates the printer profile structure, enhances text printing to use the new encoding logic, and makes minor updates to the graphics example and dependencies.
Character encoding and code table improvements:
escpos_encoding.gomodule that maps ESC/POS code tables to Go encodings, providing robust string encoding via theEncodeStringandGetEncodingmethods in theEscposprofile. This enables better support for international character sets and code pages.Escposprofile struct to use aCodeTablefield instead ofDefaultCharSet, and updated all profile creation functions (CreatePt210,CreateGP58N,CreateProfile58mm,CreateProfile80mm) to use this new field. [1] [2] [3] [4]Printer service integration:
escpos_registry.goto use the new encoding logic, ensuring all printed text is encoded according to the selected code table. Added aSetCodeTablemethod for runtime code table changes. [1] [2] [3] [4]Dependency and example updates:
golang.org/x/textas a dependency ingo.modto support extended character encoding.Documentation:
CHANGELOG.mdfor the base64 image loading feature.