Skip to content

Commit

Permalink
Add Arial font in addition to Helvetica
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Dec 1, 2022
1 parent d44daf5 commit ee87370
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
ChangeLog
=========

Unreleased
----------

- Add Arial font name in addition to Helvetica for better font fallback on some
systems.

1.0.0 (2022-09-21)
------------------
- BREAKING: Removed the ``due-date`` command line argument and the ``due_date``
Expand Down
9 changes: 5 additions & 4 deletions qrbill/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class QRBill:
allowed_currencies = ('CHF', 'EUR')
# QR reference, Creditor Reference (ISO 11649), without reference
reference_types = ('QRR', 'SCOR', 'NON')
font_family = 'Arial,Helvetica'

def __init__(
self, account=None, creditor=None, final_creditor=None, amount=None,
Expand Down Expand Up @@ -365,20 +366,20 @@ def __init__(

@property
def title_font_info(self):
return {'font_size': 12 * self.font_factor, 'font_family': 'Helvetica', 'font_weight': 'bold'}
return {'font_size': 12 * self.font_factor, 'font_family': self.font_family, 'font_weight': 'bold'}

@property
def font_info(self):
return {'font_size': 10 * self.font_factor, 'font_family': 'Helvetica'}
return {'font_size': 10 * self.font_factor, 'font_family': self.font_family}

def head_font_info(self, part=None):
return {
'font_size': (8 if part == 'receipt' else 9) * self.font_factor,
'font_family': 'Helvetica', 'font_weight': 'bold'}
'font_family': self.font_family, 'font_weight': 'bold'}

@property
def proc_font_info(self):
return {'font_size': 7 * self.font_factor, 'font_family': 'Helvetica'}
return {'font_size': 7 * self.font_factor, 'font_family': self.font_family}

def qr_data(self):
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_qrbill.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def test_spec_example1(self):
bill.as_svg(fh.name)
content = strip_svg_path(fh.read().decode())
self.assertTrue(content.startswith('<?xml version="1.0" encoding="utf-8" ?>'))
font9 = 'font-family="Helvetica" font-size="9" font-weight="bold"'
font10 = 'font-family="Helvetica" font-size="10"'
font9 = 'font-family="Arial,Helvetica" font-size="9" font-weight="bold"'
font10 = 'font-family="Arial,Helvetica" font-size="10"'
# Test the Payable by section:
expected = (
'<text {font9} x="{x}" y="{y1}">Payable by</text>'
Expand Down Expand Up @@ -476,13 +476,13 @@ def test_font_factor(self):
)
content = strip_svg_path(self._produce_svg(bill))
self.assertIn(
'<text font-family="Helvetica" font-size="18.0" font-weight="bold"'
'<text font-family="{ffamily}" font-size="18.0" font-weight="bold"'
' x="17.71654" y="{y1}">Receipt</text>'
'<text font-family="Helvetica" font-size="12.0" font-weight="bold"'
'<text font-family="{ffamily}" font-size="12.0" font-weight="bold"'
' x="17.71654" y="{y2}">Account / Payable to</text>'
'<text font-family="Helvetica" font-size="15.0" x="17.71654"'
'<text font-family="{ffamily}" font-size="15.0" x="17.71654"'
' y="{y3}">CH53 8000 5000 0102 8366 4</text>'.format(
y1=mm(11), y2=mm(16), y3=mm(19.5)
ffamily='Arial,Helvetica', y1=mm(11), y2=mm(16), y3=mm(19.5)
),
content
)
Expand Down

0 comments on commit ee87370

Please sign in to comment.