Skip to content

Commit

Permalink
Fix alternative schemes not rendering correctly (#357)
Browse files Browse the repository at this point in the history
* Fix: #356 rendering of alternative schemes

* [tests] Fix alternative schemes
  • Loading branch information
schoero authored Dec 5, 2021
1 parent eabc226 commit a02ae18
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
28 changes: 17 additions & 11 deletions src/pdf/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,35 +383,41 @@ export class PDF_ extends ExtendedPDF {
//-- AV1 and AV2

if(this._data.av1 !== undefined){

const [scheme, data] = this._data.av1.split(/(\/.+)/);

this.fontSize(7);
this.font("Helvetica-Bold");
this.text("Name AV1:", utils.mm2pt(67), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(15),
this.text(scheme, utils.mm2pt(67), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(138),
continued: true,
lineGap: 1
});

this.fontSize(7);
this.font("Helvetica");
this.text((this._data.av1.length > 87 ? this._data.av1.substr(0, 87) + "..." : this._data.av1), utils.mm2pt(81), this._marginTop + utils.mm2pt(90), {
width: utils.mm2pt(37),
lineGap: -.5
this.text(this._data.av1.length > 90 ? data.substr(0, 87) + "..." : data, {
continued: false
});

}

if(this._data.av2 !== undefined){

const [scheme, data] = this._data.av2.split(/(\/.+)/);

this.fontSize(7);
this.font("Helvetica-Bold");
this.text("Name AV2:", utils.mm2pt(67), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(15),
this.text(scheme, utils.mm2pt(67), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(138),
continued: true,
lineGap: 1
});

this.fontSize(7);
this.font("Helvetica");
this.text((this._data.av2.length > 87 ? this._data.av2.substr(0, 87) + "..." : this._data.av2), utils.mm2pt(81), this._marginTop + utils.mm2pt(93), {
width: utils.mm2pt(37),
this.text(this._data.av2.length > 90 ? data.substr(0, 87) + "..." : data, {
lineGap: -.5
});

}


Expand Down
6 changes: 4 additions & 2 deletions src/shared/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,18 @@ export function validateData(data: Data) {
//-- AV1

if(data.av1 !== undefined){
if(data.av1.length > 100){ throw new Error("AV1 must be a maximum of 100 characters."); }
if(typeof data.av1 !== "string"){ throw new Error("AV1 must be a string."); }
if(data.av1.length > 100){ throw new Error("AV1 must be a maximum of 100 characters."); }
if(data.av1.split(/(\/.+)/).length <= 2){ throw new Error("AV1 must contain a separator (e.g. /)"); }
}


//-- AV2

if(data.av2 !== undefined){
if(data.av2.length > 100){ throw new Error("AV2 must be a maximum of 100 characters."); }
if(typeof data.av2 !== "string"){ throw new Error("AV2 must be a string."); }
if(data.av2.length > 100){ throw new Error("AV2 must be a maximum of 100 characters."); }
if(data.av2.split(/(\/.+)/).length <= 2){ throw new Error("AV2 must contain a separator (e.g. /)"); }
}

}
16 changes: 8 additions & 8 deletions src/svg/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,32 +307,32 @@ export class SVG_ {

if(this._data.av1 !== undefined){

alternativeSchemeContainer.addTSpan("Name AV1:")
const [scheme, data] = this._data.av1.split(/(\/.+)/);

alternativeSchemeContainer.addTSpan(scheme)
.x(0)
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("7pt");

alternativeSchemeContainer.addTSpan(this._data.av1.length > 87 ? this._data.av1.substr(0, 87) + "..." : this._data.av1)
.x(0)
.dx("15mm")
alternativeSchemeContainer.addTSpan(this._data.av1.length > 90 ? data.substr(0, 87) + "..." : data)
.fontFamily("Arial")
.fontWeight("normal")
.fontSize("7pt");

}
if(this._data.av2 !== undefined){

alternativeSchemeContainer.addTSpan("Name AV2:")
const [scheme, data] = this._data.av2.split(/(\/.+)/);

alternativeSchemeContainer.addTSpan(scheme)
.x(0)
.dy("8pt")
.fontFamily("Arial")
.fontWeight("bold")
.fontSize("7pt");

alternativeSchemeContainer.addTSpan(this._data.av2.length > 87 ? this._data.av2.substr(0, 87) + "..." : this._data.av2)
.x(0)
.dx("15mm")
alternativeSchemeContainer.addTSpan(this._data.av2.length > 90 ? data.substr(0, 87) + "..." : data)
.fontFamily("Arial")
.fontWeight("normal")
.fontSize("7pt");
Expand Down
4 changes: 2 additions & 2 deletions tests/av1av2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
av1: "eBillUV;UltraPay005;12345",
av2: "eBillXY;XYService;54321",
av1: "eBill/UV;UltraPay005;12345",
av2: "eBill/XY;XYService;54321",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
Expand Down
4 changes: 2 additions & 2 deletions tests/no-debtor-no-amount-no-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const { writeFileSync } = require("fs");

const data = {
currency: "CHF",
av1: "eBillUV;UltraPay005;12345",
av2: "eBillXY;XYService;54321",
av1: "eBill/UV;UltraPay005;12345",
av2: "eBill/XY;XYService;54321",
creditor: {
name: "Robert Schneider ultra long name of the company to use multiple lines",
address: "Rue du Lac 1268 Ultra long address nam eto use multiple lines",
Expand Down

0 comments on commit a02ae18

Please sign in to comment.