From 8e995ef5dd2560c75fcba5d565c27ad8d463ee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= Date: Fri, 22 Jan 2021 21:46:10 +0100 Subject: [PATCH] Added option to disable outlines --- doc/api.md | 11 +++- src/swissqrbill.ts | 62 +++++++++++++++----- tests/no-scissors-no-outlines.js | 24 ++++++++ tests/no-scissors-no-separate-no-outlines.js | 24 ++++++++ tests/no-scissors-no-separate.js | 24 ++++++++ tests/no-scissors.js | 24 ++++++++ tests/no-separate-no-outlines.js | 24 ++++++++ tests/run-windows.bat | 12 ++++ tests/run.sh | 12 ++++ tests/separate-scissors.js | 24 ++++++++ tests/separate.js | 2 +- 11 files changed, 225 insertions(+), 18 deletions(-) create mode 100644 tests/no-scissors-no-outlines.js create mode 100644 tests/no-scissors-no-separate-no-outlines.js create mode 100644 tests/no-scissors-no-separate.js create mode 100644 tests/no-scissors.js create mode 100644 tests/no-separate-no-outlines.js create mode 100644 tests/separate-scissors.js diff --git a/doc/api.md b/doc/api.md index a8ed696..644962a 100644 --- a/doc/api.md +++ b/doc/api.md @@ -106,9 +106,16 @@ - **language** - `string: "DE" | "EN" | "IT" | "FR"`. *default* `"DE"`. - **size** - `string: "A4" | "A6/5"`. *default* `"A6/5"`. - **scissors** - `boolean`: *default* `true`. - > Whether you want to show the scissors icons or the text `Separate before paying in`. + Whether you want to show the scissors icons or the text `Separate before paying in`. + > **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false. + - **separate** - `boolean`: *default* `false`. + Whether you want to show the text `Separate before paying in` rather than the scissors icons. + + > **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false. + - **outlines** - `boolean`: *default* `true`. + Whether you want render the outlines. This option may be disabled if you use perforated paper. - **autoGenerate** - `boolean`: *default* `true`. - > Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit. + Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
diff --git a/src/swissqrbill.ts b/src/swissqrbill.ts index b08c64f..7e0778d 100644 --- a/src/swissqrbill.ts +++ b/src/swissqrbill.ts @@ -33,7 +33,9 @@ export interface options { language?: languages, size?: size, scissors?: boolean, - autoGenerate?: boolean + separate?: boolean, + outlines?: boolean + autoGenerate?: boolean, } export import PDFTable = ExtendedPDF.PDFTable; @@ -51,6 +53,8 @@ export class PDF extends ExtendedPDF.PDF { public size: size = "A6/5"; private _data: data; private _scissors: boolean = true; + private _separate: boolean = false; + private _outlines: boolean = true; private _language: languages = "DE"; private _marginTop: number = 0; private _autoGenerate: boolean = true; @@ -167,6 +171,18 @@ export class PDF extends ExtendedPDF.PDF { } if(options.scissors !== undefined){ this._scissors = options.scissors; + this._separate = !options.scissors; + } + if(options.separate !== undefined){ + this._separate = options.separate; + this._scissors = !options.separate; + } + if(options.scissors === false && options.separate === false){ + this._separate = false; + this._scissors = false; + } + if(options.outlines !== undefined){ + this._outlines = options.outlines; } if(options.autoGenerate !== undefined){ this._autoGenerate = options.autoGenerate; @@ -228,12 +244,30 @@ export class PDF extends ExtendedPDF.PDF { private _drawOutlines(): void { - //-- Horizontal line + //-- Lines + + if(this._outlines === true){ + + + //-- Horizontal line + + if(this.page.height > utils.mmToPoints(105)){ + + this.moveTo(0, this._marginTop) + .lineTo(utils.mmToPoints(210), this._marginTop) + .lineWidth(.75) + .strokeOpacity(1) + .dash(1, { size: 1 }) + .strokeColor("black") + .stroke(); + + } + - if(this.page.height > utils.mmToPoints(105)){ + //-- Vertical line - this.moveTo(0, this._marginTop) - .lineTo(utils.mmToPoints(210), this._marginTop) + this.moveTo(utils.mmToPoints(62), this._marginTop) + .lineTo(utils.mmToPoints(62), this._marginTop + utils.mmToPoints(105)) .lineWidth(.75) .strokeOpacity(1) .dash(1, { size: 1 }) @@ -243,15 +277,7 @@ export class PDF extends ExtendedPDF.PDF { } - //-- Vertical line - - this.moveTo(utils.mmToPoints(62), this._marginTop) - .lineTo(utils.mmToPoints(62), this._marginTop + utils.mmToPoints(105)) - .lineWidth(.75) - .strokeOpacity(1) - .dash(1, { size: 1 }) - .strokeColor("black") - .stroke(); + //-- Scissors if(this._scissors === true){ @@ -271,7 +297,12 @@ export class PDF extends ExtendedPDF.PDF { .fill(); this.translate(0, 0); - } else { + } + + + //-- Separation text + + if(this._separate === true){ if(this.page.height > utils.mmToPoints(105)){ @@ -283,6 +314,7 @@ export class PDF extends ExtendedPDF.PDF { }); } + } } diff --git a/tests/no-scissors-no-outlines.js b/tests/no-scissors-no-outlines.js new file mode 100644 index 0000000..d5026be --- /dev/null +++ b/tests/no-scissors-no-outlines.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-outline.pdf", { "scissors" : false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors-no-separate-no-outlines.js b/tests/no-scissors-no-separate-no-outlines.js new file mode 100644 index 0000000..0f310ab --- /dev/null +++ b/tests/no-scissors-no-separate-no-outlines.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate-no-outline.pdf", { "scissors" : false, "separate": false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors-no-separate.js b/tests/no-scissors-no-separate.js new file mode 100644 index 0000000..9ab998f --- /dev/null +++ b/tests/no-scissors-no-separate.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate.pdf", { "scissors" : false, "separate": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-scissors.js b/tests/no-scissors.js new file mode 100644 index 0000000..4707bed --- /dev/null +++ b/tests/no-scissors.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/no-scissors.pdf", { "scissors" : false, "size": "A4" }); \ No newline at end of file diff --git a/tests/no-separate-no-outlines.js b/tests/no-separate-no-outlines.js new file mode 100644 index 0000000..61e56b5 --- /dev/null +++ b/tests/no-separate-no-outlines.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/no-separate-no-outline.pdf", { "separate" : false, "outlines": false, "size": "A4" }); \ No newline at end of file diff --git a/tests/run-windows.bat b/tests/run-windows.bat index 21825cf..431ce59 100644 --- a/tests/run-windows.bat +++ b/tests/run-windows.bat @@ -33,10 +33,22 @@ echo "normal-iban-creditor-reference" call node normal-iban-creditor-reference echo "normal-iban-no-reference" call node normal-iban-no-reference +echo "no-scissors" + call node no-scissors +echo "no-scissors-no-outlines" + call node no-scissors-no-outlines +echo "no-scissors-no-separate" + call node no-scissors-no-separate +echo "no-separate-no-outlines" + call node no-separate-no-outlines +echo "no-scissors-no-separate-no-outlines" + call node no-scissors-no-separate-no-outlines echo "qr-iban" call node qr-iban echo "separate" call node separate +echo "separate-scissors" + call node separate-scissors echo "callback" call node callback echo "callback-with-options" diff --git a/tests/run.sh b/tests/run.sh index 7700dfd..f827bf8 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -33,6 +33,16 @@ echo "no-debtor-no-amount-no-reference" node no-debtor-no-amount-no-reference echo "no-debtor-no-reference" node no-debtor-no-reference +echo "no-scissors" + node no-scissors +echo "no-scissors-no-outlines" + node no-scissors-no-outlines +echo "no-scissors-no-separate" + node no-scissors-no-separate +echo "no-separate-no-outlines" + node no-separate-no-outlines +echo "no-scissors-no-separate-no-outlines" + node no-scissors-no-separate-no-outlines echo "normal-iban-creditor-reference" node normal-iban-creditor-reference echo "normal-iban-no-reference" @@ -41,6 +51,8 @@ echo "qr-iban" node qr-iban echo "separate" node separate +echo "separate-scissors" + node separate-scissors echo "callback" node callback echo "callback-with-options" diff --git a/tests/separate-scissors.js b/tests/separate-scissors.js new file mode 100644 index 0000000..3eb7937 --- /dev/null +++ b/tests/separate-scissors.js @@ -0,0 +1,24 @@ +const SwissQRBill = require("../"); + +const data = { + currency: "CHF", + amount: 1199.95, + reference: "210000000003139471430009017", + creditor: { + name: "Robert Schneider AG", + address: "Rue du Lac 1268", + zip: 2501, + city: "Biel", + account: "CH4431999123000889012", + country: "CH" + }, + debtor: { + name: "Pia-Maria Rutschmann-Schnyder", + address: "Grosse Marktgasse 28", + zip: 9400, + city: "Rorschach", + country: "CH" + } +}; + +const pdf = new SwissQRBill.PDF(data, "./output/separate-scissors.pdf", { "separate" : true, "scissors": true, "size": "A4" }); \ No newline at end of file diff --git a/tests/separate.js b/tests/separate.js index 1f2d39a..97455fa 100644 --- a/tests/separate.js +++ b/tests/separate.js @@ -21,4 +21,4 @@ const data = { } }; -const pdf = new SwissQRBill.PDF(data, "./output/separate.pdf", { "scissors" : false, size: "A4" }); \ No newline at end of file +const pdf = new SwissQRBill.PDF(data, "./output/separate.pdf", { "separate" : true, "size": "A4" }); \ No newline at end of file