PDF editor: New text element implementation (#4246)

* draft

* almost working

* Widgth adjustment

* Fix crash on empty text

* Change default layouts

* Fix editor bugs

* Update src/pretix/control/templates/pretixcontrol/pdf/index.html

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Show deprecated text on old text

* lockScalingFlip

* Regroup editor controls

* Update src/pretix/static/pretixcontrol/js/ui/main.js

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Update src/pretix/static/pretixcontrol/js/ui/main.js

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Update src/pretix/static/pretixcontrol/js/ui/main.js

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Update src/pretix/static/pretixcontrol/js/ui/editor.js

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Increase default height even further

* Add a small version warning

* Update src/pretix/control/templates/pretixcontrol/pdf/index.html

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Update src/pretix/control/templates/pretixcontrol/pdf/index.html

Co-authored-by: Richard Schreiber <schreiber@rami.io>

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2024-08-07 11:26:47 +02:00
committed by GitHub
parent a682eab18e
commit 022f44ad00
7 changed files with 775 additions and 263 deletions

View File

@@ -30,11 +30,11 @@ def _simple_template(w, h):
company_size = name_size - 2
return [
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "5.00",
"bottom": "%.2f" % (((h - company_size * 1.5 - name_size) / 2 + company_size * 1.5) / mm),
"bottom": "%.2f" % (h / mm / 2 + 2),
"fontsize": name_size,
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -42,19 +42,22 @@ def _simple_template(w, h):
"bold": True,
"italic": False,
"width": "%.2f" % (w / mm - 10),
"downward": False,
"height": "%.2f" % (h / mm / 2 - 7),
"content": "attendee_name",
"text": "John Doe",
"text": "Dr John Doe",
"text_i18n": {},
"rotation": 0,
"align": "center",
"verticalalign": "bottom",
"autoresize": True,
"splitlongwords": False,
},
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "5.00",
"bottom": "%.2f" % ((((h - company_size * 1.5 - name_size) / 2) + company_size) / mm),
"bottom": "5.00",
"fontsize": company_size,
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -62,12 +65,15 @@ def _simple_template(w, h):
"bold": False,
"italic": False,
"width": "%.2f" % (w / mm - 10),
"downward": True,
"height": "%.2f" % (h / mm / 2 - 7),
"content": "attendee_company",
"text": "Sample company",
"text_i18n": {},
"rotation": 0,
"align": "center",
"verticalalign": "top",
"autoresize": True,
"splitlongwords": False,
},
]
@@ -94,15 +100,17 @@ TEMPLATES = {
"layout": _simple_template(*pagesizes.portrait(pagesizes.A7)),
},
"82x203butterfly": {
"label": format_lazy(_("{width} x {height} mm butterfly badge"), width=82, height=203),
"label": format_lazy(
_("{width} x {height} mm butterfly badge"), width=82, height=203
),
"pagesize": (82 * mm, 203 * mm),
"layout": [
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "5.00",
"bottom": "152.55",
"bottom": "153.00",
"fontsize": "20.0",
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -110,19 +118,22 @@ TEMPLATES = {
"bold": True,
"italic": False,
"width": "72.00",
"downward": False,
"height": "20.00",
"content": "attendee_name",
"text": "John Doe",
"text": "Dr John Doe",
"text_i18n": {},
"rotation": 0,
"align": "center",
"verticalalign": "bottom",
"autoresize": True,
"splitlongwords": False,
},
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "5.00",
"bottom": "144.55",
"bottom": "132.10",
"fontsize": "18.0",
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -130,19 +141,22 @@ TEMPLATES = {
"bold": False,
"italic": False,
"width": "72.00",
"downward": False,
"height": "20.00",
"content": "attendee_company",
"text": "Sample company",
"text_i18n": {},
"rotation": 0,
"align": "center",
"verticalalign": "top",
"autoresize": True,
"splitlongwords": False,
},
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "77.10",
"bottom": "34.68",
"left": "76.97",
"bottom": "10.86",
"fontsize": "20.0",
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -150,19 +164,22 @@ TEMPLATES = {
"bold": True,
"italic": False,
"width": "72.00",
"downward": False,
"height": "20.00",
"content": "attendee_name",
"text": "John Doe",
"text": "Dr John Doe",
"text_i18n": {},
"rotation": 180,
"rotation": -180,
"align": "center",
"verticalalign": "bottom",
"autoresize": True,
"splitlongwords": False,
},
{
"type": "textarea",
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "77.06",
"bottom": "44.28",
"left": "77.07",
"bottom": "31.76",
"fontsize": "18.0",
"lineheight": "1",
"color": [0, 0, 0, 1],
@@ -170,12 +187,15 @@ TEMPLATES = {
"bold": False,
"italic": False,
"width": "72.00",
"downward": False,
"height": "20.00",
"content": "attendee_company",
"text": "Sample company",
"text_i18n": {},
"rotation": 180,
"rotation": -180,
"align": "center",
"verticalalign": "top",
"autoresize": True,
"splitlongwords": False,
},
],
},
@@ -235,7 +255,9 @@ TEMPLATES = {
"layout": _simple_template(40 * mm, 40 * mm),
},
"88.9x33.87": {
"label": format_lazy(_("{width} x {height} mm label"), width=88.9, height=33.87),
"label": format_lazy(
_("{width} x {height} mm label"), width=88.9, height=33.87
),
"pagesize": (88.9 * mm, 33.87 * mm),
"layout": _simple_template(88.9 * mm, 33.87 * mm),
},

View File

@@ -27,191 +27,279 @@ from django.utils.translation import gettext_lazy as _
from pretix.base.models import LoggedModel
DEFAULT_TICKET_LAYOUT = '''[{
"type":"textarea",
"left":"17.50",
"bottom":"274.60",
"fontsize":"16.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"175.00",
"content":"event_name",
"text":"Sample event name",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"262.90",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"110.00",
"content":"itemvar",
"text":"Sample product sample variation",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"252.50",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"110.00",
"content":"attendee_name",
"text":"John Doe",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"242.10",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"110.00",
"content":"event_begin",
"text":"2016-05-31 20:00",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"231.70",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"110.00",
"content":"seat",
"text":"Ground floor, Row 3, Seat 4",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"204.80",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"110.00",
"content":"event_location",
"text":"Random City",
"align":"left"
},
{
"type":"textarea",
"left":"17.50",
"bottom":"194.50",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"30.00",
"content":"order",
"text":"A1B2C",
"align":"left"
},
{
"type":"textarea",
"left":"52.50",
"bottom":"194.50",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"45.00",
"content":"price",
"text":"123.45 EUR",
"align":"right"
},
{
"type":"textarea",
"left":"102.50",
"bottom":"194.50",
"fontsize":"13.0",
"color":[
0,
0,
0,
1
],
"fontfamily":"Open Sans",
"bold":false,
"italic":false,
"width":"90.00",
"content":"secret",
"text":"tdmruoekvkpbv1o2mv8xccvqcikvr58u",
"align":"left"
},
{
"type":"barcodearea",
"left":"130.40",
"bottom":"204.50",
"size":"64.00",
"content":"secret"
},
{
"type":"poweredby",
"left":"88.72",
"bottom":"10.00",
"size":"20.00",
"content":"dark"
}]'''
DEFAULT_TICKET_LAYOUT = '''[
{
"type": "barcodearea",
"page": 1,
"left": "130.40",
"bottom": "204.50",
"size": "64.00",
"content": "secret",
"text": "",
"text_i18n": {},
"nowhitespace": false
},
{
"type": "poweredby",
"page": 1,
"left": "88.72",
"bottom": "10.00",
"size": "20.00",
"content": "dark"
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "272.09",
"fontsize": "14.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "177.07",
"height": "11.80",
"content": "event_name",
"text": "Sample event name",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "261.77",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "113.03",
"height": "7.83",
"content": "itemvar",
"text": "Sample product sample variation",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "251.30",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "113.03",
"height": "7.83",
"content": "attendee_name",
"text": "Dr John Doe",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "240.30",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "113.03",
"height": "7.83",
"content": "event_begin",
"text": "2017-05-31 20:00",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "231.30",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "113.03",
"height": "7.83",
"content": "seat",
"text": "Ground floor, Row 3, Seat 4",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.35",
"bottom": "203.43",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "113.03",
"height": "25.70",
"content": "event_location",
"text": "Random City",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "bottom",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "101.50",
"bottom": "193.33",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "91.93",
"height": "7.83",
"content": "secret",
"text": "tdmruoekvkpbv1o2mv8xccvqcikvr58u",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "51.50",
"bottom": "193.33",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "47.38",
"height": "7.83",
"content": "price",
"text": "123.45 EUR",
"text_i18n": {},
"rotation": 0,
"align": "right",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
},
{
"type": "textcontainer",
"page": 1,
"locale": "",
"left": "16.50",
"bottom": "193.33",
"fontsize": "13.0",
"lineheight": "1",
"color": [
0,
0,
0,
1
],
"fontfamily": "Open Sans",
"bold": false,
"italic": false,
"width": "32.32",
"height": "7.83",
"content": "order",
"text": "A1B2C",
"text_i18n": {},
"rotation": 0,
"align": "left",
"verticalalign": "middle",
"autoresize": true,
"splitlongwords": true
}
]'''
def bg_name(instance, filename: str) -> str: