Repository: claudep/swiss-qr-bill

Issue:
Add a font factor parameter
In certain cases, the font sizes may be judged a bit too small or too large. Adding a font-factor parameter could allow the user to specify a custom scaling factor for fonts.

Discussion:
claudep: @AntonMezger Do you think this patch might help you?
AntonMezger: We are actually away, but we will see to it next week. Thanks a lot for your awesome work!
AntonMezger: Hi Claude,

tried it out and it works fine (I use 1.1 to increase slightly my fonts. Thanks a lot.
AntonMezger: Hi Claude,

 

Thank you for that feature; it works fine.

 

However I got from UBS again some remarks. On our payments, the QR code is 44 mm instead of 46 mm and the 5mm from borders were also not very exact. I ordered now special QR perforated paper in order to make the fine adjustments and I hope they will be happy then, but I think they are a little bit picky (pinailleur en fr)

 

Best regards

 

Anne-Chantal

 

De : Claude Paroz ***@***.***> 
Envoyé : samedi 24 avril 2021 16:47
À : claudep/swiss-qr-bill ***@***.***>
Cc : Anton Mezger ***@***.***>; Mention ***@***.***>
Objet : Re: [claudep/swiss-qr-bill] Fixes #55 - Add a font_factor argument to bills (#63)

 

@AntonMezger <https://github.com/AntonMezger>  Do you think this patch might help you?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <https://github.com/claudep/swiss-qr-bill/pull/63#issuecomment-826103667> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADDFIKEGJNU4F2HYQL4HHADTKLKVZANCNFSM43QGX3WA> .



Patch:
diff --git a/qrbill/bill.py b/qrbill/bill.py
index a175623..7f6c186 100644
--- a/qrbill/bill.py
+++ b/qrbill/bill.py
@@ -198,15 +198,10 @@ class QRBill:
     # QR reference, Creditor Reference (ISO 11649), without reference
     reference_types = ('QRR', 'SCOR', 'NON')
 
-    title_font_info = {'font_size': 12, 'font_family': 'Helvetica', 'font_weight': 'bold'}
-    font_info = {'font_size': 10, 'font_family': 'Helvetica'}
-    head_font_info = {'font_size': 8, 'font_family': 'Helvetica', 'font_weight': 'bold'}
-    proc_font_info = {'font_size': 7, 'font_family': 'Helvetica'}
-
     def __init__(
             self, account=None, creditor=None, final_creditor=None, amount=None,
             currency='CHF', due_date=None, debtor=None, ref_number=None, extra_infos='',
-            alt_procs=(), language='en', top_line=True, payment_line=True):
+            alt_procs=(), language='en', top_line=True, payment_line=True, font_factor=1):
         """
         Arguments
         ---------
@@ -232,6 +227,8 @@ class QRBill:
             print a horizontal line at the top of the bill
         payment_line: bool
             print a vertical line between the receipt and the bill itself
+        font_factor: integer
+            a zoom factor for all texts in the bill
         """
         # Account (IBAN) validation
         if not account:
@@ -344,6 +341,23 @@ class QRBill:
         self.language = language
         self.top_line = top_line
         self.payment_line = payment_line
+        self.font_factor = font_factor
+
+    @property
+    def title_font_info(self):
+        return {'font_size': 12 * self.font_factor, 'font_family': 'Helvetica', 'font_weight': 'bold'}
+
+    @property
+    def font_info(self):
+        return {'font_size': 10 * self.font_factor, 'font_family': 'Helvetica'}
+
+    @property
+    def head_font_info(self):
+        return {'font_size': 8 * self.font_factor, 'font_family': 'Helvetica', 'font_weight': 'bold'}
+
+    @property
+    def proc_font_info(self):
+        return {'font_size': 7 * self.font_factor, 'font_family': 'Helvetica'}
 
     def qr_data(self):
         """
diff --git a/scripts/qrbill b/scripts/qrbill
index edc153d..81e7375 100644
--- a/scripts/qrbill
+++ b/scripts/qrbill
@@ -88,6 +88,8 @@ def run():
                         help='Do not print top separation line')
     parser.add_argument('--no-payment-line', dest="payment_line", default=True, action='store_false',
                         help='Do not print vertical separation line between receipt and payment parts')
+    parser.add_argument('--font-factor', dest="font_factor", default=1.0, type=float,
+                        help='Font factor to provide a zoom for all texts on the bill')
 
     args = parser.parse_args()
     creditor = {
@@ -128,6 +130,7 @@ def run():
             language=args.language,
             top_line=args.top_line,
             payment_line=args.payment_line,
+            font_factor=args.font_factor,
         )
     except ValueError as err:
         sys.exit("Error: %s" % err)


Test patch:
diff --git a/tests/test_qrbill.py b/tests/test_qrbill.py
index 192bcd6..9fa8d21 100644
--- a/tests/test_qrbill.py
+++ b/tests/test_qrbill.py
@@ -428,6 +428,24 @@ class QRBillTests(unittest.TestCase):
         )
         self.assertEqual(self._produce_svg(bill)[:40], '<?xml version="1.0" encoding="utf-8" ?>\n')
 
+    def test_font_factor(self):
+        bill = QRBill(
+            account="CH 53 8000 5000 0102 83664",
+            creditor={
+                'name': 'Jane', 'pcode': '1000', 'city': 'Lausanne',
+            },
+            font_factor=1.5
+        )
+        self.assertIn(
+            '<text font-family="Helvetica" font-size="18.0" font-weight="bold"'
+            ' x="17.71654" y="35.43307">Receipt</text>'
+            '<text font-family="Helvetica" font-size="12.0" font-weight="bold"'
+            ' x="17.71654" y="53.14961">Account / Payable to</text>'
+            '<text font-family="Helvetica" font-size="15.0" x="17.71654"'
+            ' y="65.55118">CH53 8000 5000 0102 8366 4</text>',
+            self._produce_svg(bill)
+        )
+
 
 class CommandLineTests(unittest.TestCase):
     def test_no_args(self):