Skip to content

feat(escpos): add graphics base64 image printing and autoencoding for printer code tables#56

Merged
adcondev merged 4 commits intomasterfrom
feat/base64
Nov 6, 2025
Merged

feat(escpos): add graphics base64 image printing and autoencoding for printer code tables#56
adcondev merged 4 commits intomasterfrom
feat/base64

Conversation

@adcondev
Copy link
Copy Markdown
Owner

@adcondev adcondev commented Nov 6, 2025

Descripción

Tipo de cambio

  • 🐛 Bug fix
  • ✨ Nueva funcionalidad
  • 📚 Solo documentación
  • 🔧 Configuración
  • ♻️ Refactoring
  • 📦 Dependencias

¿Cómo se ha probado?

  • Tests automáticos pasan
  • Probado manualmente
  • N/A (solo docs/config)

Checklist

  • El código sigue las convenciones del proyecto
  • Los tests pasan localmente
  • He actualizado la documentación si era necesario

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:

  • Added a new escpos_encoding.go module that maps ESC/POS code tables to Go encodings, providing robust string encoding via the EncodeString and GetEncoding methods in the Escpos profile. This enables better support for international character sets and code pages.
  • Refactored the Escpos profile struct to use a CodeTable field instead of DefaultCharSet, and updated all profile creation functions (CreatePt210, CreateGP58N, CreateProfile58mm, CreateProfile80mm) to use this new field. [1] [2] [3] [4]

Printer service integration:

  • Updated the printer initialization and text printing methods in escpos_registry.go to use the new encoding logic, ensuring all printed text is encoded according to the selected code table. Added a SetCodeTable method for runtime code table changes. [1] [2] [3] [4]

Dependency and example updates:

  • Added golang.org/x/text as a dependency in go.mod to support extended character encoding.
  • Updated the base64 graphics example to print additional lines with accented and special characters, demonstrating improved encoding support. [1] [2]

Documentation:

  • Minor formatting update in CHANGELOG.md for the base64 image loading feature.

- 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>
Copilot AI review requested due to automatic review settings November 6, 2025 16:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 6, 2025

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

@github-actions github-actions Bot added documentation Improvements or additions to documentation profile dependencies size/M labels Nov 6, 2025
@adcondev adcondev moved this to In review in POS RED2000 Nov 6, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DefaultCharSet to CodeTable across 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.

Comment thread pkg/profile/escpos_encoding.go Outdated
Comment thread pkg/profile/escpos_encoding.go Outdated
Comment thread pkg/service/escpos_registry.go Outdated
- 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>
@adcondev adcondev merged commit d636895 into master Nov 6, 2025
13 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in POS RED2000 Nov 6, 2025
@adcondev adcondev deleted the feat/base64 branch November 6, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies documentation Improvements or additions to documentation profile size/M

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants