PDF: Remove whitespace from qr-codes (backwards-compatible)

This commit is contained in:
Raphael Michel
2021-04-16 17:44:05 +02:00
parent 7c07a6581e
commit 3ea1a92716
3 changed files with 19 additions and 9 deletions

View File

@@ -597,7 +597,10 @@ class Renderer:
if len(content) > 128: if len(content) > 128:
level = 'L' level = 'L'
reqs = float(o['size']) * mm reqs = float(o['size']) * mm
qrw = QrCodeWidget(content, barLevel=level, barHeight=reqs, barWidth=reqs) kwargs = {}
if o.get('nowhitespace', False):
kwargs['barBorder'] = 0
qrw = QrCodeWidget(content, barLevel=level, barHeight=reqs, barWidth=reqs, **kwargs)
d = Drawing(reqs, reqs) d = Drawing(reqs, reqs)
d.add(qrw) d.add(qrw)
qr_x = float(o['left']) * mm qr_x = float(o['left']) * mm

View File

@@ -249,12 +249,14 @@
</div> </div>
<div class="row control-group squaresize"> <div class="row control-group squaresize">
<div class="col-sm-12"> <div class="col-sm-12">
<p> <div class="checkbox">
{% blocktrans trimmed %} <label class="">
The final QR code will be slightly smaller because some whitespace is required <input type="checkbox" value="off" class="checkbox"
for proper scanning. id="toolbox-qrwhitespace">
{% endblocktrans %} {% trans "Render without whitespace" %}
</p> </label><br>
<span class="text-muted">{% trans "Required for consistent size across platforms. Supported on Android starting with pretixPRINT 2.3.3 and on Desktop with pretixSCAN 1.9.3." %}</span>
</div>
</div> </div>
</div> </div>
<div class="row control-group text"> <div class="row control-group text">

View File

@@ -181,6 +181,7 @@ var editor = {
bottom: editor._px2mm(editor.pdf_viewport.height - o.height * o.scaleY - top).toFixed(2), bottom: editor._px2mm(editor.pdf_viewport.height - o.height * o.scaleY - top).toFixed(2),
size: editor._px2mm(o.height * o.scaleY).toFixed(2), size: editor._px2mm(o.height * o.scaleY).toFixed(2),
content: o.content, content: o.content,
nowhitespace: o.nowhitespace || false,
}); });
} else if (o.type === "poweredby") { } else if (o.type === "poweredby") {
d.push({ d.push({
@@ -200,6 +201,7 @@ var editor = {
o = editor._add_qrcode(); o = editor._add_qrcode();
o.content = d.content; o.content = d.content;
o.scaleToHeight(editor._mm2px(d.size)); o.scaleToHeight(editor._mm2px(d.size));
o.nowhitespace = d.nowhitespace || false;
} else if (d.type === "imagearea") { } else if (d.type === "imagearea") {
o = editor._add_imagearea(d.content); o = editor._add_imagearea(d.content);
o.content = d.content; o.content = d.content;
@@ -398,6 +400,7 @@ var editor = {
if (o.type === "barcodearea") { if (o.type === "barcodearea") {
$("#toolbox-squaresize").val(editor._px2mm(o.height * o.scaleY).toFixed(2)); $("#toolbox-squaresize").val(editor._px2mm(o.height * o.scaleY).toFixed(2));
$("#toolbox-qrwhitespace").prop("checked", o.nowhitespace || false);
} else if (o.type === "imagearea") { } else if (o.type === "imagearea") {
$("#toolbox-height").val(editor._px2mm(o.height * o.scaleY).toFixed(2)); $("#toolbox-height").val(editor._px2mm(o.height * o.scaleY).toFixed(2));
$("#toolbox-width").val(editor._px2mm(o.width * o.scaleX).toFixed(2)); $("#toolbox-width").val(editor._px2mm(o.width * o.scaleX).toFixed(2));
@@ -457,6 +460,7 @@ var editor = {
o.setScaleX(1); o.setScaleX(1);
o.setScaleY(1); o.setScaleY(1);
o.set('top', new_top) o.set('top', new_top)
o.nowhitespace = $("#toolbox-qrwhitespace").prop("checked") || false;
} else if (o.type === "imagearea") { } else if (o.type === "imagearea") {
var new_w = editor._mm2px($("#toolbox-width").val()); var new_w = editor._mm2px($("#toolbox-width").val());
var new_h = editor._mm2px($("#toolbox-height").val()); var new_h = editor._mm2px($("#toolbox-height").val());
@@ -614,6 +618,7 @@ var editor = {
lockUniScaling: true, lockUniScaling: true,
fill: '#666', fill: '#666',
content: $(this).attr("data-content"), content: $(this).attr("data-content"),
nowhitespace: true,
}); });
rect.setControlsVisibility({'mtr': false}); rect.setControlsVisibility({'mtr': false});
editor.fabric.add(rect); editor.fabric.add(rect);
@@ -918,9 +923,9 @@ var editor = {
} }
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled'); }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
$("#toolbox input[type=number], #toolbox textarea, #toolbox input[type=text]").bind('change keydown keyup' + $("#toolbox input[type=number], #toolbox textarea, #toolbox input[type=text], #toolbox input[type=checkbox]").bind('change keydown keyup' +
' input', editor._update_values_from_toolbox); ' input', editor._update_values_from_toolbox);
$("#toolbox input[type=number], #toolbox textarea, #toolbox input[type=text], #toolbox input[type=radio]").bind('change', editor._create_savepoint); $("#toolbox input[type=number], #toolbox textarea, #toolbox input[type=text], #toolbox input[type=checkbox], #toolbox input[type=radio]").bind('change', editor._create_savepoint);
$("#toolbox label.btn").bind('click change', editor._update_values_from_toolbox); $("#toolbox label.btn").bind('click change', editor._update_values_from_toolbox);
$("#toolbox select").bind('change', editor._update_values_from_toolbox); $("#toolbox select").bind('change', editor._update_values_from_toolbox);
$("#toolbox select").bind('change', editor._create_savepoint); $("#toolbox select").bind('change', editor._create_savepoint);