Skip to content

Commit

Permalink
feat: add more options to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Oct 28, 2023
1 parent d3f49c3 commit 1362941
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 152 deletions.
43 changes: 18 additions & 25 deletions src/pdf/swissqrbill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { translations } from "swissqrbill:shared:translations";
import { validateData } from "swissqrbill:shared:validator";
import { formatAmount, formatIBAN, formatReference, getReferenceType, mm2pt, pt2mm } from "swissqrbill:utils";

import type { Creditor, Data, Debtor, Languages, QRBillOptions } from "swissqrbill:types";
import type { Creditor, Data, Debtor, Language, PDFOptions } from "swissqrbill:types";


/**
Expand All @@ -17,7 +17,7 @@ export class SwissQRBill {
private scissors: boolean = true;
private separate: boolean = false;
private outlines: boolean = true;
private language: Languages = "DE";
private language: Language = "DE";
private font: string = "Helvetica";

private _x: number = 0;
Expand All @@ -28,7 +28,7 @@ export class SwissQRBill {
* @param data The data to be used for the QR Bill.
* @param options Options to define how the QR Bill should be rendered.
*/
constructor(data: Data, options?: QRBillOptions) {
constructor(data: Data, options?: PDFOptions) {

this.data = data;

Expand All @@ -39,28 +39,21 @@ export class SwissQRBill {
void validateData(this.data);

// Apply options
if(options !== undefined){
if(options.language !== undefined){
this.language = options.language;
}
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.font !== undefined){
this.font = options.font;
}
this.language = options?.language !== undefined ? options.language : this.language;
this.outlines = options?.outlines !== undefined ? options.outlines : this.outlines;
this.font = options?.font !== undefined ? options.font : this.font;

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;
}

}
Expand Down
26 changes: 8 additions & 18 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SwissQRBill types
export type Currency = "CHF" | "EUR";
export type Size = "A4" | "A6" | "A6/5";
export type Languages = "DE" | "EN" | "FR" | "IT";
export type Language = "DE" | "EN" | "FR" | "IT";
export type FontName = "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans";

export interface Data {

Expand Down Expand Up @@ -110,13 +111,13 @@ export interface QRBillOptions {
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}
* @defaultValue 'Helvetica'
*/
font?: "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans";
font?: FontName;

/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
language?: Language;

/**
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
Expand All @@ -131,6 +132,9 @@ export interface QRBillOptions {
* @defaultValue `true`
*/
scissors?: boolean;
}

export interface PDFOptions extends QRBillOptions {

/**
* Whether you want to show the text `Separate before paying in` rather than the scissors icons.
Expand All @@ -141,20 +145,6 @@ export interface QRBillOptions {
separate?: boolean;
}

export interface PDFOptions extends QRBillOptions {

/**
* 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.
* @defaultValue `true`
*/
autoGenerate?: boolean;
}

export interface SVGOptions {
export interface SVGOptions extends QRBillOptions {

/**
* The language with which the bill is rendered.
* @defaultValue `DE`
*/
language?: Languages;
}
Loading

0 comments on commit 1362941

Please sign in to comment.