Skip to content

Commit

Permalink
Merge branch 'release/0.2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
heuer committed Apr 24, 2019
2 parents eddbe2a + 8bff00c commit 64d912a
Show file tree
Hide file tree
Showing 57 changed files with 181 additions and 91 deletions.
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Changes
=======

0.2.8 -- 2018-19-17
0.2.9 -- 2019-04-24
-------------------
* Fixed typos
* PDF serializer: Added support for stroke and background color,
initial code contributed by Serge Morel (pr #52).


0.2.8 -- 2018-10-17
-------------------
* Fixed #45: CLI does not raise exceptions but indicates errors with return code 1 and
writes the error message to ``sys.stderr``
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Portable Document Format (PDF), Portable Bitmap (PBM), Portable Arbitrary Map (P
LaTeX (PGF/TikZ), X PixMap (XBM), X Bitmap (XPM) or text output. None of these
serializers require an external lib. Segno could provide more serialization
formats via a plugin architecture.
Further, it provides several high level function to create QR Codes which encode
Further, it provides several high level functions to create QR Codes which encode
contact data (MeCard, vCard) or WIFI configurations.


Expand Down
6 changes: 3 additions & 3 deletions docs/_static/chart_create.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/_static/chart_png.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/_static/chart_svg.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/comparison-qrcode-libs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Features
Description `qrcode`_ `PyQRCode`_ `qrcodegen`_ `Segno`_
============================================ ================== =================== ================== ========
Library license `BSD`_ `BSD`_ `MIT`_ `BSD`_
Library version 6.0 1.3.0 1.2.0 |version|
Library version 6.1 1.3.0 1.3.0 |version|
Mode Numeric Yes Yes Yes Yes
Mode Alphanumeric Yes Yes Yes Yes
Mode Byte Yes Yes Yes Yes
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Segno - Python QR Code and Micro QR Code encoder
================================================

Segno generates QR Codes and Micro QR Codes according to ``ISO/IEC 18004:2015(E)``.
Aside from other Pyhton QR Code generators, Segno has no 3rd party dependencies
Aside from other Python QR Code generators, Segno has no 3rd party dependencies
and is very simple to use.

Contents:
Expand Down
6 changes: 3 additions & 3 deletions sandbox/out/chart_create.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions sandbox/out/chart_png.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions sandbox/out/chart_svg.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions sandbox/out/results.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PyQRCode create,30.10
qrcodegen create,16.76
qrcode create,12.29
Segno create,13.46
PyQRCode SVG,31.62
qrcodegen SVG,17.97
qrcode SVG path,60.00
qrcode SVG rects,53.79
Segno SVG,14.25
PyQRCode PNG,119.23
qrcode PNG,17.16
Segno PNG,19.01
PyQRCode create,28.89
qrcodegen create,16.72
qrcode create,12.44
Segno create,13.14
PyQRCode SVG,35.06
qrcodegen SVG,18.51
qrcode SVG path,61.90
qrcode SVG rects,55.35
Segno SVG,15.85
PyQRCode PNG,120.46
qrcode PNG,17.84
Segno PNG,19.80
4 changes: 2 additions & 2 deletions segno/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand All @@ -21,7 +21,7 @@
except NameError: # pragma: no cover
str_type = str

__version__ = '0.2.8'
__version__ = '0.2.9'

__all__ = ('make', 'make_qr', 'make_micro', 'make_sequence', 'QRCode',
'QRCodeSequence', 'QRCodeError', 'ErrorLevelError', 'ModeError',
Expand Down
2 changes: 1 addition & 1 deletion segno/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion segno/colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion segno/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
6 changes: 3 additions & 3 deletions segno/encoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand All @@ -25,7 +25,7 @@
numeric = int
except ImportError: # pragma: no cover
_PY2 = True
from itertools import izip_longest as zip_longest
from itertools import izip_longest as zip_longest, imap as map
str_type = basestring
from numbers import Number
numeric = Number
Expand Down Expand Up @@ -895,7 +895,7 @@ def score_n4(matrix, matrix_size):
:param matrix_size: The width (or height) of the matrix.
:return int: The penalty score (feature 4) of the matrix.
"""
dark_modules = sum([sum(row) for row in matrix])
dark_modules = sum(map(sum, matrix))
total_modules = matrix_size ** 2
k = int(abs(dark_modules * 2 - total_modules) * 10 // total_modules)
return 10 * k # N4 = 10
Expand Down
2 changes: 1 addition & 1 deletion segno/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion segno/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
42 changes: 35 additions & 7 deletions segno/writers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down Expand Up @@ -332,7 +332,7 @@ def to_float(c):
raise ValueError('Invalid color "{0}". Not in range 0 .. 1'
.format(c))
return c
return 1/255.0 * c if c != 1 else c
return 1 / 255.0 * c if c != 1 else c

return tuple([to_float(i) for i in colors.color_to_rgb(clr)])

Expand Down Expand Up @@ -579,7 +579,8 @@ def as_png_data_uri(matrix, version, scale=1, border=None, color='#000',
.format(base64.b64encode(buff.getvalue()).decode('ascii'))


def write_pdf(matrix, version, out, scale=1, border=None, compresslevel=9):
def write_pdf(matrix, version, out, scale=1, border=None, color='#000',
background=None, compresslevel=9):
"""\
Serializes the QR Code as PDF document.
Expand All @@ -591,6 +592,11 @@ def write_pdf(matrix, version, out, scale=1, border=None, compresslevel=9):
:param int border: Integer indicating the size of the quiet zone.
If set to ``None`` (default), the recommended border size
will be used (``4`` for QR Codes, ``2`` for a Micro QR Codes).
:param color: Color of the modules (default: black). The
color can be provided as ``(R, G, B)`` tuple, as web color name
(like "red") or in hexadecimal format (``#RGB`` or ``#RRGGBB``).
:param background: Optional background color (default: ``None`` = no
background color). See `color` for valid values.
:param int compresslevel: Integer indicating the compression level
(default: 9). 1 is fastest and produces the least
compression, 9 is slowest and produces the most.
Expand All @@ -600,6 +606,20 @@ def write_pdf(matrix, version, out, scale=1, border=None, compresslevel=9):
def write_string(writemeth, s):
writemeth(s.encode('ascii'))

def to_pdf_color(clr):
"""\
Converts the provided color into an acceptable format for PDF's
"DeviceRGB" color space.
"""
def to_float(c):
if isinstance(c, float):
if not 0.0 <= c <= 1.0:
raise ValueError('Invalid color "{0}". Not in range 0 .. 1'
.format(c))
return c
return 1 / 255.0 * c if c != 1 else c
return tuple([to_float(i) for i in colors.color_to_rgb(clr)])

check_valid_scale(scale)
check_valid_border(border)
width, height = get_symbol_size(version, scale, border)
Expand All @@ -610,17 +630,25 @@ def write_string(writemeth, s):
cmds = []
append_cmd = cmds.append
if scale > 1:
append_cmd('{0} 0 0 {0} 0 0 cm '.format(scale))
append_cmd('{0} 0 0 {0} 0 0 cm'.format(scale))
if background is not None:
# If the background color is defined, a rect is drawn in the background
append_cmd('{} {} {} rg'.format(*to_pdf_color(background)))
append_cmd('0 0 {} {} re'.format(width, height))
append_cmd('f q')
# Set the stroke color only iff it is not black (default)
if not colors.color_is_black(color):
append_cmd('{} {} {} RG'.format(*to_pdf_color(color)))
# Current pen position y-axis
# Note: 0, 0 = lower left corner in PDF coordinate system
y = get_symbol_size(version, scale=1, border=0)[1] + border - .5
# Set the origin in the upper left corner
append_cmd('1 0 0 1 {0} {1} cm'.format(border, y))
# PDF supports absolute coordinates, only
for (x1, y1), (x2, y2) in matrix_to_lines(matrix, 0, 0, incby=-1):
append_cmd(' {0} {1} m {2} {1} l'.format(x1, y1, x2, y2))
append_cmd(' S')
graphic = zlib.compress((''.join(cmds)).encode('ascii'), compresslevel)
append_cmd('{0} {1} m {2} {1} l'.format(x1, y1, x2, y2))
append_cmd('S')
graphic = zlib.compress((' '.join(cmds)).encode('ascii'), compresslevel)
with writable(out, 'wb') as f:
write = f.write
writestr = partial(write_string, write)
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down Expand Up @@ -56,9 +56,14 @@ def read(*filenames, **kwargs):
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Multimedia :: Graphics',
'Topic :: Printing',
'Topic :: Software Development :: Libraries :: Python Modules',
Expand Down
2 changes: 1 addition & 1 deletion tests/alltests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_boosterror.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_error_code():
('pbm', b'P4\n', 'rb'),
('xbm', '#define ', 'rt'),
('xpm', '/* XPM */', 'rt'),
('tex', '%% Creator: ', 'rt'),])
('tex', '% Creator: ', 'rt'),])
def test_output(arg, ext, expected, mode):
f = tempfile.NamedTemporaryFile('w', suffix='.{0}'.format(ext), delete=False)
f.close()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data_uri.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_encoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_eps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue18.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue23_boosterror.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue32_svg2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue33_microcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue34_errorlevel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issue35_maskcheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 - 2018 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# Copyright (c) 2016 - 2019 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
Expand Down

0 comments on commit 64d912a

Please sign in to comment.