From af74ed00c6af107cb2f285ee0377d76d7224be47 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Thu, 5 Oct 2023 14:41:15 +0200 Subject: [PATCH] swap order of encoder search As described by @scott-r in Magic encoder does not use previously used code pages when possible #570 Thank you! --- CHANGELOG.rst | 4 ++++ src/escpos/magicencode.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 958d71b..da44fff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,11 +12,15 @@ changes - has - changed +- fix the encoding search so that lower encodings are found first + contributors ^^^^^^^^^^^^ - list - contributors +- scott-r in [#570](https://github.com/python-escpos/python-escpos/issues/570) + 2023-05-11 - Version 3.0a9 - "Pride Comes Before A Fall" -------------------------------------------------------- This release is the 10th alpha release of the new version 3.0. diff --git a/src/escpos/magicencode.py b/src/escpos/magicencode.py index c9847e1..7cb17be 100644 --- a/src/escpos/magicencode.py +++ b/src/escpos/magicencode.py @@ -155,7 +155,8 @@ class Encoder(object): def __encoding_sort_func(self, item): key, index = item - return (key in self.used_encodings, index) + used = key in self.used_encodings + return (not used, index) def find_suitable_encoding(self, char): """Search in a specific order for a suitable encoding.