Skip to content

feat(profile): add typography normalization, multi-codepage switching, and profile presets - #172

Merged
adcondev merged 1 commit into
masterfrom
feat/profile-magic-encode-and-catalog
Oct 18, 2026
Merged

adcondev merged 1 commit into
masterfrom
feat/profile-magic-encode-and-catalog

Conversation

@adcondev

Copy link
Copy Markdown
Owner

Summary (Area 4 of 6)

  • Typography Normalization & Magic Encode (pkg/profile/magic_encode.go, pkg/profile/escpos_encoding.go):
    • Normalize common Unicode typography (smart single/double quotes, en/em dashes, ellipsis, NBSP) to printable ASCII before encoding.
    • Add EncodeBytesSafe(text string) ([]byte, error) supporting mid-string ESC t n (0x1B 0x74 n) automatic code page switching (AutoSwitchCodePage, FallbackCodePages) and non-fatal '?' replacement (or opt-in StrictEncoding: true).
    • Expand ParseCodeTable and constants.ValidCodeTables to all 25+ supported ESC/POS code tables (PC437, PC850, PC852, PC855, PC858, PC860, PC862, PC863, PC865, PC866, WPC1250–1258, ISO8859-2/7/15, Katakana, Hiragana, ShiftJIS).
  • Commercial Printer Profile Catalog (pkg/profile/profile_factory.go):
    • Add presets for CreateEpsonTMT20III, CreateEpsonTMT88VI, CreateStarTSP100, CreateBixolonSRP350III, CreateXprinterXP58, CreateXprinterXP80, and ProfileFromModel(model string).
  • Executor & CLI Integration (pkg/document/executor/handler_executor.go, cmd/poster/parsing.go, pkg/service/printer_service.go):
    • Preserve 58mm paper width (384 dots) when PaperWidth: 0 is passed with a 58mm model preset.
    • Wire service.Printer.Print to EncodeBytesSafe.

@github-actions

Copy link
Copy Markdown
Contributor

👋 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

@adcondev
adcondev merged commit 2973fd6 into master Oct 18, 2026
12 checks passed
@adcondev
adcondev deleted the feat/profile-magic-encode-and-catalog branch October 18, 2026 19:21
@github-actions

Copy link
Copy Markdown
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Benchmark Results

📈 Performance Comparison

📊 Click to expand detailed results

Current Branch Results

BenchmarkNewDocument-4    	1000000000	         0.2926 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3444472	       346.5 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  405982	      2962 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  599170	      1942 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  536004	      2158 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	  107343	     10951 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  453805	      2597 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  290512	      4065 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  563023	      2136 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  263673	      4548 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	 8735839	       136.7 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 7664605	       155.3 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	207520796	         5.776 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	29510278	        41.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	16395567	        72.87 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  528670	      2214 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  164559	      7345 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     537	   2192562 ns/op	 3469932 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     282	   4242624 ns/op	 5481078 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     135	   8628758 ns/op	 5231171 B/op	  230423 allocs/op

Base Branch Results

BenchmarkNewDocument-4    	1000000000	         0.2890 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3499160	       348.1 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  412681	      2906 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  597354	      1911 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  551700	      2137 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	  110822	     10847 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  448550	      2535 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  290299	      4107 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  562840	      2017 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  258238	      4679 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	 8805638	       136.1 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 7641291	       156.4 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	315823830	         3.800 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	30415767	        40.10 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	16380694	        72.86 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  513650	      2201 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  162340	      7249 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     552	   2196393 ns/op	 3469942 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     283	   4241983 ns/op	 5481076 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     139	   8626513 ns/op	 5231172 B/op	  230423 allocs/op

💡 Note: Use benchstat for statistical comparison

🎯 Summary

  • Total Benchmarks: 32
  • Average Speed: 2903162 ns/op
  • Average Memory: 2396163 B/op
  • Average Allocations: 41077 allocs/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant